:root {
  --bg: #f4f6f9; --surface: #ffffff; --ink: #16202c; --ink2: #5b6b7a;
  --muted: #8a97a6; --line: #e4e9ef; --brand: #1a73c7;
  --pos: #1f9d57; --neg: #d63b3b; --warn: #c98a00; --bad: #d63b3b;
  --pos-bg: #e7f6ee; --neg-bg: #fbeaea; --warn-bg: #fbf3e0;
  --shadow: 0 1px 3px rgba(20,32,44,.08), 0 1px 2px rgba(20,32,44,.04);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141b; --surface: #171f29; --ink: #e8eef5; --ink2: #a6b3c2;
    --muted: #6d7c8c; --line: #26303c; --brand: #4ea3ec;
    --pos: #35c878; --neg: #ff6b6b; --warn: #e0a838; --bad: #ff6b6b;
    --pos-bg: #12301f; --neg-bg: #331616; --warn-bg: #2e2510;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0e141b; --surface: #171f29; --ink: #e8eef5; --ink2: #a6b3c2;
  --muted: #6d7c8c; --line: #26303c; --brand: #4ea3ec;
  --pos: #35c878; --neg: #ff6b6b; --warn: #e0a838; --bad: #ff6b6b;
  --pos-bg: #12301f; --neg-bg: #331616; --warn-bg: #2e2510;
}
:root[data-theme="light"] {
  --bg: #f4f6f9; --surface: #ffffff; --ink: #16202c; --ink2: #5b6b7a;
  --muted: #8a97a6; --line: #e4e9ef; --brand: #1a73c7;
  --pos: #1f9d57; --neg: #d63b3b; --warn: #c98a00; --bad: #d63b3b;
  --pos-bg: #e7f6ee; --neg-bg: #fbeaea; --warn-bg: #fbf3e0;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.45;
}

/* ---------- Login ---------- */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--surface); padding: 40px 34px; border-radius: 18px; box-shadow: var(--shadow);
  width: 100%; max-width: 360px; text-align: center; border: 1px solid var(--line);
}
.login-logo { font-size: 44px; }
.login-card h1 { font-size: 21px; margin: 12px 0 2px; }
.login-sub { color: var(--ink2); margin: 0 0 22px; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font-size: 16px; margin-bottom: 12px;
}
.login-card button {
  width: 100%; padding: 12px; border: none; border-radius: 10px; background: var(--brand);
  color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}
.login-card button:hover { filter: brightness(1.06); }
.login-error { color: var(--neg); background: var(--neg-bg); padding: 8px; border-radius: 8px; font-size: 14px; }
.login-warn { color: var(--warn); background: var(--warn-bg); padding: 10px; border-radius: 8px; font-size: 13px; }
.login-foot { color: var(--muted); font-size: 12px; margin: 16px 0 0; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 17px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.saved-at { color: var(--muted); font-size: 13px; }
.btn-refresh {
  padding: 8px 14px; border: 1px solid var(--brand); background: var(--brand); color: #fff;
  border-radius: 9px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-refresh:disabled { opacity: .6; cursor: wait; }
.btn-logout { padding: 8px 11px; border: 1px solid var(--line); background: var(--surface); color: var(--ink2); border-radius: 9px; cursor: pointer; }

/* ---------- Timebar ---------- */
.timebar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 14px 20px; }
.timebar button {
  padding: 7px 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink2);
  border-radius: 999px; cursor: pointer; font-size: 14px;
}
.timebar button.active { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }
.custom-range { display: inline-flex; align-items: center; gap: 6px; color: var(--ink2); font-size: 13px; }
.custom-range input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.range-label { color: var(--muted); font-size: 13px; margin-left: auto; }

.config-warn { margin: 0 20px 6px; padding: 8px 12px; background: var(--warn-bg); color: var(--warn); border-radius: 9px; font-size: 13px; }

main { padding: 8px 20px 40px; max-width: 1180px; margin: 0 auto; }

/* ---------- Hero ---------- */
.hero {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 26px; box-shadow: var(--shadow); margin-bottom: 18px; border-left: 5px solid var(--muted);
}
.hero.pos { border-left-color: var(--pos); }
.hero.neg { border-left-color: var(--neg); }
.hero.neutral { border-left-color: var(--muted); }
.hero-label { color: var(--ink2); font-size: 13px; letter-spacing: .04em; font-weight: 600; }
.hero-hint { color: var(--muted); font-weight: 400; letter-spacing: 0; }
.hero-value { font-size: 40px; font-weight: 800; margin: 4px 0 6px; letter-spacing: -.02em; }
.hero.pos .hero-value { color: var(--pos); }
.hero.neg .hero-value { color: var(--neg); }
.hero-sub { color: var(--ink2); font-size: 14px; }
.hero-sub .warn { color: var(--warn); }

/* ---------- Grid ---------- */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-height: 150px;
}
.card.wide { grid-column: span 2; }
.card h2 { font-size: 15px; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.card h2 .sub { color: var(--muted); font-weight: 400; font-size: 12px; }
.badge-real { background: var(--pos-bg); color: var(--pos); font-size: 11px; padding: 2px 7px; border-radius: 6px; font-weight: 700; }
.big { font-size: 27px; font-weight: 800; letter-spacing: -.02em; }
.big-unit { font-size: 15px; font-weight: 500; color: var(--ink2); }
.big-sub { color: var(--ink2); font-size: 13px; margin-bottom: 12px; }
.rows { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.row { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.row span { color: var(--ink2); }
.row.warn b { color: var(--warn); }
.row.bad b { color: var(--bad); }
.statuses { display: flex; flex-wrap: wrap; gap: 5px; }
.pill { background: var(--bg); color: var(--ink2); font-size: 12px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); }
.note-warn { background: var(--warn-bg); color: var(--warn); font-size: 12px; padding: 7px 9px; border-radius: 8px; margin-top: 8px; }
.err { background: var(--neg-bg); color: var(--neg); padding: 10px; border-radius: 9px; font-size: 13px; }
.err.small { font-size: 12px; padding: 6px 8px; margin-bottom: 8px; }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }
.bm-list, .agents { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.bm, .agent { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink2); padding: 3px 8px; background: var(--bg); border-radius: 7px; }
.bm-err { color: var(--warn); }

/* Sale page table */
.sp-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.sp-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 5px 8px; border-bottom: 1px solid var(--line); font-size: 12px; }
.sp-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.sp-table td.r, .sp-table th.r { text-align: right; }
.sp-table td.warn { color: var(--warn); font-weight: 600; }
.sp-table tr.bad td { background: var(--neg-bg); }
.sp-foot { color: var(--ink2); font-size: 13px; margin-top: 10px; }

.foot { color: var(--muted); font-size: 12px; margin-top: 22px; line-height: 1.6; }

@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .card.wide { grid-column: span 1; }
  .hero-value { font-size: 32px; }
}
