/* ============================================================
   CashCalc Pro – Application Stylesheet
   Aesthetic: Refined Professional / Wealth Management
   Fonts: Libre Baskerville (headings) + DM Sans (body)
   Palette: Deep navy, warm gold, slate grey, clean white
   ============================================================ */

:root {
  --navy:        #1a2e4a;
  --navy-mid:    #243d5e;
  --navy-light:  #2e5080;
  --gold:        #c4973a;
  --gold-light:  #dbb76b;
  --gold-pale:   #f5edd8;
  --slate:       #4a5568;
  --slate-light: #718096;
  --silver:      #e2e8f0;
  --ice:         #f7f9fc;
  --white:       #ffffff;
  --green:       #2d6a4f;
  --green-light: #d8f3dc;
  --red:         #9b2226;
  --red-light:   #fee2e2;
  --amber:       #92400e;
  --amber-light: #fef3c7;
  --text-dark:   #1a202c;
  --text-mid:    #4a5568;
  --text-light:  #a0aec0;
  --shadow-sm:   0 1px 3px rgba(26,46,74,.08), 0 1px 2px rgba(26,46,74,.05);
  --shadow-md:   0 4px 16px rgba(26,46,74,.10), 0 2px 6px rgba(26,46,74,.06);
  --shadow-lg:   0 8px 32px rgba(26,46,74,.14);
  --radius:      8px;
  --radius-lg:   14px;
  --sidebar-w:   240px;
  --transition:  .18s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--ice);
  color: var(--text-dark);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ─────────────────────────────────────────── */

h1, h2, h3, h4 {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.25;
}

h1 { font-size: 1.8rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: .95rem; }

p { color: var(--text-mid); line-height: 1.6; }

a { color: var(--navy-light); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--gold); }

/* ── App Shell ──────────────────────────────────────────── */

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

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-mark {
  width: 32px; height: 32px;
  background: var(--gold);
  clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
  flex-shrink: 0;
}

.brand-name {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: .9rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: .02em;
}

.sidebar-nav { flex: 1; padding: 16px 0; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  color: rgba(255,255,255,.65);
  font-size: .875rem;
  font-weight: 500;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}

.nav-item:hover { color: var(--white); background: rgba(255,255,255,.06); }

.nav-item.active {
  color: var(--white);
  background: rgba(196,151,58,.15);
  border-left-color: var(--gold);
}

.nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.user-avatar {
  width: 34px; height: 34px;
  background: var(--gold);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Libre Baskerville', serif;
  font-weight: 700;
  color: var(--navy);
  font-size: .85rem;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: .8rem; font-weight: 600; color: var(--white); truncate: ellipsis; white-space: nowrap; overflow: hidden; }
.user-role { font-size: .7rem; color: rgba(255,255,255,.45); text-transform: capitalize; }

.logout-btn { color: rgba(255,255,255,.35); font-size: 1rem; transition: color var(--transition); }
.logout-btn:hover { color: var(--gold); }

/* ── Main Content ───────────────────────────────────────── */

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
}

.page-inner { padding: 32px 36px; max-width: 1400px; }

/* ── Page Header ────────────────────────────────────────── */

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

.page-title { font-size: 1.75rem; color: var(--navy); }
.page-subtitle { font-size: .875rem; color: var(--text-light); margin-top: 4px; }
.page-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-family: 'DM Sans', sans-serif;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--navy);
  color: var(--white);
  border-color: var(--navy);
}
.btn-primary:hover { background: var(--navy-mid); color: var(--white); transform: translateY(-1px); box-shadow: var(--shadow-sm); }

.btn-gold {
  background: var(--gold);
  color: var(--white);
  border-color: var(--gold);
}
.btn-gold:hover { background: var(--gold-light); color: var(--white); transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  color: var(--navy);
  border-color: var(--silver);
}
.btn-outline:hover { background: var(--ice); border-color: var(--slate-light); color: var(--navy); }

.btn-danger {
  background: var(--red-light);
  color: var(--red);
  border-color: #fca5a5;
}
.btn-danger:hover { background: var(--red); color: var(--white); }

.btn-sm { padding: 6px 13px; font-size: .8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }

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

.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--silver);
}

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

.card-title {
  font-family: 'Libre Baskerville', serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
}

.card-body { padding: 24px; }

/* ── Stat Cards ─────────────────────────────────────────── */

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }

.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--silver);
  border-top: 3px solid var(--navy);
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card.gold   { border-top-color: var(--gold); }
.stat-card.green  { border-top-color: var(--green); }
.stat-card.red    { border-top-color: var(--red); }

.stat-label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-light); margin-bottom: 8px; }
.stat-value { font-family: 'Libre Baskerville', serif; font-size: 1.6rem; font-weight: 700; color: var(--navy); line-height: 1; }
.stat-note  { font-size: .75rem; color: var(--text-light); margin-top: 6px; }

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

.form-grid    { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.form-group   { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--navy);
  letter-spacing: .02em;
  text-transform: uppercase;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], select, textarea {
  font-family: 'DM Sans', sans-serif;
  font-size: .9rem;
  padding: 9px 13px;
  border: 1px solid var(--silver);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--text-dark);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--navy-light);
  box-shadow: 0 0 0 3px rgba(46,80,128,.12);
}

input.error, select.error { border-color: var(--red); }
.form-error { font-size: .78rem; color: var(--red); margin-top: 2px; }
.form-hint  { font-size: .78rem; color: var(--text-light); }
textarea    { resize: vertical; min-height: 90px; }

.form-section { margin-bottom: 28px; }
.form-section-title {
  font-family: 'Libre Baskerville', serif;
  font-size: .95rem;
  color: var(--navy);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--silver);
  margin-bottom: 18px;
}

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

.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--silver); }

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

thead th {
  background: var(--navy);
  color: rgba(255,255,255,.85);
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 11px 16px;
  text-align: left;
  white-space: nowrap;
}

thead th:first-child { border-radius: var(--radius-lg) 0 0 0; }
thead th:last-child  { border-radius: 0 var(--radius-lg) 0 0; }

tbody tr { border-bottom: 1px solid var(--silver); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--ice); }

tbody td { padding: 11px 16px; color: var(--text-mid); }
tbody td.num { text-align: right; font-feature-settings: "tnum"; font-weight: 600; color: var(--navy); }
tbody td.pos { color: var(--green); font-weight: 600; }
tbody td.neg { color: var(--red);   font-weight: 600; }

/* ── Alerts ─────────────────────────────────────────────── */

.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: 20px;
}

.alert-icon { font-size: 1rem; flex-shrink: 0; }
.alert-info    { background: #e8f0fc; color: #1e3a8a; border: 1px solid #bfdbfe; }
.alert-success { background: var(--green-light); color: var(--green); border: 1px solid #a7f3d0; }
.alert-warning { background: var(--amber-light); color: var(--amber); border: 1px solid #fde68a; }
.alert-error   { background: var(--red-light); color: var(--red); border: 1px solid #fca5a5; }

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

.tabs { display: flex; border-bottom: 2px solid var(--silver); margin-bottom: 28px; gap: 2px; }

.tab {
  padding: 10px 20px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
  background: none;
  border-top: none; border-left: none; border-right: none;
  font-family: 'DM Sans', sans-serif;
}

.tab:hover { color: var(--navy); }
.tab.active { color: var(--navy); border-bottom-color: var(--gold); font-weight: 600; }

.tab-content { display: none; }
.tab-content.active { display: block; }

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

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.badge-draft      { background: var(--silver); color: var(--slate); }
.badge-progress   { background: #dbeafe; color: #1d4ed8; }
.badge-review     { background: var(--amber-light); color: var(--amber); }
.badge-final      { background: var(--green-light); color: var(--green); }
.badge-archived   { background: #f3f4f6; color: #6b7280; }

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

.chart-container {
  position: relative;
  height: 340px;
  width: 100%;
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

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

/* ── Scenario tabs ──────────────────────────────────────── */

.scenario-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.scenario-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  border-radius: 99px;
  border: 1.5px solid var(--silver);
  font-size: .8rem;
  font-weight: 500;
  color: var(--slate);
  cursor: pointer;
  transition: all var(--transition);
  background: var(--white);
  text-decoration: none;
}

.scenario-chip:hover { border-color: var(--navy-light); color: var(--navy); }
.scenario-chip.active { background: var(--navy); color: var(--white); border-color: var(--navy); }
.scenario-chip .chip-star { color: var(--gold); }

/* ── Login page ─────────────────────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--navy);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(196,151,58,.15) 0%, transparent 70%);
  top: -100px; right: -100px;
  pointer-events: none;
}

.login-card {
  background: var(--white);
  border-radius: 20px;
  padding: 48px 44px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 36px;
}

.login-logo .brand-mark { width: 44px; height: 44px; }

.login-logo .brand-text h2 {
  font-size: 1.3rem;
  color: var(--navy);
  margin: 0;
}

.login-logo .brand-text p {
  font-size: .78rem;
  color: var(--text-light);
  margin: 0;
}

/* ── Misc utilities ─────────────────────────────────────── */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-right { text-align: right; }
.text-muted { color: var(--text-light); }
.font-serif { font-family: 'Libre Baskerville', serif; }
.separator { border: none; border-top: 1px solid var(--silver); margin: 24px 0; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}
.empty-state h3 { color: var(--text-light); margin-bottom: 8px; font-size: 1.1rem; }

/* ── Responsive ─────────────────────────────────────────── */

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-240px); }
  .main-content { margin-left: 0; }
  .page-inner { padding: 20px 16px; }
}

/* ── Projection table colours ───────────────────────────── */

.proj-table tbody tr.surplus td.surplus-deficit { color: var(--green); font-weight: 700; }
.proj-table tbody tr.deficit td.surplus-deficit { color: var(--red);   font-weight: 700; }

/* ── Scenario form sections ─────────────────────────────── */

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.inline-table-wrap { overflow-x: auto; }
.inline-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.inline-table th { background: var(--ice); padding: 8px 12px; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--slate); border-bottom: 1px solid var(--silver); text-align: left; }
.inline-table td { padding: 8px 12px; border-bottom: 1px solid var(--silver); }
.inline-table tr:last-child td { border-bottom: none; }
.inline-table input, .inline-table select { padding: 6px 9px; font-size: .82rem; }
.inline-table .del-row { color: var(--red); background: none; border: none; cursor: pointer; font-size: 1rem; padding: 4px; }

/* ── Quick action strip ─────────────────────────────────── */

.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
