:root, :root[data-theme="dark"] {
  --bg: #0a0f1c; --bg-alt: #111827; --surface: #1e293b; --surface-alt: #172033;
  --text: #f1f5f9; --text-muted: #94a3b8;
  --accent: #009ddc; --accent-light: #4fc3f0; --accent-orange: #fd8000;
  --accent-gradient: linear-gradient(135deg, #009ddc 0%, #fd8000 100%);
  --border: #2a374d; --shadow: 0 10px 30px rgba(0,0,0,.35);
  --green: #4ade80; --red: #f87171; --yellow: #fbbf24;
}
:root[data-theme="light"] {
  --bg: #eef1f6; --bg-alt: #e5e9f1; --surface: #ffffff; --surface-alt: #f2f5fa;
  --text: #1e293b; --text-muted: #64748b;
  --accent: #0284c7; --accent-light: #0369a1; --accent-orange: #e2680a;
  --accent-gradient: linear-gradient(135deg, #0284c7 0%, #f97316 100%);
  --border: #dce1ea; --shadow: 0 4px 16px rgba(15,23,42,.06);
  --green: #15803d; --red: #dc2626; --yellow: #b45309;
}
:root { --radius: 16px; --radius-sm: 10px; color-scheme: light dark; }
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--accent-light); text-decoration: none; }
.muted { color: var(--text-muted); }

/* ---- Login (centered) ---- */
.center { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 16px; }
.card.narrow { max-width: 400px; width: 100%; }
.logo-wrap { text-align: center; margin-bottom: 8px; }
.logo-wrap img { height: 46px; }

h1 { margin: 0 0 4px; font-size: 1.35rem; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.sub { color: var(--text-muted); margin: 0 0 20px; font-size: .92rem; }

label { display: block; font-size: .78rem; color: var(--text-muted); margin: 8px 0 4px; }
input, select, textarea { width: 100%; padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-alt); color: var(--text); font-size: .93rem; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  font-size: .9rem; font-weight: 600; cursor: pointer; background: var(--surface-alt); color: var(--text); }
.btn.primary { background: var(--accent-gradient); border: none; color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: #5c2b33; color: #ff9aa6; }
.btn.sm { padding: 5px 10px; font-size: .8rem; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; }

.err { color: #ff9aa6; font-size: .85rem; margin-top: 10px; min-height: 1em; }
.ok { color: var(--green); }

/* ---- App shell (sidebar) ---- */
.sidebar { position: fixed; top: 0; left: 0; width: 216px; height: 100vh; overflow-y: auto;
  background: var(--bg-alt); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.sidebar .brand img { height: 30px; }
.sidebar .brand span { font-weight: 700; font-size: .98rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: .9rem; font-weight: 500; }
.sidebar nav a .ic { width: 20px; text-align: center; }
.sidebar nav a:hover { background: var(--surface-alt); color: var(--text); }
.sidebar nav a.active { background: var(--accent-gradient); color: #fff; }
.sidebar .navgroup { font-size: .64rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted);
  padding: 13px 12px 5px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; }
.sidebar .navgroup:hover { color: var(--text); }
.sidebar .navgroup .cx { font-size: .7rem; transition: transform .15s; }
.sidebar .navgroup.collapsed .cx { transform: rotate(-90deg); }
.sidebar .navsection.collapsed { display: none; }
.sidebar .spacer { flex: 1; }
.sidebar .me { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--border);
  padding-top: 12px; margin-top: 4px; color: var(--text); text-decoration: none; }
.sidebar .me:hover { color: var(--accent-light); }
.sidebar .me .nm { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .me .rl { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 1px solid var(--border); }
.avatar.ph { display: grid; place-items: center; background: var(--accent-gradient); color: #fff; font-weight: 700; }
.thumb { border-radius: 8px; object-fit: cover; background: var(--surface-alt); border: 1px solid var(--border); vertical-align: middle; }
.thumb.ph { display: inline-grid; place-items: center; font-size: .9rem; }

/* Card / tile grid (SKU cards etc.) */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-top: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.tile:hover { border-color: var(--accent); }
.tile .code { font-weight: 700; font-size: .9rem; word-break: break-word; line-height: 1.25; }
.tile .meta { font-size: .77rem; color: var(--text-muted); margin-top: 2px; word-break: break-word; }
.tile .srow { display: flex; gap: 14px; margin-top: 12px; }
.tile .srow .v { font-size: 1.2rem; font-weight: 700; }
.tile .srow .k { font-size: .64rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

/* Horizontal row cards (like the old FBA orders list) */
.rowlist { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.rowcard { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 16px; }
.rowcard:hover { border-color: var(--accent); }
.rowcard .grow { flex: 1; min-width: 0; }
.rowcard .rank { width: 34px; color: var(--text-muted); font-size: .8rem; flex-shrink: 0; }
.rowcard .m { text-align: right; min-width: 66px; flex-shrink: 0; }
.rowcard .m .v { font-weight: 700; font-size: 1.02rem; }
.rowcard .m .k { font-size: .6rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
@media (max-width: 640px) { .rowcard .m { min-width: 52px; } .rowcard { gap: 8px; padding: 10px; } }

/* Grid rows sharing one header (labels shown once; --cols set per page; trailing space for future fields) */
.skuwrap { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; overflow-x: auto; }
.skutable { display: flex; flex-direction: column; gap: 6px; }
.skurow { display: grid; grid-template-columns: var(--cols, 1fr); align-items: center; gap: 10px; min-width: 560px; }
.skurow .num { text-align: right; font-variant-numeric: tabular-nums; }
.skurow.head { padding: 2px 16px; }
.skurow.head > div { font-size: .64rem; text-transform: uppercase; color: var(--text-muted); letter-spacing: .04em; }
.skurow.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 14px; }
.skurow.card:hover { border-color: var(--accent); }
.skurow .code { font-weight: 700; font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.skurow .rank { color: var(--text-muted); font-size: .78rem; }

/* Compact floating cluster in the top-right corner (like the old site). */
.topbar { position: fixed; top: 14px; right: 20px; left: auto; z-index: 150;
  display: flex; align-items: center; gap: 8px; padding: 0; background: none; border: none; }
.iconbtn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: 1rem; line-height: 1; }
.iconbtn:hover { border-color: var(--accent-light); }
.topbar .userchip { display: flex; }
.topbar .userchip .avatar { width: 34px; height: 34px; }

.content { margin-left: 216px; padding: 50px 16px 18px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 12px; }
.mod { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px; display: block; }
.mod:hover { border-color: var(--accent); }
.mod .ic { font-size: 1.6rem; }
.mod .t { font-weight: 700; margin: 8px 0 4px; color: var(--text); }
.mod .d { font-size: .82rem; color: var(--text-muted); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 15px; display: flex; flex-direction: column; justify-content: center; }
/* One uniform size for every KPI number across the whole site (overrides per-page inline sizes). */
.stat .n { font-size: 1.3rem !important; font-weight: 700; line-height: 1.2; }
.stat .l { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 3px; }

.badge { font-size: .66rem; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-muted); }
.badge.ready { color: var(--green); border-color: rgba(74,222,128,.4); }
.badge.soon { color: var(--accent-orange); border-color: rgba(253,128,0,.4); }
.badge.admin { color: var(--accent-light); border-color: rgba(79,195,240,.4); }

table { width: 100%; border-collapse: separate; border-spacing: 0 6px; margin-top: 8px; }
th, td { text-align: left; padding: 9px 12px; font-size: .88rem; vertical-align: middle; }
th { color: var(--text-muted); font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; padding: 2px 12px 4px; }
thead th { cursor: pointer; user-select: none; }
thead th:hover { color: var(--text); }
.sort-ar { color: var(--accent-light); font-size: .8em; }
/* Every body row is shown as a rounded card/tile. */
tbody td { background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
tbody td:first-child { border-left: 1px solid var(--border); border-top-left-radius: var(--radius-sm); border-bottom-left-radius: var(--radius-sm); }
tbody td:last-child { border-right: 1px solid var(--border); border-top-right-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm); }
tbody tr:hover td { border-color: var(--accent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td strong, td .big { font-weight: 700; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-alt); }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > div { flex: 1; min-width: 130px; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; place-items: center; padding: 16px; z-index: 200; }
.modal-bg.show { display: grid; }
.modal-bg .card { max-width: 460px; width: 100%; max-height: 90vh; overflow-y: auto; }

/* ---- Mobile: off-canvas drawer + hamburger ---- */
.menu-btn { display: none; position: fixed; top: 12px; left: 12px; z-index: 200;
  width: 42px; height: 42px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 1.25rem; cursor: pointer;
  align-items: center; justify-content: center; }
.backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 175;
  -webkit-backdrop-filter: blur(1px); backdrop-filter: blur(1px); }
.backdrop.show { display: block; }

/* Mobile app chrome: top app bar + bottom tab bar + drawer-only footer (all hidden on desktop).
   .sidebar .drawer-only needs this specificity to beat the base .sidebar .me / .btn display rules. */
.appbar, .bottomnav { display: none; }
.sidebar .drawer-only { display: none; }

/* Marketplace badge — tiny app-icon shown next to an account logo (replaces the AMAZON/ETSY text). */
.mkt { display: inline-grid; place-items: center; border-radius: 5px; flex-shrink: 0; overflow: hidden;
  line-height: 1; vertical-align: middle; }
.mkt svg { width: 80%; height: 80%; }
.mkt-amz { background: #232f3e; }
.mkt-etsy { background: #f1641e; color: #fff; font-family: Georgia, "Times New Roman", serif; font-weight: 800; }
/* Placeholder for an account with no logo yet — neutral dark box with its initial. */
.thumb.acc-ph { background: #0a0f1c; color: var(--text-muted); display: inline-grid; place-items: center; font-weight: 700; }

/* Hide the descriptive subtitle under each page title (kept only on the login card). */
.content .sub { display: none; }

@media (max-width: 860px) {
  .menu-btn, .topbar { display: none !important; }

  /* Top app bar — translucent, sticky, holds brand + theme + profile. */
  .appbar { display: flex; align-items: center; gap: 10px;
    position: fixed; top: 0; left: 0; right: 0; z-index: 170;
    height: calc(54px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 16px 0;
    background: var(--bg-alt); background: color-mix(in srgb, var(--bg-alt) 85%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--border); }
  .appbar .ab-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.02rem; letter-spacing: .01em; }
  .appbar .ab-brand img { height: 26px; }
  .appbar .ab-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }
  .appbar .ab-btn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-size: 1.05rem; display: grid; place-items: center; cursor: pointer; }
  .appbar .ab-av { display: flex; }
  .appbar .ab-av .avatar { width: 36px; height: 36px; }

  /* Slide-in drawer for the full menu. */
  .sidebar { transform: translateX(-100%); transition: transform .26s cubic-bezier(.4,0,.2,1);
    width: min(84vw, 300px); z-index: 190; box-shadow: 6px 0 40px rgba(0,0,0,.45);
    padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .sidebar.open { transform: translateX(0); }
  .sidebar .drawer-only { display: flex; }
  .sidebar .drawer-only.me { margin-top: 4px; }

  .content { margin-left: 0;
    padding: calc(68px + env(safe-area-inset-top)) 14px calc(90px + env(safe-area-inset-bottom)); }

  /* Bottom tab bar — primary destinations, like a native app, with an active indicator. */
  .bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 170;
    background: var(--bg-alt); background: color-mix(in srgb, var(--bg-alt) 90%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a, .bottomnav button { flex: 1; min-width: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px; padding: 9px 2px 8px;
    background: none; border: none; cursor: pointer; text-decoration: none; position: relative;
    color: var(--text-muted); font-size: .62rem; font-weight: 600; letter-spacing: .01em;
    -webkit-tap-highlight-color: transparent; font-family: inherit; }
  .bottomnav .bic { font-size: 1.4rem; line-height: 1; }
  .bottomnav a.active { color: var(--accent-light); }
  .bottomnav a.active::before { content: ""; position: absolute; top: 0; width: 24px; height: 3px;
    border-radius: 0 0 4px 4px; background: var(--accent-gradient); }

  h1 { font-size: 1.32rem; }
  .page-head { margin-bottom: 12px; }
  .card, .mod, .stat, .tile, .rowcard, .skurow.card { border-radius: 14px; }
  .card { padding: 16px; }

  /* Bigger, easier-to-tap form controls. */
  input, select, textarea { padding: 10px 12px; font-size: .95rem; border-radius: 12px; }
  .btn { padding: 11px 16px; }
  label { font-size: .74rem; margin: 6px 0 5px; }

  /* Filters: neat two-up grid instead of a cramped single row. */
  .row { gap: 10px; }
  .row > div { flex: 1 1 calc(50% - 5px); min-width: 0; }

  .stats { grid-template-columns: repeat(2, 1fr); gap: 11px; margin: 14px 0; }
  .stat { padding: 14px 15px; }
  .stat .n { font-size: 1.3rem !important; }
  .cards, .card-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Wide data tables → a clean flat table that scrolls horizontally inside itself, with the
     first column (account/name) FROZEN so the numbers always keep their label in view. */
  .content div[style*="overflow-x"] { overflow: visible !important; }
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
    min-width: 0 !important; width: 100%; border-spacing: 0; border: 1px solid var(--border);
    border-radius: 14px; background: var(--surface); }
  th, td { white-space: nowrap; }
  th { padding: 9px 12px; }
  thead th { position: sticky; top: 0; z-index: 2; background: var(--bg-alt); }
  tbody td { background: var(--surface); border-top: 0; border-bottom: 1px solid var(--border);
    border-radius: 0 !important; }
  tbody td:first-child, tbody td:last-child { border-left: 0; border-right: 0; }
  tbody tr:last-child td { border-bottom: 0; }
  th:first-child, td:first-child { position: sticky; left: 0; z-index: 3; }
  thead th:first-child { z-index: 4; background: var(--bg-alt); }
  tbody td:first-child { background: var(--surface); box-shadow: 8px 0 10px -8px rgba(0,0,0,.45); }
  .pnl-total td { position: sticky; top: 0; z-index: 2; }
  .pnl-total td:first-child { z-index: 4; background: var(--surface-alt); }
  .skurow { min-width: 520px; }

  /* Full-screen overlay modals on phones (salary detail, revenue/ads quick-view). */
  .modalbg, #qv { padding: 0 !important; }
  .modalbg .card, #qv .card { margin: 0 !important; width: 100% !important; max-width: 100% !important;
    min-height: 100dvh; border-radius: 0 !important; border-left: 0; border-right: 0; }
  .modalbg .card { padding: 16px calc(14px + env(safe-area-inset-left)) calc(20px + env(safe-area-inset-bottom)); }
}
@media (max-width: 480px) {
  .content { padding-left: 12px; padding-right: 12px; }
  th, td { padding: 10px 12px; font-size: .85rem; }
  h1 { font-size: 1.24rem; }
  .row { gap: 8px; }
  .stats { gap: 9px; }
}