/* JTA Core — the one stylesheet. Dark, dense, desktop-first, usable on mobile. */

:root {
  --bg: #0A0A0A;
  --card: #0D1A2B;
  --gold: #F4A261;
  --positive: #0D2B0D;
  --negative: #E63946;
  --text: #F2F2F2;
  --text-dim: #9AA5B1;
  --border: #1C2B3A;
}

* { box-sizing: border-box; }

/* The `hidden` attribute is toggled throughout app.js/finance.js to
   show/hide whole screens and nav tiles (login vs. app shell, Command
   Center nav, department tiles, view panels, form panels...). Several of
   those elements also carry an author rule setting `display: flex`/`block`
   on their class (`.app-shell`, `.login-screen`, `.nav-section`,
   `.nav-tile`, ...). Same-specificity author rules always beat the
   browser's UA-stylesheet default of `[hidden] { display: none }`, so
   without this, `el.hidden = true` silently does nothing on any element
   whose class sets its own `display`. One `!important` rule here, instead
   of chasing every individual class, is the actual fix. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Mono', ui-monospace, monospace;
  height: 100%;
}

h1, h2, h3, .brand-font {
  font-family: 'Archivo Black', sans-serif;
  font-weight: 400;
  letter-spacing: 0.02em;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

/* ── login screen ── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 40px 32px;
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.login-mark {
  font-family: 'Archivo Black', sans-serif;
  font-size: 22px;
  color: var(--gold);
  letter-spacing: 0.08em;
}

.login-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 28px;
}

.pin-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 26px;
  letter-spacing: 0.4em;
  text-align: center;
  padding: 12px 8px;
  margin-bottom: 16px;
}

.pin-input:focus {
  outline: none;
  border-color: var(--gold);
}

.btn-primary {
  width: 100%;
  background: var(--gold);
  color: #0A0A0A;
  border: none;
  border-radius: 6px;
  padding: 12px;
  font-family: 'Archivo Black', sans-serif;
  font-size: 13px;
  letter-spacing: 0.05em;
}

.btn-primary:active { opacity: 0.85; }

.login-error {
  margin-top: 14px;
  color: var(--negative);
  font-size: 12px;
}

/* ── app shell ── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-brand {
  font-family: 'Archivo Black', sans-serif;
  color: var(--gold);
  font-size: 15px;
  letter-spacing: 0.06em;
  padding: 6px 8px 18px;
}

.nav-heading {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  padding: 14px 8px 6px;
}

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

.nav-tile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  padding: 10px 10px;
  font-size: 13px;
  text-align: left;
}

.nav-tile:hover:not(:disabled) {
  border-color: var(--border);
  background: rgba(244, 162, 97, 0.06);
}

.nav-tile.active {
  background: rgba(244, 162, 97, 0.14);
  border-color: var(--gold);
  color: var(--gold);
}

.nav-tile-cc {
  font-family: 'Archivo Black', sans-serif;
  font-size: 12px;
}

.nav-tile-disabled {
  color: var(--text-dim);
  cursor: not-allowed;
  opacity: 0.55;
}

.nav-tile-tag {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
  color: var(--text-dim);
  white-space: nowrap;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-family: 'Archivo Black', sans-serif;
  font-size: 16px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.whoami {
  font-size: 12px;
  color: var(--text-dim);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 12px;
}

.btn-ghost:hover { border-color: var(--gold); color: var(--gold); }

.content {
  padding: 24px;
  overflow-y: auto;
}

.view[hidden] { display: none; }

/* ── stat cards ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  max-width: 900px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
}

/* ── placeholder panels (departments not built yet) ── */
.placeholder-panel {
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 28px;
  max-width: 640px;
}

.placeholder-title {
  font-family: 'Archivo Black', sans-serif;
  font-size: 16px;
  color: var(--gold);
  margin-bottom: 10px;
}

.placeholder-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-dim);
  margin: 0;
}

/* ══════════════════════ Finance department ══════════════════════ */

:root {
  /* Legible-on-dark-bg variants of the design system's core colors, used
     only for text/borders where the base --positive/--negative are too
     dark/saturated to read against var(--card). The base tokens themselves
     are untouched. */
  --positive-text: #6FCF7E;
  --negative-tint: rgba(230, 57, 70, 0.10);
  --positive-tint: rgba(111, 207, 126, 0.10);
  --gold-tint: rgba(244, 162, 97, 0.12);
}

.fin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
}

.btn-icon {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { border-color: var(--gold); color: var(--gold); }

.month-label {
  font-family: 'Archivo Black', sans-serif;
  font-size: 13px;
  min-width: 130px;
  text-align: center;
  padding: 0 4px;
}

.fin-toolbar-right { display: flex; align-items: center; gap: 10px; }

.locked-banner {
  background: var(--gold-tint);
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  font-family: 'Archivo Black', sans-serif;
  letter-spacing: 0.03em;
  margin-bottom: 14px;
}

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

.fin-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 9px 14px;
  font-size: 12px;
  font-family: 'Archivo Black', sans-serif;
  letter-spacing: 0.03em;
  margin-bottom: -1px;
}
.fin-tab:hover { color: var(--text); }
.fin-tab.active { color: var(--gold); border-bottom-color: var(--gold); }

.fin-panel[hidden] { display: none; }

/* ── generic panel/card ── */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
}

.panel-title {
  font-family: 'Archivo Black', sans-serif;
  font-size: 13px;
  color: var(--gold);
  margin-bottom: 12px;
  letter-spacing: 0.02em;
}

.panel-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

/* ── buttons ── */
.btn-secondary {
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 12px;
  font-family: 'Archivo Black', sans-serif;
  letter-spacing: 0.02em;
}
.btn-secondary:hover { background: var(--gold-tint); }
.btn-secondary:disabled, .btn-ghost:disabled, .btn-icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: var(--border) !important;
  color: var(--text-dim) !important;
  background: transparent !important;
}

.btn-small {
  padding: 4px 9px;
  font-size: 11px;
  border-radius: 5px;
}

/* ── P&L table ── */
.pnl-table {
  width: 100%;
  max-width: 640px;
  border-collapse: collapse;
  font-size: 13px;
}
.pnl-table td { padding: 9px 4px; border-bottom: 1px solid var(--border); }
.pnl-table td:last-child { text-align: right; font-weight: 700; }
.pnl-row-sub td { color: var(--text-dim); padding-left: 14px; }
.pnl-row-gross td {
  border-top: 2px solid var(--gold);
  border-bottom: 2px solid var(--gold);
  background: var(--gold-tint);
  font-family: 'Archivo Black', sans-serif;
  font-size: 13px;
}
.pnl-row-deduct td:last-child::before { content: '\2212\00A0'; color: var(--text-dim); }
.pnl-row-net td {
  font-family: 'Archivo Black', sans-serif;
  font-size: 20px;
  padding-top: 16px;
  border-bottom: none;
}
.pnl-row-net td:last-child.is-positive { color: var(--positive-text); }
.pnl-row-net td:last-child.is-negative { color: var(--negative); }
.pnl-row-margin td { color: var(--text-dim); font-size: 12px; border-bottom: none; padding-top: 0; }
.pnl-row-margin td:last-child { font-weight: 400; }

/* ── badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 11px;
  font-family: 'Archivo Black', sans-serif;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  cursor: pointer;
}
.badge-gold { background: var(--gold-tint); border-color: var(--gold); color: var(--gold); }
.badge-red { background: var(--negative-tint); border-color: var(--negative); color: var(--negative); }

/* ── data tables (transactions / expenses / commissions) ── */
.table-scroll { overflow-x: auto; max-width: 100%; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
}
.data-table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  padding: 8px 10px;
  border-bottom: 1px solid var(--gold);
  position: sticky;
  top: 0;
  background: var(--card);
}
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover td { background: rgba(244, 162, 97, 0.04); }
.data-table .num { text-align: right; font-weight: 700; }
.data-table .empty-row td { color: var(--text-dim); text-align: center; padding: 24px; font-style: italic; }

.status-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.status-pill.paid { background: var(--positive); color: var(--positive-text); }
.status-pill.refunded { background: var(--negative-tint); color: var(--negative); }

.tag-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.tag-pill.unclassified { border-color: var(--gold); color: var(--gold); }

.audit-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10px;
  font-style: normal;
  cursor: default;
}
.audit-icon:hover { border-color: var(--gold); color: var(--gold); }

.row-actions { display: flex; gap: 6px; align-items: center; }

/* ── forms ── */
.form-panel {
  background: rgba(244, 162, 97, 0.04);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
}
.form-panel[hidden] { display: none; }

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

.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.field input, .field select, .field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 9px;
  font-size: 12px;
  font-family: 'Space Mono', monospace;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--gold);
}
.field.checkbox-field { flex-direction: row; align-items: center; gap: 8px; }
.field.checkbox-field label { text-transform: none; font-size: 12px; color: var(--text); }

.radio-group { display: flex; gap: 18px; align-items: center; }
.radio-option { display: flex; align-items: center; gap: 6px; font-size: 12px; }

.form-actions { display: flex; align-items: center; gap: 10px; }
.form-msg { font-size: 11px; margin-left: 4px; }
.form-msg.is-error { color: var(--negative); }
.form-msg.is-success { color: var(--positive-text); }

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--gold-tint);
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: 20px;
  padding: 5px 6px 5px 12px;
  font-size: 11px;
  margin-bottom: 12px;
}
.filter-chip button {
  background: transparent;
  border: none;
  color: var(--gold);
  font-size: 13px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  line-height: 1;
}
.filter-chip button:hover { background: rgba(244, 162, 97, 0.25); }

/* ── CA flag panel (the one legitimate decorative use of red) ── */
.ca-flag-panel {
  border-left: 3px solid var(--negative);
  background: var(--negative-tint);
}
.ca-flag-panel .panel-title { color: var(--negative); }

/* ── mini stat row (commissions totals) ── */
.mini-stats {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.mini-stat { min-width: 120px; }
.mini-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.mini-stat-value { font-size: 18px; font-weight: 700; }

/* ── revenue chart ── */
.chart-wrap { max-width: 700px; }
.chart-legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-dim);
}
.chart-legend-item { display: flex; align-items: center; gap: 6px; }
.chart-legend-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ── reclassify inline form ── */
.reclassify-form { display: flex; gap: 6px; align-items: center; }
.reclassify-form select {
  background: var(--bg);
  border: 1px solid var(--gold);
  color: var(--text);
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 11px;
  font-family: 'Space Mono', monospace;
}

/* ── mobile ── */
@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-brand { width: 100%; padding-bottom: 8px; }
  .nav-heading { display: none; }
  .nav-section { flex-direction: row; flex-wrap: wrap; }
  .content { padding: 16px; }
}
