@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&display=swap');

/* ── CSS variables ── */
:root {
  --md-primary: #4f46e5;
  --md-primary-variant: #4338ca;
  --md-primary-container: #e8e7ff;
  --md-secondary: #03dac6;
  --md-bg: #f5f5fb;
  --md-surface: #ffffff;
  --md-surface-variant: #f0f0f8;
  --md-on-surface: #1b1b1f;
  --md-on-surface-variant: #5f5f70;
  --md-border: #e2e2ec;
  --md-error: #ba1a1a;
  --md-success: #146c2e;
  --md-asset: #2e7d32;
  --md-liability: #c62828;
  --md-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --md-shadow-md: 0 4px 12px rgba(0,0,0,0.10);
  --nav-width: 248px;
  --nav-width-collapsed: 76px;
}

[data-theme="dark"] {
  --md-primary: #a5b4fc;
  --md-primary-variant: #818cf8;
  --md-primary-container: #1e1b4b;
  --md-secondary: #4dd9c9;
  --md-bg: #121218;
  --md-surface: #1d1d24;
  --md-surface-variant: #26262f;
  --md-on-surface: #e7e7ee;
  --md-on-surface-variant: #b0b0c0;
  --md-border: #34343f;
  --md-error: #ffb4ab;
  --md-success: #7fdc97;
  --md-asset: #66bb6a;
  --md-liability: #ef5350;
  --md-shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --md-shadow-md: 0 4px 12px rgba(0,0,0,0.5);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Roboto', sans-serif;
  background: var(--md-bg);
  color: var(--md-on-surface);
  transition: background .2s, color .2s;
}
a { color: var(--md-primary); text-decoration: none; }

/* ── Material icons ── */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  font-size: 22px;
  line-height: 1;
  vertical-align: middle;
  user-select: none;
}

/* ────────────────────────────────────────────────
   APP SHELL — desktop side-nav + main area
─────────────────────────────────────────────────*/
.app-shell { display: flex; min-height: 100vh; }

/* ── Side-nav ── */
.sidenav {
  width: var(--nav-width);
  background: var(--md-surface);
  border-right: 1px solid var(--md-border);
  padding: 16px 12px;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 200;
  transition: transform .25s cubic-bezier(.4,0,.2,1), width .2s cubic-bezier(.4,0,.2,1), padding .2s ease;
}

.nav-collapse-btn {
  position: absolute;
  top: 14px; right: 10px;
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: none; border: 1px solid var(--md-border);
  color: var(--md-on-surface-variant); cursor: pointer;
  transition: background .15s, transform .2s cubic-bezier(.4,0,.2,1);
}
.nav-collapse-btn:hover { background: var(--md-surface-variant); color: var(--md-on-surface); }
.nav-collapse-btn .material-symbols-outlined { font-size: 16px; }

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px 20px;
  font-size: 17px; font-weight: 700;
  color: var(--md-primary);
  white-space: nowrap;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 24px;
  color: var(--md-on-surface-variant);
  margin-bottom: 2px; font-size: 14px; font-weight: 500;
  border: none; background: transparent; width: 100%;
  cursor: pointer; text-align: left; white-space: nowrap;
}
.nav-item:hover { background: var(--md-surface-variant); color: var(--md-on-surface); }
.nav-item.active { background: var(--md-primary-container); color: var(--md-primary); font-weight: 700; }
.nav-item.active .material-symbols-outlined { font-variation-settings: 'FILL' 1; }
.nav-item .material-symbols-outlined { flex-shrink: 0; }
.nav-section { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--md-on-surface-variant); padding: 14px 14px 4px; white-space: nowrap; }

/* ── Collapsed (icon-only ribbon) state — toggled via body.nav-collapsed ── */
body.nav-collapsed .sidenav { width: var(--nav-width-collapsed); padding: 16px 8px; }
body.nav-collapsed .main { margin-left: var(--nav-width-collapsed); }
body.nav-collapsed .brand { justify-content: center; padding: 8px 0 20px; }
body.nav-collapsed .brand-text,
body.nav-collapsed .nav-section,
body.nav-collapsed .nav-label { display: none; }
body.nav-collapsed .nav-item { justify-content: center; padding: 12px 8px; gap: 0; }
body.nav-collapsed .nav-collapse-btn { right: 50%; transform: translateX(50%) rotate(180deg); top: 12px; }
body.nav-collapsed .nav-collapse-btn:hover { transform: translateX(50%) rotate(180deg) scale(1.08); }

/* ── Mobile nav overlay & hamburger ── */
.nav-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 199;
}
.hamburger {
  display: none;
  background: none; border: none;
  cursor: pointer; padding: 8px;
  color: var(--md-on-surface);
}

/* ── Main content ── */
.main {
  flex: 1;
  margin-left: var(--nav-width);
  padding: 24px 32px;
  min-width: 0;
  transition: margin-left .2s cubic-bezier(.4,0,.2,1);
}

/* ── Top-bar ── */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 24px; gap: 12px;
}
.page-title { font-size: 22px; font-weight: 700; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

.profile-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--md-surface); border: 1px solid var(--md-border);
  border-radius: 24px; padding: 5px 14px 5px 5px; cursor: pointer;
  font-size: 13px; font-weight: 500;
}
.profile-chip:hover { background: var(--md-surface-variant); }
.avatar-icon {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--md-primary); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

/* ── Theme toggle ── */
.theme-toggle { display: flex; gap: 2px; background: var(--md-surface-variant); border-radius: 20px; padding: 3px; }
.theme-toggle button {
  border: none; background: transparent; padding: 5px 9px;
  border-radius: 16px; cursor: pointer; color: var(--md-on-surface-variant);
  display: flex; align-items: center;
}
.theme-toggle button.active { background: var(--md-primary); color: white; }

/* ────────────────────────────────────────────────
   LAYOUT UTILITIES
─────────────────────────────────────────────────*/
.grid { display: grid; gap: 20px; }
.grid-4 { grid-template-columns: repeat(4,1fr); }
.grid-3 { grid-template-columns: repeat(3,1fr); }
.grid-2 { grid-template-columns: repeat(2,1fr); }

/* ── Cards ── */
.card {
  background: var(--md-surface);
  border: 1px solid var(--md-border);
  border-radius: 16px; padding: 20px;
  box-shadow: var(--md-shadow);
  margin-bottom: 20px;
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0; }

/* ── Stat cards ── */
.stat-card .label { color: var(--md-on-surface-variant); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.stat-card .trend { font-size: 12px; margin-top: 4px; color: var(--md-on-surface-variant); }
.stat-card.asset .value { color: var(--md-asset); }
.stat-card.liability .value { color: var(--md-liability); }
.stat-card.net .value { color: var(--md-primary); }

/* ────────────────────────────────────────────────
   TABS
─────────────────────────────────────────────────*/
.tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 2px solid var(--md-border);
  margin-bottom: 20px;
}
.tab-btn {
  border: none; background: transparent;
  padding: 10px 16px; border-radius: 8px 8px 0 0;
  font-size: 13px; font-weight: 600;
  color: var(--md-on-surface-variant);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  display: flex; align-items: center; gap: 6px;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--md-primary); background: var(--md-surface-variant); }
.tab-btn.active { color: var(--md-primary); border-bottom-color: var(--md-primary); background: transparent; }
.tab-count {
  font-size: 11px; font-weight: 700;
  background: var(--md-primary-container); color: var(--md-primary);
  border-radius: 10px; padding: 1px 7px; min-width: 20px; text-align: center;
}
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ────────────────────────────────────────────────
   TABLES
─────────────────────────────────────────────────*/
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--md-border); white-space: nowrap; }
th { color: var(--md-on-surface-variant); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--md-surface-variant); }
td.wrap { white-space: normal; }

/* ── Icon-only action buttons ── */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  border: none; background: transparent; cursor: pointer;
  color: var(--md-on-surface-variant);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--md-surface-variant); color: var(--md-on-surface); }
.icon-btn.danger:hover { background: rgba(186,26,26,.12); color: var(--md-error); }
.icon-btn.primary:hover { background: var(--md-primary-container); color: var(--md-primary); }
.icon-btn .material-symbols-outlined { font-size: 20px; }
.actions-cell { display: flex; gap: 2px; align-items: center; }

/* ────────────────────────────────────────────────
   BUTTONS
─────────────────────────────────────────────────*/
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: 24px; border: none;
  background: var(--md-primary); color: white;
  font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background .15s, box-shadow .15s;
}
.btn:hover { background: var(--md-primary-variant); box-shadow: var(--md-shadow-md); }
.btn.secondary { background: transparent; color: var(--md-primary); border: 1.5px solid var(--md-primary); }
.btn.secondary:hover { background: var(--md-primary-container); box-shadow: none; }
.btn.danger { background: var(--md-error); color: white; }
.btn.danger:hover { background: #8b0000; }
.btn.ghost { background: var(--md-surface-variant); color: var(--md-on-surface); border: none; }
.btn.ghost:hover { background: var(--md-border); }
.btn.small { padding: 6px 14px; font-size: 13px; }
.btn .material-symbols-outlined { font-size: 18px; }

/* ────────────────────────────────────────────────
   FORMS
─────────────────────────────────────────────────*/
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--md-on-surface-variant); }
.form-control {
  width: 100%; padding: 11px 14px; border-radius: 10px;
  border: 1.5px solid var(--md-border);
  background: var(--md-bg); color: var(--md-on-surface); font-size: 14px;
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--md-primary); }

/* ── Icon picker ── */
.icon-picker-wrap { position: relative; }
.icon-picker-preview {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border-radius: 10px;
  border: 1.5px solid var(--md-border); background: var(--md-bg);
  cursor: pointer; font-size: 14px; user-select: none;
}
.icon-picker-preview:hover { border-color: var(--md-primary); }
.icon-picker-panel {
  display: none;
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 300;
  background: var(--md-surface); border: 1px solid var(--md-border);
  border-radius: 14px; box-shadow: var(--md-shadow-md);
  padding: 12px; width: 320px;
}
.icon-picker-panel.open { display: block; }
.icon-picker-search {
  width: 100%; padding: 8px 12px; border-radius: 8px;
  border: 1.5px solid var(--md-border); background: var(--md-bg);
  color: var(--md-on-surface); font-size: 13px; margin-bottom: 10px;
}
.icon-picker-search:focus { outline: none; border-color: var(--md-primary); }
.icon-picker-grid {
  display: grid; grid-template-columns: repeat(7,1fr); gap: 4px;
  max-height: 200px; overflow-y: auto;
}
.icon-picker-grid button {
  border: none; background: transparent; border-radius: 8px;
  padding: 6px; cursor: pointer; color: var(--md-on-surface-variant);
  display: flex; align-items: center; justify-content: center;
}
.icon-picker-grid button:hover { background: var(--md-surface-variant); color: var(--md-primary); }
.icon-picker-grid button.selected { background: var(--md-primary-container); color: var(--md-primary); }

/* ────────────────────────────────────────────────
   BADGES & FLASH
─────────────────────────────────────────────────*/
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 12px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
}
.badge.asset { background: rgba(46,125,50,.12); color: var(--md-asset); }
.badge.liability { background: rgba(198,40,40,.12); color: var(--md-liability); }
.badge.neutral { background: var(--md-surface-variant); color: var(--md-on-surface-variant); }

.flash { padding: 12px 18px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; font-weight: 500; }
.flash.success { background: rgba(20,108,46,.1); color: var(--md-success); border-left: 3px solid var(--md-success); }
.flash.error { background: rgba(186,26,26,.1); color: var(--md-error); border-left: 3px solid var(--md-error); }

/* ────────────────────────────────────────────────
   LOADING / SKELETON
─────────────────────────────────────────────────*/
.skeleton {
  background: linear-gradient(90deg, var(--md-surface-variant) 25%, var(--md-border) 50%, var(--md-surface-variant) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s infinite;
  border-radius: 6px;
}
@keyframes skeleton-shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }
.skeleton-row td { padding: 14px 10px; }
.skeleton-cell { height: 14px; border-radius: 4px; }
.skeleton-badge { height: 20px; width: 60px; border-radius: 10px; }

.page-loader {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 40px; color: var(--md-on-surface-variant); font-size: 14px;
}
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--md-border);
  border-top-color: var(--md-primary);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ────────────────────────────────────────────────
   BREAKDOWN TABLE (dashboard)
─────────────────────────────────────────────────*/
.breakdown-category {
  background: var(--md-surface-variant);
  font-weight: 700; font-size: 12px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--md-on-surface-variant);
  padding: 8px 10px;
}
.breakdown-group-total td { font-weight: 700; background: transparent; border-top: 2px solid var(--md-border); }
.breakdown-item td { padding-left: 24px; }
.breakdown-expand-btn {
  border: none; background: none; cursor: pointer; color: var(--md-on-surface-variant);
  font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 4px;
  padding: 0;
}
.breakdown-expand-btn:hover { color: var(--md-primary); }

/* ────────────────────────────────────────────────
   MISC
─────────────────────────────────────────────────*/
.section-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--md-on-surface-variant); }
.empty-state .material-symbols-outlined { font-size: 48px; opacity: .4; display: block; margin-bottom: 8px; }
/* ── Details/summary accordion (family member cards) ── */
details.card > summary { outline: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary .material-symbols-outlined:last-child {
  transform: rotate(180deg);
}
details.card > summary .material-symbols-outlined:last-child {
  transition: transform .2s;
}

.chart-card canvas { max-height: 300px; }
.amount-cell { font-variant-numeric: tabular-nums; font-weight: 500; }
.sub-text { color: var(--md-on-surface-variant); font-size: 12px; }

/* ────────────────────────────────────────────────
   RESPONSIVE
─────────────────────────────────────────────────*/
@media (max-width: 1000px) {
  .grid-4, .grid-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  .sidenav { transform: translateX(-100%); }
  .sidenav.open { transform: translateX(0); box-shadow: var(--md-shadow-md); }
  .nav-overlay.open { display: block; }
  .hamburger { display: flex; }
  .main { margin-left: 0; padding: 16px; }
  .topbar { flex-wrap: wrap; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .theme-toggle { display: none; } /* collapsed into mobile menu */
  table { font-size: 13px; }
  th, td { padding: 9px 7px; }

  /* Ribbon collapse is a desktop-only affordance; mobile always uses the
     full-width off-canvas drawer above, so hide the toggle and ignore any
     saved collapsed state. */
  .nav-collapse-btn { display: none; }
  body.nav-collapsed .sidenav { width: var(--nav-width); padding: 16px 12px; }
  body.nav-collapsed .main { margin-left: 0; }
  body.nav-collapsed .brand { justify-content: flex-start; padding: 8px 12px 20px; }
  body.nav-collapsed .brand-text,
  body.nav-collapsed .nav-section,
  body.nav-collapsed .nav-label { display: block; }
  body.nav-collapsed .nav-item { justify-content: flex-start; padding: 10px 14px; gap: 12px; }
}

@media (max-width: 480px) {
  .main { padding: 12px; }
  .card { padding: 14px; }
  .page-title { font-size: 18px; }
}
