/* =========================================================================
   Tathir Asham — single-page stock purification calculator
   Pure CSS, custom-property themed (light + dark), RTL-first
   ========================================================================= */

/* ---- Design tokens ---- */
:root {
  --bg:           #fafaf7;
  --bg-elev:     #ffffff;
  --bg-sunk:     #f5f4ef;
  --border:      #e7e5e0;
  --border-strong:#d6d3cc;
  --text:        #0c0a09;
  --text-muted:  #6b6863;
  --text-soft:   #a8a59f;
  --accent:      #047857;
  --accent-soft: #d1fae5;
  --accent-text: #065f46;
  --danger:      #b91c1c;
  --danger-soft: #fee2e2;
  --focus-ring:  rgba(4,120,87,.25);
  --shadow-card: 0 1px 2px rgba(12,10,9,.04), 0 0 0 1px var(--border);
  --shadow-hero: 0 20px 40px -20px rgba(12,10,9,.3);
  --radius:      14px;
  --radius-sm:   10px;
  --radius-lg:   20px;
  --font-ar:     "IBM Plex Sans Arabic", system-ui, -apple-system, sans-serif;
  --tap:         44px;
}
[data-theme="dark"] {
  --bg:           #0a0908;
  --bg-elev:     #161412;
  --bg-sunk:     #1f1c19;
  --border:      #2a2724;
  --border-strong:#3a3733;
  --text:        #fafaf7;
  --text-muted:  #a8a59f;
  --text-soft:   #6b6863;
  --accent:      #34d399;
  --accent-soft: #064e3b;
  --accent-text: #6ee7b7;
  --danger:      #f87171;
  --danger-soft: #450a0a;
  --focus-ring:  rgba(52,211,153,.3);
  --shadow-card: 0 1px 2px rgba(0,0,0,.4), 0 0 0 1px var(--border);
  --shadow-hero: 0 20px 60px -20px rgba(0,0,0,.6);
}

/* ---- Reset / base ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); color: var(--text); }
body {
  font-family: var(--font-ar);
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }
input { background: transparent; border: none; outline: none; }
table { border-collapse: collapse; width: 100%; }
.num-ltr { unicode-bidi: plaintext; direction: ltr; display: inline-block; font-feature-settings: "tnum" 1, "lnum" 1; }
.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; }
.visually-hidden { display: none; }

/* ---- Header ---- */
.app-header {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.header-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
}
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
[data-theme="dark"] .brand-mark { background: var(--accent); color: #052e22; }
.brand-mark svg { width: 18px; height: 18px; }
.brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.brand-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.1; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

/* Nav */
.app-nav {
  flex: 1;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.app-nav::-webkit-scrollbar { display: none; }
.nav-link {
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--bg-sunk); color: var(--text); }
.nav-link.active { background: var(--text); color: var(--bg); }
[data-theme="dark"] .nav-link.active { background: var(--accent); color: #052e22; }

.header-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

/* ---- Icon button ---- */
.icon-btn {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-sunk); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---- Main layout ---- */
main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 80px;
  display: grid;
  gap: 20px;
}
#page-generic.page-container { display: grid; gap: 20px; }
.page-header { padding: 8px 4px 0; }
.page-title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 6px; line-height: 1.15; }
.page-sub { color: var(--text-muted); font-size: 14px; margin: 0; max-width: 720px; }
.page-note { color: var(--text-muted); font-size: 12px; text-align: center; padding: 8px; }
.card-link {
  font-size: 13px; color: var(--accent); text-decoration: none; font-weight: 500;
}
.card-link:hover { text-decoration: underline; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.card-body-text { font-size: 14px; line-height: 1.7; color: var(--text); margin: 0 0 4px; }

/* ---- KPI grid ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.kpi {
  background: var(--bg-elev);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
}
.kpi-label { font-size: 12px; color: var(--text-muted); text-transform: none; letter-spacing: 0; margin-bottom: 6px; }
.kpi-value { display: flex; align-items: baseline; gap: 6px; }
.kpi-num { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; font-feature-settings: "tnum" 1, "lnum" 1; }
.kpi-unit { font-size: 12px; color: var(--text-muted); }
.kpi-emerald .kpi-num { color: var(--accent); }

/* ---- Purity distribution bar ---- */
.dist-row { display: flex; gap: 4px; padding: 4px; }
.dist-seg { flex: 1; min-width: 60px; }
.dist-bar { height: 10px; border-radius: 6px; margin-bottom: 8px; }
.dist-pure         { background: #34d399; }
.dist-mixed        { background: #fbbf24; }
.dist-non-compliant{ background: #fb7185; }
.dist-forbidden    { background: #ef4444; }
.dist-unknown      { background: #a8a29e; }
.dist-label { font-size: 12px; color: var(--text); }

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-pure         { background: #d1fae5; color: #065f46; }
.badge-mixed        { background: #fef3c7; color: #92400e; }
.badge-non-compliant{ background: #fee2e2; color: #991b1b; }
.badge-forbidden    { background: #fecaca; color: #7f1d1d; }
.badge-unknown      { background: #e7e5e0; color: #57534e; }
.badge-verified     { background: #d1fae5; color: #065f46; }
.badge-manual       { background: #fef3c7; color: #92400e; }
.badge-muted        { background: var(--bg-sunk); color: var(--text-muted); }
[data-theme="dark"] .badge-pure         { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-mixed        { background: #422006; color: #fcd34d; }
[data-theme="dark"] .badge-non-compliant{ background: #450a0a; color: #fda4af; }
[data-theme="dark"] .badge-forbidden    { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .badge-unknown      { background: #2a2724; color: #a8a59f; }
[data-theme="dark"] .badge-verified     { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-manual       { background: #422006; color: #fcd34d; }

.chip-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-inline-end: 6px; vertical-align: middle; }
.chip-dot-pure { background: #34d399; }
.chip-dot-mixed { background: #fbbf24; }
.chip-dot-non-compliant { background: #fb7185; }
.chip-dot-forbidden { background: #ef4444; }
.chip-dot-unknown { background: #a8a29e; }

/* ---- Stock detail page ---- */
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.detail-eyebrow { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.detail-header-actions { display: flex; gap: 8px; flex-shrink: 0; }
.src-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 12px; font-size: 13px; }
.year-hist { display: flex; flex-direction: column; gap: 0; }
.year-row {
  display: grid;
  grid-template-columns: 60px 140px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.year-row:last-child { border-bottom: none; }
.year-label { font-weight: 600; font-feature-settings: "tnum" 1, "lnum" 1; }
.year-value { color: var(--text); }
.year-link { font-size: 12px; color: var(--text-muted); text-decoration: none; }
.year-link:hover { color: var(--accent); }
.related-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.related-card {
  display: block;
  padding: 12px;
  background: var(--bg-sunk);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  transition: background .15s, transform .05s;
}
.related-card:hover { background: var(--border); }
.related-name { font-weight: 500; font-size: 14px; margin-bottom: 4px; }
.related-ticker { font-size: 12px; }

/* ---- Reports archive ---- */
.report-list { display: flex; flex-direction: column; gap: 8px; }
.report-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-elev);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow-card);
  transition: transform .15s;
}
.report-item:hover { transform: translateX(-4px); }
.report-year {
  width: 56px; height: 56px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px;
}
[data-theme="dark"] .report-year { background: var(--accent); color: #052e22; }
.report-title { font-weight: 500; }
.report-meta { font-size: 12px; margin-top: 2px; }
.report-action { font-size: 13px; color: var(--text-muted); }

/* ---- Methodology ---- */
.formula-box {
  background: var(--bg-sunk);
  border-radius: var(--radius-sm);
  padding: 18px;
  text-align: center;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.5px;
  border: 1px dashed var(--border-strong);
}
.class-list { display: flex; flex-direction: column; gap: 14px; padding: 4px 0; }
.class-row { display: grid; grid-template-columns: 16px 1fr; gap: 12px; align-items: flex-start; }
.class-row .chip-dot { margin-top: 6px; }
.class-label { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.class-desc { font-size: 13px; color: var(--text-muted); line-height: 1.6; }
.disclaimer-card { border-inline-start: 3px solid var(--accent); }

/* ---- Settings ---- */
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 4px; gap: 16px;
}
.settings-label { font-weight: 500; }
.settings-sub { font-size: 12px; }
.segmented {
  display: inline-flex; background: var(--bg-sunk); border-radius: 8px; padding: 3px; gap: 2px;
}
.seg { padding: 6px 14px; border-radius: 6px; font-size: 13px; color: var(--text-muted); }
.seg-active { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.1); font-weight: 500; }

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; padding: 4px 0; }
.stat { text-align: center; padding: 10px; background: var(--bg-sunk); border-radius: var(--radius-sm); }
.stat-value { font-size: 20px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 11px; margin-top: 2px; }

/* ---- Source modal ---- */
.src-modal-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px dashed var(--border);
}
.src-modal-row:last-of-type { border-bottom: none; }

/* ---- Dashboard quick-add ---- */
.quick-add { padding: 4px 0; }

/* ---- Report card ---- */
.report-card { border-inline-start: 3px solid var(--accent); }
.report-note { font-size: 13px; color: var(--text-muted); margin: 4px 0 0; }

/* ---- Compact source ribbon (replaces dashboard report hero card) ---- */
.source-ribbon {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding: 10px 16px;
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  font-size: 13px;
  border-inline-start: 3px solid var(--accent);
  box-shadow: var(--shadow-card);
}
.source-ribbon-label { color: var(--text-muted); }
.source-ribbon strong { font-weight: 600; }


/* ---- Cards ---- */
.card {
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 20px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  align-items: center;
}
.toolbar > * { min-height: 40px; }
.toolbar .btn { padding: 7px 12px; font-size: 13px; }
.toolbar .btn svg { width: 14px; height: 14px; }
.btn-block { width: 100%; justify-content: center; }
.btn.is-loading svg { animation: spin 0.9s linear infinite; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.btn:disabled { opacity: .6; cursor: wait; }

/* ---- Overflow menu (kebab) ---- */
.overflow-menu { position: relative; margin-inline-start: auto; }
.overflow-menu > summary {
  list-style: none; cursor: pointer; padding: 7px 10px; min-height: 40px;
  display: inline-flex; align-items: center;
}
.overflow-menu > summary::-webkit-details-marker { display: none; }
.overflow-menu > summary svg { width: 16px; height: 16px; }
.overflow-panel {
  position: absolute;
  inset-inline-end: 0; top: calc(100% + 6px);
  min-width: 200px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hero);
  padding: 4px;
  z-index: 20;
  display: flex; flex-direction: column;
}
.overflow-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  background: transparent; border: none;
  color: var(--text); cursor: pointer;
  font-size: 13px; text-align: start;
}
.overflow-item:hover { background: var(--bg-sunk); }
.overflow-item svg { width: 14px; height: 14px; color: var(--text-muted); }
.overflow-item-danger { color: var(--danger); }
.overflow-item-danger:hover { background: var(--danger-soft); }
.overflow-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ---- Offline banner ---- */
.offline-banner {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #fef3c7;
  color: #92400e;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
}
[data-theme="dark"] .offline-banner { background: #422006; color: #fcd34d; }
.offline-banner.show { display: flex; }
.offline-banner svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s, border-color .15s, transform .05s;
  border: 1px solid transparent;
  background: var(--bg-sunk);
  color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.1); }
[data-theme="dark"] .btn-primary { color: #052e22; }
.btn-ghost { background: transparent; border: 1px solid var(--border-strong); }
.btn-ghost:hover { background: var(--bg-sunk); }
.btn-danger { color: var(--danger); background: transparent; border: 1px solid transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 10px; font-size: 13px; min-height: 32px; }

/* =========================================================================
 * Filter tabs (above the holdings list)
 * ======================================================================= */
.filter-tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-tabs::-webkit-scrollbar { display: none; }
.filter-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  border: none;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.filter-tab:hover { color: var(--text); }
.filter-tab.active { background: var(--text); color: var(--bg); }
[data-theme="dark"] .filter-tab.active { background: var(--accent); color: #052e22; }
.filter-tab-count {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-sunk);
  color: var(--text-muted);
  font-weight: 600;
  font-feature-settings: "tnum" 1;
}
.filter-tab.active .filter-tab-count {
  background: rgba(255,255,255,.18);
  color: inherit;
}
.empty-state-filter { margin-top: 12px; padding: 32px 16px; }

/* =========================================================================
 * Holdings — stacked soft cards (replaces the table)
 * Each card is a single-column block; the headline is the purification amount.
 * Inputs are borderless / blend into the card; they reveal a bottom border on
 * focus. No spreadsheet feel.
 * ======================================================================= */
.holdings-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.holding-card {
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px 20px 16px;
  display: grid;
  gap: 14px;
  position: relative;
  transition: box-shadow .15s, background .15s;
}
.holding-card:hover { box-shadow: 0 4px 12px -4px rgba(12,10,9,.08), 0 0 0 1px var(--border); }
.holding-card.is-purified {
  border-inline-start: 3px solid var(--accent);
  background: linear-gradient(to inline-end, var(--accent-soft) 0%, var(--bg-elev) 24%);
  /* Completed items get de-emphasized so they don't compete with pending */
  opacity: .82;
  padding-top: 14px; padding-bottom: 12px;
}
[data-theme="dark"] .holding-card.is-purified {
  background: linear-gradient(to inline-end, rgba(52,211,153,.06) 0%, var(--bg-elev) 30%);
}
.holding-card.is-purified .amount-num { font-size: 22px; }
.holding-card.is-purified:hover { opacity: 1; }

/* Type toggle (clickable pill in card header) */
.type-toggle {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-sunk);
  color: var(--text-muted);
  transition: all .15s;
}
.type-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.type-toggle.type-sold {
  background: #fde8e8;
  color: #991b1b;
  border-color: #fecaca;
}
[data-theme="dark"] .type-toggle.type-sold {
  background: #450a0a;
  color: #fca5a5;
  border-color: #7f1d1d;
}

/* Sold-records inputs section */
.holding-inputs-sold {
  background: var(--bg-sunk);
  border-radius: 8px;
  padding: 10px 14px;
  border-top: none;
  border-bottom: none;
}

/* Inline segmented control for type pick on a new card */
.segmented-card {
  width: 100%;
  padding: 4px;
  background: var(--bg-sunk);
  border-radius: 8px;
}
.segmented-card .seg { flex: 1; padding: 8px 12px; font-size: 13px; }

/* Header */
.holding-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.holding-identity { min-width: 0; flex: 1; }
.holding-name {
  font-size: 16px; font-weight: 600; letter-spacing: -0.005em;
  line-height: 1.2; margin-bottom: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: block;
}
.holding-name-link { color: inherit; text-decoration: none; transition: color .15s; }
.holding-name-link:hover { color: var(--accent); }
.holding-name-placeholder { color: var(--text-muted); font-weight: 500; }
.holding-meta {
  font-size: 12px; color: var(--text-muted);
  display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.holding-ticker { font-weight: 500; color: var(--text); }
.holding-sector {}
.dot-sep { color: var(--text-soft); }

.holding-actions-top {
  display: flex; gap: 6px; align-items: center; flex-shrink: 0;
}

.status-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-sunk);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px; font-weight: 500;
  transition: all .15s;
}
.status-btn:hover { color: var(--text); border-color: var(--border-strong); }
.status-btn svg { width: 14px; height: 14px; }
.status-btn.status-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-text);
}
.status-btn.status-on:hover { filter: brightness(1.02); }
[data-theme="dark"] .status-btn.status-on { color: var(--accent); }

.icon-btn-sm { width: 32px; height: 32px; }
.icon-btn-sm svg { width: 14px; height: 14px; }

/* Hero — purification amount */
.holding-hero {
  padding: 4px 0 6px;
}
.holding-amount-label {
  font-size: 11px; color: var(--text-muted);
  text-transform: none; letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.holding-amount-value {
  display: flex; align-items: baseline; gap: 6px;
  margin-bottom: 4px;
}
.amount-num {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em;
  font-feature-settings: "tnum" 1, "lnum" 1;
  color: var(--accent);
  line-height: 1;
}
.is-purified .amount-num { color: var(--text-muted); text-decoration: line-through; text-decoration-thickness: 1px; text-decoration-color: var(--border-strong); }
.amount-unit { font-size: 13px; color: var(--text-muted); font-weight: 400; }
.holding-formula {
  font-size: 12px; color: var(--text-muted);
  font-feature-settings: "tnum" 1;
}

/* Soft borderless inputs */
.holding-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
  padding: 12px 0;
  border-top: 1px dashed var(--border);
  border-bottom: 1px dashed var(--border);
}
.card-field { display: flex; flex-direction: column; gap: 4px; }
.card-field-label {
  font-size: 11px; color: var(--text-muted);
  letter-spacing: 0.02em;
}
.card-field-row { display: flex; align-items: center; gap: 8px; }
.card-input {
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  padding: 2px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  width: 100%;
  font-feature-settings: "tnum" 1, "lnum" 1;
  transition: border-color .15s;
}
.card-input::placeholder { color: var(--text-soft); font-weight: 400; }
.card-input:hover { border-bottom-color: var(--border-strong); }
.card-input:focus { outline: none; border-bottom-color: var(--accent); }
.card-input.combo-input { font-size: 15px; }

.card-saved-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  cursor: help;
}

/* Metrics strip */
.holding-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric-label { font-size: 11px; color: var(--text-muted); }
.metric-value {
  font-size: 15px; font-weight: 600;
  font-feature-settings: "tnum" 1, "lnum" 1;
  color: var(--text);
}
.metric-unit { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.metric-sub { font-size: 10px; margin-top: 1px; }

/* Foot — purification timestamp */
.holding-foot {
  display: flex; align-items: center; gap: 8px;
  padding-top: 8px;
  margin-top: -4px;
  border-top: 1px dashed var(--border);
  font-size: 12px; color: var(--accent-text);
}
[data-theme="dark"] .holding-foot { color: var(--accent); }
.holding-foot svg { width: 14px; height: 14px; }

/* New-row picker (no company yet) */
.holding-picker {
  padding: 8px 0;
  border-top: 1px dashed var(--border);
}
.holding-picker .combo-input {
  font-size: 15px;
  background: var(--bg-sunk);
  border-radius: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
.holding-picker .combo-input:focus {
  background: var(--bg-elev);
  border-bottom-color: var(--accent);
}

/* Empty state card (replaces old empty-state) */
.empty-state-card {
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 48px 24px;
  text-align: center;
  border: 1px dashed var(--border);
}
.empty-state-card .empty-state-title {
  font-size: 17px; font-weight: 600;
  color: var(--text); margin-bottom: 6px;
}
.empty-state-card .empty-state-sub {
  font-size: 13px; color: var(--text-muted);
  max-width: 380px; margin: 0 auto;
  line-height: 1.65;
}

@media (max-width: 640px) {
  .holding-card { padding: 16px 16px 14px; }
  .holding-name { font-size: 15px; }
  .amount-num { font-size: 26px; }
  .holding-inputs { grid-template-columns: 1fr; gap: 10px; }
  .holding-metrics { grid-template-columns: 1fr 1fr 1fr; font-size: 13px; }
  .metric-value { font-size: 13px; }
}

/* ---- Rail progress + done state ---- */
.rail-progress { margin-top: 12px; }
.rail-progress-track {
  height: 6px;
  background: var(--bg-sunk);
  border-radius: 999px;
  overflow: hidden;
}
.rail-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .25s ease;
}
.rail-progress-meta {
  font-size: 11px; color: var(--text-muted);
  margin-top: 6px;
  font-feature-settings: "tnum" 1;
}
.rail-meta-done {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--accent-text); font-weight: 600;
}
[data-theme="dark"] .rail-meta-done { color: var(--accent); }

/* ---- Quick calc modal ---- */
.quick-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 8px 0 4px;
}
@media (max-width: 480px) { .quick-inputs { grid-template-columns: 1fr; } }
.quick-input {
  font-size: 18px !important;
  padding: 10px 12px !important;
  background: var(--bg-sunk) !important;
  border-radius: 8px !important;
  border: 1px solid var(--border) !important;
}
.quick-input:focus { border-color: var(--accent) !important; background: var(--bg-elev) !important; }
.quick-result {
  margin-top: 14px;
  padding: 18px 16px;
  background: var(--bg-sunk);
  border-radius: var(--radius-sm);
  text-align: center;
}
.quick-result-label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.quick-result-value {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
}
.quick-result-value #qc-result {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
  font-feature-settings: "tnum" 1, "lnum" 1;
}
.quick-result-formula {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-feature-settings: "tnum" 1;
}

/* ---- Legacy portfolio table styles (only present in old code paths) ---- */
.portfolio { padding: 0; overflow: hidden; }
.portfolio-table { font-size: 14px; }
.portfolio-table thead th {
  text-align: start;
  padding: 12px 14px;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-sunk);
  border-bottom: 1px solid var(--border);
  text-transform: none;
  letter-spacing: 0;
}
.portfolio-table tbody tr { border-bottom: 1px solid var(--border); }
.portfolio-table tbody tr:last-child { border-bottom: none; }
.portfolio-table tbody tr:hover { background: var(--bg-sunk); }
.portfolio-table td { padding: 10px 14px; vertical-align: middle; }
.portfolio-table .col-company { min-width: 200px; max-width: 320px; }
.portfolio-table .col-num { width: 160px; }
.portfolio-table .col-num input { text-align: end; }
.portfolio-table .col-num .ratio-wrap { position: relative; }
.portfolio-table .col-num .ratio-wrap .cell-input { padding-inline-start: 22px; }
.saved-dot {
  position: absolute;
  inset-inline-end: 8px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateY(-50%);
  cursor: help;
}
.portfolio-table .col-total { width: 130px; font-weight: 600; }
.portfolio-table .col-price { width: 130px; }
.portfolio-table .col-mv { width: 130px; font-weight: 600; }
.portfolio-table .col-actions { width: 50px; text-align: center; }
.cell-dim { color: var(--text-soft); font-weight: 400; }
.cell-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; font-weight: 400; }
.cell-stale strong { color: #b45309; }
[data-theme="dark"] .cell-stale strong { color: #f59e0b; }

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state-emoji { font-size: 40px; margin-bottom: 12px; opacity: .5; }
.empty-state-title { font-size: 16px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.empty-state-sub { font-size: 13px; max-width: 320px; margin: 0 auto; }

/* ---- Inputs in table ---- */
.cell-input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid transparent;
  transition: border-color .15s, background .15s;
}
.cell-input:hover { border-color: var(--border); }
.cell-input:focus { border-color: var(--accent); background: var(--bg-elev); box-shadow: 0 0 0 3px var(--focus-ring); }

/* ---- Company picker (combobox) ---- */
.combo { position: relative; }
.combo-input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid transparent;
}
.combo-input:hover { border-color: var(--border); }
.combo-input:focus { border-color: var(--accent); background: var(--bg-elev); box-shadow: 0 0 0 3px var(--focus-ring); }
.combo-list {
  position: absolute;
  top: 100%; inset-inline-start: 0;
  margin-top: 2px;
  width: max(260px, 100%);
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hero);
  z-index: 20;
  display: none;
}
.combo-list.open { display: block; }
.combo-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  width: 100%;
  padding: 10px 12px;
  text-align: start;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.combo-item:last-child { border-bottom: none; }
.combo-item:hover, .combo-item.active { background: var(--accent-soft); }
.combo-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-item-ticker { font-size: 12px; color: var(--text-muted); margin-inline-start: 8px; }
.combo-empty { padding: 14px; color: var(--text-muted); font-size: 13px; }

/* ---- Saved badge ---- */
.saved-badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 10px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-text);
  margin-inline-start: 6px;
}

/* ---- Workspace: holdings + sticky summary rail ---- */
.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}
@media (min-width: 1024px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 300px;
  }
}

.summary-rail {
  display: none;
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px 18px 14px;
}
@media (min-width: 1024px) {
  .summary-rail {
    display: block;
    position: sticky;
    top: 78px;          /* under the sticky app header */
    align-self: start;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
  }
}
.rail-hero { padding-bottom: 14px; }
.rail-label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .12em;
  margin-bottom: 8px;
}
.rail-value { display: flex; align-items: baseline; gap: 6px; }
.rail-num {
  font-size: 36px; font-weight: 700; letter-spacing: -0.02em;
  font-feature-settings: "tnum" 1, "lnum" 1;
  color: var(--accent);
  line-height: 1;
}
.rail-unit { font-size: 14px; color: var(--text-muted); }
.rail-meta { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.rail-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.rail-stat { display: flex; flex-direction: column; gap: 2px; }
.rail-stat-label { font-size: 11px; color: var(--text-muted); }
.rail-stat-value { font-size: 14px; font-weight: 600; font-feature-settings: "tnum" 1; }
.rail-divider { height: 1px; background: var(--border); margin: 0; }
.rail-actions { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; }
.rail-foot { padding-top: 10px; font-size: 11px; color: var(--text-soft); text-align: center; }

/* ---- Mobile bottom summary bar ---- */
.summary-bar {
  display: none;
  position: fixed;
  inset-inline: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px -10px rgba(0,0,0,.3);
  backdrop-filter: blur(8px);
}
@media (max-width: 1023px) {
  .summary-bar { display: block; }
  #page-portfolio-wrap { padding-bottom: 100px; }
}
.summary-bar-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 12px 16px;
  background: transparent; border: none;
  color: var(--text); cursor: pointer;
  text-align: start;
}
.summary-bar-main { display: flex; align-items: baseline; gap: 12px; flex: 1; }
.summary-bar-label { font-size: 12px; color: var(--text-muted); }
.summary-bar-value { font-size: 22px; font-weight: 700; color: var(--accent); font-feature-settings: "tnum" 1; }
.summary-bar-chev { width: 18px; height: 18px; color: var(--text-muted); transition: transform .2s; }
.summary-bar.expanded .summary-bar-chev { transform: rotate(180deg); }
.summary-bar-detail {
  padding: 0 16px 14px;
  border-top: 1px solid var(--border);
}
.summary-bar-detail[hidden] { display: none !important; }
.summary-bar-detail:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 12px;
}
.summary-bar-detail .rail-stats { grid-template-columns: 1fr 1fr; padding: 0; border: none; }

/* ---- Print-only totals (kept off-screen, shown in PDF export) ---- */
.print-only-block { display: none; }
@media print {
  .print-only-block { display: block !important; }
  .summary-rail, .summary-bar, .toolbar, .app-header { display: none !important; }
}

/* ---- Totals hero (legacy / print) ---- */
.totals {
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-lg);
  padding: 28px 28px 24px;
  box-shadow: var(--shadow-hero);
}
[data-theme="dark"] .totals {
  background: linear-gradient(135deg, #1a1614, #0a0908);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.totals-label {
  font-size: 11px;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--text-soft);
  margin-bottom: 8px;
}
[data-theme="light"] .totals-label, .totals .totals-label { color: var(--text-soft); }
.totals-value {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-feature-settings: "tnum" 1, "lnum" 1;
}
.totals-num {
  font-size: clamp(40px, 8vw, 64px);
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1;
}
.totals-currency {
  font-size: 20px;
  font-weight: 300;
  color: var(--text-soft);
}
.totals-meta {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}
.totals .totals-meta strong { color: #fff; font-weight: 600; }
[data-theme="dark"] .totals .totals-meta strong { color: var(--text); }

/* ---- Dialog ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12,10,9,.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.5);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-title { font-size: 17px; font-weight: 600; }
.modal-body { display: flex; flex-direction: column; gap: 14px; }

.drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  background: var(--bg-sunk);
  transition: border-color .15s, background .15s;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.drop-zone-icon { font-size: 32px; opacity: .5; margin-bottom: 8px; }
.drop-zone-text { font-size: 14px; color: var(--text-muted); }
.drop-zone-text strong { color: var(--text); font-weight: 500; }
.drop-zone input { position: absolute; opacity: 0; pointer-events: none; }

textarea {
  font: inherit;
  width: 100%;
  min-height: 140px;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  font-feature-settings: "tnum" 1;
}
textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }

.modal-help {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-sunk);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  line-height: 1.6;
}
.modal-help code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 11px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  bottom: 20px;
  inset-inline-end: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,.4);
  animation: toast-in .2s ease-out;
  pointer-events: auto;
  max-width: 320px;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--accent); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Drag-drop global overlay ---- */
.global-drop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: rgba(4,120,87,.08);
  border: 3px dashed var(--accent);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
}
.global-drop.dragging { display: flex; }

/* ---- Footer ---- */
.app-footer {
  max-width: 1100px;
  margin: 24px auto 40px;
  padding: 0 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-soft);
}
.app-footer a { color: var(--text-muted); text-decoration: none; }
.app-footer a:hover { color: var(--accent); }

/* ---- Responsive ---- */
@media (max-width: 720px) {
  .header-inner { padding: 12px 16px; }
  .brand-title { font-size: 16px; }
  main { padding: 16px 12px 80px; gap: 16px; }
  .card, .toolbar { padding: 14px; border-radius: 12px; }
  .totals { padding: 22px 20px; border-radius: 16px; }

  /* Stack the portfolio table as cards on mobile */
  .portfolio-table thead { display: none; }
  .portfolio-table, .portfolio-table tbody, .portfolio-table tr, .portfolio-table td { display: block; width: 100%; }
  .portfolio-table tr {
    padding: 12px;
    border-bottom: 8px solid var(--bg-sunk);
    position: relative;
  }
  .portfolio-table tr:last-child { border-bottom: none; }
  .portfolio-table td { padding: 6px 0; }
  .portfolio-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 2px;
  }
  .portfolio-table .col-actions { position: absolute; top: 12px; inset-inline-end: 8px; width: auto; padding: 0; }
  .portfolio-table .col-actions::before { display: none; }
  .toolbar { gap: 6px; }
  .btn { padding: 8px 12px; font-size: 13px; }
}

/* ---- Print (used for PDF export via window.print()) ---- */
@media print {
  @page { margin: 16mm 14mm; }
  body { background: white; color: black; font-size: 11pt; }
  .app-header, .toolbar, .app-footer, .icon-btn, .col-actions, .modal-backdrop, .toast-container, .global-drop { display: none !important; }
  main { padding: 0; max-width: none; }
  .card, .totals { box-shadow: none; border: 1px solid #ccc; background: white !important; color: black !important; border-radius: 4px; padding: 12px; }
  .totals-num { color: black; }
  .totals-currency, .totals-meta, .totals-label { color: #555; }
  .portfolio-table thead th { background: #f5f5f5; color: black; }
  .cell-input, .combo-input { border: none; padding: 0; background: transparent; }
  .saved-badge { display: none; }
  .print-only { display: block !important; margin-bottom: 16px; }
  .print-only h1 { font-size: 18pt; margin: 0 0 4px; }
  .print-only .meta { font-size: 10pt; color: #666; }
}
.print-only { display: none; }

/* ---- Misc ---- */
.label { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 4px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.row-flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
