:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1d212b; --line: #2a2f3a;
  --text: #e8eaed; --muted: #9aa3b2; --accent: #ffb703; --accent2: #2a9d8f;
  --neg: #ef4444; --pos: #22c55e; --radius: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; color: var(--text); }
.brand span { color: var(--muted); font-weight: 500; }
.topbar nav a { margin-left: 16px; }

main { max-width: 1200px; margin: 0 auto; padding: 18px; }
footer { text-align: center; color: var(--muted); padding: 24px; font-size: 13px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
h1 { margin: 0 0 6px; font-size: 22px; }
h2 { margin: 0 0 8px; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--neg); }
code { background: var(--panel2); padding: 1px 6px; border-radius: 6px; }

input, select, button {
  font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
button {
  background: var(--accent); color: #1a1300; font-weight: 600; cursor: pointer;
  border: none;
}
button:hover { filter: brightness(1.05); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.sync { background: var(--accent2); color: #04211d; }
button.save { background: var(--accent); }
.link-danger { background: none; color: var(--neg); padding: 2px 6px; }
a.btn-ghost {
  display: inline-block; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; background: var(--panel2); color: var(--text);
}
a.btn-ghost:hover { text-decoration: none; border-color: var(--accent); }
.pos-text { color: var(--pos); }
.neg-text { color: var(--neg); }

/* login */
.login-card { max-width: 360px; margin: 8vh auto; text-align: center; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

/* periods */
.new-period { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.new-period .field { display: flex; flex-direction: column; gap: 4px; }
.new-period label { font-size: 12px; color: var(--muted); }
table.periods { width: 100%; border-collapse: collapse; }
table.periods th, table.periods td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line);
}
.inline { display: inline; }

/* period grid */
.period-head { display: flex; justify-content: space-between; align-items: end; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.period-switch { display: flex; flex-direction: column; gap: 4px; }
.period-switch label { font-size: 12px; color: var(--muted); }
.toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.banner.ok { background: #11302a; color: #8ff0d8; border: 1px solid #1c5; }
.banner.err { background: #361717; color: #ffb4b4; border: 1px solid #a33; }

/* The wrapper is the scroll container for BOTH axes, with a bounded height so
   the header and first column stick within it (top:0 / left:0), instead of the
   header being pushed down onto the first product row. */
.grid-wrap {
  overflow: auto; max-height: calc(100dvh - 150px);
  border: 1px solid var(--line); border-radius: var(--radius);
}
table.grid { border-collapse: collapse; width: 100%; min-width: 900px; }
table.grid th, table.grid td {
  padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: center;
  white-space: nowrap;
}
table.grid thead th { background: var(--panel2); position: sticky; top: 0; z-index: 5; font-size: 13px; }
.sticky-col { position: sticky; left: 0; background: var(--panel); text-align: left !important; z-index: 6; }
thead .sticky-col { z-index: 7; background: var(--panel2); }
.prod { font-weight: 600; }
.prod .unit { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.cat-row td { text-align: left; background: #12151c; color: var(--accent); font-weight: 700; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }

input.num { width: 64px; text-align: center; padding: 6px; }
input.num.sales { background: #14202b; color: #9fd3ff; }
input.notes { width: 160px; text-align: left; }
.calc { background: #12151c; color: var(--muted); font-variant-numeric: tabular-nums; }
.var.neg { color: var(--neg); font-weight: 700; }
.var.pos { color: var(--pos); font-weight: 700; }
.notes-col { min-width: 160px; }

.save-bar { display: flex; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.map-add { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

.period-switch select { min-width: 170px; }
@media (max-width: 480px) {
  .period-switch select { min-width: 100%; font-size: 16px; padding: 11px 12px; }
}
