/* Earnings Monitor - visual system
   Light and dark are both first-class: every colour is a token defined on
   :root, redefined for dark. Money is always tabular-figure so columns of
   digits line up down the page. */

:root {
  color-scheme: light dark;

  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #fbfcfd;
  --sidebar:       #12161f;
  --sidebar-text:  #9aa4b8;
  --sidebar-active:#ffffff;

  --text:          #10141c;
  --text-2:        #5a6478;
  --text-3:        #8b95a8;
  --border:        #e3e7ed;
  --border-2:      #eef1f5;

  --accent:        #1d68ff;
  --accent-soft:   #e8f0ff;
  --profit:        #0e9f6e;
  --profit-soft:   #e3f6ee;
  --cost:          #e0294a;
  --cost-soft:     #fdeaee;
  --warn:          #b7791f;
  --warn-soft:     #fdf5e4;

  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 1px 2px rgba(16,20,28,.05), 0 4px 16px rgba(16,20,28,.05);
  --shadow-lg:     0 8px 40px rgba(16,20,28,.16);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0c0f16;
    --surface:       #141922;
    --surface-2:     #191f2a;
    --sidebar:       #090c12;
    --sidebar-text:  #79839a;
    --sidebar-active:#ffffff;

    --text:          #e9edf5;
    --text-2:        #9aa5ba;
    --text-3:        #6b768c;
    --border:        #232b38;
    --border-2:      #1c232e;

    --accent:        #4d8dff;
    --accent-soft:   #16233c;
    --profit:        #2bc48a;
    --profit-soft:   #10281f;
    --cost:          #ff5f78;
    --cost-soft:     #2b141a;
    --warn:          #e0a94a;
    --warn-soft:     #2a2113;

    --shadow:        0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    --shadow-lg:     0 8px 40px rgba(0,0,0,.55);
  }
}

:root[data-theme="dark"] {
  --bg:#0c0f16; --surface:#141922; --surface-2:#191f2a; --sidebar:#090c12;
  --sidebar-text:#79839a; --sidebar-active:#fff;
  --text:#e9edf5; --text-2:#9aa5ba; --text-3:#6b768c;
  --border:#232b38; --border-2:#1c232e;
  --accent:#4d8dff; --accent-soft:#16233c;
  --profit:#2bc48a; --profit-soft:#10281f;
  --cost:#ff5f78; --cost-soft:#2b141a;
  --warn:#e0a94a; --warn-soft:#2a2113;
  --shadow:0 1px 2px rgba(0,0,0,.4),0 4px 16px rgba(0,0,0,.3);
  --shadow-lg:0 8px 40px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3,h4 { margin: 0; font-weight: 650; letter-spacing: -.011em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Every number in the app aligns by digit. */
.num, td.num, .kpi-value, .money {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ------------------------------------------------------------- layout ---- */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 20px;
  color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -.02em;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--profit));
  display: grid; place-items: center; font-size: 14px;
}
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: #4d5568; padding: 16px 10px 6px; font-weight: 700;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--sidebar-text); font-weight: 500; font-size: 13.5px;
  text-decoration: none; transition: background .12s, color .12s;
}
.nav a:hover { background: rgba(255,255,255,.05); color: #d7dde9; text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.10); color: var(--sidebar-active); font-weight: 600; }
.nav a .ico { width: 16px; text-align: center; opacity: .85; flex: none; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; font-size: 11.5px; color: #4d5568; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 28px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 19px; }
.topbar .spacer { flex: 1; }
.content { padding: 24px 28px 64px; max-width: 1400px; width: 100%; }

/* -------------------------------------------------------------- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border-2);
}
.card-head h3 { font-size: 14.5px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }
.subtle { color: var(--text-2); font-size: 12.5px; font-weight: 400; }

/* ---------------------------------------------------------------- KPI ---- */
.kpi-grid {
  display: grid; gap: 14px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--border);
}
.kpi.is-profit::before { background: var(--profit); }
.kpi.is-cost::before   { background: var(--cost); }
.kpi.is-accent::before { background: var(--accent); }
.kpi-label {
  font-size: 11.5px; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px;
}
.kpi-value { font-size: 25px; font-weight: 680; letter-spacing: -.025em; line-height: 1.15; }
.kpi-sub { font-size: 12px; color: var(--text-3); margin-top: 5px; }
.kpi-value.profit { color: var(--profit); }
.kpi-value.cost   { color: var(--cost); }

/* ------------------------------------------------------------- tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-3);
  border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--surface-2); position: sticky; top: 0;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border-2); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; }
td.strong { font-weight: 600; }
tfoot td {
  padding: 12px 14px; font-weight: 680; border-top: 2px solid var(--border);
  background: var(--surface-2);
}
.empty { padding: 40px 18px; text-align: center; color: var(--text-3); }

/* ------------------------------------------------------------- pills ----- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 100px; font-size: 11.5px; font-weight: 600;
  background: var(--border-2); color: var(--text-2); white-space: nowrap;
}
.pill.ok    { background: var(--profit-soft); color: var(--profit); }
.pill.bad   { background: var(--cost-soft);   color: var(--cost); }
.pill.warn  { background: var(--warn-soft);   color: var(--warn); }
.pill.info  { background: var(--accent-soft); color: var(--accent); }

/* ------------------------------------------------------------ buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 550; font-family: inherit;
  cursor: pointer; transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { opacity: .9; background: var(--accent); }
.btn.danger { color: var(--cost); border-color: var(--border); }
.btn.danger:hover { background: var(--cost-soft); border-color: var(--cost); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ------------------------------------------------------------- forms ----- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 11.5px; color: var(--text-3); font-weight: 400; }
input, select, textarea {
  padding: 8px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: 13.5px; font-family: inherit;
  width: 100%; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.form-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 18px; }
.toolbar .field { margin-bottom: 0; min-width: 150px; }

/* ------------------------------------------------------------ notices ---- */
.notice {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 12px; border: 1px solid transparent; line-height: 1.45;
}
.notice.error { background: var(--cost-soft);  color: var(--cost);  border-color: color-mix(in srgb, var(--cost) 25%, transparent); }
.notice.warn  { background: var(--warn-soft);  color: var(--warn);  border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.notice.info  { background: var(--accent-soft);color: var(--accent);border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.notice .ico { flex: none; }

/* ------------------------------------------------------------- charts ---- */
.chart { width: 100%; height: 260px; display: block; }
.chart-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); padding: 0 18px 14px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* -------------------------------------------------------------- modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(8,11,16,.55); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: min(560px, 100%); max-height: 88vh; overflow-y: auto;
  border: 1px solid var(--border);
}
.modal-head { padding: 18px; border-bottom: 1px solid var(--border-2); display: flex; align-items: center; }
.modal-head h3 { font-size: 15.5px; }
.modal-body { padding: 18px; }
.modal-foot {
  padding: 14px 18px; border-top: 1px solid var(--border-2);
  display: flex; gap: 10px; justify-content: flex-end;
  position: sticky; bottom: 0; background: var(--surface);
}

/* --------------------------------------------------------------- misc ---- */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; width: 100%; }
.login-card { width: min(380px, 100%); }
.login-card .card-body { padding: 26px; }
.login-logo {
  width: 44px; height: 44px; border-radius: 12px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--accent), var(--profit));
  display: grid; place-items: center; font-size: 21px;
}
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 60px; gap: 12px; color: var(--text-2); }

.bar-track { height: 6px; background: var(--border-2); border-radius: 100px; overflow: hidden; min-width: 60px; }
.bar-fill { height: 100%; border-radius: 100px; background: var(--accent); }

.split { display: grid; gap: 20px; grid-template-columns: 1fr 1fr; }
.split-3 { display: grid; gap: 20px; grid-template-columns: 2fr 1fr; }
@media (max-width: 1000px) { .split, .split-3 { grid-template-columns: 1fr; } }

@media (max-width: 760px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 60;
    transform: translateX(-100%); transition: transform .2s;
  }
  .sidebar.open { transform: none; }
  .content { padding: 16px; }
  .topbar { padding: 14px 16px; }
  #menuBtn { display: inline-flex !important; }
}
#menuBtn { display: none; }
