/* DuoBudget - SaaS-grade styling for Dual-Income Working Couple Family Planner */
:root {
  --bg-canvas: #f8fafc;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-hover: #f1f5f9;

  --text-primary: #0f172a;
  --text-muted: #475569;
  --text-subtle: #94a3b8;

  --border-default: #e2e8f0;
  --border-strong: #cbd5e1;

  --brand-50: #eef0fb;
  --brand-100: #dde0f7;
  --brand-200: #b9c0ef;
  --brand-500: #7b85dc;
  --brand-600: #5e6ad2;
  --brand-700: #4a56c0;
  --brand-800: #3a45a8;
  --brand-fg: var(--brand-600);
  --brand-bg-subtle: var(--brand-50);

  /* Partner Accents */
  --p1-fg: #2563eb;
  --p1-bg: #eff6ff;
  --p1-border: #bfdbfe;

  --p2-fg: #0d9488;
  --p2-bg: #f0fdfa;
  --p2-border: #99f6e4;

  --joint-fg: #7c3aed;
  --joint-bg: #f5f3ff;
  --joint-border: #ddd6fe;

  /* Status */
  --success-fg: #15803d;
  --success-bg: #dcfce7;
  --warning-fg: #b45309;
  --warning-bg: #fef3c7;
  --error-fg: #b91c1c;
  --error-bg: #fee2e2;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.06), 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-canvas: #090d16;
    --bg-surface: #111827;
    --bg-elevated: #1f2937;
    --bg-hover: rgba(255, 255, 255, 0.04);

    --text-primary: #f8fafc;
    --text-muted: #94a3b8;
    --text-subtle: #64748b;

    --border-default: #1e293b;
    --border-strong: #334155;

    --brand-fg: #93a0fc;
    --brand-bg-subtle: rgba(94, 106, 210, 0.18);

    --p1-fg: #60a5fa;
    --p1-bg: rgba(37, 99, 235, 0.15);
    --p1-border: #1e3a8a;

    --p2-fg: #2dd4bf;
    --p2-bg: rgba(13, 148, 136, 0.15);
    --p2-border: #134e4a;

    --joint-fg: #a78bfa;
    --joint-bg: rgba(124, 58, 237, 0.15);
    --joint-border: #4c1d95;

    --success-fg: #4ade80;
    --success-bg: rgba(22, 163, 74, 0.2);
    --warning-fg: #fde047;
    --warning-bg: rgba(202, 138, 4, 0.2);
    --error-fg: #f87171;
    --error-bg: rgba(220, 38, 38, 0.2);

    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.numeric, [data-numeric="true"], .tabular-nums {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

/* App Header & Navigation Bar */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-default);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-xs);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-badge {
  background: linear-gradient(135deg, var(--brand-600), #818cf8);
  color: white;
  font-weight: 700;
  font-size: 0.95rem;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

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

.header-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--bg-canvas);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  overflow-x: auto;
  max-width: 100%;
}

.nav-tab {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  transition: all 0.12s ease;
}

.nav-tab:hover {
  color: var(--text-primary);
}

.nav-tab.active {
  background: var(--bg-surface);
  color: var(--brand-fg);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Layout Container */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Banner / Couple Quick Bar */
.couple-status-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  align-items: center;
  box-shadow: var(--shadow-xs);
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

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

/* Partner Badge / Avatar */
.partner-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
}

.partner-tag.p1 {
  background: var(--p1-bg);
  color: var(--p1-fg);
  border: 1px solid var(--p1-border);
}

.partner-tag.p2 {
  background: var(--p2-bg);
  color: var(--p2-fg);
  border: 1px solid var(--p2-border);
}

.partner-tag.joint {
  background: var(--joint-bg);
  color: var(--joint-fg);
  border: 1px solid var(--joint-border);
}

/* Grid & Card layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 1024px) {
  .dashboard-grid.two-col {
    grid-template-columns: 1.1fr 0.9fr;
  }
  .dashboard-grid.three-col {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .dashboard-grid.split-col {
    grid-template-columns: 1fr 1.3fr;
  }
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 1.15rem;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-default);
}

.card-title-group h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--brand-600);
  color: white;
  line-height: 1.2;
}

.btn:hover {
  background: var(--brand-700);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-default);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

.btn-icon {
  padding: 0.35rem;
  width: 28px;
  height: 28px;
}

.btn-danger {
  background: var(--error-bg);
  color: var(--error-fg);
  border-color: rgba(220, 38, 38, 0.2);
}

.btn-danger:hover {
  background: var(--error-fg);
  color: white;
}

/* Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-hint {
  font-size: 0.7rem;
  color: var(--text-subtle);
}

.input, .select {
  width: 100%;
  height: 32px;
  padding: 0 0.65rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus, .select:focus {
  outline: none;
  border-color: var(--brand-fg);
  box-shadow: 0 0 0 2px var(--brand-bg-subtle);
}

.input-money-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-money-symbol {
  position: absolute;
  left: 0.65rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  pointer-events: none;
}

.input-money-wrap .input {
  padding-left: 1.45rem;
}

/* Income Card */
.partner-card {
  border-top: 3px solid var(--brand-600);
}
.partner-card.p1 {
  border-top-color: var(--p1-fg);
}
.partner-card.p2 {
  border-top-color: var(--p2-fg);
}

.income-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

/* Flowchart Diagram (3-Account System) */
.flowchart-container {
  background: var(--bg-canvas);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.flow-step-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.flow-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: relative;
}

.flow-box.p1 {
  border-left: 3px solid var(--p1-fg);
}
.flow-box.p2 {
  border-left: 3px solid var(--p2-fg);
}
.flow-box.joint {
  border-left: 3px solid var(--joint-fg);
  background: var(--bg-surface);
}

.flow-arrow-down {
  text-align: center;
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 700;
  margin: -0.5rem 0;
}

/* Category & Expense Tables */
.expense-category-card {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
}

.cat-header {
  padding: 0.65rem 0.85rem;
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.cat-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.85rem;
}

.cat-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8125rem;
}

.expense-row-item {
  display: grid;
  grid-template-columns: 2fr 1fr 1.2fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border-default);
  font-size: 0.8125rem;
}

.expense-row-item:last-child {
  border-bottom: none;
}

.expense-row-item:hover {
  background: var(--bg-hover);
}

@media (max-width: 640px) {
  .expense-row-item {
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
  }
}

/* Progress bar */
.progress-bar-wrap {
  width: 100%;
  height: 6px;
  background: var(--border-default);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.progress-bar-fill.p1 { background: var(--p1-fg); }
.progress-bar-fill.p2 { background: var(--p2-fg); }
.progress-bar-fill.joint { background: var(--joint-fg); }
.progress-bar-fill.brand { background: var(--brand-600); }
.progress-bar-fill.success { background: var(--success-fg); }
.progress-bar-fill.warning { background: var(--warning-fg); }
.progress-bar-fill.error { background: var(--error-fg); }

/* Multi-segment bar */
.multi-bar-container {
  display: flex;
  width: 100%;
  height: 10px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--border-default);
}

.multi-bar-segment {
  height: 100%;
  transition: width 0.3s ease;
}

/* 50/30/20 Metric Bars */
.rule-gauge-box {
  padding: 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-canvas);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* Checklist / Date Night Review */
.check-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  transition: background 0.15s ease;
}

.check-item.completed {
  background: var(--bg-canvas);
  opacity: 0.75;
}

.check-item input[type="checkbox"] {
  margin-top: 0.15rem;
  accent-color: var(--brand-600);
  cursor: pointer;
  width: 15px;
  height: 15px;
}

/* What-If Simulator Sliders */
.slider-control {
  width: 100%;
  accent-color: var(--brand-600);
  cursor: pointer;
}

/* Modal / Dialog */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border-default);
  background: var(--bg-canvas);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Printable / Summary View */
@media print {
  body {
    background: white !important;
    color: black !important;
    font-size: 11pt;
  }
  .app-header, .header-actions, .btn, .no-print {
    display: none !important;
  }
  .main-content {
    padding: 0;
    max-width: 100%;
  }
  .card {
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    page-break-inside: avoid;
  }
}
