:root {
  --bg: #0a0e1a;
  --bg-card: #0f1423;
  --surface: #161c30;
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.16);
  --text: #e8eaf0;
  --text-2: rgba(232,234,240,0.7);
  --text-3: rgba(232,234,240,0.45);
  --accent: #4a6cf7;
  --accent-soft: rgba(74,108,247,0.18);
  --accent-bright: #8ba4ff;
  --ok: #4fbf8a;
  --warn: #d9a441;
  --font: 'Inter', -apple-system, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; }
h1, h2 { margin: 0; font-weight: 500; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.05rem; }
.muted { color: var(--text-3); font-size: 0.85rem; margin: 0; }
button, input, select { font: inherit; color: inherit; }

.btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 0.5rem 0.9rem; border-radius: 8px; cursor: pointer; font-size: 0.85rem;
  transition: border-color 0.2s ease, transform 0.1s ease;
}
.btn:hover { border-color: var(--border-hover); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 2px; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: #5b7bff; }
.btn--danger { padding: 0.25rem 0.55rem; font-size: 0.8rem; }
.btn--danger:hover { border-color: #c0564f; color: #ff9a93; }

/* Gate */
.gate { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); padding: 1rem; }
.gate__card { width: min(360px, 100%); background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; display: grid; gap: 0.6rem; }
.gate__logo { width: 220px; height: auto; margin: 0 auto 0.75rem; }
.gate__card label { font-size: 0.85rem; color: var(--text-2); }
.gate__card input { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.75rem; }
.gate__err { color: #ff9a93; font-size: 0.85rem; margin: 0; }

/* Layout */
.top {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: 1.25rem clamp(1rem, 4vw, 3rem); border-bottom: 1px solid var(--border);
}
.top__logo { width: 200px; height: auto; }
.top__title { flex: 1; min-width: 160px; }
.top__actions { display: flex; gap: 0.5rem; }
main { padding: 1.5rem clamp(1rem, 4vw, 3rem) 3rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.5rem; max-width: 1280px; margin: 0 auto; }
main > * { min-width: 0; }
.foot { padding: 1rem clamp(1rem, 4vw, 3rem) 2rem; border-top: 1px solid var(--border); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.kpi { background: var(--bg-card); padding: 1.1rem 1.25rem; display: grid; gap: 0.15rem; }
.kpi__label { font-size: 0.78rem; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.kpi__value { font-family: var(--mono); font-size: 1.9rem; font-weight: 500; letter-spacing: -0.02em; }
.kpi__value--sm { font-size: 1.25rem; }
.kpi__sub { font-size: 0.8rem; color: var(--text-3); }

.panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.panel__head { display: grid; gap: 0.2rem; margin-bottom: 1rem; }

/* Month chart (SVG) */
.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; width: 100%; height: auto; font-family: var(--mono); }
.chart .grid line { stroke: rgba(255,255,255,0.07); }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .bar { fill: var(--accent); rx: 4; transition: fill 0.15s ease; }
.chart .bar:hover, .chart .bar:focus { fill: var(--accent-bright); outline: none; }
.chart .bar--now { fill: var(--accent-bright); }
.chart .vlabel { fill: var(--text-2); font-size: 11px; text-anchor: middle; }

/* Item bars (HTML) */
.bars { display: grid; gap: 0.55rem; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 200px) 1fr 80px; gap: 0.75rem; align-items: center; font-size: 0.88rem; }
.bar-row__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row__track { height: 14px; position: relative; }
.bar-row__fill { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; transition: background 0.15s ease, width 0.4s cubic-bezier(0.16,1,0.3,1); }
.bar-row:hover .bar-row__fill { background: var(--accent-bright); }
.bar-row__fill--estimate { background: var(--accent-soft); border: 1px solid var(--accent); }
.bar-row__fill--free { background: transparent; border: 1px dashed var(--text-3); }
.bar-row__val { font-family: var(--mono); text-align: right; color: var(--text-2); }

/* Table */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 0.6rem 0.6rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
th { font-weight: 500; color: var(--text-3); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
tfoot th { color: var(--text); font-size: 0.88rem; text-transform: none; letter-spacing: 0; border-bottom: 0; border-top: 1px solid var(--border-hover); }
.num { text-align: right; font-family: var(--mono); }
td input[type=number] { width: 96px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.3rem 0.45rem; font-family: var(--mono); text-align: right; }
td select { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.3rem 0.4rem; }
td.note { color: var(--text-2); font-size: 0.8rem; max-width: 320px; }
td.plan { color: var(--text-2); }
.status { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot--confirmed { background: var(--ok); }
.dot--estimate { background: var(--warn); }
.dot--free { background: transparent; border: 1px solid var(--text-3); }
.legend { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-top: 0.9rem; font-size: 0.8rem; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }

/* Add form */
.addform { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; align-items: end; margin-top: 0.9rem; }
.field { display: grid; gap: 0.3rem; }
.field label { font-size: 0.78rem; color: var(--text-2); }
.field input, .field select { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.65rem; width: 100%; }

/* Tooltip */
.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface); border: 1px solid var(--border-hover); border-radius: 8px; padding: 0.55rem 0.7rem; font-size: 0.8rem; max-width: 280px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.tip strong { display: block; font-family: var(--mono); margin-bottom: 0.2rem; }
.tip ul { margin: 0.25rem 0 0; padding-left: 1rem; color: var(--text-2); }

.table-only .panel:not([aria-labelledby="h-table"]):not([aria-labelledby="h-add"]) { display: none; }

@media (max-width: 640px) {
  .top { gap: 0.75rem; }
  .top__logo { width: 150px; }
  .chart svg { min-width: 640px; }
  .bar-row { grid-template-columns: 1fr auto; grid-template-areas: "name val" "track track"; gap: 0.2rem 0.75rem; }
  .bar-row__name { grid-area: name; }
  .bar-row__val { grid-area: val; }
  .bar-row__track { grid-area: track; }
  .kpi__value { font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
