/* DamnDeal Capitalist Console — Material Design 2, enterprise density.
 *
 * Sharp corners throughout: the console is an instrument, not a brochure.
 * Hierarchy is carried by elevation, dividers and type — not by radius.
 * Brand purple is the storefront's own (#7C3AED); nothing here invents one.
 *
 * Two balances run through every screen and must never be confused:
 *   stock credit — teal   — buys goods, never cash
 *   earnings     — green  — the only withdrawable money
 */

:root {
  /* brand — identical to web/src/app/globals.css */
  --brand:        #7C3AED;
  --brand-dark:   #5B21B6;
  --brand-light:  #EDE9FE;
  --on-brand:     #FFFFFF;

  /* Material 2 surfaces */
  --bg:           #F5F5F7;
  --surface:      #FFFFFF;
  --surface-2:    #FAFAFA;
  --on-surface:   rgba(0, 0, 0, .87);
  --on-surface-2: rgba(0, 0, 0, .60);
  --on-surface-3: rgba(0, 0, 0, .38);
  --divider:      rgba(0, 0, 0, .12);
  --outline:      rgba(0, 0, 0, .24);

  /* semantic — Material 2 palette */
  --credit:       #00796B;   /* teal 700  */
  --credit-bg:    #E0F2F1;
  --earn:         #2E7D32;   /* green 800 */
  --earn-bg:      #E8F5E9;
  --error:        #B00020;   /* MD2 error */
  --error-bg:     #FDECEA;
  --warn:         #E65100;   /* orange 900 */
  --warn-bg:      #FFF3E0;
  --info:         #01579B;   /* light blue 900 */
  --info-bg:      #E1F5FE;

  /* elevation */
  --dp1: 0 1px 1px 0 rgba(0,0,0,.14), 0 2px 1px -1px rgba(0,0,0,.12), 0 1px 3px 0 rgba(0,0,0,.20);
  --dp2: 0 2px 2px 0 rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.12), 0 1px 5px 0 rgba(0,0,0,.20);
  --dp4: 0 4px 5px 0 rgba(0,0,0,.14), 0 1px 10px 0 rgba(0,0,0,.12), 0 2px 4px -1px rgba(0,0,0,.20);
  --dp8: 0 8px 10px 1px rgba(0,0,0,.14), 0 3px 14px 2px rgba(0,0,0,.12), 0 5px 5px -3px rgba(0,0,0,.20);

  --font: 'Roboto', -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  --mono: 'Roboto Mono', 'SF Mono', Menlo, Consolas, monospace;

  --appbar: 48px;
  --sidebar: 240px;
}

* { box-sizing: border-box; border-radius: 0 !important; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--on-surface);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ═══ App bar ═══════════════════════════════════════════════════════════ */
.appbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--appbar); z-index: 40;
  background: var(--brand); color: var(--on-brand);
  box-shadow: var(--dp4);
  display: flex; align-items: center; gap: 12px; padding: 0 12px 0 8px;
}
.appbar .menu {
  display: none; width: 40px; height: 40px; border: 0; background: transparent;
  color: inherit; cursor: pointer; font-size: 20px; line-height: 1;
}
.appbar .logo-wrap {
  height: 30px; background: #FFFFFF; padding: 4px 8px;
  display: flex; align-items: center;
}
.appbar .logo-wrap img { height: 22px; width: auto; display: block; }
.appbar .title { font-size: 15px; font-weight: 500; letter-spacing: .01em; }
.appbar .title span { opacity: .8; font-weight: 400; }
.appbar .right { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 12px; }
.appbar .right .who { text-align: right; line-height: 1.25; }
.appbar .right .who b { display: block; font-weight: 500; }
.appbar .right .who small { opacity: .8; }
.appbar .right button {
  background: transparent; border: 1px solid rgba(255,255,255,.55); color: #fff;
  font: inherit; font-size: 12px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase;
  padding: 0 10px; height: 30px; cursor: pointer;
}
.appbar .right button:hover { background: rgba(255,255,255,.12); }

/* ═══ Sidebar ═══════════════════════════════════════════════════════════ */
.sidebar {
  position: fixed; top: var(--appbar); bottom: 0; left: 0; width: var(--sidebar); z-index: 30;
  background: var(--surface); box-shadow: var(--dp1);
  display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar .section {
  padding: 14px 16px 6px; font-size: 11px; font-weight: 500;
  letter-spacing: .08em; text-transform: uppercase; color: var(--on-surface-3);
}
.nav {
  display: flex; align-items: center; gap: 12px;
  height: 40px; padding: 0 16px; cursor: pointer;
  color: var(--on-surface-2); font-size: 13px; font-weight: 500;
  border-left: 3px solid transparent;
  user-select: none;
}
.nav:hover { background: rgba(0,0,0,.04); }
.nav.on { background: var(--brand-light); color: var(--brand-dark); border-left-color: var(--brand); }
.nav .ic { width: 20px; text-align: center; font-size: 15px; opacity: .85; }
.nav .lbl { flex: 1; }
.nav .badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--error); color: #fff; font-size: 10.5px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center;
}
.nav .badge.lock { background: transparent; color: var(--on-surface-3); font-size: 13px; }
.sidebar .foot {
  margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--divider);
  font-size: 11px; color: var(--on-surface-3); line-height: 1.5;
}

/* ═══ Content ═══════════════════════════════════════════════════════════ */
.content { margin-left: var(--sidebar); padding: calc(var(--appbar) + 16px) 16px 40px; }
.page-head {
  display: flex; align-items: baseline; gap: 12px; margin: 0 0 12px;
}
.page-head h1 { margin: 0; font-size: 18px; font-weight: 500; letter-spacing: 0; }
.page-head .crumb { font-size: 12px; color: var(--on-surface-2); }

/* ═══ Surfaces ══════════════════════════════════════════════════════════ */
.card { background: var(--surface); box-shadow: var(--dp1); margin-bottom: 16px; }
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--divider);
}
.card-head h2 { margin: 0; font-size: 14px; font-weight: 500; }
.card-head .sub { font-size: 12px; color: var(--on-surface-2); }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }

/* KPI tiles — dense, sharp, one number each */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); box-shadow: var(--dp1); padding: 12px 14px; border-top: 3px solid var(--divider); }
.kpi.credit { border-top-color: var(--credit); }
.kpi.earn { border-top-color: var(--earn); }
.kpi .k { font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--on-surface-2); }
.kpi .v { font-size: 22px; font-weight: 500; letter-spacing: -.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi.credit .v { color: var(--credit); }
.kpi.earn .v { color: var(--earn); }
.kpi .n { font-size: 11px; color: var(--on-surface-2); margin-top: 4px; line-height: 1.4; }

/* ═══ Tables ════════════════════════════════════════════════════════════ */
.tbl { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 560px; }
th {
  text-align: left; padding: 0 16px; height: 36px;
  font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase;
  color: var(--on-surface-2); border-bottom: 1px solid var(--divider); white-space: nowrap;
  background: var(--surface-2);
}
td { padding: 0 16px; height: 40px; border-bottom: 1px solid var(--divider); vertical-align: middle; }
tbody tr:hover td { background: rgba(0,0,0,.02); }
tbody tr:last-child td { border-bottom: 0; }
th.n, td.n { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { display: block; font-size: 11px; color: var(--on-surface-2); }
td.pos { color: var(--earn); }
td.neg { color: var(--error); }

/* ═══ Chips ═════════════════════════════════════════════════════════════ */
.chip {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px;
  font-size: 11px; font-weight: 500; letter-spacing: .02em; white-space: nowrap;
  border: 1px solid transparent;
}
.chip.ok    { background: var(--earn-bg);   color: var(--earn); }
.chip.wait  { background: var(--warn-bg);   color: var(--warn); }
.chip.no    { background: var(--error-bg);  color: var(--error); }
.chip.info  { background: var(--info-bg);   color: var(--info); }
.chip.off   { background: rgba(0,0,0,.06);  color: var(--on-surface-2); }
.chip.credit{ background: var(--credit-bg); color: var(--credit); }

/* ═══ Banners (inline, page-level) ══════════════════════════════════════ */
.banner {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 16px; margin-bottom: 12px; border-left: 4px solid;
  background: var(--surface); box-shadow: var(--dp1); font-size: 12.5px;
}
.banner .ic { font-size: 16px; line-height: 1.3; }
.banner .txt { flex: 1; }
.banner .txt b { font-weight: 500; }
.banner.warn  { border-color: var(--warn); }
.banner.error { border-color: var(--error); }
.banner.info  { border-color: var(--info); }
.banner.ok    { border-color: var(--earn); }
.banner .act { margin-left: auto; }

/* ═══ Forms — Material filled fields ════════════════════════════════════ */
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 11px; font-weight: 500; letter-spacing: .03em;
  color: var(--on-surface-2); margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  width: 100%; font: inherit; font-size: 13.5px; color: var(--on-surface);
  background: var(--surface-2); border: 0; border-bottom: 1px solid var(--outline);
  padding: 9px 12px; height: 38px; outline: none;
}
.field textarea { height: auto; min-height: 72px; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-bottom: 2px solid var(--brand); padding-bottom: 8px; background: #F3F0FA;
}
.field.error input, .field.error select { border-bottom: 2px solid var(--error); padding-bottom: 8px; background: var(--error-bg); }
.field .help { font-size: 11px; color: var(--on-surface-2); margin-top: 4px; line-height: 1.4; }
.field.error .help { color: var(--error); }
.field input:disabled { color: var(--on-surface-3); background: rgba(0,0,0,.03); }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row .field { margin-bottom: 0; flex: 1; min-width: 160px; }

/* ═══ Buttons ═══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 16px; min-width: 64px;
  font: inherit; font-size: 13px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase;
  border: 1px solid var(--outline); background: var(--surface); color: var(--brand);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: rgba(124,58,237,.06); }
.btn.contained { background: var(--brand); border-color: var(--brand); color: var(--on-brand); box-shadow: var(--dp2); }
.btn.contained:hover { background: var(--brand-dark); }
.btn.text { border-color: transparent; background: transparent; }
.btn.danger { color: var(--error); border-color: var(--error); }
.btn.danger.contained { background: var(--error); color: #fff; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn:focus-visible, .nav:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 12px; }

/* ═══ Product list (dense rows, not cards) ══════════════════════════════ */
.plist { display: flex; flex-direction: column; }
.prow {
  display: grid; grid-template-columns: 56px 1fr 120px 120px 100px 110px 120px;
  align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--divider);
}
.prow:last-child { border-bottom: 0; }
.prow:hover { background: rgba(0,0,0,.02); }
.prow img, .prow .noimg { width: 56px; height: 44px; object-fit: cover; background: rgba(0,0,0,.06); display: block; }
.prow .name { font-weight: 500; font-size: 13px; line-height: 1.3; }
.prow .meta { font-size: 11px; color: var(--on-surface-2); }
.prow .cell { font-variant-numeric: tabular-nums; }
.prow .cell .k { display: block; font-size: 10.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--on-surface-3); }
.prow .cell .v { font-size: 13px; font-weight: 500; }
.prow .cell.you .v { color: var(--credit); font-size: 14px; }
.prow .was { text-decoration: line-through; color: var(--on-surface-3); font-size: 11px; }
.plist-head {
  display: grid; grid-template-columns: 56px 1fr 120px 120px 100px 110px 120px;
  gap: 12px; padding: 0 16px; height: 36px; align-items: center;
  font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase;
  color: var(--on-surface-2); border-bottom: 1px solid var(--divider); background: var(--surface-2);
}

/* ═══ Blocked / empty states ════════════════════════════════════════════ */
.blocked {
  padding: 40px 24px; text-align: center; max-width: 520px; margin: 0 auto;
}
.blocked .ic { font-size: 40px; color: var(--on-surface-3); }
.blocked h3 { margin: 8px 0 4px; font-size: 16px; font-weight: 500; }
.blocked p { margin: 0 0 16px; color: var(--on-surface-2); font-size: 13px; }
.empty { padding: 28px 16px; text-align: center; color: var(--on-surface-2); font-size: 12.5px; }
.loading { padding: 24px; text-align: center; color: var(--on-surface-3); font-size: 12px; }

/* ═══ Dialog ════════════════════════════════════════════════════════════ */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.32); z-index: 60;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.scrim.show { display: flex; }
.dialog { background: var(--surface); box-shadow: var(--dp8); width: 480px; max-width: 100%; max-height: 90vh; overflow-y: auto; }
.dialog .d-head { padding: 16px 20px 8px; font-size: 16px; font-weight: 500; }
.dialog .d-sub { padding: 0 20px 12px; font-size: 12.5px; color: var(--on-surface-2); }
.dialog .d-body { padding: 0 20px 8px; }
.dialog .d-acts { padding: 8px 12px 12px; display: flex; justify-content: flex-end; gap: 4px; }

/* ═══ Snackbar ══════════════════════════════════════════════════════════ */
.snackbar {
  position: fixed; left: 16px; bottom: 16px; z-index: 90;
  min-width: 280px; max-width: 560px; padding: 12px 16px;
  background: #323232; color: rgba(255,255,255,.92); font-size: 13px;
  box-shadow: var(--dp4); border-left: 4px solid transparent;
  display: flex; align-items: center; gap: 12px;
}
.snackbar.ok { border-left-color: #66BB6A; }
.snackbar.error { border-left-color: #EF5350; }
.snackbar .x { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; font-size: 16px; opacity: .8; }

/* ═══ Sign-in ═══════════════════════════════════════════════════════════ */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: var(--bg); }
.auth { width: 400px; max-width: 100%; background: var(--surface); box-shadow: var(--dp2); }
.auth .a-brand { background: var(--brand); padding: 16px 24px; display: flex; align-items: center; gap: 12px; }
.auth .a-brand .logo-wrap { background: #fff; padding: 5px 8px; height: 34px; display: flex; align-items: center; }
.auth .a-brand img { height: 24px; width: auto; display: block; }
.auth .a-brand .t { color: #fff; font-size: 14px; font-weight: 500; }
.auth .a-body { padding: 20px 24px 24px; }
.auth h1 { margin: 0 0 4px; font-size: 18px; font-weight: 500; }
.auth .lede { margin: 0 0 18px; font-size: 12.5px; color: var(--on-surface-2); }
.otp { display: flex; gap: 8px; }
.otp input { text-align: center; font-size: 20px; font-weight: 500; padding: 8px 0; height: 46px; }

/* ═══ Catalogue toolbar: search, category chips, pager ══════════════════ */
.toolbar { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; padding: 12px 16px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 16px 12px; border-top: 1px solid var(--divider); }
.chip-btn {
  font: inherit; font-size: 12px; font-weight: 500; letter-spacing: .01em;
  height: 28px; padding: 0 12px; cursor: pointer;
  background: var(--surface-2); color: var(--on-surface-2); border: 1px solid var(--divider);
}
.chip-btn:hover { background: rgba(0,0,0,.06); color: var(--on-surface); }
.chip-btn.on { background: var(--brand-light); color: var(--brand-dark); border-color: var(--brand); font-weight: 700; }
.chip-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.pager {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 14px 0 4px; font-size: 12.5px; color: var(--on-surface-2); font-variant-numeric: tabular-nums;
}
.empty a { color: var(--brand); font-weight: 500; }

.spin {
  display: inline-block; width: 14px; height: 14px; vertical-align: -2px;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; animation: sp .7s linear infinite;
}
.btn:not(.contained) .spin { border-color: rgba(124,58,237,.3); border-top-color: var(--brand); }
@keyframes sp { to { transform: rotate(360deg); } }

/* ═══ Responsive ════════════════════════════════════════════════════════ */
@media (max-width: 960px) {
  .appbar .menu { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar { transform: translateX(-100%); transition: transform .18s ease; box-shadow: var(--dp8); }
  .sidebar.open { transform: none; }
  .content { margin-left: 0; padding-left: 12px; padding-right: 12px; }
  .prow, .plist-head { grid-template-columns: 48px 1fr 100px 100px; }
  .prow .cell.min, .prow .cell.stock, .plist-head .h-min, .plist-head .h-stock { display: none; }
  .appbar .title span { display: none; }
  .appbar .right .who small { display: none; }
}
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } .sidebar { transition: none; } }

/* ═══ Phone ══════════════════════════════════════════════════════════════
   The console is an operator tool, and a capitalist checks it from a phone in
   a shop more often than from a desk. Below 600px the dense grid becomes a
   card per product, the KPI tiles pair up, the dialog becomes a bottom sheet,
   and the drawer gets a scrim so a tap outside closes it. */
.scrim-nav { position: fixed; inset: 0; top: var(--appbar); background: rgba(0,0,0,.32); z-index: 25; display: none; }
.scrim-nav.show { display: block; }

@media (max-width: 600px) {
  body { font-size: 13.5px; }
  .content { padding: calc(var(--appbar) + 12px) 10px 32px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 2px; margin-bottom: 10px; }
  .page-head h1 { font-size: 17px; }

  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .v { font-size: 19px; }
  .grid-2 { grid-template-columns: 1fr; }

  .card-head { flex-wrap: wrap; padding: 10px 12px; }
  .card-body { padding: 12px; }
  .toolbar { padding: 10px 12px; }
  .toolbar .btn { flex: 1; }
  .chips { padding: 8px 12px 10px; }

  /* product rows → one card each: image + name on the first line, the four
     figures inline on the second, the button full-width on the third. Done
     with flex order so the markup stays the desktop markup. */
  .plist-head { display: none; }
  .prow { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px 12px; padding: 12px; }
  .prow img, .prow .noimg { order: 0; flex: none; width: 64px; height: 64px; }
  .prow > div:nth-child(2) { order: 1; flex: 1 1 0; min-width: 0; }
  .prow::before { content: ""; order: 2; flex-basis: 100%; height: 0; }
  .prow .cell { order: 2; display: flex; flex-direction: column; flex: 0 0 auto; }
  .prow .cell.min, .prow .cell.stock { display: flex; }
  .prow .cell .k { font-size: 10px; }
  .prow .cell .v { font-size: 13px; }
  .prow .cell.you .v { font-size: 15px; }
  .prow > div:last-child { order: 3; flex-basis: 100%; }
  .prow > div:last-child .btn { width: 100%; }

  table { min-width: 520px; font-size: 12px; }
  th, td { padding: 0 10px; }

  .dialog {
    width: 100%; max-width: none; max-height: 92vh;
    position: fixed; left: 0; right: 0; bottom: 0;
    box-shadow: var(--dp8);
  }
  .scrim { align-items: flex-end; padding: 0; }
  .d-acts .btn { flex: 1; }

  .snackbar { left: 8px; right: 8px; bottom: 8px; min-width: 0; max-width: none; }
  .auth-wrap { padding: 12px; align-items: flex-start; }
  .auth .a-body { padding: 16px; }
}
