/* ==========================================================================
   Smart Stock & Crypto Calculator (ver3) — Linear / Koyfin Flat Design System
   Western Market Semantics: GREEN = Gain/Up · RED = Loss/Down
   Above-the-Fold Engineered · 1080px 2-Column Workspace · Cmd+K Palette
   Typography: Inter + System Sans · tabular-nums · Zero Emoji / Zero Neon Slop
   ========================================================================== */

:root,
:root[data-theme="dark"] {
  --bg: #0b0e14;
  --surface: #12161f;
  --surface-2: #171c27;
  --card-bg: #12161f;
  --row-bg: #171c27;
  --input-bg: #1a202c;
  --result-bg: #12161f;

  --border: #232a38;
  --border-strong: #323c4f;
  --card-border: #232a38;
  --card-border-strong: #323c4f;
  --result-border: #283142;

  --header-bg: rgba(11, 14, 20, 0.9);
  --nav-bg: rgba(11, 14, 20, 0.9);

  --text: #f1f5f9;
  --subtext: #94a3b8;
  --muted: #64748b;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.13);
  --primary-text: #60a5fa;
  --hero-accent: #f1f5f9;

  /* Western market semantics: Green = Up/Gain/Target, Red = Down/Loss/Stop */
  --accent: #22c55e;
  --accent-soft: rgba(34, 197, 94, 0.13);
  --accent-text: #4ade80;
  --mkt-up: #22c55e;

  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.13);
  --warning-text: #fbbf24;

  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.13);
  --danger-text: #f87171;
  --mkt-down: #ef4444;

  --chip-bg: #1a202c;
  --chip-border: #283142;

  --seg-bg: #0f131b;
  --seg-active-bg: #1f2736;
  --seg-active-text: #f1f5f9;

  --card-shadow: none;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 14px 36px rgba(0, 0, 0, 0.5);
  --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.28);

  --radius-sm: 8px;
  --radius-md: 11px;
  --radius-lg: 14px;
  --container-max: 1080px;

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --card-bg: #ffffff;
  --row-bg: #f8fafc;
  --input-bg: #f8fafc;
  --result-bg: #ffffff;

  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --card-border: #e2e8f0;
  --card-border-strong: #cbd5e1;
  --result-border: #e2e8f0;

  --header-bg: rgba(255, 255, 255, 0.92);
  --nav-bg: rgba(255, 255, 255, 0.92);

  --text: #0f172a;
  --subtext: #475569;
  --muted: #64748b;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-text: #1d4ed8;
  --hero-accent: #0f172a;

  /* Western market semantics: Green = Up/Gain/Target, Red = Down/Loss/Stop */
  --accent: #16a34a;
  --accent-soft: #dcfce7;
  --accent-text: #15803d;
  --mkt-up: #16a34a;

  --warning: #d97706;
  --warning-soft: #fef3c7;
  --warning-text: #b45309;

  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --danger-text: #b91c1c;
  --mkt-down: #dc2626;

  --chip-bg: #f1f5f9;
  --chip-border: #e2e8f0;

  --seg-bg: #eef2f6;
  --seg-active-bg: #ffffff;
  --seg-active-text: #0f172a;

  --card-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 14px 36px rgba(15, 23, 42, 0.14);
  --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.22);

  color-scheme: light;
}

/* ---------- Base Reset & English Typography ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.52;
  min-height: 100vh;
  overflow-wrap: break-word;
  transition: background-color 0.16s ease, color 0.16s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img,
svg {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--primary-text);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

/* Monochrome Inline SVG Icons & Global Market Badges */
.sc-icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}

.sc-icon-sm {
  width: 14px;
  height: 14px;
}

.sc-icon-lg {
  width: 18px;
  height: 18px;
}

.sc-badge-svg,
.flag-icon {
  width: 18px;
  height: 13px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
}

.sc-badge-coin,
.sc-badge-curr {
  width: 16px;
  height: 16px;
  display: inline-block;
  flex-shrink: 0;
}

/* Tabular numerals for zero-jitter financial figures */
.num,
.input-field,
.input-box,
.fx-input,
.fee-custom-input,
.result-num,
.res-val,
.kpi-value,
.slot-avg-badge,
table.data-table td,
table.comp-table td {
  font-variant-numeric: tabular-nums;
}

/* Accessibility Helpers */
.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;
}

.skip-link {
  position: fixed;
  top: -100px;
  left: 16px;
  z-index: 200;
  background: var(--primary);
  color: #ffffff;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 12px;
  text-decoration: none;
}

/* ---------- Slim 52px Sticky Header (.site-header) ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.site-header-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 20px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  font-size: 0.92rem;
  letter-spacing: -0.025em;
  white-space: nowrap;
  flex-shrink: 0;
}

.brand-link:hover {
  text-decoration: none;
  color: var(--primary-text);
}

.brand-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  flex-shrink: 0;
}

.site-header .global-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  justify-content: center;
  min-width: 0;
}

.g-nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 5px 9px;
  border-radius: 7px;
  color: var(--subtext);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 0.14s ease, color 0.14s ease;
}

.g-nav-link:hover {
  color: var(--text);
  background: var(--chip-bg);
  text-decoration: none;
}

.g-nav-link.active,
.g-nav-link[aria-current="page"] {
  background: var(--primary-soft);
  color: var(--primary-text);
  font-weight: 700;
}

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

.cmdk-btn,
.icon-btn,
.bookmark-btn,
.lang-btn,
.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  min-width: 32px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--subtext);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.14s ease, color 0.14s ease, background-color 0.14s ease;
}

.cmdk-btn {
  background: var(--surface);
}

.cmdk-kbd {
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--subtext);
  line-height: 1.3;
}

.bookmark-btn,
.theme-btn,
.icon-btn-square {
  width: 32px;
  padding: 0;
}

.lang-btn {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.cmdk-btn:hover,
.icon-btn:hover,
.bookmark-btn:hover,
.lang-btn:hover,
.theme-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--chip-bg);
  text-decoration: none;
}

/* ---------- Page Container & Compact Page Header ---------- */
.page-shell,
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 14px 20px 56px;
  min-width: 0;
}

.page-shell-narrow {
  max-width: 760px;
}

.page-header {
  margin-bottom: 12px;
}

.page-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.38rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.22;
}

.page-header .page-subtitle,
.page-header p {
  font-size: 0.85rem;
  color: var(--subtext);
  margin-top: 3px;
  line-height: 1.45;
}

/* Right Header Cluster: Inline Currency Control + Quiet Saved Indicator */
.page-header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* Inline Currency Segmented Control (.curr-seg) */
.curr-seg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 32px;
  padding: 2px;
  border-radius: 8px;
  background: var(--seg-bg);
  border: 1px solid var(--border);
}

.curr-seg > button,
.curr-seg-btn {
  height: 26px;
  padding: 0 9px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--subtext);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transition: background-color 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.curr-seg > button:hover:not(.active),
.curr-seg-btn:hover:not(.active) {
  color: var(--text);
}

.curr-seg > button.active,
.curr-seg-btn.active {
  background: var(--seg-active-bg);
  color: var(--seg-active-text);
  font-weight: 700;
  box-shadow: var(--shadow-xs);
}

/* Quiet Auto-Save Status (.autosave-pill) */
.autosave-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  transition: color 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
}

.autosave-pill.saved {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-text);
}

/* ---------- Mode Tab Bar (.mode-scenario-bar) ---------- */
.mode-scenario-bar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.tabs,
.main-tabs {
  display: inline-flex;
  gap: 3px;
  background: var(--seg-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 14px;
}

.mode-scenario-bar .main-tabs,
.mode-scenario-bar .tabs {
  margin-bottom: 0;
  flex: 0 1 auto;
}

.tab-btn {
  flex: 1;
  min-width: 0;
  min-height: 34px;
  padding: 7px 14px;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--subtext);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mode-scenario-bar .tab-btn {
  flex: 0 0 auto;
}

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

.tab-btn.active,
.tab-btn[aria-selected="true"] {
  background: var(--seg-active-bg);
  color: var(--seg-active-text);
  font-weight: 700;
  box-shadow: var(--shadow-xs);
}

.sub-tabs {
  display: inline-flex;
  gap: 2px;
  background: var(--seg-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.sub-tab-btn {
  padding: 4px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--subtext);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.14s ease;
}

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

.sub-tab-btn.active {
  background: var(--seg-active-bg);
  color: var(--seg-active-text);
  font-weight: 700;
  box-shadow: var(--shadow-xs);
}

/* ---------- Desktop 2-Column Split Workspace (1.12fr | 0.88fr) ---------- */
.calc-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(0, 0.88fr);
  gap: 16px;
  align-items: start;
}

.calc-inputs {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.calc-results {
  min-width: 0;
  position: sticky;
  top: 66px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- Workspace Toolbar, Market Toggle & Ticker Chips ---------- */
.workspace-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding: 5px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  min-height: 44px;
}

.asset-mode-bar {
  display: inline-flex;
  gap: 3px;
  background: var(--seg-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  flex-shrink: 0;
}

.asset-card-btn {
  min-height: 30px;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  color: var(--subtext);
  font-size: 0.79rem;
  font-weight: 600;
  white-space: nowrap;
  transition: 0.14s ease;
}

.asset-card-btn:hover {
  color: var(--text);
}

.asset-card-btn.active,
.asset-card-btn[aria-pressed="true"] {
  background: var(--seg-active-bg);
  color: var(--seg-active-text);
  font-weight: 700;
  box-shadow: var(--shadow-xs);
}

.slot-slider-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.slide-arrow {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--subtext);
  width: 26px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: 0.14s ease;
}

.slide-arrow:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--chip-bg);
}

.slot-bar {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  scroll-behavior: smooth;
  padding: 1px;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
}

.slot-bar::-webkit-scrollbar {
  display: none;
}

.slot-chip {
  background: var(--chip-bg);
  border: 1px solid transparent;
  color: var(--subtext);
  padding: 4px 9px;
  min-height: 30px;
  border-radius: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: 0.14s ease;
}

.slot-chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.slot-chip.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-text);
  font-weight: 700;
}

.slot-avg-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--subtext);
  opacity: 0.9;
}

.slot-chip.active .slot-avg-badge {
  color: var(--primary-text);
  opacity: 1;
}

.slot-pnl-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
}

.slot-pnl-dot.up {
  background: var(--accent);
}

.slot-pnl-dot.down {
  background: var(--danger);
}

.slot-chip .del-slot {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 2px;
  display: inline-flex;
  align-items: center;
}

.slot-chip .del-slot:hover {
  color: var(--danger);
}

.btn-portfolio,
.btn-fixed-add {
  background: var(--chip-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  height: 30px;
  padding: 0 9px;
  border-radius: 7px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: 0.14s ease;
}

.btn-portfolio:hover,
.btn-portfolio.open,
.btn-fixed-add:hover {
  border-color: var(--primary);
  color: var(--primary-text);
  background: var(--primary-soft);
}

/* Collapsible Portfolio Glance Panel */
.portfolio-glance-panel {
  display: none;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--card-shadow);
}

.portfolio-glance-panel.open {
  display: block;
}

.portfolio-glance-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
}

.portfolio-glance-totals {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--subtext);
}

tr.portfolio-row {
  cursor: pointer;
}

/* ---------- Collapsible 1-Line Config Bar (.config-bar) ---------- */
.config-bar {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 11px;
  transition: border-color 0.15s ease;
}

.config-bar.has-active {
  border-color: var(--primary);
  border-left: 3px solid var(--primary);
}

.config-bar.has-active-warn {
  border-color: var(--warning);
  border-left: 3px solid var(--warning);
}

.config-bar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 28px;
}

.config-bar-summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.79rem;
  font-weight: 600;
  color: var(--text);
  min-width: 0;
}

.config-bar-meta {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--subtext);
}

.config-bar.has-active .config-bar-meta {
  color: var(--primary-text);
}

.config-bar-controls {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.config-bar-toggle {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--subtext);
  height: 26px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 0.73rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: 0.14s ease;
}

.config-bar-toggle:hover,
.config-bar-toggle.open {
  border-color: var(--primary);
  color: var(--primary-text);
  background: var(--primary-soft);
}

.config-bar-body {
  display: none;
  padding-top: 10px;
  margin-top: 9px;
  border-top: 1px solid var(--border);
}

.config-bar-body.open {
  display: block;
}

/* ---------- Flat Cards & Section Headers ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--card-shadow);
}

.calc-inputs > .card,
.calc-results > .card,
.calc-results > .result-card {
  margin-bottom: 0;
}

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

.calc-inputs > .card + .card,
.calc-results > .card + .card {
  margin-top: 0;
}

.card-head,
.slim-card-head,
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.title-inline-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.section-title,
.card-title-text {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.inline-edit-input {
  background: var(--input-bg);
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 700;
  width: 140px;
}

.btn-mini-rename {
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--subtext);
  font-size: 0.73rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: 0.14s ease;
}

.btn-mini-rename:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* Flat Minimal Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
}

.badge-primary {
  background: var(--primary-soft);
  color: var(--primary-text);
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.badge-warning {
  background: var(--warning-soft);
  color: var(--warning-text);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger-text);
}

.badge-muted {
  background: var(--chip-bg);
  color: var(--subtext);
}

/* ---------- Grids, Form Controls & Inline Validation ---------- */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.form-group,
.input-group {
  margin-bottom: 10px;
  min-width: 0;
}

.grid-2 > .form-group,
.grid-2 > .input-group,
.grid-3 > .form-group,
.grid-3 > .input-group,
.grid-4 > .form-group,
.grid-4 > .input-group {
  margin-bottom: 0;
}

.input-group label,
.form-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--subtext);
  margin-bottom: 5px;
}

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

.input-prefix,
.input-suffix {
  position: absolute;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
  pointer-events: none;
  user-select: none;
}

.input-prefix {
  left: 11px;
}

.input-suffix {
  right: 11px;
}

.input-field,
.input-box,
.select-field {
  width: 100%;
  min-height: 40px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  padding: 8px 11px;
  font-size: 0.96rem;
  font-weight: 700;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.input-field,
.input-box {
  text-align: right;
}

.input-box.text-left,
.input-field.text-left {
  text-align: left;
}

.input-wrap.has-prefix .input-field,
.input-wrap.has-prefix .input-box {
  padding-left: 28px;
}

.input-wrap.has-suffix .input-field,
.input-wrap.has-suffix .input-box {
  padding-right: 36px;
}

.input-field::placeholder,
.input-box::placeholder {
  color: var(--muted);
  font-weight: 500;
}

.input-field:hover,
.input-box:hover,
.select-field:hover {
  border-color: var(--border-strong);
}

.input-field:focus,
.input-box:focus,
.select-field:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: var(--focus-ring);
}

.input-invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px var(--danger-soft) !important;
}

.inline-error-msg {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--danger-text);
  margin-top: 4px;
  line-height: 1.4;
}

.unit-sub {
  font-size: 0.74rem;
  color: var(--subtext);
  text-align: right;
  margin-top: 3px;
  font-weight: 600;
  min-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.field-hint {
  font-size: 0.75rem;
  color: var(--subtext);
  margin-top: 4px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"],
.checkbox-label input[type="radio"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* ---------- Dynamic Step Rows (Buy / Scale-Out Steps) ---------- */
.row-list {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
  border-top: 1px solid var(--border);
}

.slim-row {
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.slim-row-main {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) minmax(0, 1.15fr) 26px;
  gap: 8px;
  align-items: center;
}

.row-num-badge {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--subtext);
  background: var(--chip-bg);
  padding: 7px 0;
  border-radius: 6px;
  text-align: center;
  white-space: nowrap;
}

.qty-wrap {
  display: flex;
  gap: 4px;
  align-items: center;
}

.btn-quick {
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--subtext);
  font-size: 0.71rem;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: 0.14s ease;
}

.btn-quick:hover {
  border-color: var(--primary);
  color: var(--primary-text);
  background: var(--primary-soft);
}

.pct-chips-bar {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.pct-chip {
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--subtext);
  font-size: 0.71rem;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: 0.14s ease;
}

.pct-chip:hover {
  border-color: var(--primary);
  color: var(--primary-text);
  background: var(--primary-soft);
}

.pct-chip.highlight {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary-text);
  font-weight: 700;
}

.pct-chip.highlight:hover {
  background: var(--primary);
  color: #ffffff;
}

.slim-row-sub {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  padding-left: 48px;
}

.slim-row-sub-left {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.sub-hint-text {
  color: var(--subtext);
  white-space: nowrap;
}

.sub-sum-text {
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.del-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: 0.14s ease;
}

.del-btn:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

/* ---------- Quick Chips & Presets ---------- */
.quick-bar,
.fee-presets {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 10px;
}

.quick-bar-lbl {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  margin-right: 2px;
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 5px;
  margin-bottom: 10px;
}

.q-chip,
.curr-btn,
.unit-btn,
.preset-chip {
  flex: 0 0 auto;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--subtext);
  border-radius: 7px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  transition: 0.14s ease;
}

.q-chip {
  padding: 5px 10px;
  font-size: 0.76rem;
}

.curr-btn {
  min-width: 72px;
  padding: 6px 10px;
  font-size: 0.78rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.unit-btn {
  min-width: 56px;
  padding: 5px 10px;
  font-size: 0.76rem;
}

.preset-chip {
  padding: 4px 9px;
  font-size: 0.74rem;
  border-radius: 6px;
}

.q-chip:hover,
.curr-btn:hover,
.unit-btn:hover,
.preset-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.q-chip.active,
.curr-btn.active,
.unit-btn.active,
.preset-chip.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-text);
  font-weight: 700;
}

.fee-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  margin-bottom: 10px;
}

.fee-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.fee-top label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.fee-top input[type="checkbox"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
}

.fee-custom-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.fee-custom-input {
  width: 68px;
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 4px 7px;
  border-radius: 7px;
  text-align: right;
  font-size: 0.84rem;
  font-weight: 700;
}

.fee-custom-input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: var(--focus-ring);
}

.fx-bar {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 11px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.8rem;
}

.fx-left,
.fx-right {
  display: flex;
  align-items: center;
  gap: 7px;
}

.fx-input {
  width: 84px;
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 7px;
  text-align: right;
  font-size: 0.86rem;
  font-weight: 700;
}

.fx-input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn-fx-refresh {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--subtext);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: 0.14s ease;
}

.btn-fx-refresh:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary-text);
  background: var(--primary-soft);
}

.btn-fx-refresh:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* ---------- Flat Action Buttons ---------- */
.btn-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.btn,
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 13px;
  border-radius: 9px;
  font-size: 0.82rem;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: 0.14s ease;
}

.action-btn {
  flex: 1;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  text-decoration: none;
}

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

.btn-secondary:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  text-decoration: none;
}

.btn-outline {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--subtext);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary-text);
  text-decoration: none;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger-text);
}

.btn-danger:hover {
  background: var(--danger);
  color: #ffffff;
}

.btn-add {
  background: var(--chip-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
}

.btn-add:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-text);
}

.btn-reset {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--subtext);
  flex: 0 0 auto;
  min-width: 74px;
}

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

.btn-sync-data,
.btn-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: var(--primary-soft);
  border: 1px solid transparent;
  color: var(--primary-text);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.14s ease;
}

.btn-sync-data:hover,
.btn-copy:hover {
  background: var(--primary);
  color: #ffffff;
}

/* ---------- Flagship Result Card, KPIs & Single-Row Actions ---------- */
.result-card {
  background: var(--result-bg);
  border: 1px solid var(--result-border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--card-shadow);
}

.result-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 9px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.result-hero-block {
  margin-bottom: 10px;
}

.result-hero-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.result-box {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.result-box.full {
  grid-column: span 2;
}

.result-box.border-top {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 2px;
}

.result-lbl {
  font-size: 0.75rem;
  color: var(--subtext);
  font-weight: 600;
  margin-bottom: 3px;
}

.result-num {
  font-size: 1.04rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.result-num.hero {
  font-size: 1.56rem;
  font-weight: 800;
  color: var(--hero-accent);
  letter-spacing: -0.03em;
  line-height: 1.22;
}

.result-num.green,
.result-num.profit,
.res-val.profit,
.kpi-value.profit {
  color: var(--accent-text);
}

.result-num.yellow,
.result-num.warn,
.res-val.warn,
.kpi-value.warn {
  color: var(--warning-text);
}

.result-num.red,
.result-num.loss,
.res-val.loss,
.kpi-value.loss {
  color: var(--danger-text);
}

.result-num.blue,
.kpi-value.blue {
  color: var(--primary-text);
}

.res-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.res-row > div {
  min-width: 0;
}

.res-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.res-row:first-child {
  padding-top: 0;
}

.res-label {
  font-size: 0.82rem;
  color: var(--subtext);
  font-weight: 500;
  flex-shrink: 0;
}

.res-val {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  text-align: right;
  white-space: nowrap;
}

.res-val.highlight {
  font-size: 1.42rem;
  font-weight: 800;
  color: var(--hero-accent);
  letter-spacing: -0.03em;
}

.sub-unit,
.sub-unit-line {
  display: block;
  font-size: 0.74rem;
  color: var(--subtext);
  font-weight: 600;
  margin-top: 2px;
  white-space: normal;
  line-height: 1.38;
}

/* Unified 2x2 KPI Tiles */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 8px;
}

.kpi-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kpi-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 0;
}

.kpi-label {
  font-size: 0.72rem;
  color: var(--subtext);
  font-weight: 600;
  margin-bottom: 3px;
}

.kpi-value {
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
}

.kpi-sub {
  font-size: 0.71rem;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.35;
}

/* ---------- Visual Price Bar (/) & Dual Split Bar (/compound, /profit) ---------- */
.price-bar-box {
  margin-top: 8px;
  padding: 8px 11px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.price-bar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--subtext);
  margin-bottom: 8px;
}

.price-bar-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--chip-bg);
  margin: 4px 0 8px;
}

.price-bar-span {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 999px;
  transition: left 0.18s ease, width 0.18s ease;
}

.price-bar-span.up {
  background: var(--accent);
}

.price-bar-span.down {
  background: var(--danger);
}

.price-bar-dot {
  position: absolute;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--subtext);
  border: 1.5px solid var(--surface);
  transform: translate(-50%, -50%);
}

.price-bar-dot.current {
  width: 11px;
  height: 11px;
  background: var(--text);
  border: 2px solid var(--surface);
  z-index: 3;
}

.price-bar-dot.current.up {
  background: var(--accent);
}

.price-bar-dot.current.down {
  background: var(--danger);
}

.price-bar-tick {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2.5px;
  border-radius: 2px;
  background: var(--primary);
  transform: translateX(-50%);
  z-index: 2;
}

.price-bar-captions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  font-size: 0.71rem;
  font-weight: 600;
  color: var(--subtext);
  font-variant-numeric: tabular-nums;
}

.price-bar-captions > span:nth-child(2) {
  text-align: center;
  color: var(--primary-text);
  font-weight: 700;
}

.price-bar-captions > span:nth-child(3) {
  text-align: right;
}

/* Dual Proportion Split Bar (Principal vs Profit / Stock vs FX) */
.split-bar-box {
  margin-top: 10px;
}

.split-bar-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--chip-bg);
  overflow: hidden;
  display: flex;
}

.split-bar-seg-a {
  height: 100%;
  background: var(--primary);
  transition: width 0.2s ease;
}

.split-bar-seg-b {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease;
}

.split-bar-seg-b.neg-seg {
  background: var(--danger);
}

.split-bar-legend {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 5px;
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--subtext);
  font-variant-numeric: tabular-nums;
}

/* ---------- Calm 3px Left-Accent Callouts (.callout) ---------- */
.callout {
  margin-top: 8px;
  padding: 8px 11px;
  border-radius: 9px;
  font-size: 0.81rem;
  font-weight: 500;
  line-height: 1.48;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  color: var(--text);
}

.callout strong {
  font-weight: 700;
  color: var(--text);
}

.callout-info {
  border-left-color: var(--primary);
  background: var(--primary-soft);
  color: var(--text);
}

.callout-success {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.callout-warning {
  border-left-color: var(--warning);
  background: var(--warning-soft);
  color: var(--text);
}

.callout-danger {
  border-left-color: var(--danger);
  background: var(--danger-soft);
  color: var(--text);
}

/* ---------- Single-Row Result Actions & Compact 2-Col Handoff ---------- */
.result-actions {
  display: grid;
  grid-template-columns: 1.25fr 1fr auto;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.result-actions:has(> :nth-child(4)) {
  grid-template-columns: 1.25fr 1fr 1fr auto;
}

.result-actions > button,
.result-actions > a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  min-height: 34px;
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 0.77rem;
  font-weight: 600;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: 0.14s ease;
}

.result-actions > button:hover,
.result-actions > a:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-text);
  text-decoration: none;
}

.result-actions > .btn-act-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  font-weight: 700;
}

.result-actions > .btn-act-primary:hover {
  background: var(--primary-hover);
  color: #ffffff;
}

.result-actions > .btn-act-reset {
  background: transparent;
  color: var(--subtext);
  padding: 6px 10px;
}

/* Status Toggle Pill */
.status-toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--chip-bg);
  color: var(--subtext);
  font-size: 0.73rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.14s ease;
}

.status-toggle-chip.on {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-text);
  font-weight: 700;
}

.status-toggle-chip:hover {
  border-color: var(--primary);
  color: var(--text);
}

/* Receipt-Style Fee & Tax Breakdown */
.receipt-list {
  margin-top: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.receipt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--subtext);
}

.receipt-row strong,
.receipt-row .num {
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.receipt-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2px 0;
}

.receipt-row.receipt-total {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

/* Compact 2-Column Handoff Bar */
.handoff-bar {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
}

.handoff-title {
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 5px;
}

.handoff-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.handoff-links-2col,
.handoff-links-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.handoff-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.14s ease, background-color 0.14s ease, color 0.14s ease;
}

.handoff-link:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-text);
  text-decoration: none;
}

.handoff-link-text {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

.handoff-arrow {
  color: var(--primary-text);
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  transition: transform 0.14s ease;
}

.handoff-link:hover .handoff-arrow {
  transform: translateX(2px);
}

/* ---------- Inline SVG Chart & Comparison Bars ---------- */
.chart-box {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--subtext);
}

.chart-legend {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 0.73rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.compare-bar-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.compare-bar-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--chip-bg);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.2s ease;
}

.progress-fill.accent {
  background: var(--accent);
}

.progress-fill.danger {
  background: var(--danger);
}

/* ---------- Collapsible Advanced Drawer ---------- */
.pro-drawer-wrap {
  margin-top: 10px;
}

.pro-toggle-btn,
.btn-pro-toggle {
  width: 100%;
  min-height: 38px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--subtext);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  transition: 0.14s ease;
}

.pro-toggle-btn.has-active,
.btn-pro-toggle.has-active {
  border-color: var(--primary);
  border-left: 3px solid var(--primary);
  color: var(--text);
}

.pro-toggle-btn:hover,
.btn-pro-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.pro-toggle-btn.open,
.btn-pro-toggle.open {
  border-color: var(--border-strong);
  color: var(--text);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.pro-drawer-body {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-top: none;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  padding: 13px;
  flex-direction: column;
  gap: 11px;
}

.pro-drawer-body.open {
  display: flex;
}

.pro-section {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.pro-section:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.pro-sec-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 7px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

/* ---------- Data Tables ---------- */
.table-wrap {
  margin-top: 10px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
}

.table-wrap.no-max-height {
  max-height: none;
}

table.data-table,
table.comp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.81rem;
}

table.data-table th,
table.comp-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  color: var(--subtext);
  padding: 9px 10px;
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

table.data-table th:first-child,
table.data-table td:first-child,
table.comp-table th:first-child,
table.comp-table td:first-child {
  text-align: center;
}

table.data-table td,
table.comp-table td {
  padding: 8px 10px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

table.data-table tbody tr:last-child td,
table.comp-table tbody tr:last-child td {
  border-bottom: none;
}

table.data-table tbody tr:hover,
table.comp-table tbody tr:hover {
  background: var(--primary-soft);
}

table.data-table tr.row-highlight,
table.comp-table tr.row-highlight {
  background: var(--primary-soft);
}

.pos,
.mkt-up {
  color: var(--accent-text);
  font-weight: 700;
}

.neg,
.mkt-down {
  color: var(--danger-text);
  font-weight: 700;
}

/* ---------- Editorial Lower Sections (Field Notes / Tables / FAQ / Related) ---------- */
.editorial-wrap {
  margin-top: 36px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.guide-section,
.insight-section,
.faq-section,
.related-section {
  background: transparent;
  border: none;
  padding: 0;
  margin-top: 24px;
}

.editorial-wrap .guide-section,
.editorial-wrap .insight-section,
.editorial-wrap .faq-section,
.editorial-wrap .related-section {
  margin-top: 0;
}

.editorial-wrap > section + section {
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.guide-section h2,
.insight-section h2,
.faq-section h2,
.related-section h2 {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.025em;
  margin-bottom: 10px;
}

.section-intro {
  font-size: 0.85rem;
  color: var(--subtext);
  margin-top: -4px;
  margin-bottom: 14px;
  line-height: 1.5;
}

.guide-section h3,
.insight-section h3 {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text);
  margin: 16px 0 8px;
}

.guide-section p,
.guide-section li,
.insight-section > p {
  font-size: 0.87rem;
  color: var(--subtext);
  line-height: 1.62;
}

.guide-list {
  margin: 8px 0;
  padding-left: 18px;
}

.guide-list li + li {
  margin-top: 5px;
}

.guide-list strong {
  color: var(--text);
}

.formula-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 11px 14px;
  margin: 12px 0;
  font-size: 0.84rem;
  color: var(--text);
  font-weight: 600;
  line-height: 1.58;
  overflow-x: auto;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.insight-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.insight-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 16px;
  min-width: 0;
  box-shadow: var(--card-shadow);
}

.insight-kicker {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary-text);
}

.insight-kicker.accent { color: var(--accent-text); }
.insight-kicker.warn { color: var(--warning-text); }
.insight-kicker.danger { color: var(--danger-text); }
.insight-kicker.muted { color: var(--subtext); }

.insight-title,
.guide-section h3.insight-title,
.insight-section h3.insight-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.38;
  letter-spacing: -0.02em;
  margin: 0;
}

.insight-body {
  font-size: 0.83rem;
  color: var(--subtext);
  line-height: 1.58;
  flex: 1;
}

.insight-body strong {
  color: var(--text);
  font-weight: 700;
}

.insight-stat {
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.42;
}

.insight-stat.primary { background: var(--primary-soft); border-color: transparent; color: var(--primary-text); }
.insight-stat.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.insight-stat.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger-text); }
.insight-stat.warn { background: var(--warning-soft); border-color: transparent; color: var(--warning-text); }

.faq-list {
  display: flex;
  flex-direction: column;
}

.faq-item {
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.faq-item:first-child { padding-top: 2px; }
.faq-item:last-child { border-bottom: none; padding-bottom: 0; }

.faq-item h3,
.faq-q {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 5px;
  line-height: 1.42;
}

.faq-item p,
.faq-a {
  font-size: 0.85rem;
  color: var(--subtext);
  line-height: 1.62;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.related-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--card-shadow);
  transition: border-color 0.14s ease, background-color 0.14s ease;
}

.related-card:hover {
  border-color: var(--primary);
  background: var(--surface-2);
  text-decoration: none;
}

.related-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.related-card-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
}

.related-card-arrow {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  transition: transform 0.14s ease, color 0.14s ease;
}

.related-card:hover .related-card-arrow {
  color: var(--primary-text);
  transform: translateX(2px);
}

.related-card-desc {
  font-size: 0.79rem;
  color: var(--subtext);
  line-height: 1.48;
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  font-size: 0.79rem;
  color: var(--muted);
}

.footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.footer-links a,
.footer-links button {
  background: none;
  border: none;
  padding: 2px 4px;
  font-size: 0.79rem;
  font-weight: 600;
  color: var(--subtext);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.footer-links a:hover,
.footer-links button:hover {
  color: var(--text);
  text-decoration: underline;
}

.footer-links .footer-ko-link {
  color: var(--primary-text);
}

.footer-note {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ---------- Global Cmd/Ctrl+K Command Palette Modal ---------- */
.cmdk-backdrop {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(5, 8, 14, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 13vh;
}

.cmdk-backdrop.open {
  display: flex;
}

.cmdk-dialog {
  width: calc(100vw - 24px);
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.cmdk-search-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--subtext);
}

.cmdk-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 500;
}

.cmdk-input::placeholder {
  color: var(--muted);
}

.cmdk-list {
  max-height: min(56vh, 380px);
  overflow-y: auto;
  padding: 6px;
}

.cmdk-group-title {
  padding: 8px 10px 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.cmdk-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.cmdk-item:hover,
.cmdk-item.active {
  background: var(--primary-soft);
}

.cmdk-item-left {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.cmdk-item-icon {
  color: var(--subtext);
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.cmdk-item.active .cmdk-item-icon {
  color: var(--primary-text);
}

.cmdk-item-title {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cmdk-item-meta {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--subtext);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.cmdk-empty {
  padding: 24px 14px;
  text-align: center;
  font-size: 0.84rem;
  color: var(--muted);
}

.cmdk-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.72rem;
  color: var(--muted);
}

/* ---------- Toast Notifications ---------- */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 350;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: #191f28;
  color: #f9fafb;
  border: 1px solid #333d4b;
  border-radius: 10px;
  padding: 10px 15px;
  font-size: 0.83rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  text-align: center;
  line-height: 1.45;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.toast-success { border-color: var(--accent); }
.toast.toast-warning { border-color: var(--warning); }
.toast.toast-error { border-color: var(--danger); }

/* ---------- 404 Error Page Layout ---------- */
.error-hero {
  text-align: center;
  padding: 34px 20px;
}

.error-code {
  display: inline-block;
  font-size: 3.1rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--primary);
  margin-bottom: 10px;
}

.error-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}

.error-desc {
  font-size: 0.88rem;
  color: var(--subtext);
  max-width: 460px;
  margin: 0 auto 18px;
  line-height: 1.58;
}

.error-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Small Utility Classes ---------- */
.hidden { display: none !important; }
.muted { color: var(--subtext); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 12px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 12px; }

/* ---------- Responsive Tablet / Mobile (< 900px) ---------- */
@media (max-width: 899px) {
  .site-header-inner {
    flex-wrap: wrap;
    padding: 8px 14px;
    gap: 8px;
    min-height: auto;
  }

  .cmdk-btn {
    width: 32px;
    padding: 0;
  }

  .cmdk-btn .cmdk-kbd {
    display: none;
  }

  .site-header .global-nav {
    order: 3;
    flex: 1 0 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
  }

  .g-nav-link {
    min-width: 0;
    min-height: 32px;
    padding: 5px 4px;
    font-size: 0.76rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .page-shell,
  .container {
    padding: 12px 14px 48px;
  }

  .workspace-toolbar {
    flex-wrap: wrap;
    gap: 7px;
  }

  .asset-mode-bar {
    width: 100%;
  }

  .asset-card-btn {
    flex: 1;
  }

  .mode-scenario-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 10px;
  }

  .mode-scenario-bar .main-tabs,
  .mode-scenario-bar .tabs {
    width: 100%;
  }

  .mode-scenario-bar .tab-btn {
    flex: 1;
  }

  .calc-workspace {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .calc-results {
    position: static;
  }

  .insight-grid,
  .insight-grid-2 {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
}

@media (max-width: 599px) {
  .page-shell,
  .container {
    padding: 12px 12px 44px;
  }

  .card,
  .result-card {
    padding: 14px;
    border-radius: 13px;
  }

  .page-header h1 {
    font-size: 1.24rem;
  }

  .page-header .page-subtitle,
  .page-header p {
    font-size: 0.8rem;
  }

  /* Prevent iOS Safari focus zoom */
  .input-field,
  .input-box,
  .select-field,
  .fx-input,
  .fee-custom-input,
  .inline-edit-input,
  .cmdk-input {
    font-size: 16px;
  }

  .fx-input { width: 92px; }
  .fee-custom-input { width: 76px; }

  .tab-btn {
    font-size: 0.79rem;
    padding: 7px 6px;
  }

  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-3 > .input-group:first-child,
  .grid-3 > .form-group:first-child {
    grid-column: span 2;
  }

  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .related-grid,
  .handoff-links-2col,
  .handoff-links-row {
    grid-template-columns: 1fr;
  }

  .result-actions:has(> :nth-child(4)) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .slot-slider-wrap .slide-arrow {
    display: none;
  }

  .btn-portfolio,
  .btn-fixed-add {
    height: 28px;
    padding: 0 7px;
    font-size: 0.72rem;
  }

  .slim-row-main {
    grid-template-columns: 36px minmax(0, 1fr) minmax(0, 1.15fr) 24px;
    gap: 6px;
  }

  .slim-row-sub {
    padding-left: 0;
  }

  .res-row {
    flex-wrap: wrap;
    gap: 4px 10px;
  }

  .res-row > div,
  .res-row > .res-val {
    margin-left: auto;
    max-width: 100%;
  }

  .res-label {
    flex-shrink: 1;
  }

  .res-val {
    white-space: normal;
  }

  .btn-row {
    flex-wrap: wrap;
  }

  .btn-row > .btn,
  .btn-row > .action-btn {
    flex: 1 1 auto;
    max-width: 100%;
    white-space: normal;
  }

  .receipt-row {
    flex-wrap: wrap;
    gap: 4px 8px;
  }

  .receipt-row > strong,
  .receipt-row > .num,
  .receipt-row > span:last-child {
    margin-left: auto;
    max-width: 100%;
    white-space: normal;
    text-align: right;
  }

  .result-num.hero {
    font-size: 1.4rem;
  }
}

@media (max-width: 380px) {
  .brand-link span { font-size: 0.85rem; }
  .tab-btn { font-size: 0.75rem; padding: 7px 4px; }
  .result-num.hero { font-size: 1.3rem; }
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ---------- Print / Share Friendliness ---------- */
@media print {
  :root,
  :root[data-theme="dark"],
  :root[data-theme="light"] {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --card-bg: #ffffff;
    --row-bg: #f8fafc;
    --input-bg: #ffffff;
    --result-bg: #ffffff;
    --border: #cbd5e1;
    --border-strong: #94a3b8;
    --card-border: #cbd5e1;
    --result-border: #94a3b8;
    --text: #0f172a;
    --subtext: #475569;
    --muted: #64748b;
  }

  body { background: #ffffff; }

  .site-header,
  .btn-row,
  .quick-bar,
  .mode-scenario-bar,
  .handoff-bar,
  .result-actions,
  .pro-toggle-btn,
  .btn-pro-toggle,
  .related-section,
  .toast-container,
  .cmdk-backdrop,
  .skip-link {
    display: none !important;
  }

  .calc-workspace { grid-template-columns: 1fr; }
  .calc-results { position: static; }
  .card, .result-card { break-inside: avoid; box-shadow: none; }
  .table-wrap { max-height: none; overflow: visible; }
}
