:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e9eef5;
  --text: #172033;
  --muted: #667085;
  --line: #d9e1ea;
  --blue: #2563eb;
  --green: #0f9f6e;
  --red: #c24136;
  --amber: #b7791f;
  --ink: #243447;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

body.locked {
  overflow: hidden;
}

body.locked .sidebar,
body.locked .app {
  display: none;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-screen.hidden {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  padding: 24px;
  display: grid;
  gap: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(15, 23, 42, 0.12);
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
}

.login-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.login-error {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
}

button,
input,
select,
textarea {
  font: inherit;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  background: #1f2a37;
  color: #fff;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: #eef6ff;
  color: #1f5fd0;
  border-radius: 8px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
}

.brand p,
.section-head p,
.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.sidebar .brand p,
.sidebar .schedule {
  color: #b7c2d0;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a,
.schedule-title,
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.nav a {
  color: #d6deea;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
}

.nav a.active,
.nav a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.nav svg,
.icon-btn svg,
.schedule-title svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.schedule {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.schedule-title {
  color: #fff;
  font-weight: 650;
}

.app {
  margin-left: 248px;
  padding: 28px;
  display: grid;
  gap: 22px;
}

.topbar,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.topbar h2,
.section-head h3 {
  margin: 0;
}

.page {
  display: none;
  gap: 18px;
}

.page.active {
  display: grid;
}

.actions,
.form-actions,
.compact-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
  outline: none;
}

input,
select {
  height: 40px;
}

textarea {
  min-height: 120px;
  padding: 12px;
  resize: vertical;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.icon-btn {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 650;
  white-space: nowrap;
}

.icon-btn.primary {
  color: #fff;
  background: var(--blue);
}

.icon-btn.success {
  color: #fff;
  background: var(--green);
}

.icon-btn.secondary {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.icon-btn.ghost {
  color: var(--muted);
  background: transparent;
}

.icon-btn.danger {
  color: #fff;
  background: var(--red);
}

.icon-btn.icon-only {
  width: 40px;
  justify-content: center;
  padding: 0;
}

.icon-btn:disabled {
  cursor: wait;
  opacity: 0.65;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
}

.metric,
.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric {
  padding: 18px;
  display: grid;
  gap: 8px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 26px;
  letter-spacing: 0;
}

.section {
  padding: 18px;
  display: grid;
  gap: 16px;
}

.shop-form {
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
}

.form-grid,
.debug-grid,
.filter-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

.wide {
  grid-column: 1 / -1;
}

.credential-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.credential-builder {
  display: grid;
  gap: 10px;
}

.credential-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(130px, 1fr) minmax(180px, 2fr) 86px 76px 40px;
  gap: 8px;
  align-items: end;
}

.check-label,
.mini-check {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.check-label input,
.mini-check input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.hidden {
  display: none !important;
}

.shop-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.shop-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
  background: #fff;
}

.shop-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.shop-title strong {
  display: block;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e8f2ff;
  color: #185abc;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.danger-pill {
  background: #fdecec;
  color: #a43128;
}

.success-pill {
  background: #e7f7ef;
  color: #08734e;
}

.shop-meta {
  color: var(--muted);
  font-size: 13px;
  display: grid;
  gap: 4px;
}

.shop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.debug-meta {
  color: var(--muted);
  font-size: 13px;
  min-height: 20px;
}

.debug-result {
  max-height: 520px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101828;
  color: #d7e2f2;
  line-height: 1.55;
  font-size: 12px;
}

.table-shell {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #465469;
  background: #f8fafc;
  font-weight: 700;
}

td.amount,
td.qty,
th.amount,
th.qty {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-footer {
  display: flex;
  justify-content: center;
}

.bars {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.bar-track {
  height: 10px;
  background: #e8edf4;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #0f9f6e);
}

.job-status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  color: #185abc;
  background: #e8f2ff;
  font-size: 13px;
  font-weight: 650;
}

.job-recent {
  display: grid;
  gap: 8px;
}

.task-progress {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.task-progress-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.task-progress-head > div {
  display: grid;
  gap: 4px;
}

.task-progress-head span,
.task-step {
  color: var(--muted);
  font-size: 13px;
}

.task-progress-head strong:last-child {
  font-size: 22px;
  letter-spacing: 0;
  color: var(--blue);
}

.task-progress-track {
  height: 12px;
  background: #e8edf4;
  border-radius: 999px;
  overflow: hidden;
}

.task-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2563eb, #0f9f6e);
  transition: width 0.2s ease;
}

.task-progress[data-status="completed"] .task-progress-head strong:last-child,
.task-progress[data-status="completed"] .task-step {
  color: var(--green);
}

.task-progress[data-status="completed_with_errors"] .task-progress-head strong:last-child,
.task-progress[data-status="failed"] .task-progress-head strong:last-child,
.task-progress[data-status="failed"] .task-step {
  color: var(--red);
}

.task-progress[data-status="completed"] .task-progress-fill {
  background: var(--green);
}

.task-progress[data-status="completed_with_errors"] .task-progress-fill,
.task-progress[data-status="failed"] .task-progress-fill {
  background: var(--red);
}

.job-row {
  display: grid;
  grid-template-columns: 62px 82px minmax(150px, 1fr) minmax(170px, 1fr) 78px 92px;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  background: #fff;
}

.job-row strong {
  color: var(--text);
}

.filter-panel {
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.custom-template {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.custom-template strong {
  display: block;
  margin-bottom: 10px;
}

.check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #172033;
  color: #fff;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.22);
  transform: translateY(120px);
  opacity: 0;
  transition: 0.2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.credential-dialog {
  width: min(900px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.credential-dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.credential-dialog form,
.credential-dialog > .dialog-head,
.task-detail-body {
  padding: 18px;
}

.credential-dialog form {
  display: grid;
  gap: 16px;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h3 {
  margin: 0;
}

.dialog-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.dialog-body {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.task-detail-body {
  display: grid;
  gap: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
}

.detail-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
}

@media (max-width: 1120px) {
  .metrics {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .credential-row,
  .job-row {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 980px) {
  .sidebar {
    position: static;
    width: auto;
    min-height: auto;
  }

  .app {
    margin-left: 0;
    padding: 20px;
  }

  .topbar,
  .section-head,
  .task-progress-head {
    display: grid;
  }

  .form-grid,
  .debug-grid,
  .filter-panel,
  .custom-template,
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 14px;
  }

  .metrics,
  .shop-list {
    grid-template-columns: 1fr;
  }

  .credential-row {
    grid-template-columns: 1fr;
  }

  .icon-btn {
    width: 100%;
    justify-content: center;
  }

  .icon-btn.icon-only {
    width: 40px;
  }
}
