/* ============================================================
   CalmTheCash — Shared Design System
   ============================================================ */

/* ── CSS Variables ── */
:root {
  --bg:       #0a0b0d;
  --surface:  #13151a;
  --surface2: #1a1d24;
  --border:   #252830;
  --text:     #e6e8f0;
  --muted:    #6b7280;
  --faint:    #2a2e3a;

  --gold:     #f0c040;
  --orange:   #fb923c;
  --green:    #4ade80;
  --blue:     #60a5fa;
  --purple:   #a78bfa;
  --red:      #f87171;

  /* Semantic aliases used by calculator pages */
  --accent:   var(--gold);
  --accent2:  var(--green);
  --accent3:  var(--blue);
  --accent4:  var(--orange);
  --danger:   var(--red);

  --serif: 'Playfair Display', serif;
  --mono:  'DM Mono', monospace;
  --sans:  'DM Sans', sans-serif;

  --sidebar-w: 240px;
  --sidebar-collapsed-w: 56px;
  --topbar-h: 56px;
}

[data-theme="light"] {
  --bg:       #f5f4f0;
  --surface:  #ffffff;
  --surface2: #eeeae1;
  --border:   #dddad0;
  --text:     #1a1b1e;
  --muted:    #7a7d8a;
  --faint:    #e4e0d4;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.25s ease, color 0.25s ease;
}

/* ── Background grain overlay ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* ============================================================
   APP LAYOUT — Sidebar + Main Content
   ============================================================ */

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

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 300;
  transition: width 0.2s ease, transform 0.2s ease;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
}

.sidebar-close {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}

.sidebar-close:hover {
  color: var(--text);
  background: var(--border);
}

/* ── Logo ── */
.logo {
  display: flex;
  align-items: baseline;
  gap: 2px;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}

.logo-word {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.5px;
}

.logo-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  margin-left: 2px;
  margin-bottom: 2px;
  flex-shrink: 0;
  animation: pulse-dot 3s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.7); }
}

/* ── Sidebar Navigation ── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.sidebar-section {
  padding: 0 12px;
  margin-bottom: 8px;
}

.sidebar-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 12px 6px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 400;
  transition: color 0.15s, background 0.15s;
  border-left: 3px solid transparent;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-link:hover {
  color: var(--text);
  background: var(--surface2);
}

.sidebar-link.active {
  color: var(--text);
  background: var(--surface2);
  border-left-color: var(--gold);
  font-weight: 500;
}

.sidebar-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.sidebar-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* ── Sidebar Overlay (mobile) ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 299;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sidebar-overlay.visible {
  display: block;
  opacity: 1;
}

/* ── Main Content ── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  position: relative;
  z-index: 1;
  transition: margin-left 0.2s ease;
}

/* ── Top Bar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 28px;
  height: var(--topbar-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s, border-color 0.3s;
}

.topbar.scrolled {
  background: rgba(10,11,13,0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

[data-theme="light"] .topbar.scrolled {
  background: rgba(245,244,240,0.95);
}

.hamburger {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
}

.hamburger:hover {
  color: var(--text);
  background: var(--surface2);
}

.hamburger svg { display: block; margin: auto; }

.topbar-title {
  flex: 1;
  font-family: var(--serif);
  font-size: clamp(18px, 2.5vw, 24px);
  font-weight: 700;
  letter-spacing: -0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title span {
  color: var(--gold);
}

/* ── Theme toggle ── */
.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  flex-shrink: 0;
  padding: 0;
}

.theme-toggle:hover {
  border-color: var(--muted);
  color: var(--text);
  background: var(--surface2);
}

.theme-toggle svg { display: block; }

/* ── Content Area ── */
.content-area {
  max-width: 1280px;
  padding: 32px 28px 40px;
  position: relative;
  z-index: 1;
}

/* ============================================================
   COMMON COMPONENTS
   ============================================================ */

/* ── Page Header ── */
.page-top {
  margin-bottom: 32px;
}

.page-top header {
  margin-bottom: 0;
}

.page-top header h1 {
  font-family: var(--serif);
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.page-top header h1 span { color: var(--gold); }

.page-top header p {
  color: var(--muted);
  margin-top: 8px;
  font-size: 15px;
  font-weight: 300;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  margin-bottom: 32px;
  width: fit-content;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 8px 20px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--accent, var(--gold));
  color: #0e0f11;
}

.tab-btn:hover:not(.active) {
  color: var(--text);
  background: var(--surface2);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
}

.card + .card {
  margin-top: 16px;
}

.card-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 20px;
}

/* ── Calculator Layout (2-column) ── */
.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  align-items: start;
}

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

/* ── Form Elements ── */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.input-wrap {
  position: relative;
}

.input-prefix, .input-suffix {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
  pointer-events: none;
}

.input-prefix { left: 12px; }
.input-suffix { right: 12px; }

input[type="number"],
input[type="text"],
select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  padding: 12px 14px;
  transition: border-color 0.2s;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.has-prefix input { padding-left: 28px; }
.has-suffix input { padding-right: 36px; }

input:focus, select:focus {
  outline: none;
  border-color: var(--gold);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

select option {
  background: var(--surface2);
}

/* ── Range Slider ── */
.range-group {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--gold);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--gold);
}

.range-val {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  min-width: 40px;
  text-align: right;
}

/* ── Results Summary ── */
.results-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.result-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.result-label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 4px;
}

.result-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.result-item.highlight { border-color: var(--gold); }
.result-item.highlight .result-value { color: var(--gold); }
.result-item.conservative .result-value { color: var(--green); }
.result-item.stretch .result-value { color: var(--orange); }
.result-item.danger .result-value { color: var(--red); }

@media (max-width: 600px) {
  .results-summary { grid-template-columns: 1fr 1fr; }
}

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: var(--mono);
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  padding: 10px 12px;
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}

tbody td {
  padding: 8px 12px;
  color: var(--text);
  border-bottom: 1px solid var(--faint, var(--border));
}

tbody tr:hover {
  background: var(--surface2);
}

[data-theme="light"] tbody tr {
  border-bottom: 1px solid var(--border);
}

/* ── Chart Area ── */
.chart-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}

.chart-area canvas {
  width: 100%;
  display: block;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* ============================================================
   FOOTER
   ============================================================ */

footer {
  margin-top: 48px;
  padding: 40px 0 24px;
  border-top: 1px solid var(--border);
}

.footer-inner {
  max-width: 1280px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 24px;
}

.footer-copy {
  font-size: 13px;
  color: var(--muted);
}

.footer-links {
  display: flex;
  gap: 24px;
  list-style: none;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  transition: color 0.2s;
}

.footer-links a:hover { color: var(--text); }

.divider-line {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}

/* ============================================================
   RELATED ARTICLES SECTION
   ============================================================ */

.related-articles {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.related-articles h2 {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.related-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-decoration: none;
  transition: border-color 0.2s, transform 0.2s;
  display: block;
}

.related-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.related-card .tag {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold);
  margin-bottom: 8px;
}

.related-card h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.3;
}

.related-card p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

/* ============================================================
   RESPONSIVE — Tablet
   ============================================================ */

@media (max-width: 1024px) {
  :root {
    --sidebar-w: var(--sidebar-collapsed-w);
  }

  .sidebar {
    width: var(--sidebar-collapsed-w);
  }

  .sidebar .sidebar-header {
    padding: 16px 12px;
    justify-content: center;
  }

  .sidebar .logo-word {
    display: none;
  }

  .sidebar .sidebar-label {
    font-size: 0;
    padding: 4px 0;
    text-align: center;
  }

  .sidebar .sidebar-label::after {
    content: '';
    display: block;
    width: 20px;
    height: 1px;
    background: var(--border);
    margin: 0 auto;
  }

  .sidebar .sidebar-link {
    justify-content: center;
    padding: 10px 8px;
    border-left: none;
    border-radius: 10px;
    gap: 0;
  }

  .sidebar .sidebar-link.active {
    border-left: none;
    background: var(--surface2);
    box-shadow: inset 0 0 0 1px var(--gold);
  }

  .sidebar .sidebar-text {
    display: none;
  }

  .sidebar .sidebar-icon {
    font-size: 18px;
  }

  .main-content {
    margin-left: var(--sidebar-collapsed-w);
  }

  .content-area {
    padding: 24px 20px 40px;
  }
}

/* ============================================================
   RESPONSIVE — Mobile
   ============================================================ */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    z-index: 301;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar.open .sidebar-close {
    display: flex;
  }

  .sidebar.open .logo-word {
    display: inline;
  }

  .sidebar.open .sidebar-label {
    font-size: 10px;
  }

  .sidebar.open .sidebar-label::after {
    display: none;
  }

  .sidebar.open .sidebar-link {
    justify-content: flex-start;
    gap: 12px;
    border-left: 3px solid transparent;
    padding: 10px 12px;
  }

  .sidebar.open .sidebar-link.active {
    border-left-color: var(--gold);
    box-shadow: none;
  }

  .sidebar.open .sidebar-text {
    display: inline;
  }

  .sidebar.open .sidebar-icon {
    font-size: 16px;
  }

  .main-content {
    margin-left: 0;
  }

  .hamburger {
    display: flex;
  }

  .content-area {
    padding: 20px 16px 40px;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .results-summary {
    grid-template-columns: 1fr 1fr;
  }

  .tabs {
    width: 100%;
  }

  .tab-btn {
    flex: 1;
    text-align: center;
    padding: 8px 12px;
    font-size: 12px;
  }

  .footer-inner {
    flex-direction: column;
    align-items: flex-start;
    padding: 0 16px;
  }
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

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

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
