/* App shell + component styles. Sharp edges, minimal chrome, sidebar navigation. */

* { box-sizing: border-box; }

/* No spin-button arrows on any number input, anywhere (see gm_context_prompt_v1.yaml ui_interaction_standards) — they add width, misalign with adjacent fields, and this app has no use for click-to-increment. */
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#root { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */

.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 0;
}

.sidebar-brand {
  padding: 0 16px 16px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.sidebar-brand small {
  display: block;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 2px;
}

.sidebar-nav { flex: 1; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  border-left: 2px solid transparent;
  font-size: 13px;
  user-select: none;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.nav-item .icon { width: 16px; height: 16px; flex: 0 0 16px; }

.sidebar-footer {
  padding: 12px 16px 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Main area ───────────────────────────────────────────────────────── */

.main { flex: 1; overflow-y: auto; }

.page { padding: 24px 28px 48px; max-width: 1200px; }

/* Views with content that genuinely wants the full viewport width (e.g. the Sales Pipeline
   Kanban board) opt out of the 1200px reading-width cap via this modifier, added by the view
   itself — see app.js renderRoute(), which resets #page's class on every navigation so this
   never leaks onto other views. */
.page.page-wide { max-width: none; }

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.page-title { font-size: 19px; font-weight: 700; margin: 0; }
.page-subtitle { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }

/* ── Cards / tiles ───────────────────────────────────────────────────── */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card + .card { margin-top: 14px; }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.tile {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.tile-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.tile-value { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.tile-value.positive { color: var(--positive); }
.tile-value.negative { color: var(--negative); }
.tile-value.warning { color: var(--warning); }

.link-plain { color: inherit; text-decoration: none; cursor: pointer; border-bottom: 1px dashed var(--border-strong); }
.link-plain:hover { color: var(--accent); border-bottom-color: var(--accent); }

.tile-link, .card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.12s ease;
}
.tile-link:hover, .card-link:hover { border-color: var(--accent); }

/* ── Tables ──────────────────────────────────────────────────────────── */

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table .num { text-align: right; }
.data-table .empty-row td { text-align: center; color: var(--text-faint); padding: 24px; }

/*
 * ── Vertical rhythm ─────────────────────────────────────────────────────
 * .stack: consistent gap between sibling blocks (form sections, a table
 * followed by a toggle, etc.) via the spacing scale (tokens.css), instead
 * of a one-off inline margin-top picked per call site. .section-divider
 * additionally draws the border line used to separate grouped sub-sections
 * inside one card/form (was previously copy-pasted inline with a
 * different pixel value each time it was needed).
 */
.stack > * + * { margin-top: var(--space-4); }
.stack-sm > * + * { margin-top: var(--space-2); }
.section-divider { border-top: 1px solid var(--border); padding-top: var(--space-3); }

/* ── Forms ───────────────────────────────────────────────────────────── */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; }

.field label { font-size: 11.5px; color: var(--text-muted); font-weight: 600; }

.field input:not([type="checkbox"]), .field select, .field textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 9px;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.field.checkbox { flex-direction: row; align-items: center; gap: 8px; }

/* ── Toggle switch (used instead of a plain checkbox for an on/off choice with a visible consequence, e.g. "has a trade-in") ── */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: background 0.15s; pointer-events: none; }
.switch-track::before { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.15s; }
.switch input:checked ~ .switch-track { background: var(--accent); }
.switch input:checked ~ .switch-track::before { transform: translateX(16px); }
.switch input:focus-visible ~ .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.field.switch-field { flex-direction: row; align-items: center; gap: 10px; }

/*
 * ── Pill toggle (Exchange/Finance "enable this row" control) ──
 * A two-state status button rather than a slider — reads as "Pending" vs
 * "Approved"/"Enabled", which fits a table's first column (where the
 * .switch component doesn't) better than an on/off switch does. Same
 * underlying single-click toggle behavior either way.
 */
.pill-toggle {
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  background: var(--bg-elevated);
  color: var(--text-muted);
  white-space: nowrap;
}
.pill-toggle:hover { background: var(--bg-hover); }
.pill-toggle.on { background: var(--positive-soft); border-color: var(--positive); color: var(--positive); }

/* ── Ledger-style table footer (running total) ── */
.data-table tfoot td { border-top: 2px solid var(--border-strong); font-weight: 700; padding-top: 8px; }
.payment-add-row td { padding: 6px 10px; }

/* Inline, per-field validation shown on blur (see gm_context_prompt_v1.yaml ui_interaction_standards) — not a submit-time alert/toast. */
.field-error { color: var(--negative); font-size: 11px; margin-top: 3px; }
.field input.invalid { border-color: var(--negative); }

/* ── Buttons ─────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn:hover { background: var(--bg-hover); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger { color: var(--negative); border-color: var(--negative); background: transparent; }
.btn-danger:hover { background: var(--negative-soft); }

/*
 * Sizing is height-driven, not padding-driven — every default-size button
 * (icon or text) is 32px tall, every .btn-sm is 26px tall, so a row mixing
 * a text button ("Save Payment") with an icon button (Edit/Delete) lines up
 * instead of the icon button looking short. Icon buttons are square at
 * that height, never stretched by their padding like text buttons are.
 */
.btn { height: 32px; }
.btn-sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn-icon { width: 32px; padding: 0; justify-content: center; }
.btn-icon.btn-sm { width: 26px; }

/* ── Badges ──────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge-positive { background: var(--positive-soft); color: var(--positive); }
.badge-negative { background: var(--negative-soft); color: var(--negative); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-neutral { background: var(--bg-hover); color: var(--text-muted); }

/* ── Modal ───────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px; overflow-y: auto; z-index: 50;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  padding: 20px;
}

.modal-wide { max-width: 860px; }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 18px; }

/* ── Toast / banner ──────────────────────────────────────────────────── */

.banner {
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.banner-success { background: var(--positive-soft); color: var(--positive); border-color: var(--positive); }
.banner-error { background: var(--negative-soft); color: var(--negative); border-color: var(--negative); }
.banner-info { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}

.toast {
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  border: 1px solid transparent;
  box-shadow: var(--shadow);
  cursor: pointer;
  animation: toast-in 0.15s ease-out;
}

.toast-leaving { animation: toast-out 0.18s ease-in forwards; }

.toast-error { background: var(--negative-soft); color: var(--negative); border-color: var(--negative); }
.toast-success { background: var(--positive-soft); color: var(--positive); border-color: var(--positive); }
.toast-info { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px); } }

/* ── Chart containers ────────────────────────────────────────────────── */

.chart-card { padding: 14px 16px 8px; }
.chart-card .chart-title { font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.chart-container { width: 100%; height: 220px; }

/* ── Tabs ────────────────────────────────────────────────────────────── */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }

.tab {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Calendar grid ───────────────────────────────────────────────────── */

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }

.cal-weekday {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0 2px 4px;
}

.cal-cell {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  min-height: 64px;
  cursor: pointer;
}

.cal-cell:hover { border-color: var(--accent); background: var(--bg-hover); }
.cal-cell-empty { border: none; cursor: default; }
.cal-cell-empty:hover { border: none; background: none; }
.cal-cell-selected { border-color: var(--accent); background: var(--accent-soft); }

.cal-cell-daynum { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.cal-cell-amt { font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cal-cell-in { color: var(--positive); }
.cal-cell-out { color: var(--negative); }

@media (max-width: 700px) {
  .cal-grid { grid-template-columns: repeat(7, minmax(38px, 1fr)); }
  .cal-cell { padding: 4px; min-height: 48px; }
  .cal-cell-amt { font-size: 9.5px; }
}

/* ── Category trend + donut rows (Calendar view) ────────────────────────── */

.kind-row { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.kind-row-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.kind-row-header h3 { margin: 0; }
.kind-donut-wrap { display: flex; align-items: center; justify-content: center; min-height: 140px; }

@media (max-width: 900px) { .kind-row { grid-template-columns: 1fr; } }

/* ── Utility ─────────────────────────────────────────────────────────── */

.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-positive { color: var(--positive); }
.text-negative { color: var(--negative); }
.mt-0 { margin-top: 0; }
.flex-row { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; }

/* ── Mobile shell ────────────────────────────────────────────────────────
   The employee using this app day to day is mostly on a phone, not a
   desktop — this isn't a cosmetic breakpoint, it's the primary way this
   app gets used. Below 640px the fixed 220px sidebar (over half a typical
   360-400px phone's width) becomes a horizontally-scrollable top tab bar
   instead: icon-over-label nav items, brand text and the sync-status
   string hidden (not needed once you're actually using the app, and both
   cost more width than they're worth on a phone), theme-toggle/log-out
   stay visible. #root/.main switch from the desktop's fixed-viewport
   flex-scroll layout to normal document flow, since two independently
   scrolling panes is a worse mobile pattern than one page that just
   scrolls. */
@media (max-width: 640px) {
  #root { flex-direction: column; height: auto; min-height: 100vh; overflow: visible; }

  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    padding: 4px 6px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .sidebar-brand { display: none; }

  .sidebar-nav {
    flex: 1;
    display: flex;
    overflow-x: auto;
    gap: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .nav-item {
    flex: 0 0 auto;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 6px 11px;
    border-left: none;
    border-bottom: 2px solid transparent;
    font-size: 10px;
    text-align: center;
    white-space: nowrap;
  }

  .nav-item.active { border-left-color: transparent; border-bottom-color: var(--accent); }
  .nav-item .icon { width: 18px; height: 18px; flex: 0 0 18px; margin: 0 auto; }

  .sidebar-footer {
    flex: 0 0 auto;
    border-top: none;
    padding: 0 0 0 4px;
    gap: 6px;
  }

  .sidebar-footer > .text-faint { display: none; } /* "Synced just now" — not worth the width on a phone */

  .main { overflow-y: visible; }
  .page { padding: 14px 12px 36px; max-width: 100%; }

  /* Any content still wider than the phone (a dense table, a form-grid row that
     doesn't quite wrap) scrolls its own row instead of breaking the page layout. */
  .page { overflow-x: auto; }

  .modal-backdrop { padding: 16px 10px; align-items: stretch; }
  .modal { padding: 16px; }
}
::-webkit-scrollbar-track { background: transparent; }
