/* ============ DESIGN TOKENS ============ */
:root {
  /* Brand */
  --np-navy:#153673;
  --np-teal:#73C2C2;
  --np-aqua:#85CFC7;

  /* Surfaces & text */
  --np-ink:#0F172A;
  --np-paper: rgb(251, 252, 251);
  --np-gradient:linear-gradient(90deg, #153673 0%, #85CFC7 100%);

  /* Semantics */
  --surface: var(--np-paper);
  --surface-muted: #F6F9FA;
  --border-subtle: rgba(21,54,115,0.12);
  --border-strong: rgba(21,54,115,0.2);
  --text: var(--np-ink);

  /* Form */
  --field-bg: #fff;
  --field-border: #cbd5e1;
  --field-focus: var(--np-teal);

  /* Shadows */
  --elev-1: 0 1px 3px rgba(0,0,0,.1);
  --elev-2: 0 6px 16px rgba(0,0,0,.08);
}

/* Mobile polish overrides */
@media (max-width: 819px) {
  .mobile-controls { border-bottom: 1px solid var(--border-subtle); z-index: 50; }
  .mobile-btn[aria-pressed="true"] { background: var(--np-navy); color: #fff; }
  .mobile-btn:hover { background: #f4f7fb; }
}

/* ============ BASE / RESET ============ */
* { box-sizing: border-box; }
html, body {
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
html { background: var(--surface); }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: var(--surface);
  line-height: 1.5;
}
a { color: var(--np-navy); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--np-teal); outline-offset: 2px; border-radius: 4px; }

/* Reduce motion if the user prefers it */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ============ AUTH OVERLAY (unchanged structure) ============ */
.auth-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--np-gradient);
  backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-overlay.visible { display: flex; }
.auth-card {
  width: 100%; max-width: 420px; background: #fff; color: #0f172a;
  border-radius: 14px; box-shadow: 0 20px 40px rgba(0,0,0,0.25);
  padding: 20px 20px 16px;
}
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.brand .logo-img { height: 28px; width: auto; border-radius: 6px; }
.brand-name { font-weight: 700; letter-spacing: 0.2px; }
.brand-sub { font-size: 12px; color: #6b7280; }
.auth-tabs { display: flex; gap: 6px; margin: 10px 0 8px; }
.auth-tabs .tab {
  flex: 1; padding: 8px 10px; border-radius: 999px; border: 1px solid #e5e7eb;
  background: #f8fafc; cursor: pointer; color: #334155; font-weight: 600;
}
.auth-tabs .tab.active { background: var(--np-navy); color: #fff; border-color: var(--np-navy); }
.auth-form { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.auth-form label { font-size: 12px; color: #475569; }
.auth-form input {
  padding: 10px 12px; border: 1px solid var(--field-border); border-radius: 10px;
  font-size: 14px; background: var(--field-bg);
}
.auth-form .btn.primary {
  background: var(--np-navy); color: #fff; border: none; border-radius: 10px; padding: 10px 12px;
}
.auth-error { color: #b91c1c; font-size: 13px; min-height: 18px; margin-top: 6px; }
.auth-note { color: #64748b; font-size: 12px; margin-top: 6px; }

/* ============ LAYOUT (3 columns) ============ */
.layout { display: flex; min-height: 100vh; position: relative; width: 100%; }
.col {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
  border: 1px solid var(--border-subtle);
  position: relative;
}
.left   { flex: 0 0 25%; background: var(--surface); }
.middle { flex: 0 0 50%; background: var(--surface); }
.right  { flex: 0 0 25%; background: var(--surface); }

/* Collapsed states (JS toggles these classes) */
.collapsed-left .left  { display: none; }
.collapsed-right .right{ display: none; }
/* One side collapsed -> middle 75% */
.collapsed-left:not(.collapsed-right) .middle,
.collapsed-right:not(.collapsed-left) .middle { flex-basis: 75%; }
/* Both collapsed -> middle 100% */
.collapsed-left.collapsed-right .middle { flex-basis: 100%; }

/* Collapse/expand controls */
.btn {
  border: none; background: #fff; color: var(--np-ink);
  box-shadow: var(--elev-1);
  border-radius: 999px; padding: 0.35rem 0.6rem; cursor: pointer; line-height: 1;
}
.btn.icon { font-size: 1rem; }
.btn:hover { background: #f3f3f3; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--np-teal); outline-offset: 2px; }
.btn.primary { background: var(--np-navy); color: #fff; }
.btn.primary:hover { background: #0f2a5a; }
.btn.primary:active { background: #0c2249; }
.btn.small { padding: 0.3rem 0.55rem; font-size: 0.9rem; }
.btn-compact { padding: 0.3rem 0.6rem; font-size: 0.9rem; line-height: 1.1; box-shadow: none; border: 1px solid var(--border-subtle); background: #fff; }

.btn-collapse-left { position: absolute; right: 8px; top: 8px; z-index: 201; }
.btn-collapse-right { position: absolute; left:  8px; top: 8px; z-index: 201; }
.expand-btn { position: absolute; top: 8px; z-index: 200; display: none; pointer-events: auto; }
.expand-left { left: 8px; } .expand-right { right: 8px; }
.collapsed-left .expand-left { display: inline-block; }
.collapsed-right .expand-right { display: inline-block; }
.collapsed-left .btn-collapse-left, .collapsed-right .btn-collapse-right { display: none; }

/* ============ CHAT (middle column) ============ */
.middle .content.middle-content { width: 100%; height: 100%; padding: 0; }
.chat {
  display: flex; flex-direction: column; width: 100%; height: calc(100vh - 2rem); position: relative;
}
.chat-header {
  padding: 0.75rem 1rem; font-weight: 600; border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  display: flex; align-items: center; justify-content: space-between;
}
.chat-header::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: var(--np-gradient); opacity: 0.35; pointer-events: none;
}
.chat-header-right { display: flex; align-items: center; gap: 8px; }
.chat-header-right.hidden { display: none; }
.header-logo { font-size: 18px; opacity: 0.95; }
.chat-header-right .btn { font-size: 12px; font-weight: 600; padding: 6px 10px; }
.chat-title-logo { height: 112px; width: auto; display: block; border-radius: 6px; }
.chat-thread {
  flex: 1; overflow: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem;
  min-height: 0; overscroll-behavior: contain;
}
.bubble {
  max-width: 80%; padding: 0.5rem 0.75rem; border-radius: 10px; box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  transition: box-shadow 120ms ease, transform 120ms ease;
}
.bubble.user { align-self: flex-end; background: rgba(133,207,199,0.18); border: 1px solid rgba(133,207,199,0.35); }
.bubble.assistant { align-self: flex-start; background: #fff; border: 1px solid var(--border-subtle); }
.bubble.system { align-self: center; background: var(--surface-muted); border: 1px solid var(--border-subtle); font-size: 0.9rem; }
.bubble.tool { align-self: center; background: #fff; border: 1px dashed rgba(21,54,115,0.25); font-size: 0.85rem; }
.bubble.widget { background: #fff; border: 1px dashed rgba(0,0,0,0.2); }
.bubble.guidance-bubble { border-style: solid; border-color: rgba(0,0,0,0.18); background: #f8fafc; }
.bubble:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
.bubble-guidance { font-size: 0.9rem; color: var(--text-muted, #425466); margin-bottom: 0.4rem; }
.bubble-guidance-title { font-weight: 600; color: var(--text-strong, #1f2933); margin-bottom: 0.3rem; }

.ff-buttons { display: flex; gap: 0.5rem; margin-top: 0.4rem; }
.chat-input {
  display: flex; gap: 0.5rem; padding: 0.75rem; border-top: 1px solid var(--border-subtle); align-items: center;
}
.chat-input textarea {
  flex: 1; padding: 0.6rem 0.8rem; border-radius: 12px; border: 1px solid var(--border-subtle);
  background: var(--surface-muted); transition: border-color 120ms ease, background-color 120ms ease; min-width: 0;
  resize: none; min-height: 44px; max-height: 180px; line-height: 1.35; overflow-y: auto;
}
.chat-input textarea:focus { border-color: var(--np-teal); background: #fff; outline: none; }
.chat-input .btn { background: var(--np-navy); color: #fff; }
.chat-input .btn:hover { background: #0f2a5a; }
.chat-input .btn:active { background: #0c2249; }
.send-btn { width: 44px; height: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; }
.send-btn svg { width: 18px; height: 18px; display: block; fill: currentColor; }

/* Typing indicator */
.typing { display: inline-flex; align-items: center; gap: 6px; }
.typing .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--np-teal);
  opacity: 0.6; animation: typingBlink 1.2s infinite ease-in-out;
}
.typing .dot:nth-child(2) { animation-delay: 0.15s; }
.typing .dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBlink { 0%,80%,100%{transform:translateY(0);opacity:.4} 40%{transform:translateY(-3px);opacity:1} }

/* ============ LEFT COLUMN (cards) ============ */
.left .content { display: flex; flex-direction: column; height: 100%; box-sizing: border-box; }
.export-row {
  position: sticky; top: 0; background: var(--surface); padding: 0.5rem;
  border-bottom: 1px solid var(--border-subtle); z-index: 10;
}
.export-row .btn { min-width: 110px; font-size: 12px; font-weight: 600; padding: 6px 10px; }
.tool-cards { display: flex; flex-direction: column; gap: 6px; margin: 0; width: 100%; max-width: 520px; }
.card {
  background: #fff; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  border: 1px solid var(--border-subtle); padding: 0.75rem 1rem; transition: box-shadow 120ms ease, transform 120ms ease;
}
.card:hover { box-shadow: var(--elev-2); transform: translateY(-1px); }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-toggle { border: none; background: transparent; color: #64748b; cursor: pointer; padding: 2px 6px; line-height: 1; }
.card-toggle::after { content: '▾'; display: inline-block; transform-origin: center; }
.card.collapsed .card-toggle::after { content: '▸'; }
.card .card-title { font-weight: 600; margin-bottom: 0.25rem; }
.card .muted { color: #555; font-size: 0.9rem; }
.card-details { margin-top: 6px; }
.card.collapsed .card-details { display: none; }

/* Compact card styles in left column */
.left .card { font-size: 12px; line-height: 1.3; padding: 8px 10px; font-variant-numeric: tabular-nums; }
.left .card .card-title { font-size: 12px; margin-bottom: 2px; }
.left .card .muted { font-size: 11px; }

/* Simple gauges */
.gauge { margin-top:6px; }
.gauge-label { font-size:12px; color:#64748b; margin-bottom:4px; }
.gauge-bar { height:6px; background: var(--border-subtle); border-radius:6px; overflow:hidden; }
.gauge-fill { height:100%; width:0%; transition: width .25s ease; }
.gauge-ok { background:#2e7d32; } .gauge-warn { background:#f9a825; } .gauge-bad { background:#c62828; }

/* Risk chips used on Portfolio card */
.risk-chip { display:inline-block; padding:2px 8px; border-radius:999px; font-size:12px; font-weight:600; color:#fff; }
.risk-va { background:#d93025; }
.risk-ag { background:#f57c00; }
.risk-gm { background:#fbbc04; color:#222; }
.risk-inc { background:#1e88e5; }
.risk-cons { background:#43a047; }
.risk-pres { background:#6d4c41; }

/* Monte Carlo layout */
.mc-card-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mc-card-main .mc-stats { flex: 1; }
.mc-card-main .mc-gauge { flex: 0 0 auto; display: flex; align-items: flex-end; }
.thermo { display:flex; align-items:flex-end; gap:10px; margin-top:8px; }
.thermo .bar { position:relative; width: 12px; height: 96px; border-radius: 12px; background: var(--surface-muted); border:1px solid var(--border-subtle); overflow:hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,0.06); }
.thermo .fill { position:absolute; bottom:0; left:0; width:100%; height:0%; transition: height .3s ease; border-radius: 8px 8px 0 0; }
.thermo .ok { background:#2e7d32; } .thermo .warn { background:#f9a825; } .thermo .bad { background:#c62828; }
.thermo .label { font-size: 13px; color:#374151; }

/* ============ RIGHT COLUMN (Inputs) ============ */
.right .content { display: flex; flex-direction: column; height: 100%; box-sizing: border-box; padding-bottom: 12px; }
.side-panel { display: none; flex-direction: column; width: 100%; flex: 1; }
.side-panel.visible { display: flex; }
.panel-header {
  position: sticky; top: 0; z-index: 15;
  font-weight: 700; font-size: 12px; padding: 8px 0 10px;
  background: var(--surface); border-bottom: 1px solid rgba(0,0,0,0.1);
  display: flex; align-items: center; gap: 10px;
}
.inputs-progress { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }
.inputs-progress .bar { position: relative; width: 120px; height: 6px; background: #e5e7eb; border-radius: 4px; overflow: hidden; }
.inputs-progress .label { font-size: 12px; color: #374151; }

.panel-middle {
  flex: 1; display: flex; flex-direction: column; gap: 0.8rem;
  overflow: auto; padding: 10px 0 8px;
}

/* Section cards (each <details> block) */
.panel-section {
  background: #fff;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 6px 10px 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}
.panel-section summary {
  list-style: none;
  font-size: 12px; font-weight: 700; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px;
}
.panel-section summary::-webkit-details-marker { display: none; }
.panel-section summary::after {
  content: '▾'; margin-left: auto; opacity: .7; transform: translateY(1px);
}
.panel-section[open] summary::after { content: '▴'; }
.panel-section label { font-size: 12px; font-weight: 600; }
.panel-section .hint { color: #666; font-size: 12px; }
.panel-section .hint.error { color: #b91c1c; margin-top: 6px; }
.panel-section.highlight {
  border-color: var(--np-teal);
  box-shadow: 0 0 0 2px rgba(16,185,129,0.2);
}

.panel-section input[type="text"],
.panel-section input[type="number"],
.panel-section input[type="email"],
.panel-section input[type="password"],
.panel-section select,
.panel-section textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--field-border);
  border-radius: 10px;
  background: var(--field-bg);
  font-size: 14px;
}
.panel-section textarea { min-height: 72px; resize: vertical; }
.panel-section input:focus,
.panel-section select:focus,
.panel-section textarea:focus {
  outline: none; border-color: var(--field-focus); box-shadow: 0 0 0 3px rgba(115,194,194,0.25);
}

/* Row groups provide a compact, consistent grid for label/field stacks */
.row-group { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-top: 6px; }
.row-group .row { display: flex; flex-direction: column; gap: 6px; }
.row-group .row .row { margin-top: 0; } /* nested rows in People/Insurance */
.row-label { font-weight: 700; font-size: 12px; color: #334155; margin-bottom: 2px; }

/* Buttons inside sections */
.panel-section .btn { align-self: flex-start; font-size: 12px; font-weight: 600; padding: 6px 10px; margin-top: 6px; }
.people-list,
.income-list,
.asset-list,
.liability-list,
.contrib-list,
.policy-list,
.goal-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.people-empty,
.income-empty,
.asset-empty,
.liability-empty,
.contrib-empty,
.policy-empty,
.goal-empty {
  font-size: 12px;
  color: #64748b;
  background: var(--surface-muted);
  border: 1px dashed var(--border-subtle);
  border-radius: 10px;
  padding: 10px;
}
.person-card,
.income-card,
.asset-card,
.liability-card,
.contrib-card,
.policy-card,
.goal-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: #fff;
  box-shadow: var(--elev-1);
}
.person-card-actions,
.income-card-actions,
.asset-card-actions,
.liability-card-actions,
.contrib-card-actions,
.policy-card-actions,
.goal-card-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.person-card-actions .btn,
.income-card-actions .btn,
.asset-card-actions .btn,
.liability-card-actions .btn,
.contrib-card-actions .btn,
.policy-card-actions .btn,
.goal-card-actions .btn {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  box-shadow: none;
  border: 1px solid var(--border-subtle);
  background: #f8fafc;
}
.person-card-actions .btn:hover,
.income-card-actions .btn:hover,
.asset-card-actions .btn:hover,
.liability-card-actions .btn:hover,
.contrib-card-actions .btn:hover,
.policy-card-actions .btn:hover,
.goal-card-actions .btn:hover {
  background: #eef2ff;
}
.person-card-role,
.income-card-type,
.asset-card-type,
.liability-card-type,
.contrib-card-scope,
.policy-card-type,
.goal-card-type { font-weight: 600; font-size: 13px; color: var(--np-ink); }
.person-card-detail,
.income-card-detail,
.asset-card-detail,
.liability-card-detail,
.contrib-card-detail,
.policy-card-detail,
.goal-card-detail { font-size: 12px; color: #475569; display: flex; flex-direction: column; gap: 2px; }
.person-card-flags,
.income-card-meta,
.asset-card-meta,
.liability-card-meta,
.contrib-card-meta,
.policy-card-meta,
.goal-card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.income-card-amount,
.asset-card-value,
.liability-card-balance,
.contrib-card-amount,
.policy-card-premium,
.goal-card-amount { font-weight: 600; font-size: 12px; color: #0f172a; }
.income-card-owner,
.asset-card-owner,
.contrib-card-owner,
.policy-card-insured,
.goal-card-owner { font-size: 12px; color: #1e293b; }
.person-flag,
.income-meta-pill,
.asset-meta-pill,
.liability-meta-pill,
.contrib-meta-pill,
.policy-meta-pill,
.goal-meta-pill {
  background: rgba(115, 194, 194, 0.16);
  border: 1px solid rgba(115, 194, 194, 0.45);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  color: #0f172a;
}

.panel-group {
  padding: 0;
}
.panel-group summary {
  padding: 12px 14px;
  font-size: 13px;
}
.panel-group .panel-group-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 14px 14px;
}
.panel-group .panel-subsection {
  background: #f9fafb;
  border-radius: 10px;
  border-color: rgba(15,23,42,0.08);
  box-shadow: none;
  padding: 6px 10px 10px;
}
.panel-group .panel-subsection summary {
  font-size: 12px;
}

/* Data controls at bottom */
#data-controls { margin-top: auto; padding-top: 0.75rem; border-top: 1px dashed var(--border-subtle); }
#data-controls .btn { font-size: 12px; font-weight: 600; padding: 6px 10px; }

/* Keep content below the corner collapse buttons on desktop */
@media (min-width: 820px) {
  .left .content { padding-top: 40px; }
  .right .content { padding-top: 40px; }
}

/* ============ POPUP ============ */
.popup-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: none; align-items: center; justify-content: center; z-index: 1100;
}
.popup-overlay.visible { display: flex; }
.popup-card {
  background: #fff; border-radius: 12px; padding: 16px 18px; max-width: 420px; width: calc(100% - 32px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.popup-card .title { font-weight: 700; margin-bottom: 6px; }
.popup-card .body { color: #374151; margin-bottom: 10px; }
.popup-card .actions { display: flex; justify-content: flex-end; }

/* ============ MOBILE (single-column) ============ */
.mobile-controls { display: none; }

@media (max-width: 819px) {
  .layout {
    display: block; min-height: 100dvh; padding-top: 3rem; width: 100%; max-width: 100vw;
  }
  .btn-collapse-left, .btn-collapse-right, .expand-btn { display: none !important; }

  .mobile-controls {
    position: sticky; top: 0; display: flex; gap: 0.5rem; justify-content: center; align-items: center;
    background: #fff; padding: calc(0.5rem + env(safe-area-inset-top, 0px)) 0.5rem 0.5rem 0.5rem;
    box-shadow: 0 1px 6px rgba(0,0,0,0.08); z-index: 100; width: 100%; max-width: 100vw;
  }
  .mobile-btn { font-size: 0.95rem; padding: 0.4rem 0.8rem; }

  /* Prevent iOS zoom on tap */
  .chat-input textarea, .chat-input .btn, input, select, textarea, button { font-size: 16px; }

  /* Only one column visible; JS toggles .show-left/.show-right/.show-middle */
  .col { display: none; border-left: none; border-right: none; padding: 0; }
  .col .content { width: 100%; }
  .show-left .left,
  .show-right .right,
  .show-middle .middle { display: flex; width: 100vw; height: calc(100dvh - 3rem); }
  .show-middle .middle .chat { height: calc(100dvh - 3rem - 2px); }
  .chat-thread { justify-content: flex-end; }
  .chat-input { padding-bottom: max(0px, env(safe-area-inset-bottom)); }

  /* Inputs panel: larger touch targets, single-column fields */
  .panel-middle { padding: 10px 0 80px; } /* extra bottom room for keyboard */
  .panel-section { border-radius: 12px; }
  .panel-section summary { font-size: 14px; }
  .panel-section label { font-size: 13px; }
  .row-group { grid-template-columns: 1fr; gap: 8px; }
}

/* ============ UTILITIES ============ */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,1px,1px); white-space: nowrap; border: 0; }

/* Optional: mark fields invalid (future JS can toggle .invalid on inputs) */
input.invalid, select.invalid, textarea.invalid { border-color: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,0.15); }
