:root {
  color-scheme: light;
  --ink: #2d2924;
  --muted: #766b62;
  --paper: #f7f0e8;
  --paper-soft: #fbf6ef;
  --panel: #fffdf8;
  --panel-soft: #fff6ec;
  --line: #e6d9cc;
  --deep: #0f675e;
  --deep-2: #094c45;
  --blue: #4f7fd7;
  --teal: #63bdb4;
  --amber: #f0b84a;
  --red: #eb6b6e;
  --green: #2f9b63;
  --peach: #ffb39e;
  --pink: #f59aae;
  --lavender: #a893e6;
  --accent-panel: #dff3ed;
  --shadow: 0 18px 44px rgba(92, 72, 55, 0.11);
  --chart-text: #7d726a;
  --chart-grid: #eadfd3;
  --chart-market: #819bd3;
  --chart-return: #dfad55;
  --chart-average: #d96f73;
  --chart-positive: #438b61;
  --chart-negative: #d96f73;
  --heatmap-positive-rgb: 159, 216, 187;
  --heatmap-negative-rgb: 246, 198, 183;
  --font-sans: "Pretendard Variable", Pretendard, "SUIT Variable", SUIT, "Wanted Sans Variable", "Wanted Sans", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  --font-display: "Pretendard Variable", Pretendard, "SUIT Variable", SUIT, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #eee6da;
  --muted: #b7aa9c;
  --paper: #171411;
  --paper-soft: #201c18;
  --panel: #25211d;
  --panel-soft: #2d2721;
  --line: #463c33;
  --deep: #8bd3ca;
  --deep-2: #c3f0e8;
  --blue: #9cb7f1;
  --teal: #83cdc5;
  --amber: #edc46f;
  --red: #f0989d;
  --green: #89d2a4;
  --peach: #e9a28d;
  --pink: #ee99aa;
  --lavender: #c5b3ee;
  --accent-panel: #2b403b;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.24);
  --chart-text: #b7aa9c;
  --chart-grid: #4a4038;
  --chart-market: #aab9e6;
  --chart-return: #e8bf72;
  --chart-average: #ee9b9f;
  --chart-positive: #92cda7;
  --chart-negative: #ee9b9f;
  --heatmap-positive-rgb: 92, 151, 126;
  --heatmap-negative-rgb: 176, 91, 98;
}

html[data-theme="dark"] body {
  background: #171411;
}

html[data-theme="dark"] .app-header {
  border-bottom-color: rgba(255, 242, 225, 0.08);
  background: rgba(24, 20, 16, 0.9);
}

html[data-theme="dark"] .brand-mark {
  border-color: rgba(255, 232, 200, 0.18);
  background: #8bd3ca;
  color: #14231f;
}

html[data-theme="dark"] .profile-switcher,
html[data-theme="dark"] .command-search input,
html[data-theme="dark"] .source-meta,
html[data-theme="dark"] .top-nav,
html[data-theme="dark"] .icon-button,
html[data-theme="dark"] .button.ghost,
html[data-theme="dark"] .chart-controls select,
html[data-theme="dark"] .filters input,
html[data-theme="dark"] .filters select,
html[data-theme="dark"] .holding-form input,
html[data-theme="dark"] .holding-form select {
  background: rgba(37, 32, 27, 0.88);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: none;
}

html[data-theme="dark"] .app-shell {
  background: transparent;
}

html[data-theme="dark"] .top-nav {
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

html[data-theme="dark"] .command-search svg {
  stroke: #998c7e;
}

html[data-theme="dark"] .top-nav a {
  color: #b7aa9c;
}

html[data-theme="dark"] .top-nav a:hover,
html[data-theme="dark"] .top-nav a[aria-current="page"] {
  border-color: rgba(134, 201, 193, 0.35);
  background: rgba(134, 201, 193, 0.12);
  color: var(--deep-2);
}

html[data-theme="dark"] .metric,
html[data-theme="dark"] .panel {
  background: rgba(37, 32, 27, 0.92);
  border-color: var(--line);
}

html[data-theme="dark"] .metric.accent {
  background: var(--accent-panel);
  border-color: rgba(255, 232, 200, 0.12);
  color: var(--ink);
}

html[data-theme="dark"] .metric.accent span,
html[data-theme="dark"] .metric.accent small {
  color: #d8ccb9;
}

html[data-theme="dark"] .theme-toggle[aria-pressed="true"] {
  background: rgba(232, 191, 114, 0.14);
  border-color: rgba(232, 191, 114, 0.34);
  color: var(--amber);
}

html[data-theme="dark"] .privacy-toggle[aria-pressed="true"] {
  background: rgba(238, 155, 159, 0.14);
  border-color: rgba(238, 155, 159, 0.34);
  color: var(--red);
}

html[data-theme="dark"] .button.primary {
  background: #8bd3ca;
  color: #14231f;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24);
}

html[data-theme="dark"] .button.secondary {
  background: rgba(232, 191, 114, 0.14);
  border-color: rgba(232, 191, 114, 0.3);
  color: var(--amber);
}

html[data-theme="dark"] .button.danger {
  background: rgba(238, 155, 159, 0.12);
  border-color: rgba(238, 155, 159, 0.3);
}

html[data-theme="dark"] .micro-track,
html[data-theme="dark"] .bar-track {
  background: #40372f;
}

html[data-theme="dark"] .heatmap-tile {
  border-color: rgba(255, 242, 225, 0.08);
  background: var(--paper-soft);
}

html[data-theme="dark"] .heatmap-tile span {
  color: rgba(238, 230, 218, 0.68);
}

html[data-theme="dark"] .heading-meta span {
  border-color: rgba(232, 191, 114, 0.26);
  background: rgba(232, 191, 114, 0.12);
  color: var(--amber);
}

html[data-theme="dark"] .label-pill {
  border-color: rgba(134, 201, 193, 0.28);
  background: rgba(134, 201, 193, 0.12);
  color: var(--deep-2);
}

html[data-theme="dark"] .label-pill.family {
  border-color: rgba(193, 174, 223, 0.3);
  background: rgba(193, 174, 223, 0.12);
  color: var(--lavender);
}

html[data-theme="dark"] .label-pill.mixed {
  border-color: rgba(232, 191, 114, 0.3);
  background: rgba(232, 191, 114, 0.12);
  color: var(--amber);
}

html[data-theme="dark"] .overview-table-wrap,
html[data-theme="dark"] .table-wrap {
  scrollbar-color: #5d5147 #211c18;
}

html[data-theme="dark"] .overview-table-wrap::-webkit-scrollbar-thumb,
html[data-theme="dark"] .table-wrap::-webkit-scrollbar-thumb {
  border-color: #211c18;
  background: #5d5147;
}

html[data-theme="dark"] .overview-table-wrap::-webkit-scrollbar-track,
html[data-theme="dark"] .table-wrap::-webkit-scrollbar-track {
  background: #211c18;
}

html[data-theme="dark"] th,
html[data-theme="dark"] td {
  border-bottom-color: #3d342d;
}

html[data-theme="dark"] th {
  background: #211c18;
  color: #c9bdaf;
}

html[data-theme="dark"] th:first-child,
html[data-theme="dark"] td:first-child {
  background: var(--panel);
  box-shadow: 1px 0 0 #3d342d;
}

html[data-theme="dark"] th:first-child {
  background: #211c18;
}

html[data-theme="dark"] tbody tr:hover,
html[data-theme="dark"] tbody tr.selected {
  background: #2c2620;
}

html[data-theme="dark"] .overview-table tbody tr,
html[data-theme="dark"] .holdings-panel tbody tr {
  background: var(--panel);
  border-color: var(--line);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.16);
}

html[data-theme="dark"] .overview-table tbody tr:hover,
html[data-theme="dark"] .overview-table tbody tr.selected,
html[data-theme="dark"] .holdings-panel tbody tr:hover,
html[data-theme="dark"] .holdings-panel tbody tr.selected {
  background: #2c2620;
  border-color: #5a4e43;
}

html[data-theme="dark"] .positive {
  color: var(--green);
}

html[data-theme="dark"] .negative {
  color: var(--red);
}

html[data-theme="dark"] .toast {
  border-color: rgba(255, 242, 225, 0.12);
  background: #2d2721;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  scroll-padding-top: 150px;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  gap: 12px;
  padding: 18px 28px 14px;
  border-bottom: 1px solid rgba(132, 103, 75, 0.14);
  background: rgba(251, 246, 239, 0.92);
  backdrop-filter: blur(18px);
}

.header-main,
.header-sub {
  display: flex;
  align-items: center;
  gap: 16px;
  width: min(1500px, 100%);
  margin: 0 auto;
}

.header-main {
  justify-content: space-between;
}

.header-sub {
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  flex: 0 0 auto;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid rgba(186, 137, 112, 0.24);
  border-radius: 8px;
  background: #bfe2da;
  color: #173a35;
  font-family: var(--font-display);
  font-weight: 700;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0;
}

.brand div > span {
  color: var(--muted);
  font-size: 12px;
}

.profile-switcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 244, 0.88);
  color: var(--ink);
  box-shadow: 0 12px 24px rgba(92, 72, 55, 0.06);
}

.profile-switcher svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.profile-switcher span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.profile-switcher select {
  min-height: 38px;
  border: 0;
  background: transparent;
  color: var(--deep);
  cursor: pointer;
  font-weight: 850;
}

.command-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 420px;
  max-width: 520px;
}

.command-search svg {
  position: absolute;
  left: 14px;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #a18f82;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.command-search input {
  width: 100%;
  min-height: 42px;
  padding: 0 16px 0 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 244, 0.9);
  color: var(--ink);
  box-shadow: 0 12px 24px rgba(92, 72, 55, 0.07);
}

.command-search input:focus,
.profile-switcher select:focus,
.filters input:focus,
.filters select:focus,
.chart-controls select:focus,
.holding-form input:focus,
.holding-form select:focus {
  outline: 2px solid rgba(13, 138, 122, 0.2);
  border-color: rgba(116, 184, 177, 0.72);
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border: 1px solid rgba(132, 103, 75, 0.13);
  border-radius: 8px;
  background: rgba(255, 250, 244, 0.68);
  overflow-x: auto;
}

.top-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #806f64;
  text-decoration: none;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.top-nav svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.top-nav a:hover,
.top-nav a[aria-current="page"] {
  border-color: #d7cabc;
  background: #fffaf4;
  color: var(--deep-2);
}

.source-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 244, 0.74);
  white-space: nowrap;
}

.source-meta span {
  max-width: 320px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
}

.source-meta strong {
  font-size: 13px;
}

.workspace {
  min-width: 0;
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 28px;
}

#dashboard,
#stock-overview,
#portfolio-map,
#stock-chart,
#position-ledger,
#editor {
  scroll-margin-top: 150px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--deep);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
}

h1 {
  font-size: 32px;
  line-height: 1.16;
}

h2 {
  font-size: 19px;
  line-height: 1.25;
}

.topbar-actions,
.form-actions,
.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  transform: translateY(-1px);
}

.icon-button[aria-pressed="true"] {
  background: #ffe9e7;
  border-color: #efb1aa;
  color: #9d4d4c;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 750;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.button:hover,
.button:focus-visible {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.64;
  transform: none;
}

.button.primary {
  background: var(--deep);
  color: white;
  box-shadow: 0 12px 24px rgba(94, 136, 142, 0.22);
}

.button.secondary {
  background: #fff0d3;
  color: #875f1d;
  border-color: #edd4a4;
}

.button.ghost {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}

.button.danger {
  background: #ffeceb;
  color: var(--red);
  border-color: #f0c3c0;
}

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

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 244, 0.94);
  box-shadow: var(--shadow);
}

.metric {
  display: grid;
  gap: 8px;
  min-height: 132px;
  padding: 18px;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.metric span,
.metric small {
  color: var(--muted);
}

.metric span {
  font-size: 13px;
  font-weight: 750;
}

.metric strong {
  font-family: var(--font-display);
  font-size: 28px;
  line-height: 1.12;
  word-break: keep-all;
}

.metric small {
  font-size: 12px;
}

.metric.accent {
  background: var(--accent-panel);
  border-color: rgba(209, 174, 149, 0.62);
  color: var(--ink);
}

.metric.accent span,
.metric.accent small {
  color: #71675f;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.8fr) minmax(260px, 0.8fr);
  gap: 14px;
  margin-bottom: 14px;
}

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

.insight-card {
  display: grid;
  gap: 8px;
  min-height: 128px;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.insight-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.insight-card strong {
  overflow: hidden;
  font-size: 19px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.insight-card small {
  color: var(--muted);
  font-size: 12px;
}

.micro-track {
  align-self: end;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #efe3d8;
}

.micro-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 220ms ease;
}

.positive-track i {
  background: var(--green);
}

.negative-track i {
  background: var(--red);
}

.neutral-track i {
  background: var(--amber);
}

.stock-overview-grid {
  display: grid;
  grid-template-columns: 1fr;
  margin-bottom: 14px;
}

.stock-chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  margin-bottom: 14px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 14px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.trend-panel {
  display: flex;
  flex-direction: column;
  align-self: start;
  grid-column: span 2;
  min-height: 420px;
}

.portfolio-map-panel {
  grid-column: span 2;
}

.stock-chart-panel {
  min-height: 390px;
}

.stock-chart-heading {
  align-items: center;
}

.chart-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.chart-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chart-controls select {
  min-height: 38px;
  max-width: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 10px;
  font: inherit;
  font-weight: 700;
}

.chart-canvas {
  display: block;
  width: 100%;
  height: 330px;
}

.trend-panel .chart-canvas {
  flex: 1 1 300px;
  min-height: 300px;
  height: auto;
}

.stock-canvas {
  height: 280px;
}

.chart-frame {
  position: relative;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.legend {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.line {
  display: inline-block;
  width: 20px;
  height: 3px;
  margin-right: 6px;
  border-radius: 999px;
  vertical-align: middle;
}

.line.market {
  background: var(--blue);
}

.line.return {
  background: var(--amber);
}

.line.avg {
  background: var(--red);
}

.stock-legend {
  justify-content: flex-end;
  margin-top: -8px;
  margin-bottom: 4px;
}

.bar-list {
  display: grid;
  gap: 14px;
}

.bar-item {
  display: grid;
  gap: 7px;
}

.bar-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.bar-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-meta span {
  color: var(--muted);
  white-space: nowrap;
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #efe3d8;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.bar-list.compact .bar-track {
  height: 7px;
}

.map-scale {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.map-scale i,
.map-scale b {
  display: inline-block;
  width: 24px;
  height: 8px;
  border-radius: 999px;
}

.map-scale i {
  background: #f2b2b1;
}

.map-scale b {
  background: #9fd8bb;
}

.return-heatmap {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
}

.heatmap-tile {
  display: grid;
  gap: 4px;
  min-height: 76px;
  padding: 10px;
  border: 1px solid rgba(132, 103, 75, 0.14);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.heatmap-tile:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(92, 72, 55, 0.11);
}

.heatmap-tile strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.heatmap-tile span {
  overflow: hidden;
  color: rgba(47, 41, 36, 0.68);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.heatmap-tile b {
  font-size: 14px;
}

.table-heading {
  align-items: center;
}

.heading-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.heading-meta span,
.heading-meta strong {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.heading-meta span {
  padding: 8px 10px;
  border: 1px solid #ead9c8;
  border-radius: 8px;
  background: #fff1d8;
  color: #8b6427;
}

.overview-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  scrollbar-color: #dccdbd #f7ecdf;
  scrollbar-width: thin;
}

.overview-table {
  min-width: 1060px;
}

.overview-table tbody tr {
  cursor: pointer;
}

.overview-symbol {
  display: grid;
  gap: 3px;
}

.overview-symbol strong {
  font-size: 14px;
}

.overview-symbol span {
  color: var(--muted);
  font-size: 12px;
}

.label-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid #cde3dd;
  border-radius: 999px;
  background: #eefaf6;
  color: var(--deep);
  font-size: 12px;
  font-weight: 850;
}

.label-pill.family {
  border-color: #ded4ee;
  background: #f8f1ff;
  color: var(--blue);
}

.label-pill.mixed {
  border-color: #efd9a7;
  background: #fff6dc;
  color: var(--amber);
}

.allocation-cell {
  display: grid;
  min-width: 130px;
  gap: 6px;
}

.allocation-cell span {
  color: var(--muted);
  font-size: 12px;
}

.allocation-cell .bar-track {
  height: 7px;
}

.filters input,
.filters select,
.holding-form input,
.holding-form select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.filters input {
  width: min(340px, 100%);
  padding: 0 12px;
}

.filters select {
  padding: 0 10px;
}

.table-wrap {
  overflow: auto;
  max-height: 620px;
  border: 1px solid var(--line);
  border-radius: 8px;
  scrollbar-color: #dccdbd #f7ecdf;
  scrollbar-width: thin;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 940px;
  font-size: 13px;
}

th,
td {
  padding: 12px 12px;
  border-bottom: 1px solid #f0e5da;
  text-align: right;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fbf1e6;
  color: #7b6b60;
  font-size: 12px;
  font-weight: 800;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #fff5ec;
}

.symbol-cell {
  display: grid;
  gap: 2px;
}

.symbol-cell strong {
  font-size: 14px;
}

.symbol-cell span {
  color: var(--muted);
  font-size: 12px;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.editor-panel {
  position: sticky;
  top: 24px;
}

.holding-form {
  display: grid;
  gap: 12px;
}

.holding-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.holding-form input,
.holding-form select {
  width: 100%;
  padding: 0 10px;
  color: var(--ink);
  font-weight: 550;
}

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

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid rgba(93, 82, 75, 0.18);
  border-radius: 8px;
  background: #3f3731;
  color: white;
  box-shadow: 0 16px 34px rgba(92, 72, 55, 0.22);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

@media (hover: hover) and (pointer: fine) {
  .top-nav a:hover,
  .top-nav a:focus-visible {
    transform: translateY(-1px);
  }

  .metric:hover,
  .insight-card:hover {
    border-color: #dcc7b6;
    box-shadow: 0 20px 44px rgba(92, 72, 55, 0.13);
    transform: translateY(-2px);
  }

  .overview-table tbody tr:hover td,
  .holdings-panel tbody tr:hover td,
  .holdings-panel tbody tr.selected td {
    background: #fff5ec;
  }

  .overview-table tbody tr:hover td:first-child,
  .holdings-panel tbody tr:hover td:first-child,
  .holdings-panel tbody tr.selected td:first-child {
    box-shadow: inset 3px 0 0 var(--teal);
  }
}

@media (min-width: 821px) {
  .overview-table-wrap,
  .table-wrap {
    max-height: 540px;
  }

  .overview-table-wrap::-webkit-scrollbar,
  .table-wrap::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  .overview-table-wrap::-webkit-scrollbar-thumb,
  .table-wrap::-webkit-scrollbar-thumb {
    border: 2px solid #f7ecdf;
    border-radius: 999px;
    background: #d4c0ae;
  }

  .overview-table-wrap::-webkit-scrollbar-track,
  .table-wrap::-webkit-scrollbar-track {
    background: #f7ecdf;
  }

  th:first-child,
  td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--panel);
    box-shadow: 1px 0 0 #f0e5da;
  }

  th:first-child {
    z-index: 4;
    background: #fbf1e6;
  }
}

@media (min-width: 1181px) {
  .app-header {
    padding: 16px 32px 12px;
    box-shadow: 0 10px 30px rgba(92, 72, 55, 0.07);
  }

  .header-main {
    display: grid;
    grid-template-columns: auto auto minmax(320px, 1fr) auto;
  }

  .topbar-actions {
    justify-content: flex-end;
    flex-wrap: nowrap;
  }

  .topbar-actions .button,
  .theme-toggle,
  .privacy-toggle {
    white-space: nowrap;
  }

  .workspace {
    padding: 28px 34px 48px;
  }

  .topbar {
    align-items: center;
    min-height: 52px;
  }

  .metric-grid {
    grid-template-columns: minmax(340px, 1.35fr) repeat(3, minmax(220px, 1fr));
    gap: 16px;
  }

  .metric {
    min-height: 140px;
    padding: 20px;
  }

  .metric:first-child {
    min-height: 156px;
    padding: 24px;
  }

  .metric:first-child strong {
    font-size: 40px;
  }

  .metric.accent strong {
    font-size: 36px;
  }

  .insight-grid,
  .dashboard-grid,
  .content-grid {
    gap: 16px;
  }

  .stock-overview-grid,
  .dashboard-grid,
  .stock-chart-grid,
  .content-grid {
    margin-bottom: 16px;
  }

  .overview-table-wrap {
    max-height: 500px;
  }

  .dashboard-grid {
    grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.78fr);
    align-items: stretch;
  }

  .trend-panel {
    grid-column: 1;
    grid-row: 1 / span 2;
    min-height: 500px;
  }

  .dashboard-grid > .panel:nth-child(2) {
    grid-column: 2;
    grid-row: 1;
  }

  .dashboard-grid > .panel:nth-child(3) {
    grid-column: 2;
    grid-row: 2;
  }

  .portfolio-map-panel {
    grid-column: 1 / -1;
  }

  .trend-panel .chart-canvas {
    flex-basis: 360px;
    min-height: 360px;
  }

  .stock-chart-panel {
    min-height: 460px;
  }

  .stock-canvas {
    height: 340px;
  }

  .content-grid {
    grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
  }

  .table-wrap {
    max-height: 680px;
  }

  .editor-panel {
    top: 150px;
  }
}

@media (max-width: 1180px) {
  .app-header {
    position: static;
  }

  .header-main,
  .header-sub {
    flex-wrap: wrap;
  }

  .dashboard-grid,
  .stock-overview-grid,
  .stock-chart-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

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

  .trend-panel,
  .portfolio-map-panel {
    grid-column: auto;
  }

  .editor-panel {
    position: static;
  }
}

@media (max-width: 820px) {
  .workspace {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  .header-main,
  .header-sub {
    display: grid;
  }

  .command-search {
    max-width: none;
  }

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

  .table-heading,
  .panel-heading {
    display: grid;
  }

  .filters {
    width: 100%;
  }

  .chart-controls,
  .chart-controls select,
  .filters input,
  .filters select,
  .command-search,
  .privacy-toggle,
  .topbar-actions .button {
    flex: 1 1 100%;
  }
}

@media (max-width: 560px) {
  html {
    scroll-padding-top: 112px;
  }

  body {
    background: #d9d2c8;
  }

  .app-shell {
    max-width: 430px;
    margin: 0 auto;
    background: #fbf4ec;
  }

  .app-header {
    position: sticky;
    z-index: 40;
    gap: 8px;
    padding: 16px 14px 10px;
    border-bottom: 0;
    background: #fbf4ec;
    box-shadow: none;
    backdrop-filter: none;
  }

  .header-main,
  .header-sub {
    width: 100%;
    margin: 0;
  }

  .header-main {
    display: grid;
    gap: 10px;
  }

  .brand {
    min-height: 44px;
    gap: 10px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 50%;
  }

  .brand strong {
    font-size: 20px;
  }

  .profile-switcher {
    width: 100%;
    min-height: 44px;
    justify-content: space-between;
    box-shadow: none;
  }

  .profile-switcher select {
    flex: 1;
    min-width: 0;
  }

  .command-search {
    order: 2;
    width: 100%;
    flex: initial;
  }

  .command-search input {
    min-height: 46px;
    box-shadow: none;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .privacy-toggle,
  .topbar-actions .button {
    flex: initial;
    width: 100%;
  }

  .privacy-toggle,
  .theme-toggle,
  #refreshQuotesButton {
    min-height: 48px;
  }

  #themeToggle {
    grid-column: 1;
    grid-row: 1;
  }

  .privacy-toggle {
    grid-column: 2;
    grid-row: 1;
  }

  #resetButton {
    grid-column: 1;
    grid-row: 2;
  }

  #snapshotButton {
    grid-column: 2;
    grid-row: 2;
  }

  #refreshQuotesButton {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  #resetButton,
  #snapshotButton {
    min-height: 36px;
    font-size: 12px;
  }

  .header-sub {
    display: block;
  }

  .source-meta {
    display: none;
  }

  .top-nav {
    position: fixed;
    left: 50%;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    width: min(402px, calc(100vw - 22px));
    padding: 8px;
    overflow: visible;
    border: 1px solid rgba(132, 103, 75, 0.15);
    border-radius: 8px;
    background: rgba(255, 250, 244, 0.96);
    box-shadow: 0 18px 42px rgba(92, 72, 55, 0.18);
    transform: translateX(-50%);
  }

  .top-nav a {
    display: grid;
    min-height: 54px;
    padding: 6px 2px;
    place-items: center;
    gap: 3px;
    font-size: 11px;
    line-height: 1.1;
  }

  .top-nav svg {
    display: block;
    width: 20px;
    height: 20px;
  }

  .top-nav a:hover,
  .top-nav a[aria-current="page"] {
    border-color: #93c8c2;
    background: #e7f6f2;
    color: var(--deep-2);
  }

  .workspace {
    padding: 14px 14px 106px;
  }

  #dashboard,
  #stock-overview,
  #portfolio-map,
  #stock-chart,
  #position-ledger,
  #editor {
    scroll-margin-top: 112px;
  }

  .topbar {
    display: grid;
    justify-items: center;
    gap: 4px;
    margin: 2px 0 16px;
    text-align: center;
  }

  .eyebrow {
    font-size: 10px;
  }

  h1 {
    max-width: 350px;
    font-size: 24px;
    line-height: 1.18;
    word-break: keep-all;
  }

  h2 {
    font-size: 18px;
  }

  .metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 0 0 12px;
    padding: 0;
    overflow: visible;
  }

  .insight-grid::-webkit-scrollbar {
    display: none;
  }

  .metric {
    container-type: inline-size;
    min-width: 0;
    min-height: 118px;
    padding: 16px;
  }

  .metric:first-child {
    grid-column: 1 / -1;
    min-width: 100%;
    min-height: 156px;
    place-items: center;
    border: 0;
    background: transparent;
    box-shadow: none;
    text-align: center;
  }

  .metric:first-child strong {
    max-width: 100%;
    font-size: 34px;
    overflow-wrap: anywhere;
  }

  .metric:not(:first-child) strong {
    font-size: clamp(17px, 12cqw, 22px);
    overflow-wrap: anywhere;
  }

  .metric.accent {
    grid-column: 1 / -1;
    min-height: 104px;
    background: var(--accent-panel);
  }

  .insight-grid {
    display: flex;
    gap: 10px;
    margin: 0 -14px 12px;
    padding: 0 14px 4px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
  }

  .insight-card {
    min-width: 206px;
    min-height: 132px;
    scroll-snap-align: start;
  }

  .dashboard-grid,
  .stock-overview-grid,
  .stock-chart-grid,
  .content-grid {
    gap: 12px;
    margin-bottom: 12px;
  }

  .panel {
    padding: 16px;
    box-shadow: 0 14px 30px rgba(92, 72, 55, 0.1);
  }

  .panel-heading {
    gap: 10px;
    margin-bottom: 12px;
  }

  .heading-meta {
    justify-content: space-between;
    width: 100%;
  }

  .chart-controls,
  .filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .chart-controls select,
  .filters input,
  .filters select {
    width: 100%;
    max-width: none;
    flex: initial;
  }

  .chart-canvas {
    height: 238px;
  }

  .trend-panel .chart-canvas {
    flex: initial;
    min-height: 238px;
    height: 238px;
  }

  .stock-canvas {
    height: 226px;
  }

  .legend {
    flex-wrap: wrap;
    white-space: normal;
  }

  .stock-legend {
    justify-content: flex-start;
    margin-top: 0;
  }

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

  .heatmap-tile {
    min-height: 88px;
  }

  .overview-table-wrap,
  .table-wrap {
    overflow: visible;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .overview-table,
  .holdings-panel table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  .overview-table thead,
  .holdings-panel thead {
    display: none;
  }

  .overview-table tbody,
  .holdings-panel tbody {
    display: grid;
    gap: 10px;
  }

  .overview-table tbody tr,
  .holdings-panel tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    padding: 14px;
    border: 1px solid #eadfd3;
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 10px 18px rgba(92, 72, 55, 0.08);
  }

  .overview-table tbody tr:hover,
  .overview-table tbody tr.selected,
  .holdings-panel tbody tr:hover,
  .holdings-panel tbody tr.selected {
    background: var(--panel);
    border-color: #d7c1ad;
  }

  .overview-table td,
  .holdings-panel td {
    display: none;
    padding: 0;
    border: 0;
    white-space: normal;
    text-align: left;
  }

  .overview-table td[colspan],
  .holdings-panel td[colspan] {
    display: block;
    grid-column: 1 / -1;
    color: var(--muted);
  }

  .overview-table td:first-child,
  .holdings-panel td:first-child {
    display: block;
    grid-column: 1;
    grid-row: 1 / span 2;
    min-width: 0;
  }

  .overview-table td:nth-child(2),
  .holdings-panel td:nth-child(2) {
    display: block;
    grid-column: 1;
    grid-row: 3;
  }

  .overview-table td:nth-child(5) {
    display: block;
    grid-column: 1 / -1;
    grid-row: 4;
  }

  .overview-table td:nth-child(6),
  .overview-table td:nth-child(8),
  .holdings-panel td:nth-child(6),
  .holdings-panel td:nth-child(8) {
    display: block;
    grid-column: 2;
    min-width: 92px;
    font-weight: 800;
    text-align: right;
  }

  .overview-table td:nth-child(6),
  .holdings-panel td:nth-child(6) {
    grid-row: 1;
  }

  .overview-table td:nth-child(8),
  .holdings-panel td:nth-child(8) {
    grid-row: 2;
  }

  .holdings-panel td:nth-child(3) {
    display: block;
    grid-column: 1;
    grid-row: 4;
    color: var(--muted);
    font-size: 12px;
  }

  .allocation-cell {
    min-width: 0;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .form-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .form-actions .danger {
    grid-column: 1 / -1;
  }

  .toast {
    right: 14px;
    bottom: calc(92px + env(safe-area-inset-bottom));
    left: 14px;
    z-index: 70;
    max-width: none;
  }
}
