:root {
  --bg: #0f1420;
  --bg-2: #161d2e;
  --card: #1b2236;
  --card-2: #212a42;
  --line: #2b3550;
  --text: #e6ebf5;
  --muted: #93a0bd;
  --accent: #5b8cff;
  --accent-2: #38d39f;
  --santos: #5b8cff;
  --esmichu: #ff7eb6;
  --warn: #ffb454;
  --danger: #ff6b6b;
  --ok: #38d39f;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0,0,0,.28);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1d2740 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

a { color: var(--accent); }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 14px 22px;
  background: rgba(15,20,32,.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 800; color: #08111f;
}
.brand h1 { font-size: 17px; margin: 0; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 12px; }

.controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.control { display: flex; flex-direction: column; gap: 3px; }
.control label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

select, input, button, textarea {
  font: inherit; color: var(--text);
  background: var(--card-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 11px; outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
button { cursor: pointer; }

.seg { display: inline-flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  border: none; background: transparent; padding: 7px 14px; border-radius: 7px;
  color: var(--muted); font-weight: 600;
}
.seg button.active { background: var(--accent); color: #08111f; }
.seg button.active.santos { background: var(--santos); }
.seg button.active.esmichu { background: var(--esmichu); color: #2a0a1a; }

.btn-primary { background: linear-gradient(135deg, var(--accent), #4a7bff); color: #08111f; border: none; font-weight: 700; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { border-color: var(--accent); }
.icon-btn { background: transparent; border: 1px solid transparent; padding: 5px 8px; border-radius: 7px; }
.icon-btn:hover { background: var(--card-2); border-color: var(--line); }

main { padding: 18px; max-width: 1760px; margin: 0 auto; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi .k-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.kpi .k-value { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.accent::after { content:''; position:absolute; inset:0 auto 0 0; width:4px; background: var(--accent); }
.kpi.santos::after { content:''; position:absolute; inset:0 auto 0 0; width:4px; background: var(--santos); }
.kpi.esmichu::after { content:''; position:absolute; inset:0 auto 0 0; width:4px; background: var(--esmichu); }
.pos { color: var(--ok); } .neg { color: var(--danger); }

/* ---------- charts ---------- */
.charts { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; margin-bottom: 18px; }
.charts .wide { grid-column: 1 / -1; }
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 12px; font-size: 14px; font-weight: 700; color: var(--text); display:flex; align-items:center; gap:8px; }
.panel h3 small { color: var(--muted); font-weight: 500; }
.chart-wrap { position: relative; height: 280px; }
.chart-wrap.sm { height: 240px; }
@media (max-width: 900px) { .charts { grid-template-columns: 1fr; } }

/* ---------- table ---------- */
.table-panel { padding: 0; overflow: hidden; }
.table-head { display:flex; align-items:center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 12.5px; }
th, td { padding: 6px 7px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); z-index: 1; padding-left: 12px; }
td:last-child, th:last-child { padding-left: 2px; padding-right: 8px; }
thead th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .02em; font-weight: 600; background: var(--bg-2); position: sticky; top: 0; }
thead th:first-child { z-index: 2; background: var(--bg-2); }
tbody tr.clickable { cursor: pointer; }
tbody tr:hover td { background: var(--card-2); }
tbody tr:hover td:first-child { background: var(--card-2); }
td.calc { color: var(--muted); }
td.total { font-weight: 700; color: var(--text); }
.col-santos { color: #aac4ff; }
.col-esmichu { color: #ffc1de; }
.dim { opacity: .35; }
tfoot td { font-weight: 700; background: var(--bg-2); border-top: 2px solid var(--line); }
.note-dot { color: var(--warn); cursor: help; }
.row-actions { display: inline-flex; gap: 2px; }
.muted { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(6,9,16,.6); backdrop-filter: blur(3px);
  display: none; align-items: flex-start; justify-content: center; z-index: 50; padding: 30px 16px; overflow:auto;
}
.modal-back.open { display: flex; }
.modal {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px;
  width: min(820px, 100%); box-shadow: var(--shadow);
}
.modal header { display:flex; align-items:center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 17px; }
.modal .body { padding: 18px 20px; }
.modal footer { display:flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.fieldset legend { padding: 0 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field:last-child { margin-bottom: 0; }
.field label { font-size: 12px; color: var(--muted); display:flex; justify-content: space-between; align-items:center; }
.field input[type=number], .field input[type=text], .field textarea, .field select { width: 100%; }
.field .with-note { display:flex; gap: 6px; }
.field .with-note input { flex: 1; }
.note-toggle { border: 1px solid var(--line); background: var(--card-2); border-radius: 8px; padding: 0 10px; color: var(--muted); }
.note-toggle.has { color: var(--warn); border-color: var(--warn); }
.note-input { margin-top: 4px; }
.preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 4px; }
.preview .p { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.preview .p .pl { font-size: 11px; color: var(--muted); }
.preview .p .pv { font-size: 17px; font-weight: 700; }
.help { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }
@media (max-width: 680px) { .form-grid { grid-template-columns: 1fr; } }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--card); border: 1px solid var(--line); padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow); opacity: 0; transition: .25s; z-index: 80;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--danger); }
