/* Mehadrin Stock — Black & Gold Design System + Crisp Print Stylesheet */
:root {
  color-scheme: dark;
  --bg: #0b0b0d;
  --surface: #141417;
  --surface-2: #1c1c21;
  --surface-3: #26262d;
  --line: #2c2c34;
  --line-strong: #40404c;
  --text: #f4efe6;
  --text-2: #bdb6aa;
  --text-3: #8c867c;
  --gold: #d4af37;
  --gold-hi: #e8c96b;
  --gold-soft: rgba(212, 175, 55, .14);
  --gold-line: rgba(212, 175, 55, .42);
  --on-gold: #151107;
  --gold-grad: linear-gradient(145deg, #e5c45f, #b58d28);

  --ok: #6fd09b;
  --ok-bg: rgba(111, 208, 155, .14);
  --ok-line: rgba(111, 208, 155, .42);
  --warn: #f0b956;
  --warn-bg: rgba(240, 185, 86, .15);
  --warn-line: rgba(240, 185, 86, .46);
  --bad: #f27970;
  --bad-bg: rgba(242, 121, 112, .16);
  --bad-line: rgba(242, 121, 112, .48);
  --info: #8db9ea;
  --info-bg: rgba(141, 185, 234, .14);
  --info-line: rgba(141, 185, 234, .42);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100vw;
}
a { color: var(--gold-hi); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

/* PIN Lock Screen */
.pin-wrap {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px 16px;
  background: radial-gradient(circle at 50% 15%, #1e1a10 0%, #0b0b0d 62%);
}
.pin-card {
  width: 100%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--gold-line);
  border-radius: 20px; padding: 28px 22px 24px;
  text-align: center; box-shadow: var(--shadow);
}
.brand-mark {
  width: 56px; height: 56px; margin: 0 auto 12px;
  border-radius: 16px; background: var(--gold-grad);
  display: flex; align-items: center; justify-content: center;
  color: var(--on-gold); font-weight: 800; font-size: 24px;
  letter-spacing: -0.5px; box-shadow: 0 4px 18px rgba(212,175,55,.32);
}
.pin-title { margin: 0; font-size: 21px; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.pin-sub { margin: 4px 0 18px; color: var(--text-2); font-size: 13px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 14px 0 18px; }
.pin-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line-strong); background: transparent;
  transition: all .12s ease;
}
.pin-dot.filled { border-color: var(--gold); background: var(--gold); transform: scale(1.08); }
.pin-dot.err { border-color: var(--bad); background: var(--bad); }
.pin-err { min-height: 20px; color: var(--bad); font-size: 13px; margin-bottom: 10px; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-key {
  height: 58px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 22px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background .1s, border-color .1s, transform .06s;
}
.pin-key:hover { border-color: var(--gold-line); background: var(--surface-3); }
.pin-key:active { transform: scale(.96); background: var(--gold-soft); }
.pin-key.muted { font-size: 15px; color: var(--text-2); }
.pin-hint { margin-top: 14px; font-size: 12px; color: var(--text-3); }

/* App Shell */
.app-shell { min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: 74px; }
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(14, 14, 17, .94); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px; display: flex; align-items: center; gap: 12px; justify-content: space-between;
}
.top-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-logo {
  width: 34px; height: 34px; border-radius: 10px; background: var(--gold-grad);
  color: var(--on-gold); font-weight: 800; font-size: 15px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.top-name { font-size: 16px; font-weight: 700; white-space: nowrap; }
.top-sub { font-size: 11px; color: var(--gold); letter-spacing: .04em; text-transform: uppercase; }
.desk-nav { display: none; align-items: center; gap: 4px; }
.desk-nav button {
  padding: 8px 14px; border-radius: var(--r-sm); font-size: 14px; font-weight: 600;
  color: var(--text-2); transition: all .12s;
}
.desk-nav button:hover { color: var(--text); background: var(--surface-2); }
.desk-nav button.active { color: var(--on-gold); background: var(--gold-grad); }
.top-actions { display: flex; align-items: center; gap: 8px; }

.main-wrap { width: 100%; max-width: 1280px; margin: 0 auto; padding: 14px 14px 28px; flex: 1; }

/* Mobile Bottom Nav */
.bot-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  background: rgba(16, 16, 20, .97); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}
.bot-nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 6px 2px; border-radius: 10px;
  color: var(--text-3); font-size: 11px; font-weight: 600; min-height: 46px;
}
.bot-nav button svg { width: 20px; height: 20px; stroke-width: 2; }
.bot-nav button.active { color: var(--gold-hi); background: var(--gold-soft); }

@media (min-width: 860px) {
  .app-shell { padding-bottom: 0; }
  .bot-nav { display: none; }
  .desk-nav { display: flex; }
  .topbar { padding: 10px 24px; }
  .main-wrap { padding: 20px 24px 36px; }
}

/* Cards, Grids & Typography */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 16px; margin-bottom: 14px;
}
.card.gold-border { border-color: var(--gold-line); background: linear-gradient(160deg, #1b1710, #131316); }
.card.alert-banner { border-color: var(--bad-line); background: linear-gradient(155deg, rgba(242,121,112,.14), #151214); }
.card.warn-banner { border-color: var(--warn-line); background: linear-gradient(155deg, rgba(240,185,86,.13), #161411); }

.sec-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 12px;
}
.sec-title { margin: 0; font-size: 16px; font-weight: 700; color: var(--text); }
.sec-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.page-title { margin: 0; font-size: 21px; font-weight: 800; letter-spacing: -.01em; }
.page-sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }

.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
@media (min-width: 720px) { .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; } }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 13px 14px;
}
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); font-weight: 700; }
.kpi-val { font-size: 22px; font-weight: 800; margin-top: 4px; color: var(--text); line-height: 1.15; }
.kpi-val.gold { color: var(--gold-hi); }
.kpi-val.ok { color: var(--ok); }
.kpi-val.warn { color: var(--warn); }
.kpi-val.bad { color: var(--bad); }
.kpi-sub { font-size: 12px; color: var(--text-2); margin-top: 4px; }

.action-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 14px; }
@media (min-width: 680px) { .action-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.action-tile {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 14px 15px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--line);
  transition: border-color .14s, transform .08s;
}
.action-tile:hover { border-color: var(--gold-line); }
.action-tile:active { transform: scale(.99); }
.action-tile.primary { background: linear-gradient(145deg, rgba(212,175,55,.18), var(--surface-2)); border-color: var(--gold-line); }
.action-tile.danger { background: linear-gradient(145deg, rgba(242,121,112,.15), var(--surface-2)); border-color: var(--bad-line); }
.tile-ico {
  width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-3); color: var(--gold-hi); font-size: 18px;
}
.action-tile.primary .tile-ico { background: var(--gold-grad); color: var(--on-gold); }
.action-tile.danger .tile-ico { background: var(--bad-bg); color: var(--bad); border: 1px solid var(--bad-line); }
.tile-title { font-size: 14px; font-weight: 700; color: var(--text); }
.tile-desc { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* Buttons & Inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 700; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  transition: all .12s;
}
.btn:hover { border-color: var(--gold-line); background: var(--surface-3); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.gold { background: var(--gold-grad); color: var(--on-gold); border-color: transparent; }
.btn.gold:hover { filter: brightness(1.06); }
.btn.danger { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-line); }
.btn.danger:hover { background: rgba(242,121,112,.24); }
.btn.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.btn.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 12px; border-radius: 7px; }
.btn.xs { min-height: 28px; padding: 0 8px; font-size: 11px; border-radius: 6px; }

.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 8px 11px;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font-size: 14px;
  outline: none; transition: border-color .12s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--gold); }
.textarea { min-height: 92px; resize: vertical; line-height: 1.45; }
.label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 760px) { .form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 960px) { .form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* Pills & Badges */
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  padding: 7px 12px; border-radius: var(--r-pill); font-size: 12px; font-weight: 700;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2);
  min-height: 34px; display: inline-flex; align-items: center; gap: 5px;
}
.pill:hover { border-color: var(--gold-line); color: var(--text); }
.pill.active { background: var(--gold-grad); color: var(--on-gold); border-color: transparent; }
.pill.bad.active { background: var(--bad); color: #1a0605; }
.pill.warn.active { background: var(--warn); color: #1c1303; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 700; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface-3); color: var(--text-2);
}
.badge.gold { background: var(--gold-soft); border-color: var(--gold-line); color: var(--gold-hi); }
.badge.ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.badge.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.badge.bad { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad); }
.badge.info { background: var(--info-bg); border-color: var(--info-line); color: var(--info); }

/* Upload Dropzone */
.dropzone {
  border: 2px dashed var(--gold-line); border-radius: var(--r-lg);
  background: linear-gradient(160deg, rgba(212,175,55,.07), var(--surface-2));
  padding: 26px 16px; text-align: center; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.dropzone:hover, .dropzone.dragover { background: rgba(212,175,55,.15); border-color: var(--gold-hi); }
.dropzone-title { font-size: 16px; font-weight: 700; color: var(--text); margin: 6px 0 4px; }
.dropzone-sub { font-size: 12px; color: var(--text-2); }

/* Tables & Responsive Cards */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; padding: 9px 10px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: var(--text-3);
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.tbl td {
  padding: 10px; border-bottom: 1px solid rgba(44,44,52,.65);
  vertical-align: middle;
}
table.tbl tr:hover td { background: rgba(255,255,255,.025); }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl tr.clickable { cursor: pointer; }
table.tbl tr.row-alert td { background: rgba(242,121,112,.06); }
table.tbl tr.row-warn td { background: rgba(240,185,86,.06); }

/* Mobile-friendly row cards (replaces wide tables on < 760px where needed) */
.desk-only { display: none; }
.mob-only { display: block; }
@media (min-width: 780px) {
  .desk-only { display: block; }
  .mob-only { display: none; }
}

.row-card {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 12px; margin-bottom: 9px;
}
.row-card.is-bad { border-color: var(--bad-line); background: linear-gradient(155deg, rgba(242,121,112,.09), var(--surface-2)); }
.row-card.is-warn { border-color: var(--warn-line); background: linear-gradient(155deg, rgba(240,185,86,.09), var(--surface-2)); }
.rc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.rc-title { font-size: 14px; font-weight: 700; color: var(--text); }
.rc-meta { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.rc-nums {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line);
}
.rc-num-lbl { font-size: 10px; text-transform: uppercase; color: var(--text-3); font-weight: 700; }
.rc-num-val { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 1px; }

/* Review table row inputs */
.rev-card {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 11px; margin-bottom: 8px;
}
.rev-card.unmatched { border-color: var(--warn-line); }
.rev-card.skipped { opacity: .45; }

/* Modals & Toasts */
.modal-bg {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0, 0, 0, .76); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
@media (min-width: 640px) { .modal-bg { align-items: center; padding: 16px; } }
.modal {
  width: 100%; max-width: 520px; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--gold-line);
  border-radius: 18px 18px 0 0; padding: 18px 16px 22px; box-shadow: var(--shadow);
}
@media (min-width: 640px) { .modal { border-radius: 18px; padding: 20px; } }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 95;
  background: var(--surface-3); border: 1px solid var(--gold-line); color: var(--text);
  padding: 10px 16px; border-radius: var(--r-pill); font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow); max-width: calc(100vw - 24px); text-align: center;
}
@media (min-width: 860px) { .toast { bottom: 24px; } }

.empty { text-align: center; padding: 28px 14px; color: var(--text-2); }
.empty-title { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 4px; }

.yoy-note {
  margin-top: 6px; padding: 6px 9px; border-radius: 8px;
  font-size: 12px; background: rgba(242,121,112,.12); border: 1px solid var(--bad-line);
  color: #ffc5bf;
}
.yoy-note.warn { background: rgba(240,185,86,.12); border-color: var(--warn-line); color: #ffe2ad; }

.split-2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 920px) { .split-2 { grid-template-columns: 1fr 1fr; } }

.flex-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-2 { margin-bottom: 8px; }
.text-muted { color: var(--text-2); font-size: 12px; }
.text-gold { color: var(--gold-hi); }

/* Print Sheet Overlay (screen preview + @media print black-on-white) */
.print-overlay {
  position: fixed; inset: 0; z-index: 100; background: #e8e8e8; color: #111;
  overflow-y: auto; padding: 16px;
}
.print-bar {
  max-width: 920px; margin: 0 auto 14px; display: flex; align-items: center;
  justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: #141417; color: #f4efe6; padding: 10px 14px; border-radius: 10px;
}
.print-sheet {
  max-width: 920px; margin: 0 auto; background: #fff; color: #111;
  padding: 26px 28px; border-radius: 6px; box-shadow: 0 4px 20px rgba(0,0,0,.18);
}
.ps-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 2px solid #111; padding-bottom: 10px; margin-bottom: 14px; gap: 12px;
}
.ps-brand { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.ps-meta { font-size: 12px; color: #444; margin-top: 3px; }
.ps-kpis {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px;
}
.ps-kpi { border: 1px solid #ccc; border-radius: 6px; padding: 8px 10px; }
.ps-kpi-l { font-size: 10px; text-transform: uppercase; color: #555; font-weight: 700; }
.ps-kpi-v { font-size: 17px; font-weight: 800; margin-top: 2px; }
.ps-h2 { font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 6px; border-bottom: 1px solid #bbb; padding-bottom: 4px; }
table.ps-tbl { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 12px; }
table.ps-tbl th { text-align: left; border-bottom: 2px solid #222; padding: 6px 6px; font-size: 11px; text-transform: uppercase; }
table.ps-tbl td { border-bottom: 1px solid #ddd; padding: 6px 6px; vertical-align: top; }
table.ps-tbl td.num, table.ps-tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.ps-tbl tr.tot td { border-top: 2px solid #222; font-weight: 800; background: #f6f6f6; }
.ps-flag { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 700; border: 1px solid #111; }
.ps-flag.bad { background: #fde8e6; color: #9b1c1c; border-color: #9b1c1c; }
.ps-flag.warn { background: #fef3c7; color: #92400e; border-color: #92400e; }

@media print {
  @page { size: A4; margin: 12mm; }
  html, body { background: #fff !important; color: #000 !important; }
  .app-shell, .pin-wrap, .modal-bg, .toast, .print-bar { display: none !important; }
  .print-overlay { position: static !important; background: #fff !important; padding: 0 !important; overflow: visible !important; }
  .print-sheet { box-shadow: none !important; padding: 0 !important; max-width: none !important; }
}
