/*
Copyright (c) 2026 Terry Packer.

This file is part of Terry Packer's Work.
See www.terrypacker.com for further info.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/* ============================================================
   RETIREMENT PLANNER — Main Stylesheet
   Aesthetic: Financial precision meets warm human planning
   Typefaces: Playfair Display (headings) + IBM Plex Sans (body)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=IBM+Plex+Sans:wght@300;400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

/* ── CSS Variables ── */
:root {
  --bg-primary:       #0f1117;
  --bg-secondary:     #161b27;
  --bg-card:          #1c2333;
  --bg-card-hover:    #212840;
  --bg-input:         #111520;

  --border:           #2a3148;
  --border-focus:     #4a6fa5;

  --text-primary:     #e8ecf4;
  --text-secondary:   #8a94b0;
  --text-muted:       #4e5870;
  --text-accent:      #c9d4f0;

  --accent-blue:      #4a6fa5;
  --accent-blue-light:#6b91cc;
  --accent-gold:      #c9a84c;
  --accent-gold-light:#e4c76b;
  --accent-green:     #3d9e72;
  --accent-green-light:#52c490;
  --accent-red:       #c0455a;
  --accent-red-light: #e05570;
  --accent-teal:      #3a8fa0;

  --us-color:         #4a6fa5;
  --aus-color:        #c9a84c;

  --shadow-card:      0 4px 24px rgba(0,0,0,0.4);
  --shadow-input:     0 2px 8px rgba(0,0,0,0.3);

  --radius-sm:        6px;
  --radius-md:        10px;
  --radius-lg:        16px;

  --transition:       all 0.2s ease;

  --sidebar-width:    280px;
  --header-height:    60px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: 'IBM Plex Sans', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-blue); }

/* ── Layout ── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

.app-header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.app-logo {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.app-logo span { color: var(--accent-gold); }

.header-nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-tab {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.nav-tab:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-tab.active {
  background: var(--bg-card);
  color: var(--accent-gold-light);
  border-bottom: 2px solid var(--accent-gold);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.currency-toggle {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.currency-toggle button {
  padding: 5px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
}
.currency-toggle button.active {
  background: var(--accent-blue);
  color: white;
}

.fx-rate-display {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: var(--transition);
}
.fx-rate-display:hover { border-color: var(--border); color: var(--text-secondary); }

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: var(--transition);
}
.btn-icon:hover { background: var(--bg-card); color: var(--text-primary); }

/* ── Main Content Area ── */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  padding-bottom: 40px;
}

.sidebar-section {
  border-bottom: 1px solid var(--border);
  padding: 16px;
}
.sidebar-section:last-child { border-bottom: none; }

.sidebar-section-title {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sidebar-section-title .flag { font-size: 0.9rem; }

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Panel / Card ── */
.panel {
  display: none;
}
.panel.active { display: flex; flex-direction: column; gap: 24px; }

/* ── Form Controls ── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}
.form-group:last-child { margin-bottom: 0; }

.form-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.form-label .help-icon {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--text-muted);
  color: var(--text-muted);
  font-size: 0.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.form-label .help-icon:hover { border-color: var(--accent-blue); color: var(--accent-blue); }

.form-input,
.form-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.82rem;
  padding: 7px 10px;
  width: 100%;
  transition: var(--transition);
  outline: none;
}
.form-input:focus,
.form-select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(74, 111, 165, 0.15);
}
.form-input.mono { font-family: 'IBM Plex Mono', monospace; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.input-prefix-wrap {
  position: relative;
}
.input-prefix {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  pointer-events: none;
}
.input-prefix-wrap .form-input { padding-left: 22px; }

/* ── Range Slider ── */
.slider-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.form-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.form-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent-gold);
  border-radius: 50%;
  border: 2px solid var(--bg-card);
  box-shadow: 0 0 0 2px var(--accent-gold);
  transition: var(--transition);
}
.form-range::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}
.slider-value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--accent-gold-light);
  min-width: 36px;
  text-align: right;
}

/* ── Cards in main area ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-card);
}

.card-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 16px;
}

.card-title {
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── KPI Summary Bar ── */
.kpi-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}
.kpi-card.blue::before   { background: var(--accent-blue); }
.kpi-card.gold::before   { background: var(--accent-gold); }
.kpi-card.green::before  { background: var(--accent-green); }
.kpi-card.red::before    { background: var(--accent-red); }

.kpi-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.kpi-value {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
}
.kpi-sub {
  font-size: 0.72rem;
  color: var(--text-secondary);
}
.kpi-delta {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 10px;
  display: inline-block;
  margin-top: 4px;
}
.kpi-delta.pos { background: rgba(61,158,114,0.15); color: var(--accent-green-light); }
.kpi-delta.neg { background: rgba(192,69,90,0.15); color: var(--accent-red-light); }

/* ── Chart containers ── */
.chart-container {
  position: relative;
  width: 100%;
}
.chart-container canvas {
  max-width: 100%;
}

/* ── Timeline / Move Slider ── */
.move-slider-card {
  background: linear-gradient(135deg, rgba(74,111,165,0.08), rgba(201,168,76,0.08));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}
.move-slider-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.move-flags {
  font-size: 1.4rem;
  line-height: 1;
}
.move-title {
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  color: var(--text-primary);
}
.move-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.move-year-display {
  margin-left: auto;
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent-gold-light);
}
.move-slider-track {
  position: relative;
  padding: 10px 0;
}
.move-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  background: linear-gradient(to right, var(--us-color) 0%, var(--us-color) var(--progress, 50%), var(--aus-color) var(--progress, 50%), var(--aus-color) 100%);
}
.move-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: white;
  border: 3px solid var(--accent-gold);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  cursor: grab;
  transition: transform 0.15s;
}
.move-range::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.15); }

.move-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.68rem;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
}

/* ── Account list ── */
.account-list { display: flex; flex-direction: column; gap: 8px; }
.account-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: var(--transition);
}
.account-item:hover { border-color: var(--accent-blue); }
.account-flag { font-size: 1rem; }
.account-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
}
.account-type-badge {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 4px;
}
.badge-401k { background: rgba(74,111,165,0.2); color: var(--accent-blue-light); }
.badge-roth  { background: rgba(61,158,114,0.2); color: var(--accent-green-light); }
.badge-ira   { background: rgba(58,143,160,0.2); color: var(--accent-teal); }
.badge-super { background: rgba(201,168,76,0.2); color: var(--accent-gold-light); }
.badge-brokerage { background: rgba(192,69,90,0.15); color: var(--accent-red-light); }
.badge-property { background: rgba(139,92,246,0.2); color: #a78bfa; }

.account-value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--text-accent);
}
.account-actions { display: flex; gap: 4px; }
.btn-sm {
  padding: 3px 8px;
  font-size: 0.7rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}
.btn-sm:hover { background: var(--bg-card); color: var(--text-primary); }
.btn-sm.danger:hover { border-color: var(--accent-red); color: var(--accent-red-light); }

.btn-add {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
  justify-content: center;
  margin-top: 8px;
}
.btn-add:hover { border-color: var(--accent-blue); color: var(--accent-blue-light); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  transform: translateY(10px);
  transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.modal-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  font-weight: 600;
  flex: 1;
}
.modal-close {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.modal-close:hover { background: var(--accent-red); color: white; border-color: var(--accent-red); }
.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Buttons ── */
.btn {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  outline: none;
}
.btn-primary {
  background: var(--accent-blue);
  color: white;
}
.btn-primary:hover { background: var(--accent-blue-light); }
.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-secondary:hover { background: var(--bg-input); color: var(--text-primary); }
.btn-gold {
  background: var(--accent-gold);
  color: var(--bg-primary);
  font-weight: 600;
}
.btn-gold:hover { background: var(--accent-gold-light); }

/* ── Tax summary bands ── */
.tax-band {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
}
.tax-band:last-child { border-bottom: none; }
.tax-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.tax-band-name { flex: 1; color: var(--text-secondary); }
.tax-band-rate { font-family: 'IBM Plex Mono', monospace; color: var(--text-accent); }
.tax-band-range { font-family: 'IBM Plex Mono', monospace; color: var(--text-muted); font-size: 0.7rem; margin-left: auto; }

/* ── Projection table ── */
.proj-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.proj-table th {
  text-align: right;
  padding: 6px 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
}
.proj-table th:first-child { text-align: left; }
.proj-table td {
  padding: 7px 12px;
  border-bottom: 1px solid rgba(42,49,72,0.5);
  text-align: right;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--text-accent);
}
.proj-table td:first-child {
  text-align: left;
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--text-secondary);
  font-weight: 500;
}
.proj-table tr:hover td { background: rgba(74,111,165,0.05); }
.proj-table tr.milestone td { color: var(--accent-gold-light); }
.proj-table tr.milestone td:first-child { color: var(--accent-gold); }
.proj-table .pos { color: var(--accent-green-light); }
.proj-table .neg { color: var(--accent-red-light); }

/* ── Legend ── */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── Tabs inside panels ── */
.inner-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 16px;
  width: fit-content;
}
.inner-tab {
  padding: 5px 14px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: 'IBM Plex Sans', sans-serif;
}
.inner-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ── Country indicator pill ── */
.country-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.pill-us  { background: rgba(74,111,165,0.15); color: var(--accent-blue-light); border: 1px solid rgba(74,111,165,0.3); }
.pill-aus { background: rgba(201,168,76,0.15); color: var(--accent-gold-light); border: 1px solid rgba(201,168,76,0.3); }

/* ── Net worth gauge ── */
.gauge-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-blue);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.8rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-card);
  animation: slideIn 0.2s ease;
  min-width: 220px;
}
.toast.success { border-left-color: var(--accent-green); }
.toast.warning { border-left-color: var(--accent-gold); }
.toast.error   { border-left-color: var(--accent-red); }

@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Help panel ── */
.help-iframe {
  width: 100%;
  border: none;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  min-height: 600px;
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  .kpi-bar { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 800px) {
  .sidebar { display: none; }
  .kpi-bar { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .kpi-bar { grid-template-columns: 1fr; }
  .app-logo { font-size: 1rem; }
}
