/* =====================================================================
   RETRO COMMERCE — modern retro theme
   warm paper + ink outlines + hard offset shadows + 70s sunset accents
   ===================================================================== */
:root {
  --paper: #f5eedf;
  --paper-2: #fffaf0;
  --paper-3: #efe4cd;
  --ink: #2a2118;
  --ink-soft: #54463a;
  --muted: #8a7a67;
  --line: #2a2118;
  --hair: #d9ccb2;
  --mustard: #f2b134;
  --orange: #e8672c;
  --cherry: #d1433b;
  --teal: #1f8a83;
  --olive: #6f9a3a;
  --blue: #3f6ea6;
  --plum: #7d4e8b;
  --ok-bg: #d9efd0;   --ok-fg: #2f6b22;
  --bad-bg: #f8d6d2;  --bad-fg: #9d2a22;
  --warn-bg: #fbe7b8; --warn-fg: #8a5a00;
  --info-bg: #d4e7f3; --info-fg: #24557f;
  --neutral-bg: #ebe2d0; --neutral-fg: #5b4d3f;
  --sidebar: #2a2118;
  --sidebar-ink: #f5eedf;
  --shadow: 4px 4px 0 var(--line);
  --shadow-sm: 2px 2px 0 var(--line);
  --radius: 14px;
  --font-display: "Righteous", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #17120d;
  --paper-2: #221b14;
  --paper-3: #2c231a;
  --ink: #f3e8d4;
  --ink-soft: #d6c7ad;
  --muted: #a5947c;
  --line: #0a0806;
  --hair: #3d3226;
  --ok-bg: #20391a;   --ok-fg: #a6e08e;
  --bad-bg: #45201c;  --bad-fg: #ffab9f;
  --warn-bg: #45350f; --warn-fg: #ffd276;
  --info-bg: #17324a; --info-fg: #9fcdf2;
  --neutral-bg: #2f271e; --neutral-fg: #d6c7ad;
  --sidebar: #0f0b08;
  --sidebar-ink: #f3e8d4;
  --shadow: 4px 4px 0 #000;
  --shadow-sm: 2px 2px 0 #000;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font-body); font-size: 14.5px; line-height: 1.45; color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(rgba(42,33,24,.06) 1px, transparent 1px);
  background-size: 18px 18px;
}
:root[data-theme="dark"] body { background-image: radial-gradient(rgba(243,232,212,.04) 1px, transparent 1px); }
a { color: var(--blue); text-decoration: none; }
:root[data-theme="dark"] a { color: #8fbbe8; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 400; letter-spacing: .3px; margin: 0; }
code, .mono { font-family: var(--font-mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tick { color: var(--olive); font-weight: 700; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------ shell ------------------------------------------------ */
.shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-ink); position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; border-right: 3px solid var(--line); z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px 16px; color: var(--sidebar-ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 50%; flex: none; border: 2px solid var(--sidebar-ink);
  background: linear-gradient(180deg, var(--mustard) 0 25%, var(--orange) 25% 50%, var(--cherry) 50% 75%, var(--plum) 75% 100%);
  box-shadow: 3px 3px 0 #000;
}
.brand-name { font-family: var(--font-display); font-size: 21px; line-height: 1; }
.brand-sub { font-size: 10.5px; letter-spacing: 2.4px; text-transform: uppercase; opacity: .7; margin-top: 3px; }
.stripes { height: 8px; margin: 0 18px 10px; border-radius: 4px; background: linear-gradient(90deg, var(--mustard) 0 25%, var(--orange) 25% 50%, var(--cherry) 50% 75%, var(--teal) 75%); }
.nav { padding: 6px 12px 20px; flex: 1; }
.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: 2px; opacity: .55; margin: 16px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; color: var(--sidebar-ink); padding: 8px 12px; border-radius: 10px;
  border: 2px solid transparent; font-weight: 500; margin-bottom: 2px;
}
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav a.active { background: var(--mustard); color: #2a2118; border-color: #000; box-shadow: 3px 3px 0 #000; }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { padding: 14px 18px; font-size: 11.5px; opacity: .6; border-top: 1px dashed rgba(255,255,255,.2); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px; padding: 12px 28px;
  background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 2px solid var(--hair);
}
.topbar h1 { font-size: 24px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }
.quick-search { position: relative; }
.quick-search input { width: 220px; padding-left: 34px; }
.quick-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; color: var(--muted); }
.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-display);
  background: var(--teal); color: #fff; border: 2px solid var(--line); box-shadow: var(--shadow-sm);
}
.user-meta { line-height: 1.15; }
.user-meta small { color: var(--muted); display: block; font-size: 11px; }
.content { padding: 24px 28px 48px; max-width: 1600px; width: 100%; }

/* ------------------------------------------------ cards ------------------------------------------------ */
.card { background: var(--paper-2); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card, .card + .grid, .grid + .card, .grid + .grid { margin-top: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 2px dashed var(--hair); flex-wrap: wrap; }
.card-head h3 { font-size: 18px; }
.card-head .sub { font-size: 12.5px; color: var(--muted); font-family: var(--font-body); }
.card-body { padding: 16px 18px; }
.card-body.tight { padding: 0; }
.grid { display: grid; gap: 20px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 20px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
.kpi {
  position: relative; overflow: hidden; background: var(--paper-2); border: 2px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-sm); padding: 14px 14px 12px; transition: transform .12s ease, box-shadow .12s ease; color: var(--ink);
}
a.kpi:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow); text-decoration: none; }
.kpi::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; background: var(--tone, var(--mustard)); }
.kpi-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin-top: 4px; }
.kpi-value { font-family: var(--font-display); font-size: 28px; line-height: 1.1; margin-top: 6px; }
.kpi-value.sm { font-size: 22px; }
.kpi-foot { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.t-mustard { --tone: var(--mustard); } .t-orange { --tone: var(--orange); } .t-cherry { --tone: var(--cherry); }
.t-teal { --tone: var(--teal); } .t-olive { --tone: var(--olive); } .t-blue { --tone: var(--blue); } .t-plum { --tone: var(--plum); }
.t-ink { --tone: var(--ink-soft); }

.hero-money { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; }
.hero-money > div { padding: 18px 20px; border-right: 2px dashed var(--hair); }
.hero-money > div:last-child { border-right: 0; }
.hero-money .kpi-value { font-size: 26px; }

.section-title { display: flex; align-items: center; gap: 10px; margin: 26px 0 12px; font-family: var(--font-display); font-size: 17px; }
.section-title::after { content: ""; flex: 1; height: 2px; background: repeating-linear-gradient(90deg, var(--hair) 0 8px, transparent 8px 14px); }

/* ------------------------------------------------ badges ------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  border: 1.5px solid currentColor; white-space: nowrap; line-height: 1.6;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--paper-3); border: 1px solid var(--hair); font-size: 12px; }

/* ------------------------------------------------ buttons & forms ------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 15px; border-radius: 10px; cursor: pointer;
  font: 600 13.5px var(--font-body); color: #2a2118; background: var(--mustard); border: 2px solid var(--line); box-shadow: var(--shadow-sm);
  transition: transform .08s ease, box-shadow .08s ease; white-space: nowrap; text-decoration: none;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--line); text-decoration: none; }
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn svg { width: 16px; height: 16px; }
.btn-orange { background: var(--orange); color: #fff; }
.btn-teal { background: var(--teal); color: #fff; }
.btn-cherry { background: var(--cherry); color: #fff; }
.btn-ghost { background: var(--paper-2); color: var(--ink); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn[disabled] { opacity: .5; pointer-events: none; }
form.inline { display: inline; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .6px; }
input, select, textarea {
  width: 100%; font: 14px var(--font-body); color: var(--ink); background: var(--paper-2); border: 2px solid var(--line); border-radius: 9px;
  padding: 8px 11px; outline: none; transition: box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--mustard) 60%, transparent); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--orange); vertical-align: middle; padding: 0; }
textarea { min-height: 90px; font-family: var(--font-mono); font-size: 13px; }
.field { margin-bottom: 14px; }
.field small { color: var(--muted); display: block; margin-top: 4px; font-size: 11.5px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 16px; }
.form-grid .span-2 { grid-column: span 2; }
.check { display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 13.5px; color: var(--ink); cursor: pointer; }
.secret { display: flex; gap: 8px; align-items: center; }
.secret .set { font-size: 11px; color: var(--ok-fg); background: var(--ok-bg); border-radius: 6px; padding: 2px 6px; white-space: nowrap; }
.form-section { font-family: var(--font-display); font-size: 15px; margin: 8px 0 12px; padding-bottom: 6px; border-bottom: 2px dashed var(--hair); grid-column: 1 / -1; }

.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; align-items: end; }
.filters .field { margin: 0; }
.filters .actions { display: flex; gap: 8px; }

/* ------------------------------------------------ tables ------------------------------------------------ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; font-weight: 700; color: var(--ink-soft);
  background: var(--paper-3); padding: 10px 12px; border-bottom: 2px solid var(--line); white-space: nowrap; position: sticky; top: 0;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--hair); vertical-align: top; }
.table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--paper-3) 35%, transparent); }
.table tbody tr:hover td { background: color-mix(in srgb, var(--mustard) 14%, transparent); }
.table td.r, .table th.r { text-align: right; }
.table .cell-link { font-weight: 600; }
.empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.empty-art { font-family: var(--font-display); font-size: 26px; color: var(--hair); display: block; margin-bottom: 6px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }

/* key/value lists */
.kv { display: grid; grid-template-columns: minmax(120px, 42%) 1fr; gap: 7px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* ------------------------------------------------ tabs ------------------------------------------------ */
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 6px; scrollbar-width: thin; border-bottom: 2px solid var(--line); }
.tabs button {
  font: 600 13px var(--font-body); color: var(--ink-soft); background: var(--paper-3); border: 2px solid var(--line); border-bottom: 0;
  border-radius: 10px 10px 0 0; padding: 7px 13px; cursor: pointer; white-space: nowrap; position: relative; top: 2px;
}
.tabs button.active { background: var(--paper-2); color: var(--ink); z-index: 1; }
.tabs button .count { font-family: var(--font-mono); font-size: 11px; background: var(--ink); color: var(--paper-2); border-radius: 999px; padding: 0 6px; margin-left: 4px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tab-card { border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }

/* ------------------------------------------------ order header / lifecycle ------------------------------------------------ */
.order-hero { display: flex; gap: 20px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; padding: 18px 20px; }
.order-hero h2 { font-size: 30px; }
.order-hero .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.order-hero .badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.lifecycle { display: flex; gap: 0; overflow-x: auto; padding: 16px 20px 20px; border-top: 2px dashed var(--hair); }
.stage { flex: 1 0 110px; text-align: center; position: relative; font-size: 12px; color: var(--muted); }
.stage::before { content: ""; position: absolute; top: 13px; left: -50%; width: 100%; height: 3px; background: var(--hair); z-index: 0; }
.stage:first-child::before { display: none; }
.stage .dot {
  width: 28px; height: 28px; border-radius: 50%; margin: 0 auto 6px; display: grid; place-items: center; position: relative; z-index: 1;
  background: var(--paper-2); border: 2px solid var(--hair); font-size: 12px; font-weight: 700;
}
.stage.done { color: var(--ink); }
.stage.done .dot { background: var(--teal); border-color: var(--line); color: #fff; box-shadow: var(--shadow-sm); }
.stage.done::before { background: var(--teal); }
.stage.alert .dot { background: var(--cherry); border-color: var(--line); color: #fff; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 4px 0 4px 8px; position: relative; }
.timeline::before { content: ""; position: absolute; left: 17px; top: 6px; bottom: 6px; width: 3px; background: repeating-linear-gradient(180deg, var(--hair) 0 6px, transparent 6px 10px); }
.timeline li { position: relative; padding: 0 0 16px 38px; }
.timeline .ev-dot { position: absolute; left: 2px; top: 1px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); background: var(--tone, var(--mustard)); box-shadow: var(--shadow-sm); }
.timeline .ev-title { font-weight: 600; }
.timeline .ev-meta { font-size: 12px; color: var(--muted); }
.timeline .ev-detail { font-size: 12.5px; color: var(--ink-soft); }
.cat-Order { --tone: var(--mustard); } .cat-Checkout { --tone: var(--plum); } .cat-Payment, .cat-Transaction { --tone: var(--olive); }
.cat-Invoice { --tone: var(--blue); } .cat-Fulfillment, .cat-Shipment { --tone: var(--orange); } .cat-Tracking { --tone: var(--teal); }
.cat-Refund, .cat-Return { --tone: var(--cherry); } .cat-COD, .cat-Settlement, .cat-Wallet, .cat-CourierCharge { --tone: var(--ink-soft); }

/* raw json */
pre.json {
  background: #1d1812; color: #f3e8d4; border: 2px solid var(--line); border-radius: 12px; padding: 14px 16px; overflow: auto; max-height: 520px;
  font: 12.5px/1.55 var(--font-mono); margin: 0; white-space: pre;
}

/* flash */
.flash {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border: 2px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-sm);
  margin-bottom: 18px; font-weight: 500;
}
.flash-ok { background: var(--ok-bg); color: var(--ok-fg); }
.flash-bad { background: var(--bad-bg); color: var(--bad-fg); }
.flash button { margin-left: auto; background: none; border: 0; font-size: 18px; cursor: pointer; color: inherit; }

/* dialog */
dialog { border: 2px solid var(--line); border-radius: var(--radius); box-shadow: 8px 8px 0 var(--line); background: var(--paper-2); color: var(--ink); padding: 0; width: min(640px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(20, 14, 8, .55); }
dialog .card-head { border-bottom: 2px dashed var(--hair); }
dialog .dlg-close { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--ink); }
dialog .card-body { max-height: 70vh; overflow: auto; }

/* chart */
.chart-box { position: relative; height: 260px; }
.bar-list { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 14px; background: var(--paper-3); border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--tone, var(--teal)); border-right: 1.5px solid var(--line); }

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); }
.login-card .card-body { padding: 26px; }
.login-sun { height: 120px; border-radius: var(--radius) var(--radius) 0 0; border-bottom: 2px solid var(--line); position: relative; overflow: hidden;
  background: linear-gradient(180deg, #ffe7a8 0%, #f6c177 45%, #ee8f4f 100%); }
.login-sun::before { content: ""; position: absolute; width: 150px; height: 150px; border-radius: 50%; left: 50%; bottom: -80px; transform: translateX(-50%);
  background: repeating-linear-gradient(180deg, var(--mustard) 0 14px, var(--orange) 14px 22px, var(--cherry) 22px 30px); border: 2px solid var(--line); }
.login-sun h1 { position: absolute; top: 16px; left: 0; right: 0; text-align: center; color: #2a2118; font-size: 28px; }

/* printable invoice */
.invoice-doc { max-width: 900px; margin: 0 auto; }
@media print {
  .sidebar, .topbar, .no-print, .flash { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; }
  .card { box-shadow: none; }
  body { background: #fff; }
}

/* ------------------------------------------------ responsive ------------------------------------------------ */
@media (max-width: 1200px) {
  .hero-money { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-money > div:nth-child(2) { border-right: 0; }
  .hero-money > div:nth-child(-n+2) { border-bottom: 2px dashed var(--hair); }
  .g-main-side, .g3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1000px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 270px; transform: translateX(-105%); transition: transform .2s ease; box-shadow: 8px 0 0 rgba(0,0,0,.25); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  .menu-btn { display: inline-flex; }
  .quick-search { display: none; }
  .g2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .topbar h1 { font-size: 19px; }
  .user-meta { display: none; }
  .content { padding: 16px 16px 40px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-value { font-size: 23px; }
  .hero-money { grid-template-columns: minmax(0, 1fr); }
  .hero-money > div { border-right: 0 !important; border-bottom: 2px dashed var(--hair); }
  .form-grid .span-2 { grid-column: auto; }
  .order-hero h2 { font-size: 24px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .bar-row { grid-template-columns: 90px 1fr auto; }
}
