/* KEDR Dashboard — design system.
   One file owns: tokens, type, layout, components.
   No utility classes outside what's needed; no preprocessors. */

:root {
  /* Color tokens */
  --bg:        #0e1116;
  --bg-elev:   #161a21;
  --bg-elev-2: #1c2129;
  --line:      #262b35;
  --line-hi:   #364050;
  --text:      #e8eaed;
  --text-2:    #b8bec8;
  --muted:     #8a92a3;
  --accent:    #4f8cff;
  --accent-2:  #6ea1ff;
  --green:     #2ecc71;
  --green-bg:  rgba(46,204,113,0.10);
  --yellow:    #f5a623;
  --yellow-bg: rgba(245,166,35,0.10);
  --red:       #ff4d4f;
  --red-bg:    rgba(255,77,79,0.10);

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Scale */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px;
  --s6: 24px; --s8: 32px; --s10: 40px;
  --r:   10px;
  --r-s: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); text-decoration: underline; }

/* Typography */
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.011em; margin: 0; }
h1 { font-size: 22px; line-height: 1.25; }
h2 { font-size: 18px; line-height: 1.3; }
h3 { font-size: 15px; line-height: 1.4; }
h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px;
     color: var(--muted); font-weight: 500; }
.muted { color: var(--muted); }
.mono  { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num   { font-variant-numeric: tabular-nums; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(14,17,22,0.85);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1480px; margin: 0 auto;
  padding: 14px 24px;
  display: flex; align-items: center; gap: var(--s6);
}
.brand {
  font-weight: 700; font-size: 15px; letter-spacing: 0.04em;
  color: var(--text); text-decoration: none;
}
.brand:hover { text-decoration: none; }
.topnav { display: flex; gap: var(--s5); margin-left: auto; }
.topnav a {
  color: var(--muted); text-decoration: none; font-size: 13px;
  padding: 6px 0; border-bottom: 2px solid transparent;
}
.topnav a:hover { color: var(--text); text-decoration: none; }
.topnav a.active { color: var(--text); border-bottom-color: var(--accent); }

.container {
  max-width: 1480px; margin: 0 auto;
  padding: var(--s6) 24px var(--s10);
}
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--s4); flex-wrap: wrap;
  margin-bottom: var(--s5);
}
.page-head h1 { line-height: 1; }
.subtitle { color: var(--muted); font-size: 13px; margin-top: 4px; }
.section { margin-top: var(--s8); }
.section > h2 { margin-bottom: var(--s3); }
.section > .h-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s3); margin-bottom: var(--s3);
}

/* Card */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: var(--s4);
}
.card.tight { padding: var(--s3); }

/* KPI grid */
.kpi-grid {
  display: grid; gap: var(--s3);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 16px;
}
.kpi .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--muted); font-weight: 500;
}
.kpi .value {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 22px; font-weight: 600; line-height: 1.2;
  margin-top: 6px; color: var(--text);
}
.kpi .delta { font-size: 12px; margin-top: 4px; }
.kpi.alert  .value { color: var(--red); }
.kpi.warn   .value { color: var(--yellow); }
.kpi.good   .value { color: var(--green); }

/* Pills + badges */
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 500; font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.pill.red    { background: var(--red-bg);    color: var(--red); }
.pill.yellow { background: var(--yellow-bg); color: var(--yellow); }
.pill.green  { background: var(--green-bg);  color: var(--green); }
.pill.gray   { background: rgba(255,255,255,0.06); color: var(--muted); }

.badge {
  display: inline-block; min-width: 18px; padding: 1px 6px;
  margin-left: 6px; background: var(--red); color: white;
  border-radius: 9px; font-size: 11px; font-weight: 600;
  line-height: 1.35; text-align: center; vertical-align: middle;
}

.neg { color: var(--red); }
.pos { color: var(--green); }

/* Table */
.table-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th, table.t td {
  padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.t tbody tr:last-child td { border-bottom: none; }
table.t th {
  font-weight: 500; font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  background: var(--bg-elev-2);
}
table.t td.num, table.t th.num {
  text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono);
  font-size: 12.5px;
}
table.t tbody tr.clickable { cursor: pointer; transition: background 80ms; }
table.t tbody tr.clickable:hover td:not([style*="background"]) {
  background: rgba(255,255,255,0.028);
}
.sku-cell {
  font-family: var(--mono); font-size: 12px; color: var(--text);
}

/* Empty state */
.empty {
  padding: 40px; text-align: center; color: var(--muted);
  background: var(--bg-elev); border: 1px dashed var(--line);
  border-radius: var(--r);
}

/* Pickers / tabs */
.picker {
  display: inline-flex; gap: var(--s1); align-items: center;
  padding: 4px; background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--r-s);
}
.picker a {
  padding: 5px 11px; border-radius: 4px; color: var(--muted);
  text-decoration: none; font-size: 12px; font-weight: 500;
}
.picker a:hover { color: var(--text); text-decoration: none; }
.picker a.active { background: var(--accent); color: white; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 7px 14px;
  font: 500 13px var(--font);
  border-radius: var(--r-s); border: 1px solid var(--line);
  background: transparent; color: var(--text); cursor: pointer;
  transition: all 120ms;
}
.btn:hover { border-color: var(--line-hi); background: rgba(255,255,255,0.025); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.icon { width: 26px; height: 26px; padding: 0; font-size: 13px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--r); padding: var(--s6);
  min-width: 360px; max-width: 480px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.modal h3 { margin-bottom: 4px; }
.modal .sub {
  color: var(--muted); font-size: 12px; margin-bottom: var(--s4);
  font-family: var(--mono);
}
.modal label {
  display: block; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 6px; font-weight: 500;
}
.modal input[type="number"], .modal input[type="text"] {
  width: 100%; padding: 10px 12px; font-size: 17px;
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  text-align: right; background: rgba(0,0,0,0.35); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-s); outline: none;
  transition: border-color 120ms;
}
.modal input:focus { border-color: var(--accent); }
.modal .row {
  display: flex; gap: var(--s2); margin-top: var(--s5); justify-content: flex-end;
}
.modal .err-msg { color: var(--red); font-size: 12px; margin-top: var(--s2); min-height: 16px; }
.modal .current { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* Inline price cell */
.price-cell { white-space: nowrap; }
.price-val { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Sparkline */
.spark { display: inline-block; vertical-align: middle; }
.spark path.line { stroke: var(--accent); stroke-width: 1.5; fill: none; }
.spark path.area { fill: rgba(79,140,255,0.12); stroke: none; }
.spark.up   path.line { stroke: var(--green); }
.spark.up   path.area { fill: rgba(46,204,113,0.12); }
.spark.down path.line { stroke: var(--red); }
.spark.down path.area { fill: rgba(255,77,79,0.12); }

/* Header on /sku */
.sku-header {
  display: grid; grid-template-columns: 96px 1fr auto;
  gap: var(--s5); align-items: start;
  padding: var(--s5);
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--r);
}
.sku-header .photo {
  width: 96px; height: 96px; border-radius: var(--r-s);
  background: var(--bg-elev-2); object-fit: cover;
}
.sku-header .title { font-size: 18px; font-weight: 600; line-height: 1.3; margin-bottom: 6px; }
.sku-header .meta { color: var(--muted); font-size: 13px; }
.sku-header .meta .mono { color: var(--text-2); }
.sku-header .price-block { text-align: right; }
.sku-header .price-now {
  font-family: var(--mono); font-size: 24px; font-weight: 600; color: var(--text);
}

/* Two-column grid for sections that take side panes */
.two-col {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4);
}
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .sku-header { grid-template-columns: 64px 1fr; }
  .sku-header .photo { width: 64px; height: 64px; }
  .sku-header .price-block { grid-column: 1 / -1; text-align: left; margin-top: var(--s2); }
}

/* Day row drilldown (days.html) */
tr.day-row { cursor: pointer; }
tr.day-row .caret {
  display: inline-block; width: 8px; color: var(--muted);
  transition: transform 150ms; font-size: 10px;
}
tr.day-row.open .caret { transform: rotate(90deg); color: var(--text); }
tr.sku-row { background: rgba(0,0,0,0.30); display: none; font-size: 12px; }
tr.sku-row td { padding: 5px 14px; color: var(--text-2); border-bottom: 1px solid #14171d; }
tr.sku-row td.sku-name {
  padding-left: 38px; font-family: var(--mono); color: var(--text);
}

/* Messages */
.msg-list { background: var(--bg-elev); border: 1px solid var(--line);
            border-radius: var(--r); overflow: hidden; }
.msg-item { display: grid; grid-template-columns: 160px 1fr 180px;
            gap: var(--s4); padding: 12px 16px;
            border-bottom: 1px solid var(--line); align-items: start; }
.msg-item:last-child { border-bottom: none; }
.msg-item:hover { background: rgba(255,255,255,0.025); }
.msg-item.unread { background: rgba(79,140,255,0.05); }
.msg-item.unread .msg-sku::before { content: "● "; color: var(--accent); }
.msg-sku { font-family: var(--mono); font-size: 12px; color: var(--text);
           white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-text { line-height: 1.55; word-wrap: break-word; }
.msg-text .dir { color: var(--muted); font-size: 11px; text-transform: uppercase;
                 letter-spacing: 0.4px; margin-right: 6px; }
.msg-meta { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.msg-meta .when { display: block; margin-bottom: 4px; font-family: var(--mono); }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
                 color: var(--muted); margin: var(--s5) 0 var(--s2); font-weight: 500; }

/* Tab bar (left as utility for messages) */
.tab-bar { display: flex; gap: var(--s2); margin: var(--s5) 0 0;
           border-bottom: 1px solid var(--line); }
.tab { padding: 10px 16px; cursor: pointer; color: var(--muted);
       border-bottom: 2px solid transparent; margin-bottom: -1px;
       font-size: 13px; font-weight: 500; user-select: none; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .badge { background: var(--muted); margin-left: 6px; }
.tab.has-unread .badge { background: var(--red); }
.panel { display: none; padding-top: var(--s4); }
.panel.active { display: block; }
