/* Design tokens ported from the Python app's palette (CARD_BG, BTN_*, COLOUR_*) */
:root {
  --app-bg: #1a1a1a;
  --card-bg: #262626;
  --card-bg-raised: #333333;
  --border-subtle: #3a3a3a;

  --btn-primary: #1f6feb;
  --btn-primary-hov: #388bfd;
  --btn-neutral: #3a3a3a;
  --btn-neutral-hov: #4a4a4a;
  --btn-accent: #1a6b5c;
  --btn-accent-hov: #228877;
  --btn-destructive: #8b3a3a;
  --btn-destructive-hov: #a04848;

  --gain: #2CC985;
  --loss: #FF5555;
  --warning: #FFA500;
  --highlight: #E0AA00;
  --muted: #9aa0a6;

  --font: "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--app-bg);
  color: #eaeaea;
  font-family: var(--font);
  font-size: 14px;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 32px;
  width: 340px;
}
.app-title { font-size: 24px; font-weight: bold; margin: 0 0 4px 0; color: #4CC9F0; }
.app-subtitle { color: var(--muted); margin: 0 0 20px 0; }
.login-card label, .modal-card label { display: block; margin: 12px 0 4px; color: var(--muted); font-size: 12px; }
.login-card input, .modal-card input, .modal-card select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--card-bg-raised);
  color: #fff;
  font-family: var(--font);
  font-size: 14px;
}
.error-text { color: var(--loss); font-size: 12px; min-height: 16px; margin-top: 8px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font);
  font-weight: bold;
  font-size: 13px;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  color: #fff;
  background: var(--btn-neutral);
  transition: background 0.15s;
}
.btn:hover { background: var(--btn-neutral-hov); }
.btn-primary { background: var(--btn-primary); }
.btn-primary:hover { background: var(--btn-primary-hov); }
.btn-neutral { background: var(--btn-neutral); }
.btn-accent { background: var(--btn-accent); }
.btn-accent:hover { background: var(--btn-accent-hov); }
.btn-destructive { background: var(--btn-destructive); }
.btn-destructive:hover { background: var(--btn-destructive-hov); }
.btn-block { width: 100%; margin-top: 14px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.file-btn { display: inline-flex; align-items: center; justify-content: center; }

/* ---------- App shell ---------- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
  z-index: 50;
}
.header-left { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.app-title-sm { font-size: 18px; margin: 0; white-space: nowrap; }
.app-version { color: var(--muted); font-size: 12px; white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.user-email { color: var(--muted); font-size: 12px; }

@media (max-width: 860px) {
  .app-header { padding: 10px 12px; gap: 8px; }
  .header-left { gap: 6px; }
  .header-right { gap: 8px; }
  .app-title-sm { font-size: 15px; }
  .app-version { display: none; } /* redundant clutter at this width */
  .user-email { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (max-width: 420px) {
  .user-email { display: none; } /* Sign Out button alone is enough context */
}

.menu-toggle {
  display: inline-block;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: #fff;
  border-radius: 6px;
  font-size: 16px;
  line-height: 1;
  padding: 6px 10px;
  cursor: pointer;
  align-self: center;
}

/* ---------- Sidebar (left menu: portfolio switch + actions) ----------
   Always an off-canvas, slide-in/out burger menu — on every screen size,
   not just mobile — toggled via .menu-toggle / #btnMenuToggle. */
.app-body {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 53px); /* 53px ≈ header height */
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--card-bg);
  border-right: 1px solid var(--border-subtle);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 150;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  box-shadow: 2px 0 16px rgba(0, 0, 0, 0.5);
  overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }

.sidebar-divider { height: 1px; background: var(--border-subtle); margin: 8px 0; }
.sidebar-section-title {
  font-size: 11px;
  font-weight: bold;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.sidebar-actions { display: flex; flex-direction: column; gap: 8px; }
.sidebar-actions .btn { margin-top: 0; }
.sidebar-viewing { display: flex; flex-direction: column; gap: 6px; }
.sidebar-viewing .select { width: 100%; }

.tab-bar-vertical { display: flex; flex-direction: column; gap: 4px; }
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: var(--font);
  font-weight: bold;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.tab-btn.active { background: var(--btn-primary); border-color: var(--btn-primary); color: #fff; }

.sidebar-overlay {
  display: none;
}
.sidebar-overlay.visible {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 140;
}

.stale-warning {
  margin: 0 0 16px;
  background: #4a3410;
  border: 1px solid var(--warning);
  color: var(--warning);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
}

.view-container { flex: 1; min-width: 0; padding: 16px 24px 40px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.select {
  background: var(--card-bg-raised);
  color: #fff;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--font);
}
.snapshot-picker-label { color: var(--muted); font-size: 12px; }

.mobile-col-toggle { display: none; } /* desktop: all columns already visible */

@keyframes colSlideIn {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ---------- Narrow screens: tighten spacing, stack panels ---------- */
@media (max-width: 860px) {
  .view-container { padding: 16px 14px 32px; }
  .summary-bar { gap: 20px; }

  /* Provider table: hide the detail columns (Start, History, One-off Pay
     In, Withdrawal, Std Monthly / Day, Std Monthly Out / Day) by default —
     the "Show More Columns" toggle above the table reveals them again. */
  .mobile-col-toggle { display: inline-block; margin: 10px 10px 0; }
  .rows-table { min-width: 0; }
  .rows-table .col-extra { display: none; }
  .rows-table.show-extra-cols { min-width: 1400px; }
  .rows-table.show-extra-cols .col-extra {
    display: table-cell;
    animation: colSlideIn 0.2s ease;
  }

  .bottom-row { flex-direction: column; }
  .panel-compact { max-width: none; }
  .dashboard-chart-panel { min-width: 0; }
}

.summary-bar { display: flex; gap: 36px; align-items: center; flex-wrap: wrap; }
.stat-title { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-size: 22px; font-weight: bold; margin-top: 2px; }
.stat-lg { font-size: 22px; }
.stat-sublabel { font-size: 11px; color: var(--muted); margin-top: 2px; }
.notify-label { margin-left: auto; color: var(--muted); font-size: 12px; }

/* Benchmark result, moved into the summary bar (far right) to free up the
   space the standalone Benchmark card used to take. */
.stat-benchmark { min-width: 180px; max-width: 260px; }
.stat-benchmark .panel-result { margin-top: 2px; }

.panel-title { font-size: 11px; font-weight: bold; color: var(--muted); letter-spacing: 0.05em; margin-bottom: 8px; }
/* Projector card doesn't need the full table width — keep it compact and
   left-aligned. The freed-up space to its right holds the all-providers
   growth chart, in the same visual format as the per-provider charts. */
.panel-compact { max-width: 420px; flex-shrink: 0; }

.bottom-row { display: flex; gap: 16px; align-items: stretch; flex-wrap: wrap; }
.dashboard-chart-panel { flex: 1; min-width: 320px; display: flex; flex-direction: column; }
.dashboard-chart-canvas-wrap { min-height: 280px; flex: 1; }
.dashboard-chart-panel .chart-footer { max-height: 110px; margin-top: 8px; }
.panel-result { font-size: 14px; margin-top: 8px; }
.panel-result-lg { font-size: 18px; font-weight: bold; color: var(--highlight); }
.panel-sublabel { font-size: 11px; color: var(--muted); margin-top: 4px; }
.proj-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; align-items: center; }
.proj-grid label { font-size: 12px; color: var(--muted); }
.input {
  background: var(--card-bg-raised);
  color: #fff;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: var(--font);
  width: 100%;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 12px; color: var(--muted); }

/* ---------- Table ---------- */
.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.rows-table { border-collapse: collapse; width: 100%; min-width: 1400px; }
.rows-table th {
  text-align: left;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  background: var(--card-bg);
}
.rows-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.rows-table input[type=text], .rows-table input[type=number] {
  background: var(--card-bg-raised);
  color: #fff;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 5px 6px;
  width: 90px;
  font-family: var(--font);
  font-size: 13px;
}
.rows-table input.readonly-name { background: transparent; border: none; color: #fff; font-weight: bold; width: 140px; }
.rows-table input.day-input { width: 40px; }
.day-pair { display: flex; gap: 4px; align-items: center; }
.day-pair span { color: var(--muted); font-size: 11px; }
.cell-value { font-weight: bold; }
.cell-muted { color: var(--muted); }
.cell-gain { color: var(--gain); }
.cell-loss { color: var(--loss); }
.cell-auto { color: var(--warning); }
.row-actions { display: flex; gap: 4px; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
}
.icon-btn:hover { color: #fff; border-color: #666; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--card-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 24px;
  width: 380px;
  max-height: 90vh;
  overflow-y: auto;
}
/* Chart modal takes over almost the whole viewport so the graph itself gets
   as much room as possible, instead of being squeezed into a ~900px card. */
.modal-card-wide {
  width: 97vw;
  max-width: none;
  height: 94vh;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-card h2 { margin: 0 0 4px 0; }
.modal-note { color: var(--muted); font-size: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-header-row { display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }

.chart-canvas-wrap { flex: 1; min-height: 0; position: relative; margin-top: 8px; }
.chart-canvas-wrap canvas { width: 100% !important; height: 100% !important; }

.chart-footer {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  line-height: 1.6;
  flex-shrink: 0;
  max-height: 22vh;
  overflow-y: auto;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-bg-raised);
  border: 1px solid var(--border-subtle);
  padding: 12px 20px;
  border-radius: 8px;
  z-index: 200;
  font-size: 13px;
}
