:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --green: #047857;
  --green-soft: #d1fae5;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --slate-soft: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.05);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

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

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 280px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.28);
}

.brand-mark span {
  font-size: 10px;
  opacity: 0.75;
  align-self: flex-end;
  margin-bottom: 14px;
}

.brand-text h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-text p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.meta-stack {
  text-align: right;
  margin-right: 6px;
  line-height: 1.35;
}

.quota {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

.quota.warn {
  color: var(--amber);
}

.quota.bad {
  color: var(--red);
}

.sync-line {
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

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

.btn-ghost:hover {
  background: #eef2f7;
  color: var(--ink);
}

.btn-icon {
  font-size: 14px;
  line-height: 1;
}

/* ---------------------------------------------------------------- layout */
.page {
  max-width: 1560px;
  margin: 0 auto;
  padding: 22px 28px 48px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------------------------------------------------------------- cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.card {
  position: relative;
  text-align: left;
  padding: 15px 16px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;

  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card:hover {
  border-color: #a5b4fc;
  transform: translateY(-1px);
}

.card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.card-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.card-hint {
  font-size: 11.5px;
  color: var(--muted);
}

.card.accent-green .card-value {
  color: var(--green);
}

.card.accent-amber .card-value {
  color: var(--amber);
}

.card.accent-red .card-value {
  color: var(--red);
}

.card.accent-indigo .card-value {
  color: var(--primary);
}

/* ---------------------------------------------------------------- panel */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.panel-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.panel-head-right .btn {
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-green {
  background: #10b981;
}

.dot-amber {
  background: #f59e0b;
}

.dot-red {
  background: #ef4444;
}

.dot + .dot {
  margin-left: 10px;
}

/* ---------------------------------------------------------------- filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--line);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 128px;
}

.field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field input,
.field select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #fff;
  font-size: 13px;
  min-width: 128px;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.field-search {
  flex: 1 1 260px;
  min-width: 220px;
}

.field-search input {
  width: 100%;
}

.filters-spacer {
  flex: 1 1 0;
}

.filters .btn {
  height: 34px;
  padding: 0 12px;
}

/* ---------------------------------------------------------------- progress */
.progress {
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.progress-text {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.progress-text strong {
  color: var(--ink);
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  transition: width 0.25s ease;
}

.progress-bar.indeterminate {
  width: 40% !important;
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(260%);
  }
}

/* ---------------------------------------------------------------- table */
.table-wrap {
  overflow-x: auto;
}

table.orders {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  white-space: nowrap;
}

table.orders thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

table.orders tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}

table.orders tbody tr.row {
  cursor: pointer;
}

table.orders tbody tr.row:hover {
  background: #f8fafc;
}

table.orders tbody tr.expanded {
  background: #f5f7ff;
}

.col-order {
  min-width: 150px;
}

.col-date {
  min-width: 108px;
}

.col-tracking {
  min-width: 205px;
}

.col-event {
  white-space: normal;
  min-width: 260px;
  max-width: 380px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  letter-spacing: -0.01em;
}

.order-number {
  font-weight: 600;
  color: var(--ink);
}

.sub-line {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}

.tracking-line {
  display: flex;
  align-items: center;
  gap: 6px;
}

.copy-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 10.5px;
  color: var(--muted);
  cursor: pointer;
}

.copy-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.muted {
  color: var(--muted);
}

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-slate {
  background: var(--slate-soft);
  color: #475569;
}

.badge-green {
  background: var(--green-soft);
  color: var(--green);
}

.badge-amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge-red {
  background: var(--red-soft);
  color: var(--red);
}

.badge-indigo {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.badge-outline {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--muted);
}

/* ---------------------------------------------------------------- events */
tr.detail-row > td {
  padding: 0;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

.detail-box {
  padding: 14px 20px 16px;
  white-space: normal;
}

.detail-head {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.detail-head strong {
  color: var(--ink);
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 0 16px;
  border-left: 2px solid #e2e8f0;
}

.timeline li {
  position: relative;
  padding: 0 0 10px 14px;
}

.timeline li::before {
  content: '';
  position: absolute;
  left: -21px;
  top: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #a5b4fc;
  border: 2px solid #fff;
}

.timeline li:first-child::before {
  background: var(--primary);
}

.timeline-time {
  font-size: 11px;
  color: var(--muted);
  display: block;
}

.timeline-desc {
  font-size: 12.5px;
}

.timeline-loc {
  font-size: 11px;
  color: var(--muted);
}

/* ---------------------------------------------------------------- pager */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
}

.page-info {
  font-size: 12px;
  color: var(--muted);
}

.pager-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-size {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.page-size select {
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 6px;
  background: #fff;
}

.pager .btn {
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
}

.empty-row td {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.loading-row td {
  padding: 30px 20px;
  text-align: center;
  color: var(--muted);
}

/* ---------------------------------------------------------------- notes */
.notes {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 20px 18px;
}

.notes h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
}

.notes ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.notes strong {
  color: var(--ink);
}

.notes code {
  background: #f1f5f9;
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 11.5px;
}

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 10px;
  background: #0f172a;
  color: #fff;
  font-size: 12.5px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}

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

.toast.error {
  background: #991b1b;
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .topbar {
    padding: 14px 16px;
  }

  .page {
    padding: 16px 16px 36px;
  }

  .topbar-actions {
    width: 100%;
  }

  .meta-stack {
    text-align: left;
  }

  .panel-head,
  .filters,
  .pager {
    padding-left: 14px;
    padding-right: 14px;
  }
}

/* ---------------------------------------------------------------- share */
.share-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar-meta {
  font-size: 11.5px;
  color: var(--muted);
}

.stale-warning {
  color: var(--red);
  font-weight: 600;
}

.link-btn {
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
  border-bottom: 1px dashed var(--line-strong);
}

.link-btn:hover {
  color: var(--primary);
}

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 10%, #eef2ff, #f8fafc 55%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  padding: 28px 26px 24px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

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

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

.login-card label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 6px;
}

.login-card input[type='password'] {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 14px;
  margin-bottom: 14px;
}

.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.login-card .btn {
  width: 100%;
  justify-content: center;
  height: 42px;
}

.login-foot {
  margin-top: 16px;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}

/* ---------------------------------------------------------------- sortable */
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable:hover {
  color: var(--primary);
}

th.sortable .sort-ind {
  display: inline-block;
  margin-left: 4px;
  font-size: 12px;
  color: var(--primary);
}

/* ---------------------------------------------------------------- plates */
table.plates .col-fp {
  min-width: 110px;
}

table.orders.nested {
  font-size: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

table.orders.nested thead th {
  position: static;
  background: #f8fafc;
}

.plate-row.expanded {
  background: #f5f7ff;
}

.plate-row {
  cursor: pointer;
}

.plate-row:hover {
  background: #f8fafc;
}

.detail-actions {
  display: inline-flex;
  gap: 6px;
  margin-left: auto;
}

.track-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
