:root {
  --bg: #f5f6fa; --card: #ffffff; --text: #151a23; --muted: #667085; --line: #e6e8ee; --soft: #f9fafc;
  --accent: #2f5bea; --accent-2: #1d3fb8; --accent-soft: #e7edfd;
  --rev: #2f5bea; --rev-future: #c9d6fb; --cost: #8b95a7; --cost-future: #e1e5ec; --bal: #0f9b8e; --bal-soft: #d8f1ee;
  --good: #12805c; --good-soft: #dcf5ea; --bad: #c0362c; --bad-soft: #fde7e4; --warn: #8a5a00; --warn-soft: #fff3d6;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --sidebar: 236px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 Inter, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
a { color: var(--accent); }

/* ── Login ─────────────────────────────────────────── */
#login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero { background: linear-gradient(150deg, #1d3fb8 0%, #2f5bea 55%, #0f9b8e 130%); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-hero h1 { font-size: 34px; line-height: 1.15; margin: 0 0 14px; max-width: 460px; }
.login-hero p { opacity: .85; max-width: 420px; margin: 0; }
.login-hero ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 10px; }
.login-hero li::before { content: "✓"; margin-right: 10px; opacity: .8; }
.login-pane { display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; position: relative; }
.login-card h2 { margin: 0 0 4px; font-size: 22px; }
.login-card .sub { margin-bottom: 18px; }
@media (max-width: 860px) { #login { grid-template-columns: 1fr; } .login-hero { display: none; } }

/* ── Controls ──────────────────────────────────────── */
label.field { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
input[type=email], input[type=password], input[type=text], input[type=date], input[type=month], input[type=number], select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-height: 36px; }
.w-full { width: 100%; }
input:focus, select:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.btn { padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; white-space: nowrap; min-height: 36px; }
.btn:hover { background: #f2f4f8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 3px 10px; min-height: 28px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; min-height: 34px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
.error { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 10px; }
.status { font-size: 13px; color: var(--muted); }
.status.ok { color: var(--good); } .status.err { color: var(--bad); }
.sub { color: var(--muted); font-size: 12.5px; }

/* ── Shell ─────────────────────────────────────────── */
#app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: #0f1729; color: #c8d0e0; padding: 18px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: #fff; padding: 4px 8px 18px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(140deg, #2f5bea, #0f9b8e); display: grid; place-items: center; flex: none; }
.logo svg { width: 18px; height: 18px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: inherit; text-decoration: none; }
.nav a svg { width: 18px; height: 18px; opacity: .8; flex: none; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.on { background: rgba(47, 91, 234, .28); color: #fff; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6f7c95; padding: 14px 10px 4px; }
.sidebar .spacer { flex: 1; }
.sidebar .seg { background: transparent; border-color: #2a3550; align-self: flex-start; margin: 0 8px; }
.sidebar .seg button { color: #c8d0e0; } .sidebar .seg button + button { border-left-color: #2a3550; }
.sidebar .seg button.on { background: rgba(47, 91, 234, .35); color: #fff; }
.side-user { font-size: 12.5px; padding: 10px 8px 0; color: #8d99b3; word-break: break-all; }

.topbar { position: sticky; top: 0; z-index: 5; background: rgba(245, 246, 250, .9); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.topbar-in { padding: 12px 28px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; margin: 0; font-weight: 650; }
.topbar .spacer { flex: 1; }
.org-pick { display: flex; align-items: center; gap: 8px; }
main { padding: 22px 28px 60px; display: grid; gap: 18px; max-width: 1320px; width: 100%; }
.menu-btn { display: none; }

/* ── Cards ─────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 15px; margin: 0; font-weight: 650; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head .spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }
.grid-2e { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); 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: 4px; background: var(--rev); }
.kpi.cost::before { background: var(--cost); } .kpi.bal::before { background: var(--bal); }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 25px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .note { margin-top: 4px; font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.delta { font-weight: 600; padding: 1px 7px; border-radius: 99px; font-size: 12px; }
.delta.up { background: var(--good-soft); color: var(--good); } .delta.down { background: var(--bad-soft); color: var(--bad); }
.delta.flat { background: #eef0f4; color: var(--muted); }

.chart-wrap { position: relative; height: 300px; }
.chart-wrap.short { height: 230px; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--soft); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f6f8fd; }
tr.total td { font-weight: 650; border-top: 2px solid var(--line); background: var(--soft); }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.table-scroll table tr:last-child td { border-bottom: 0; }
.empty { color: var(--muted); padding: 28px 10px; text-align: center; }
.bar-cell { position: relative; }
.bar-cell .bar { position: absolute; left: 0; top: 6px; bottom: 6px; background: var(--accent-soft); border-radius: 4px; z-index: 0; }
.bar-cell span { position: relative; z-index: 1; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill.revenue, .pill.draft { background: var(--accent-soft); color: var(--accent-2); }
.pill.cost, .pill.deleted, .pill.voided, .pill.soon { background: #eceff3; color: #475467; }
.pill.preview, .pill.shadow { background: var(--warn-soft); color: var(--warn); }
.pill.posted, .pill.live, .pill.ok { background: var(--good-soft); color: var(--good); }
.pill.failed { background: var(--bad-soft); color: var(--bad); }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 12px; color: var(--muted); }
.search { min-width: 260px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--accent-2); border-bottom-color: var(--accent); font-weight: 600; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.stat-list { display: grid; gap: 10px; }
.stat-list div { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
.stat-list div:last-child { border-bottom: 0; }
.integ { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.integ .card { display: flex; flex-direction: column; gap: 12px; }
.integ-logo { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; color: #fff; }
.settings-grid { display: grid; gap: 14px; max-width: 760px; }
.settings-grid label { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.jl td.dr, .jl td.cr { text-align: right; }

/* ── Drawer ────────────────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(15, 20, 30, .38); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100%); background: var(--card); z-index: 21; overflow-y: auto; box-shadow: -10px 0 30px rgba(20, 30, 50, .15); }
.drawer-head { position: sticky; top: 0; background: var(--card); border-bottom: 1px solid var(--line); padding: 16px 22px; display: flex; align-items: flex-start; gap: 12px; z-index: 1; }
.drawer-head h3 { margin: 0; font-size: 17px; }
.drawer-body { padding: 18px 22px 32px; display: grid; gap: 16px; }
.line-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.line-card .top { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.line-card .desc { font-weight: 600; flex: 1; }
.meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; margin: 6px 0 10px; }
.sched { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.sched td, .sched th { padding: 6px 10px; }
.sched tr.past td { color: var(--muted); }

/* ── Responsive / print ────────────────────────────── */
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-2, .grid-2e { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar); z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar-in, main { padding-left: 16px; padding-right: 16px; }
  .search { min-width: 0; width: 100%; }
}
@media (max-width: 520px) { .kpis { grid-template-columns: 1fr; } }
@media print {
  .sidebar, .topbar, .no-print, .scrim, .drawer { display: none !important; }
  #app { display: block; } main { padding: 0; } .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}
