/* ============================================================
   QuickBooks Financial Dashboard — Stylesheet
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Reset & base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:    #0b1120;
  --bg-surface: #111827;
  --bg-card:    #1e293b;
  --bg-hover:   #263347;
  --border:     #1e3a5f33;
  --border-card:#1e293b;
  --text-1:     #f1f5f9;
  --text-2:     #94a3b8;
  --text-3:     #475569;
  --accent:     #3b82f6;
  --accent-dark:#1d4ed8;
  --green:      #22c55e;
  --red:        #ef4444;
  --amber:      #f59e0b;
  --purple:     #8b5cf6;
  --radius:     10px;
  --shadow:     0 4px 24px rgba(0,0,0,0.35);
  --sidebar-w:  230px;
}

html { font-size: 14px; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-1);
  min-height: 100vh;
  display: flex;
}

a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-logo .company-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-1);
  letter-spacing: -0.01em;
}

.sidebar-logo .company-sub {
  font-size: 0.72rem;
  color: var(--text-2);
  margin-top: 2px;
}

.sidebar-logo-img {
  width: 100%;
  max-width: 170px;
  height: auto;
  display: block;
  margin-bottom: 8px;
  filter: brightness(1.05);
}

.sidebar-logo .qb-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(34,197,94,0.12);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 0.68rem;
  color: var(--green);
  margin-top: 8px;
  font-weight: 500;
}

/* Company switcher — hidden entirely via [hidden] when there's only one company
   (default: just Road Runner), so a single-company install looks unchanged. */
.company-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.company-tab {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
}

.company-tab:hover { border-color: var(--accent); color: var(--text-1); }

.company-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 8px 10px 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--text-2);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  margin-bottom: 1px;
}

.nav-link:hover { background: var(--bg-hover); color: var(--text-1); }
.nav-link.active { background: rgba(59,130,246,0.15); color: var(--accent); }
.nav-link .icon { width: 18px; text-align: center; font-size: 1rem; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 0.72rem;
  color: var(--text-3);
  text-align: center;
}

/* ── Main layout ───────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top bar ───────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(11,17,32,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-1);
}

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

.period-selector {
  display: flex;
  background: var(--bg-card);
  border-radius: 7px;
  padding: 3px;
  border: 1px solid rgba(255,255,255,0.06);
}

.period-btn {
  padding: 5px 12px;
  border-radius: 5px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-2);
  border: none;
  background: transparent;
  transition: background 0.15s, color 0.15s;
}
.period-btn:hover { color: var(--text-1); }
.period-btn.active { background: var(--accent); color: #fff; }

.year-select {
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
  color: var(--text-1);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.year-select:hover { border-color: rgba(59,130,246,0.4); }
.year-select option { background: var(--bg-surface); }

.as-of {
  font-size: 0.72rem;
  color: var(--text-3);
  padding: 5px 10px;
  background: var(--bg-card);
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.06);
}

.demo-pill {
  background: rgba(245,158,11,0.15);
  border: 1px solid rgba(245,158,11,0.3);
  color: var(--amber);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.04em;
}

/* ── Content area ──────────────────────────────────────── */
.content { padding: 24px 28px; flex: 1; }

.section { display: block; }

/* ── Section heading ───────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-1);
}

.section-sub {
  font-size: 0.78rem;
  color: var(--text-2);
  margin-top: 2px;
}

/* ── KPI grid ──────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: border-color 0.2s;
}

.kpi-card:hover { border-color: rgba(59,130,246,0.3); }

.kpi-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.02em;
  line-height: 1;
  margin-bottom: 8px;
}

.kpi-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 12px;
}

.badge-up   { background: rgba(34,197,94,0.12);  color: var(--green); }
.badge-down { background: rgba(239,68,68,0.12);   color: var(--red);   }

.kpi-icon {
  font-size: 1.4rem;
  float: right;
  margin-top: -2px;
  opacity: 0.5;
}

/* ── Chart grid ────────────────────────────────────────── */
.chart-grid {
  display: grid;
  gap: 18px;
  margin-bottom: 24px;
}

.chart-grid-2 { grid-template-columns: 1fr 1fr; }
.chart-grid-3 { grid-template-columns: 2fr 1fr; }

/* chart-grid-3 pairs a chart card with a table card (e.g. Expenses by Category +
   Category Detail) — grid rows stretch both cards to match the taller one, but a
   fixed-height chart-wrap doesn't grow with it, leaving dead space under the chart
   when its neighboring table is long. Let the chart card fill that height instead. */
.chart-grid-3 > .card {
  display: flex;
  flex-direction: column;
}
.chart-grid-3 > .card > .chart-wrap {
  flex: 1;
  height: auto;
  min-height: 280px;
}
.chart-grid-3 > .card > .chart-wrap-md {
  flex: 1;
  height: auto;
  min-height: 240px;
}

.card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-1);
}

.card-sub {
  font-size: 0.72rem;
  color: var(--text-2);
  margin-top: 2px;
}

.chart-wrap {
  position: relative;
  height: 280px;
}

.chart-wrap-sm {
  position: relative;
  height: 220px;
}

.chart-wrap-md {
  position: relative;
  height: 240px;
}

/* ── Tables ────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

table.tbl-lg { font-size: 0.92rem; }
table.tbl-lg thead th { font-size: 0.75rem; padding: 11px 12px; }
table.tbl-lg tbody td { padding: 13px 12px; }

thead th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-3);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

tbody tr {
  border-bottom: 1px solid rgba(255,255,255,0.03);
  transition: background 0.12s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.025); }

tbody td {
  padding: 11px 12px;
  color: var(--text-2);
  vertical-align: middle;
}

td.name-cell { color: var(--text-1); font-weight: 500; }
td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-1); }
td.date-cell { color: var(--text-3); white-space: nowrap; }
td.mono { font-family: 'Courier New', monospace; font-size: 0.78rem; color: var(--text-2); }
td.text-green { color: var(--green); }

.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: rgba(255,255,255,0.05);
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-3);
}

/* ── Inline bar ────────────────────────────────────────── */
.bar-wrap {
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
  min-width: 80px;
  margin-bottom: 2px;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.bar-pct {
  font-size: 0.7rem;
  color: var(--text-3);
}

/* ── Status badges ─────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
}

.b-green  { background: rgba(34,197,94,0.12);   color: var(--green); }
.b-blue   { background: rgba(59,130,246,0.12);  color: var(--accent); }
.b-amber  { background: rgba(245,158,11,0.12);  color: var(--amber); }
.b-red    { background: rgba(239,68,68,0.12);   color: var(--red); }

.tx-type { font-weight: 500; color: var(--text-1); }

/* ── Aging summary callouts ────────────────────────────── */
.aging-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.aging-item {
  background: rgba(255,255,255,0.03);
  border-radius: 7px;
  padding: 10px 12px;
  text-align: center;
}

.aging-item .ai-label { font-size: 0.68rem; color: var(--text-3); margin-bottom: 4px; }
.aging-item .ai-value { font-size: 0.95rem; font-weight: 700; color: var(--text-1); }

/* ── Profit margin ring ────────────────────────────────── */
.margin-ring-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  padding: 20px 0;
}

.margin-ring-val { font-size: 2rem; font-weight: 700; color: var(--green); }
.margin-ring-lbl { font-size: 0.72rem; color: var(--text-2); }

/* ── Scrollbar styling ─────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-3); border-radius: 3px; }

/* ── Loading & error states ────────────────────────────── */
.section-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(59,130,246,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.section-error {
  background: rgba(239,68,68,0.06);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  margin-bottom: 18px;
}

/* ── Refresh button ────────────────────────────────────── */
.refresh-btn {
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background: rgba(59,130,246,0.12);
  border: 1px solid rgba(59,130,246,0.3);
  color: var(--accent);
  border-radius: 6px;
  transition: background 0.15s;
  white-space: nowrap;
}
.refresh-btn:hover { background: rgba(59,130,246,0.22); }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 1024px) {
  .chart-grid-2, .chart-grid-3 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}
