:root {
  --bg: #f5f6fa; --card: #fff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #6366f1; --green: #10b981; --red: #ef4444; --blue: #3b82f6; --amber: #f59e0b;
  --side: #111827; --side-text: #cbd5e1;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b0f19; --card: #151b2b; --text: #e5e7eb; --muted: #94a3b8; --line: #263045; --side: #070a12; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); font-weight: 400; }
.xs { font-size: 12px; }
.pos { color: var(--green); } .neg { color: var(--red) !important; }

/* sidebar */
.side { width: 220px; background: var(--side); color: var(--side-text); padding: 20px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; flex-shrink: 0; }
.brand { font-size: 18px; color: #fff; padding: 0 10px 18px; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a { color: var(--side-text); padding: 9px 10px; border-radius: 8px; display: flex; gap: 10px; }
.side nav a:hover { background: #1f2937; }
.side nav a.on { background: var(--accent); color: #fff; }
.side-foot { display: flex; justify-content: space-between; padding: 10px; font-size: 12px; }

main { flex: 1; padding: 24px 28px 60px; max-width: 1400px; min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

/* period chips */
.periods { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--text); font-size: 13px; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.periods input[type=date] { padding: 5px 8px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; color: var(--text); display: block; }
.kpi .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kpi .val { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpis.small .kpi .val { font-size: 20px; }
.kpi .val small { font-size: 14px; color: var(--muted); font-weight: 500; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.hero { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; border: 0; }
.kpi.hero .lbl, .kpi.hero .sub { color: #e0e7ff; }
.kpi.hero .val.neg { color: #fecaca !important; }
a.kpi:hover { border-color: var(--accent); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > * { min-width: 0; }
.chart { height: 260px; position: relative; }
.tips ul { margin: 0; padding-left: 18px; } .tips li { margin: 4px 0; }
.tips { border-left: 4px solid var(--amber); }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 12px; }
.danger { display: flex; gap: 8px; }

/* tables */
.tbl { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr[onclick] { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.r { text-align: right; white-space: nowrap; }
.clip { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; vertical-align: middle; }
.tag.green { background: #d1fae5; color: #065f46; } .tag.red { background: #fee2e2; color: #991b1b; }
.tag.blue { background: #dbeafe; color: #1e40af; } .tag.amber { background: #fef3c7; color: #92400e; }

/* forms */
input, select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); width: 100%; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; align-items: end; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form .wide { grid-column: 1 / -1; }
.form.inline { display: flex; margin-top: 10px; }
.btn { font: inherit; background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { filter: brightness(1.1); }
.btn.sm { padding: 6px 12px; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.red { background: var(--red); }
.x { background: none; border: 0; color: var(--muted); cursor: pointer; }
.search input { width: 280px; }

.login { align-items: center; justify-content: center; }
.loginbox { width: 320px; display: flex; flex-direction: column; gap: 12px; }
.loginbox .brand { color: var(--text); padding: 0; }

@media (max-width: 900px) {
  body { flex-direction: column; }
  .side { width: 100%; height: auto; position: sticky; z-index: 5; padding: 10px 8px; }
  .brand, .side-foot { display: none; }
  .side nav { flex-direction: row; overflow-x: auto; }
  .side nav a { white-space: nowrap; padding: 7px 10px; }
  main { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .search, .search input { width: 100%; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi .val { font-size: 19px; }
}
.periods input[type=date] { width: auto; }
