:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f9faf8;
  --surface-3: #eef3ef;
  --ink: #17201c;
  --muted: #66716c;
  --faint: #8b9690;
  --line: #dce2de;
  --line-strong: #c8d1cc;
  --nav: #17302b;
  --nav-soft: #214139;
  --accent: #1f6f64;
  --accent-2: #9b3f3a;
  --warn: #a66b19;
  --good: #0f7657;
  --bad: #b2413c;
  --shadow: 0 18px 42px rgba(25, 42, 37, 0.10);
  --shadow-soft: 0 8px 24px rgba(25, 42, 37, 0.07);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(244, 245, 242, 0) 260px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  padding: 0 15px;
  cursor: pointer;
  font-weight: 750;
  letter-spacing: 0;
  white-space: nowrap;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 140ms ease,
    box-shadow 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(31, 111, 100, 0.18);
}

button:active {
  transform: translateY(0);
  box-shadow: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(31, 111, 100, 0.68);
  box-shadow: 0 0 0 3px rgba(31, 111, 100, 0.12);
}

input[type="file"] {
  padding: 7px 9px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 130px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(31, 111, 100, 0.16), transparent 34%),
    linear-gradient(315deg, rgba(155, 63, 58, 0.12), transparent 36%),
    #eef1ed;
}

.login-panel {
  width: min(430px, 100%);
  display: grid;
  gap: 17px;
  padding: 34px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(220, 226, 222, 0.86);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 0;
  font-size: 27px;
  letter-spacing: 0;
}

.login-subtitle {
  margin: -10px 0 6px;
  color: var(--muted);
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--nav);
  color: #fff;
  font-weight: 850;
  letter-spacing: 0;
}

.brand-mark.compact {
  width: 38px;
  height: 38px;
  font-size: 13px;
}

.form-error,
.status-text {
  min-height: 18px;
  color: var(--bad);
  font-size: 13px;
}

.notice {
  padding: 12px 14px;
  background: #fff8ea;
  border: 1px solid #e4c885;
  border-radius: var(--radius);
  color: #775116;
  font-size: 14px;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 22px;
  padding: 20px;
  background: linear-gradient(180deg, var(--nav), #11231f);
  color: #edf5f2;
}

.sidebar-title {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}

.sidebar-title strong {
  display: block;
  font-size: 16px;
}

.sidebar-title span {
  display: block;
  color: #a7bbb3;
  font-size: 12px;
  margin-top: 3px;
}

.nav {
  display: grid;
  align-content: start;
  gap: 8px;
}

.nav-btn,
.ghost-btn {
  background: transparent;
  color: inherit;
  border-color: rgba(255, 255, 255, 0.13);
}

.nav-btn {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: start;
  text-align: left;
  padding: 0 11px;
}

.nav-btn span {
  width: 36px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #d9e8e2;
  font-size: 12px;
}

.nav-btn.active {
  background: #f2f7f4;
  color: var(--nav);
  border-color: #f2f7f4;
  box-shadow: none;
}

.nav-btn.active span {
  background: rgba(31, 111, 100, 0.12);
  color: var(--accent);
}

.ghost-btn {
  color: var(--muted);
  border-color: var(--line);
}

.sidebar .ghost-btn {
  color: #dce8e5;
  border-color: rgba(255, 255, 255, 0.16);
}

.secondary-btn {
  background: var(--surface-3);
  color: var(--nav);
  border-color: var(--line);
}

.secondary-btn:hover,
.ghost-btn:hover {
  background: #fff;
  color: var(--accent);
  border-color: rgba(31, 111, 100, 0.24);
}

.workspace {
  min-width: 0;
  padding: 24px 30px 36px;
}

.topbar {
  min-height: 74px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 4px;
}

.topbar h2 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
}

.topbar p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.status-text {
  min-width: 180px;
  padding-top: 8px;
  text-align: right;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 16px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.90);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.toolbar .grow {
  flex: 1 1 280px;
}

.weekly-query-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.78fr);
  gap: 9px;
  align-items: stretch;
}

.weekly-query-row .toolbar {
  min-width: 0;
}

.stat-grid,
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 12px;
}

.stat-card,
.metric-card {
  min-height: 84px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(22, 32, 28, 0.04);
}

.stat-card span,
.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.stat-card strong,
.metric-card strong {
  display: block;
  margin-top: 9px;
  font-size: 22px;
  line-height: 1.15;
}

.weekly-stat-card-title {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.weekly-stat-list {
  display: grid;
  gap: 5px;
  margin-top: 8px;
}

.weekly-stat-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.weekly-stat-row strong {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  text-align: right;
}

.weekly-freshness-notice {
  grid-column: 1 / -1;
  padding: 9px 12px;
  border: 1px solid #e3c8a0;
  border-radius: 10px;
  background: #fff8eb;
  color: #7b5727;
  font-size: 12px;
  line-height: 1.4;
}

.stale-nav-cell {
  color: #7b5727;
  white-space: nowrap;
}

.stale-nav-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 5px;
  padding: 2px 5px;
  border-radius: 999px;
  background: #fff0d8;
  color: #895d20;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.metric-card strong {
  font-size: 18px;
}

.table-actions,
.download-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1060px;
}

th,
td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #edf2ee;
  color: #27342f;
  font-size: 12px;
  text-transform: none;
}

#weeklyView .table-wrap {
  max-height: calc(100vh - 340px);
}

.weekly-mobile-list {
  display: none;
}

#weeklyTable th {
  height: 44px;
}

#weeklyTable .section-row td {
  position: sticky;
  top: 44px;
  z-index: 3;
}

#weeklyTable input[type="checkbox"] {
  width: 14px;
  height: 14px;
  min-height: 0;
  padding: 0;
  vertical-align: middle;
}

td:first-child,
th:first-child,
td:nth-child(2),
th:nth-child(2),
td:nth-child(4),
th:nth-child(4) {
  text-align: left;
}

.spark-cell {
  min-width: 154px;
  width: 154px;
  padding-right: 25px;
}

#weeklyTable th:nth-child(3),
#weeklyTable td:nth-child(3) {
  min-width: 154px;
  padding-right: 25px;
}

#weeklyTable th:nth-child(4),
#weeklyTable td:nth-child(4) {
  min-width: 142px;
  padding-left: 25px;
}

.sparkline {
  width: 112px;
  height: 30px;
  display: inline-block;
  vertical-align: middle;
}

.sparkline svg {
  width: 100%;
  height: 100%;
  display: block;
}

tr:hover td {
  background: #f7faf8;
}

.section-row td {
  background: #e2ebe6;
  color: #18322e;
  font-weight: 820;
}

.index-row td {
  color: var(--accent);
  font-weight: 750;
}

.pos {
  color: var(--bad);
}

.neg {
  color: var(--good);
}

.muted {
  color: var(--muted);
}

.analysis-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 16px;
  background: var(--nav);
  color: #edf7f5;
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.analysis-header strong {
  font-size: 20px;
}

.analysis-header span {
  color: #adc4bf;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.chart-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-soft);
}

.chart-panel h3 {
  margin: 0 0 10px;
  font-size: 16px;
  text-align: center;
}

.chart {
  width: 100%;
  height: 320px;
}

.chart svg {
  width: 100%;
  height: 100%;
  display: block;
}

.portfolio-hero {
  min-height: 112px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(31, 111, 100, 0.18), rgba(255, 255, 255, 0) 52%),
    linear-gradient(315deg, rgba(155, 63, 58, 0.13), rgba(255, 255, 255, 0) 44%),
    #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
}

.portfolio-hero p {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 850;
}

.portfolio-hero h3 {
  margin: 0;
  max-width: 780px;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
}

.portfolio-hero-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.portfolio-workbench {
  display: grid;
  grid-template-columns: minmax(230px, 0.82fr) minmax(460px, 1.45fr) minmax(280px, 0.95fr);
  gap: 14px;
  align-items: start;
}

.workbench-panel,
.position-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-soft);
}

.setup-panel,
.selected-panel {
  position: sticky;
  top: 18px;
}

.panel-title {
  margin-bottom: 10px;
  color: #263431;
  font-size: 16px;
  font-weight: 850;
}

.small-title {
  margin-top: 14px;
  margin-bottom: 8px;
  font-size: 13px;
}

.panel-title-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-title-row .panel-title {
  margin-bottom: 2px;
}

.panel-title-row p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.panel-title-row label {
  min-width: 136px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.compact-form {
  margin-bottom: 12px;
}

.admin-tools {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.search-field {
  margin-bottom: 12px;
}

.position-list {
  max-height: min(560px, calc(100vh - 330px));
  overflow: auto;
  display: grid;
  gap: 9px;
  padding-right: 4px;
}

.position-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px 150px;
  gap: 9px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  transition:
    border-color 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease;
}

.position-row.selected {
  border-color: rgba(31, 111, 100, 0.40);
  background: #f1f7f3;
  box-shadow: 0 0 0 3px rgba(31, 111, 100, 0.08);
}

.position-check {
  min-width: 0;
  display: flex;
  grid-template-columns: none;
  gap: 9px;
  align-items: center;
  color: var(--ink);
  font-size: 14px;
  font-weight: 780;
}

.position-check input {
  width: 16px;
  height: 16px;
  min-height: 0;
  flex: 0 0 auto;
  padding: 0;
  accent-color: var(--accent);
}

.position-check span {
  min-width: 0;
}

.position-check strong,
.position-check small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.position-check small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.position-row select,
.position-row input[type="number"] {
  min-width: 0;
}

.empty-state {
  padding: 14px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.selected-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.selected-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.selected-item strong,
.selected-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-item span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.selected-item button {
  min-height: 30px;
  padding: 0 9px;
}

.scenario-list {
  display: grid;
  gap: 8px;
  align-items: center;
}

.scenario-chip {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.scenario-chip strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-chip span {
  color: var(--muted);
  font-size: 12px;
}

.scenario-chip .scenario-color {
  width: 20px;
  height: 6px;
  border-radius: 2px;
}

.scenario-chip button {
  min-height: 30px;
  padding: 0 9px;
  color: var(--muted);
}

.portfolio-main-chart .chart {
  height: 420px;
}

#portfolioCompareTable {
  min-width: 900px;
}

#portfolioCompareTable th:first-child,
#portfolioCompareTable td:first-child,
#portfolioEntryTable th:first-child,
#portfolioEntryTable td:first-child {
  text-align: left;
}

#portfolioEntryTable {
  min-width: 860px;
}

.admin-form {
  align-items: end;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

#yearlyTable {
  table-layout: fixed;
  min-width: 920px;
}

#yearlyTable th,
#yearlyTable td {
  width: 14.28%;
  text-align: center;
  font-size: 15px;
  padding: 12px 14px;
}

@media (max-width: 1180px) {
  .portfolio-workbench {
    grid-template-columns: minmax(260px, 0.86fr) minmax(420px, 1.14fr);
  }

  .selected-panel {
    grid-column: 1 / -1;
    position: static;
  }

  .selected-list,
  .scenario-list {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    max-height: none;
  }
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    grid-template-rows: auto;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  .status-text {
    min-width: 0;
    text-align: left;
  }

  .portfolio-hero {
    display: grid;
  }

  .portfolio-hero-actions {
    justify-content: start;
  }

  .portfolio-workbench,
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .setup-panel {
    position: static;
  }

  .position-row {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .panel-title-row {
    display: grid;
    align-items: start;
  }

  .chart-panel:first-child {
    grid-row: auto;
  }
}

/* Portfolio workbench v2: compact two-column configuration and results. */
.app {
  transition: grid-template-columns 180ms ease;
}

.sidebar {
  transition: padding 180ms ease;
}

.sidebar-title {
  position: relative;
}

.sidebar-copy {
  min-width: 0;
  flex: 1;
}

.sidebar-toggle {
  width: 30px;
  min-width: 30px;
  min-height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #dce8e5;
  font-size: 20px;
  line-height: 1;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.13);
}

.nav-btn,
.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-btn span.nav-initial,
.sidebar-logout span.nav-initial {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font-size: 11px;
  font-weight: 850;
}

.nav-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-btn.active .nav-icon {
  color: var(--accent);
}

.nav-btn span.nav-label,
.sidebar-logout span.nav-label {
  width: auto;
  height: auto;
  display: inline;
  background: transparent;
  color: inherit;
  font-size: 13px;
}

.app.sidebar-collapsed {
  grid-template-columns: 76px minmax(0, 1fr);
}

.app.sidebar-collapsed .sidebar {
  padding: 18px 12px;
}

.app.sidebar-collapsed .sidebar-title {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.app.sidebar-collapsed .sidebar-copy,
.app.sidebar-collapsed .nav-label {
  display: none;
}

.app.sidebar-collapsed .nav-btn,
.app.sidebar-collapsed .sidebar-logout {
  justify-content: center;
  padding: 0;
}

.app.sidebar-collapsed .nav-icon {
  width: 23px;
  height: 23px;
  flex-basis: 23px;
}

.app.sidebar-collapsed .sidebar-toggle {
  position: static;
}

.portfolio-page {
  width: 100%;
  max-width: none;
}

.catalog-summary {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.portfolio-workbench-v2 {
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(0, 1.65fr);
  gap: 18px;
  align-items: start;
}

.portfolio-builder-column,
.portfolio-main-column {
  min-width: 0;
  display: grid;
  gap: 14px;
}

.portfolio-builder-column {
  position: sticky;
  top: 14px;
}

.portfolio-builder-column .portfolio-card {
  padding: 18px 20px;
}

.portfolio-builder-column .parameter-grid {
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 16px;
}

.amount-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  align-items: stretch;
}

.amount-field input {
  border-radius: var(--radius) 0 0 var(--radius);
}

.amount-field span {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.amount-field.compact {
  grid-template-columns: minmax(90px, 1fr) 34px;
}

.fund-library-card {
  overflow: hidden;
}

.fund-library-card .fund-picker {
  margin: 16px -20px -18px;
  padding: 15px 20px 18px;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.fund-library-card .fund-picker-toolbar {
  grid-template-columns: 1fr;
  gap: 10px;
}

.fund-library-card .position-list {
  max-height: min(44vh, 430px);
}

.fund-library-card .fund-list-header,
.fund-library-card .position-row {
  grid-template-columns: minmax(0, 1fr) 58px;
}

.fund-library-card .position-check small {
  display: block;
  max-width: none;
  overflow: visible;
  white-space: normal;
}

.fund-meta {
  display: grid !important;
  gap: 2px;
  margin-top: 3px;
  line-height: 1.35;
}

.fund-meta span:last-child {
  color: #52645e;
  font-variant-numeric: tabular-nums;
}

.holdings-actions {
  display: flex;
  gap: 8px;
}

.allocation-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.allocation-summary > div {
  display: grid;
  gap: 4px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.allocation-summary span {
  color: var(--muted);
  font-size: 11px;
}

.allocation-summary strong {
  color: var(--ink);
  font-size: 16px;
}

.portfolio-main-column .holdings-table {
  max-height: 410px;
  overflow-y: auto;
}

.portfolio-main-column .holdings-table-header,
.portfolio-main-column .holdings-table .selected-item {
  grid-template-columns: minmax(180px, 1fr) minmax(130px, 160px) 64px;
}

.portfolio-main-column .scenario-section {
  border-top: 1px solid var(--line);
}

.portfolio-results {
  margin-top: 4px;
  padding-top: 18px;
}

.interactive-chart svg {
  cursor: crosshair;
  touch-action: none;
}

.chart-hit-area {
  pointer-events: all;
}

.chart-crosshair {
  stroke: #7f908a;
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.chart-tooltip-bg {
  fill: rgba(16, 34, 42, 0.94);
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 1;
}

.chart-tooltip-date,
.chart-tooltip-label,
.chart-tooltip-value {
  fill: #f5faf8;
  font-size: 11px;
}

.chart-tooltip-date,
.chart-tooltip-value {
  font-weight: 800;
}

.analysis-data-source {
  display: block;
  margin-top: 5px;
  color: rgba(239, 248, 245, 0.7);
  font-size: 11px;
  font-weight: 600;
}

@media (max-width: 1180px) {
  .portfolio-workbench-v2 {
    grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.4fr);
  }

  .allocation-summary {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
}

@media (max-width: 940px) {
  .portfolio-workbench-v2 {
    grid-template-columns: 1fr;
  }

  .portfolio-builder-column {
    position: static;
    grid-template-columns: minmax(260px, 0.8fr) minmax(340px, 1.2fr);
  }
}

@media (max-width: 860px) {
  .app.sidebar-collapsed,
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar-toggle {
    display: none;
  }

  .portfolio-intro,
  .portfolio-builder-column {
    grid-template-columns: 1fr;
  }

  .catalog-summary {
    white-space: normal;
  }
}

@media (max-width: 620px) {
  .allocation-summary {
    grid-template-columns: 1fr;
  }
}

/* Portfolio backtester: a stacked, testfolio-inspired workflow. */
.portfolio-page {
  width: min(1320px, 100%);
  margin: 0 auto;
  gap: 18px !important;
}

.portfolio-intro,
.results-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 4px 4px 2px;
}

.portfolio-intro h3,
.results-heading h3 {
  margin: 3px 0 5px;
  font-size: 28px;
  line-height: 1.2;
}

.portfolio-intro p,
.portfolio-card-heading p,
.scenario-heading p,
.chart-title-row p {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.12em;
}

.portfolio-card,
.portfolio-runbar {
  background: #fff;
  border: 1px solid #d9e2de;
  border-radius: 15px;
  box-shadow: 0 10px 28px rgba(20, 45, 38, 0.07);
}

.portfolio-card {
  padding: 22px 24px;
}

.portfolio-card-heading,
.scenario-heading,
.chart-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.portfolio-card-heading > div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.portfolio-card-heading h4,
.scenario-heading h5 {
  margin: 0 0 3px;
  color: #21322d;
}

.portfolio-card-heading h4 {
  font-size: 19px;
}

.scenario-heading h5 {
  font-size: 15px;
}

.section-number {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #eaf3ef;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
}

.parameter-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.25fr) minmax(180px, 0.85fr) minmax(210px, 1fr) minmax(230px, 1.1fr);
  gap: 14px;
  align-items: stretch;
  margin-top: 20px;
}

.parameter-note {
  display: grid;
  align-content: center;
  gap: 3px;
  min-height: 62px;
  padding: 10px 13px;
  border: 1px solid #d7e7df;
  border-radius: 9px;
  background: #f3f8f5;
}

.parameter-note strong {
  color: var(--accent);
  font-size: 12px;
}

.parameter-note span {
  color: var(--muted);
  font-size: 12px;
}

.holdings-card {
  padding-bottom: 0;
  overflow: hidden;
}

.holdings-table {
  display: block;
  max-height: none;
  margin: 19px -24px 0;
  overflow: visible;
  border-top: 1px solid var(--line);
}

.holdings-table-header,
.holdings-table .selected-item {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 180px 74px;
  gap: 14px;
  align-items: center;
  padding: 11px 24px;
}

.holdings-table-header {
  color: var(--muted);
  background: #f5f8f6;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.04em;
}

.holdings-table .selected-item {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
}

.holdings-table .selected-item:hover {
  background: #fbfdfc;
}

.selected-fund-name strong,
.selected-fund-name span {
  display: block;
}

.selected-fund-name span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.holdings-table .selected-item button {
  min-height: 34px;
  padding: 0 10px;
}

.holdings-empty {
  display: grid;
  justify-items: center;
  gap: 5px;
  margin: 18px 24px 22px;
  padding: 26px;
  text-align: center;
}

.holdings-empty strong {
  color: var(--ink);
}

.holdings-empty span {
  font-size: 12px;
}

.fund-picker {
  margin: 0 -24px;
  padding: 18px 24px 20px;
  background: #f5f8fa;
  border-bottom: 1px solid var(--line);
}

.fund-picker-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 200px auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.fund-picker-toolbar .grow {
  min-width: 0;
}

.fund-list-header,
.fund-picker .position-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 12px;
  align-items: center;
}

.fund-list-header {
  padding: 0 13px 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.fund-list-header span:last-child {
  text-align: center;
}

.fund-picker .position-list {
  display: block;
  max-height: 390px;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.fund-picker .position-row {
  padding: 11px 13px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
}

.fund-picker .position-row:last-child {
  border-bottom: 0;
}

.fund-picker .position-row.selected {
  background: #eef7f2;
  box-shadow: inset 3px 0 var(--accent);
}

.fund-add-state {
  justify-self: center;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.scenario-section {
  margin: 0 -24px;
  padding: 19px 24px 22px;
  background: #fbfcfb;
}

.scenario-actions {
  display: flex;
  gap: 9px;
}

.scenario-list {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 14px;
}

.scenario-list .empty-state {
  width: 100%;
  padding: 12px 14px;
}

.scenario-chip {
  min-width: 240px;
  flex: 0 1 auto;
  background: #fff;
}

.portfolio-runbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 20px;
}

.portfolio-runbar strong,
.portfolio-runbar span {
  display: block;
}

.portfolio-runbar span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.primary-action {
  min-width: 160px;
  min-height: 46px;
  font-size: 15px;
}

details.admin-tools {
  margin: 0;
  padding: 0;
}

details.admin-tools summary {
  padding: 16px 20px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.admin-tool-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(200px, 0.7fr) auto;
  gap: 12px;
  align-items: end;
  padding: 0 20px 18px;
}

.upload-preview,
.upload-manager {
  grid-column: 1 / -1;
}

.upload-preview {
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #f8faf9;
}

.upload-preview-heading,
.upload-manager-heading,
.upload-preview-actions,
.upload-source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.upload-preview-heading > div,
.upload-manager-heading,
.upload-source-main {
  min-width: 0;
}

.upload-preview-heading span,
.upload-manager-heading span,
.upload-source-main > span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.upload-preview-list,
.upload-source-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.upload-preview-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, auto) minmax(110px, auto);
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 12px;
}

.upload-preview-row div span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

.upload-preview-row b {
  color: var(--good);
  text-align: right;
}

.upload-preview-row.conflict b,
.upload-preview-row.blocked b,
.upload-blocked-note {
  color: var(--bad);
}

.upload-preview-actions {
  justify-content: flex-end;
  margin-top: 12px;
}

.upload-preview-actions .primary-action {
  min-height: 38px;
}

.upload-manager {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.upload-manager-heading {
  justify-content: flex-start;
}

.upload-manager-heading span {
  margin: 0;
}

.upload-source-row {
  align-items: flex-start;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.upload-source-main {
  flex: 1;
}

.upload-fund-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.upload-fund-tags > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border-radius: 999px;
  background: #edf3f0;
  font-size: 12px;
}

.upload-fund-tags button {
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--bad);
  box-shadow: none;
}

.upload-fund-tags em {
  color: var(--muted);
  font-size: 12px;
}

.danger-btn {
  color: var(--bad);
}

.compact-empty {
  padding: 12px;
}

.portfolio-results {
  display: grid;
  gap: 15px;
  margin-top: 12px;
  padding-top: 24px;
  border-top: 1px solid var(--line-strong);
}

.result-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 5px;
  background: #e8eeeb;
  border-radius: 10px;
}

.result-tab {
  min-height: 38px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  box-shadow: none;
}

.result-tab:hover {
  transform: none;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: none;
}

.result-tab.active {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 3px 10px rgba(20, 45, 38, 0.08);
}

.portfolio-tab-panel {
  display: none;
}

.portfolio-tab-panel.active {
  display: grid;
  gap: 14px;
}

.portfolio-metrics {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.portfolio-main-chart {
  padding: 20px;
}

.chart-title-row h3 {
  margin: 0 0 3px;
  text-align: left;
}

.chart-title-row p {
  font-size: 12px;
}

.benchmark-menu {
  position: relative;
  flex: 0 0 auto;
}

.benchmark-menu summary {
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--nav);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  list-style: none;
}

.benchmark-menu summary::-webkit-details-marker {
  display: none;
}

.benchmark-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 12;
  width: 280px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
}

.benchmark-popover > p {
  margin: 3px 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.benchmark-options {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.benchmark-option {
  min-width: 0;
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font-size: 13px;
}

.benchmark-option input {
  width: 15px;
  height: 15px;
  min-height: 0;
  flex: 0 0 auto;
  padding: 0;
  accent-color: var(--accent);
}

.benchmark-option small {
  color: var(--muted);
  font-weight: 650;
}

.benchmark-popover button {
  width: 100%;
}

@media (max-width: 1180px) {
  .parameter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .portfolio-metrics {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }
}

@media (max-width: 860px) {
  .portfolio-intro,
  .results-heading,
  .portfolio-card-heading,
  .scenario-heading,
  .portfolio-runbar {
    align-items: stretch;
  }

  .portfolio-intro,
  .results-heading,
  .scenario-heading,
  .portfolio-runbar {
    display: grid;
  }

  .portfolio-card {
    padding: 18px;
  }

  .holdings-table,
  .fund-picker,
  .scenario-section {
    margin-left: -18px;
    margin-right: -18px;
  }

  .holdings-table-header {
    display: none;
  }

  .holdings-table .selected-item {
    grid-template-columns: 1fr 1fr;
    padding: 14px 18px;
  }

  .selected-fund-name {
    grid-column: 1 / -1;
  }

  .benchmark-menu,
  .benchmark-popover {
    position: static;
    width: 100%;
  }

  .benchmark-menu summary {
    justify-content: center;
  }

  .benchmark-popover {
    margin-top: 8px;
  }

  .fund-picker-toolbar,
  .admin-tool-grid {
    grid-template-columns: 1fr;
  }

  .upload-preview-row {
    grid-template-columns: 1fr;
  }

  .upload-preview-row b {
    text-align: left;
  }

  .portfolio-metrics {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }
}

@media (max-width: 560px) {
  .parameter-grid,
  .portfolio-metrics {
    grid-template-columns: 1fr;
  }

  .holdings-table .selected-item {
    grid-template-columns: 1fr;
  }

  .scenario-actions {
    display: grid;
  }
}

/* Keep the established production shell and palette outside the portfolio redesign. */
:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #f9fbfa;
  --surface-3: #eef3f2;
  --surface-soft: #eef3f2;
  --ink: #18211f;
  --text: #18211f;
  --muted: #63706b;
  --faint: #8b9690;
  --line: #d9e2df;
  --line-strong: #c8d1cc;
  --nav: #10222a;
  --nav-soft: #1c3f52;
  --accent: #245b7a;
  --accent-2: #0d8b68;
  --warn: #b7791f;
  --good: #0a7a55;
  --bad: #b2413c;
  --shadow: 0 18px 45px rgba(33, 48, 45, 0.12);
  --shadow-soft: none;
  --radius: 8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

button {
  border: 0;
  padding: 0 16px;
  font-weight: 400;
  transition: none;
}

button:hover,
button:active {
  transform: none;
  box-shadow: none;
}

label {
  font-size: 13px;
  font-weight: 700;
}

.login-shell {
  background:
    linear-gradient(135deg, rgba(36, 91, 122, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(13, 139, 104, 0.12), transparent 36%),
    var(--bg);
}

.login-panel {
  width: min(410px, 100%);
  gap: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-panel h1 {
  margin: 0 0 6px;
  font-size: 25px;
}

.brand-mark {
  background: #1c3f52;
}

.app {
  grid-template-columns: 248px 1fr;
}

.sidebar {
  padding: 22px;
  background: #10222a;
  color: #edf7f5;
}

.sidebar-title {
  padding-bottom: 0;
  border-bottom: 0;
}

.nav-btn {
  min-height: 38px;
  display: block;
  padding: 0 16px;
}

.nav-btn.active {
  background: #e9f4ef;
  color: #10222a;
  border-color: transparent;
}

.workspace {
  padding: 22px 28px 34px;
}

.topbar {
  min-height: 70px;
  margin-bottom: 0;
}

.topbar h2 {
  font-size: 25px;
}

.view.active {
  gap: 18px;
}

.toolbar,
.stat-card,
.metric-card,
.table-wrap,
.chart-panel {
  border-radius: 8px;
  box-shadow: none;
}

.toolbar {
  background: var(--surface);
}

th {
  background: #e9efed;
  color: #263431;
  font-size: 13px;
}

tr:hover td {
  background: #f7faf9;
}

.section-row td {
  background: #dfe9e6;
}

.analysis-header {
  background: #10222a;
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
  }

  .workspace {
    padding: 18px;
  }
}

/* Final portfolio width override: use the full 16:9 workspace. */
.portfolio-page {
  width: 100%;
  max-width: none;
  margin: 0;
}

/* Weekly report: compact full-height workspace and stable sticky rows. */
@media (min-width: 861px) {
  .app.weekly-mode {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }

  .app.weekly-mode .workspace {
    height: 100vh;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    padding: 14px 22px 16px;
  }

  .app.weekly-mode .topbar {
    min-height: 54px;
    align-items: center;
  }

  .app.weekly-mode .topbar h2 {
    font-size: 22px;
  }

  .app.weekly-mode .topbar p {
    margin-top: 2px;
    font-size: 13px;
  }

  #weeklyView.active {
    height: 100%;
    min-height: 0;
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 9px;
    overflow: hidden;
  }

  .weekly-query-row {
    grid-template-columns: minmax(0, 1fr) minmax(360px, 0.78fr);
  }

  #weeklyView .toolbar {
    flex-wrap: nowrap;
    gap: 10px;
    padding: 9px 12px;
  }

  #weeklyView .toolbar label {
    gap: 3px;
  }

  #weeklyView .toolbar input,
  #weeklyView .toolbar select,
  #weeklyView .toolbar button {
    min-height: 35px;
  }

  #weeklyStats {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
    gap: 8px;
  }

  #weeklyStats .stat-card {
    min-height: 56px;
    padding: 9px 12px;
    border-left: 3px solid rgba(36, 91, 122, 0.48);
  }

  #weeklyStats .weekly-stat-list {
    margin-top: 6px;
  }

  #weeklyView .table-actions {
    min-height: 33px;
  }

  #weeklyView .table-actions button {
    min-height: 33px;
  }

  #weeklyView .table-wrap {
    height: 100%;
    min-height: 0;
    max-height: none;
  }
}

@media (max-width: 1100px) {
  .weekly-query-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  #weeklyStats {
    grid-template-columns: 1fr;
  }
}

#weeklyTable {
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

#weeklyTable th {
  top: 0;
  height: 44px;
  background: #e9efed !important;
  box-shadow: inset 0 -1px 0 var(--line-strong);
}

#weeklyTable .section-row td {
  top: 43px;
  background: #dfe9e6 !important;
  box-shadow:
    0 -1px 0 #dfe9e6,
    inset 0 -1px 0 #cbd8d4;
  color: #18322e !important;
}

#weeklyTable tbody tr:not(.section-row):hover td {
  background: #f5f9f7;
}

#weeklyTable .section-row:hover td {
  background: #dfe9e6 !important;
}

#weeklyTable .fund-name-cell {
  font-weight: 680;
}

.weekly-fund-link {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  color: #1c4f6b;
  text-overflow: ellipsis;
  vertical-align: middle;
  cursor: pointer;
  user-select: none;
}

.weekly-fund-link:hover,
.weekly-fund-link:focus-visible {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  outline: none;
}

#weeklyTable .spark-cell[data-weekly-spark-row] {
  border-radius: 5px;
  cursor: zoom-in;
  outline: none;
}

#weeklyTable .spark-cell[data-weekly-spark-row]:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(36, 91, 122, 0.34);
}

.weekly-spark-preview {
  position: fixed;
  z-index: 1000;
  width: min(470px, calc(100vw - 24px));
  padding: 15px 16px 12px;
  border: 1px solid #cbd8d4;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(16, 34, 42, 0.20);
  pointer-events: none;
}

.weekly-spark-preview-heading {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 7px;
}

.weekly-spark-preview-heading strong,
.weekly-spark-preview-heading span {
  display: block;
}

.weekly-spark-preview-heading strong {
  color: var(--ink);
  font-size: 16px;
}

.weekly-spark-preview-heading span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.weekly-spark-preview-heading > b {
  font-size: 19px;
}

.weekly-spark-preview-close {
  display: none;
}

.weekly-spark-preview svg {
  width: 100%;
  height: auto;
  display: block;
}

.weekly-spark-preview-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 2px 4px 0;
  color: var(--muted);
  font-size: 12px;
}

.weekly-spark-preview-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.weekly-spark-preview-legend i {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 2px solid #b2413c;
}

.weekly-spark-preview-legend .weekly-spark-legend-benchmark {
  border-top-color: #8d9894;
  border-top-style: dashed;
}

.weekly-spark-preview-stats {
  display: flex;
  justify-content: flex-end;
  gap: 18px;
  padding-top: 5px;
  border-top: 1px solid #edf1ef;
  color: var(--muted);
  font-size: 12px;
}

.weekly-spark-preview-stats b {
  color: var(--ink);
}

/* Final sidebar alignment override for both expanded and compact modes. */
.nav-btn,
.sidebar-logout {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
}

.nav-btn {
  padding: 0 14px;
}

.nav-btn .nav-label,
.sidebar-logout .nav-label {
  line-height: 1;
}

.app.sidebar-collapsed .nav-btn,
.app.sidebar-collapsed .sidebar-logout {
  justify-content: center;
  gap: 0;
  padding: 0;
}

/* Saved portfolio scenarios are account-backed, inspectable configuration cards. */
.scenario-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
  gap: 10px;
}

.scenario-chip {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  min-width: 0;
  padding: 13px;
  background: #fff;
}

.scenario-chip.editing {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(36, 91, 122, 0.1);
}

.scenario-chip.renaming {
  border-color: #b7791f;
  box-shadow: 0 0 0 2px rgba(183, 121, 31, 0.12);
}

.scenario-chip.dirty {
  border-color: #0d8b68;
  box-shadow: 0 0 0 3px rgba(13, 139, 104, 0.13);
}

.scenario-chip-heading {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.scenario-funds {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.scenario-funds span {
  max-width: 100%;
  padding: 4px 8px;
  overflow: hidden;
  color: #40504c;
  background: #f1f5f3;
  border-radius: 999px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  margin-top: auto;
}

.scenario-chip.selected-for-run {
  border-color: var(--accent);
  background: #f7fbf9;
}

.scenario-select {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.scenario-select input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.scenario-name-input {
  width: 100%;
  min-height: 34px;
  padding: 5px 8px;
  font-weight: 800;
}

.scenario-inline-editor {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: #f5f8f7;
  border-radius: 8px;
}

.scenario-fund-edit-row {
  display: grid;
  grid-template-columns: minmax(100px, 1fr) 126px auto;
  align-items: center;
  gap: 8px;
}

.scenario-add-fund-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(130px, 1.2fr) auto;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.scenario-main-save,
.scenario-save-btn {
  min-width: 132px;
  min-height: 38px;
  padding: 0 16px;
  box-shadow: 0 5px 14px rgba(36, 91, 122, 0.2);
}

.scenario-chip .scenario-edit-btn,
.scenario-chip .scenario-rename-btn {
  color: var(--accent);
  background: #eef6f3;
  border-color: #bfd6ce;
  font-weight: 800;
}

.scenario-chip .scenario-save-btn {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 900;
}

.scenario-chip .scenario-save-btn:disabled {
  color: #66736f;
  background: #e5eae8;
  border-color: #d2d9d6;
  box-shadow: none;
  cursor: default;
}

.scenario-chip .scenario-cancel-btn {
  color: #34433f;
  background: #fff;
  border: 1px solid #aebbb6;
  font-weight: 800;
}

.new-scenario-btn {
  min-height: 38px;
  padding: 0 15px;
  color: var(--accent);
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 8px;
  font-weight: 800;
}

.new-scenario-btn:hover {
  color: #fff;
  background: var(--accent);
}

@media (max-width: 680px) {
  .scenario-fund-edit-row,
  .scenario-add-fund-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) {
  .scenario-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .scenario-list {
    grid-template-columns: 1fr;
  }
}

/* Keep navigation rows fixed while the sidebar width animates. */
.sidebar {
  grid-template-rows: 80px minmax(0, 1fr) auto;
}

.sidebar-title {
  min-height: 80px;
  height: 80px;
  align-self: start;
}

.app.sidebar-collapsed .sidebar {
  padding-top: 22px;
  padding-bottom: 22px;
}

/* Collapse only changes horizontal geometry; all vertical anchors stay fixed. */
.sidebar {
  transition: none;
}

.sidebar-title,
.app.sidebar-collapsed .sidebar-title {
  position: relative;
  display: block;
  height: 80px;
  min-height: 80px;
}

.sidebar-title .brand-mark.compact {
  position: absolute;
  top: 0;
  left: 0;
  transition: left 180ms ease;
}

.sidebar-copy,
.app.sidebar-collapsed .sidebar-copy {
  position: absolute;
  top: 0;
  left: 50px;
  display: block;
  width: 118px;
  overflow: hidden;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 90ms ease;
}

.sidebar-toggle {
  position: absolute;
  right: 0;
  bottom: 4px;
}

.app.sidebar-collapsed .sidebar-title .brand-mark.compact {
  left: 7px;
}

.app.sidebar-collapsed .sidebar-copy {
  opacity: 0;
  pointer-events: none;
}

.app.sidebar-collapsed .sidebar-toggle {
  position: absolute;
  right: 11px;
  bottom: 4px;
}

.nav-btn,
.sidebar-logout {
  position: relative;
}

.nav-btn .nav-icon,
.sidebar-logout .nav-icon {
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  transition: left 180ms ease, transform 180ms ease;
}

.nav-btn .nav-label,
.sidebar-logout .nav-label,
.app.sidebar-collapsed .nav-btn .nav-label,
.app.sidebar-collapsed .sidebar-logout .nav-label {
  position: absolute;
  top: 50%;
  left: 50px;
  display: inline;
  transform: translateY(-50%);
  white-space: nowrap;
  opacity: 1;
  transition: opacity 90ms ease;
}

.app.sidebar-collapsed .nav-btn .nav-icon,
.app.sidebar-collapsed .sidebar-logout .nav-icon {
  left: 50%;
  transform: translate(-50%, -50%);
}

.app.sidebar-collapsed .nav-btn .nav-label,
.app.sidebar-collapsed .sidebar-logout .nav-label {
  opacity: 0;
  pointer-events: none;
}

/* Mobile-only layout: keep the desktop shell untouched while making every view reachable. */
@media (max-width: 860px) {
  html,
  body {
    overflow-x: hidden;
  }

  .app,
  .app.sidebar-collapsed {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: block;
    height: auto;
    max-height: none;
    padding: 8px 10px 7px;
    overflow: visible;
  }

  .sidebar-title,
  .app.sidebar-collapsed .sidebar-title {
    position: static;
    display: flex;
    align-items: center;
    gap: 8px;
    height: auto;
    min-height: 32px;
  }

  .sidebar-title .brand-mark.compact,
  .app.sidebar-collapsed .sidebar-title .brand-mark.compact {
    position: static;
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    font-size: 11px;
  }

  .sidebar-copy,
  .app.sidebar-collapsed .sidebar-copy {
    display: none;
  }

  .sidebar-toggle {
    display: none;
  }

  .nav {
    display: flex;
    grid-template-columns: none;
    gap: 6px;
    padding: 8px 0 2px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }

  .nav-btn,
  .sidebar-logout,
  .app.sidebar-collapsed .nav-btn,
  .app.sidebar-collapsed .sidebar-logout {
    position: static;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: auto;
    min-height: 36px;
    gap: 6px;
    padding: 0 10px;
  }

  .nav-btn .nav-icon,
  .sidebar-logout .nav-icon,
  .app.sidebar-collapsed .nav-btn .nav-icon,
  .app.sidebar-collapsed .sidebar-logout .nav-icon {
    position: static;
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    transform: none;
  }

  .nav-btn .nav-label,
  .sidebar-logout .nav-label,
  .app.sidebar-collapsed .nav-btn .nav-label,
  .app.sidebar-collapsed .sidebar-logout .nav-label {
    position: static;
    display: inline;
    transform: none;
    white-space: nowrap;
    opacity: 1;
    pointer-events: auto;
    line-height: 1;
  }

  .sidebar-logout {
    margin-top: 6px;
  }

  .workspace {
    min-width: 0;
    padding: 10px;
    overflow-x: hidden;
  }

  .topbar {
    min-height: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
  }

  .topbar > div:first-child {
    min-width: 0;
    flex: 1 1 auto;
  }

  .topbar h2 {
    font-size: 20px;
  }

  .topbar p {
    margin-top: 2px;
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .status-text {
    min-width: 0;
    max-width: 42%;
    padding-top: 0;
    overflow-wrap: anywhere;
    text-align: right;
    font-size: 11px;
  }

  .view.active {
    gap: 10px;
  }

  .portfolio-page.view.active {
    gap: 12px !important;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 8px;
    padding: 10px;
  }

  .toolbar label,
  .toolbar .grow {
    min-width: 0;
  }

  .toolbar .grow {
    flex: none;
  }

  .toolbar > button {
    width: 100%;
    min-width: 0;
    padding-right: 8px;
    padding-left: 8px;
  }

  .weekly-query-row {
    gap: 8px;
  }

  .table-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    align-items: stretch;
  }

  .table-actions button {
    width: 100%;
    min-width: 0;
    padding-right: 8px;
    padding-left: 8px;
  }

  .table-wrap {
    max-width: 100%;
  }

  #weeklyView .table-wrap {
    min-height: 220px;
    max-height: min(62dvh, 520px);
  }

  #weeklyTable th,
  #weeklyTable td {
    padding: 9px 10px;
  }

  .weekly-spark-preview {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    padding: 10px;
  }

  .weekly-spark-preview-heading {
    gap: 8px;
  }

  .weekly-spark-preview-stats {
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
  }

  .analysis-header {
    padding: 12px;
  }

  .chart-grid {
    gap: 10px;
  }

  .chart-panel {
    padding: 10px;
  }

  .chart-panel h3 {
    margin-bottom: 6px;
    font-size: 15px;
  }

  .chart {
    height: 240px;
  }

  .portfolio-intro,
  .results-heading {
    gap: 10px;
    padding: 0;
  }

  .portfolio-intro h3,
  .results-heading h3 {
    font-size: 22px;
  }

  .portfolio-card,
  .portfolio-runbar {
    border-radius: 10px;
  }

  .portfolio-card,
  .portfolio-builder-column .portfolio-card,
  .portfolio-runbar {
    padding: 12px;
  }

  .portfolio-card-heading,
  .scenario-heading,
  .chart-title-row {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 10px;
  }

  .portfolio-card-heading > div {
    min-width: 0;
    gap: 8px;
  }

  .portfolio-card-heading h4 {
    font-size: 17px;
  }

  .parameter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
  }

  .holdings-actions,
  .scenario-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    width: 100%;
  }

  .holdings-actions button,
  .scenario-actions button {
    width: 100%;
    min-width: 0;
    padding-right: 8px;
    padding-left: 8px;
  }

  .allocation-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-top: 10px;
  }

  .allocation-summary > div {
    padding: 9px 8px;
  }

  .holdings-table,
  .fund-picker,
  .scenario-section {
    margin-right: -12px;
    margin-left: -12px;
  }

  .holdings-table {
    margin-top: 12px;
  }

  .holdings-table-header,
  .holdings-table .selected-item {
    grid-template-columns: minmax(0, 1fr) 92px auto;
    gap: 8px;
    padding: 10px 12px;
  }

  .selected-fund-name {
    grid-column: auto;
    min-width: 0;
  }

  .fund-picker {
    padding: 12px;
  }

  .fund-picker-toolbar {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 10px;
  }

  .fund-picker .position-list {
    max-height: min(38dvh, 320px);
  }

  .fund-picker .position-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px 12px;
  }

  .scenario-section {
    padding: 12px;
  }

  .scenario-list {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 10px;
  }

  .scenario-chip {
    padding: 10px;
  }

  .scenario-chip-heading {
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 6px;
  }

  .scenario-card-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .scenario-card-actions button {
    width: 100%;
    min-width: 0;
    padding-right: 5px;
    padding-left: 5px;
    font-size: 12px;
  }

  .portfolio-runbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .portfolio-runbar .primary-action {
    width: 100%;
  }

  .download-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
  }

  .download-strip button {
    width: 100%;
    min-width: 0;
    padding-right: 6px;
    padding-left: 6px;
  }

  .portfolio-results {
    margin-top: 0;
    padding-top: 14px;
  }

  .result-tabs {
    gap: 3px;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .result-tab {
    flex: 0 0 auto;
    min-height: 36px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .portfolio-main-chart {
    padding: 12px;
  }

  .portfolio-main-chart .chart {
    height: 260px;
  }

  .benchmark-popover {
    padding: 10px;
  }

  .upload-source-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .upload-source-row > button {
    width: 100%;
  }

  .login-shell {
    padding: 12px;
  }

  .login-panel {
    padding: 22px;
  }
}

@media (max-width: 380px) {
  .workspace {
    padding: 8px;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .parameter-grid {
    grid-template-columns: 1fr;
  }

  .allocation-summary > div {
    padding-right: 6px;
    padding-left: 6px;
  }

  .holdings-table-header,
  .holdings-table .selected-item {
    grid-template-columns: minmax(0, 1fr) 84px auto;
    gap: 6px;
  }

  .scenario-card-actions {
    grid-template-columns: 1fr;
  }

  .download-strip {
    grid-template-columns: 1fr;
  }
}

/* Mobile weekly report: replace the desktop spreadsheet with scannable fund cards. */
@media (max-width: 860px) {
  .app,
  .app.sidebar-collapsed {
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .sidebar,
  .workspace,
  .nav {
    min-width: 0;
    width: 100%;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    gap: 4px;
    overflow: visible;
  }

  .nav-btn {
    min-width: 0;
    gap: 4px;
    padding: 0 4px;
    font-size: 10px;
  }

  .nav-btn .nav-icon {
    width: 16px;
    height: 16px;
    flex-basis: 16px;
  }

  .nav-btn span.nav-label {
    width: auto;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    font-size: 10px;
    text-align: center;
    text-overflow: ellipsis;
  }

  .sidebar-logout {
    width: 100%;
    min-height: 32px;
    padding: 0 8px;
    font-size: 11px;
  }

  #weeklyView.active {
    gap: 8px;
  }

  #weeklyView .weekly-query-row {
    gap: 8px;
  }

  #weeklyView .weekly-query-row .toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    padding: 10px;
  }

  #weeklyView .weekly-query-row .toolbar .grow {
    grid-column: 1;
    min-width: 0;
  }

  #weeklyView .weekly-query-row .toolbar > button {
    grid-column: 2;
    grid-row: 2;
    align-self: end;
    width: 100%;
    min-width: 0;
  }

  #weeklyStats {
    grid-template-columns: minmax(0, 1.12fr) minmax(0, 0.88fr);
    gap: 8px;
  }

  #weeklyStats .stat-card {
    min-height: 0;
    padding: 10px 11px;
    border-radius: 12px;
  }

  #weeklyStats .weekly-stat-list {
    gap: 3px;
    margin-top: 5px;
  }

  #weeklyStats .weekly-stat-row {
    gap: 6px;
    font-size: 11px;
  }

  #weeklyStats .weekly-stat-row strong {
    max-width: 68%;
    overflow-wrap: anywhere;
    font-size: 12px;
  }

  #weeklyView .table-actions {
    position: sticky;
    top: 0;
    z-index: 8;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 4px 0;
    background: var(--bg);
  }

  #weeklyView .table-actions button {
    min-width: 0;
    min-height: 38px;
    padding: 0 5px;
    font-size: 12px;
  }

  #weeklyView > .table-wrap {
    display: none;
  }

  #weeklyMobileList {
    display: grid;
    gap: 8px;
    min-width: 0;
  }

  .weekly-mobile-list-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding: 0 3px 2px;
    color: var(--muted);
    font-size: 11px;
  }

  .weekly-mobile-list-meta strong {
    color: var(--ink);
    font-size: 13px;
  }

  .weekly-spark-preview {
    pointer-events: auto;
  }

  .weekly-spark-preview-heading {
    padding-right: 30px;
  }

  .weekly-spark-preview-close {
    position: absolute;
    top: -4px;
    right: 0;
    display: grid;
    width: 28px;
    min-height: 28px;
    place-items: center;
    padding: 0;
    border: 1px solid #d4dfdb;
    border-radius: 50%;
    background: #f4f8f6;
    color: var(--muted);
    font-size: 20px;
    font-weight: 500;
    line-height: 1;
  }

  .weekly-spark-preview-close:hover,
  .weekly-spark-preview-close:active {
    background: #e7f0ec;
    color: var(--accent);
    box-shadow: none;
    transform: none;
  }

  .weekly-mobile-section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 3px;
    padding: 8px 10px;
    border: 1px solid #d2dfda;
    border-radius: 10px;
    background: #e4eeea;
    color: #18322e;
    font-size: 13px;
    font-weight: 800;
  }

  .weekly-mobile-section-heading b {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
  }

  .weekly-mobile-card {
    display: grid;
    gap: 9px;
    min-width: 0;
    padding: 11px 12px 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 5px 16px rgba(25, 42, 37, 0.06);
    content-visibility: auto;
    contain-intrinsic-size: 175px;
  }

  .weekly-mobile-card.is-index {
    border-color: #b9d0c8;
    border-left: 3px solid var(--accent);
    background: #f1f7f4;
  }

  .weekly-mobile-card-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 9px;
    min-width: 0;
    align-items: start;
  }

  .weekly-mobile-check {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    min-width: 30px;
    min-height: 40px;
    margin: 0;
    padding: 0;
    cursor: pointer;
  }

  .weekly-mobile-check input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
  }

  .weekly-mobile-check > span {
    display: block;
    width: 23px;
    height: 23px;
    border: 2px solid #9ca9a4;
    border-radius: 7px;
    background: #fff;
  }

  .weekly-mobile-check input:focus-visible + span {
    outline: 3px solid rgba(31, 111, 100, 0.18);
    outline-offset: 2px;
  }

  .weekly-mobile-check input:checked + span {
    border-color: var(--accent);
    background: var(--accent);
    box-shadow: inset 0 0 0 4px #fff;
  }

  .weekly-mobile-index-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    min-height: 40px;
    color: var(--accent);
    font-size: 10px;
    font-weight: 850;
    writing-mode: vertical-rl;
  }

  .weekly-mobile-identity {
    min-width: 0;
    padding-top: 1px;
  }

  .weekly-mobile-fund-name {
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #1c4f6b;
    padding: 0;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
    font-weight: 850;
  }

  .weekly-mobile-fund-name:hover,
  .weekly-mobile-fund-name:active {
    transform: none;
    box-shadow: none;
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  .weekly-mobile-fund-name:focus-visible {
    outline: 3px solid rgba(31, 111, 100, 0.18);
    outline-offset: 3px;
  }

  .weekly-mobile-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 8px;
    min-width: 0;
    margin-top: 2px;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.35;
  }

  .weekly-mobile-meta span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .weekly-mobile-performance {
    display: grid;
    gap: 4px;
    min-width: 72px;
    padding-top: 1px;
    text-align: right;
  }

  .weekly-mobile-performance-item span,
  .weekly-mobile-metric span,
  .weekly-mobile-detail-grid span {
    display: block;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.2;
  }

  .weekly-mobile-performance-item strong {
    display: block;
    margin-top: 1px;
    font-size: 13px;
    line-height: 1.15;
  }

  .weekly-mobile-performance-item.is-primary strong {
    font-size: 17px;
  }

  .weekly-mobile-card-chart {
    min-width: 0;
    padding-top: 7px;
    border-top: 1px solid #edf1ef;
  }

  .weekly-mobile-spark {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
    min-height: 42px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    padding: 0;
    text-align: right;
    cursor: zoom-in;
  }

  .weekly-mobile-spark:hover,
  .weekly-mobile-spark:active {
    transform: none;
    box-shadow: none;
    background: #f5f9f7;
  }

  .weekly-mobile-spark:focus-visible {
    outline: 3px solid rgba(31, 111, 100, 0.18);
    outline-offset: 2px;
  }

  .weekly-mobile-spark .sparkline {
    width: 100%;
    height: 42px;
  }

  .weekly-mobile-spark .sparkline svg {
    width: 100%;
    height: 42px;
  }

  .weekly-mobile-spark > span:last-child {
    min-width: 42px;
    font-size: 10px;
  }

  .weekly-mobile-spark.is-empty {
    display: flex;
    align-items: center;
    min-height: 30px;
  }

  .weekly-mobile-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .weekly-mobile-metric {
    min-width: 0;
    padding: 7px 5px 6px;
    border: 1px solid #edf1ef;
    border-radius: 9px;
    background: #f7faf8;
    text-align: center;
  }

  .weekly-mobile-metric b {
    display: block;
    margin-top: 2px;
    overflow: hidden;
    font-size: 12px;
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .weekly-mobile-details {
    border-top: 1px solid #edf1ef;
  }

  .weekly-mobile-details summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 7px;
    color: var(--accent);
    cursor: pointer;
    font-size: 11px;
    font-weight: 750;
    list-style: none;
  }

  .weekly-mobile-details summary::-webkit-details-marker {
    display: none;
  }

  .weekly-mobile-details summary span:last-child {
    color: var(--faint);
    font-size: 10px;
    font-weight: 650;
  }

  .weekly-mobile-details[open] summary span:last-child {
    color: var(--accent);
  }

  .weekly-mobile-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px 10px;
    padding-top: 8px;
  }

  .weekly-mobile-detail-grid > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
    min-width: 0;
  }

  .weekly-mobile-detail-grid b {
    min-width: 0;
    overflow: hidden;
    color: var(--ink);
    font-size: 11px;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .weekly-mobile-detail-grid b.pos {
    color: var(--bad);
  }

  .weekly-mobile-detail-grid b.neg {
    color: var(--good);
  }
}

/* Keep the mobile shell light: logout stays available in the title bar without taking a row. */
@media (max-width: 860px) {
  .sidebar-title {
    padding-right: 58px;
  }

  .sidebar-logout,
  .app.sidebar-collapsed .sidebar-logout {
    position: absolute;
    top: 9px;
    right: 10px;
    width: auto;
    min-width: 0;
    min-height: 26px;
    margin: 0;
    gap: 4px;
    padding: 0 6px;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    color: var(--muted);
    font-size: 10px;
  }

  .sidebar-logout:hover {
    border-color: rgba(36, 91, 122, 0.12);
    background: rgba(255, 255, 255, 0.7);
    color: var(--accent);
  }

  .sidebar-logout .nav-icon,
  .app.sidebar-collapsed .sidebar-logout .nav-icon {
    width: 15px;
    height: 15px;
    flex-basis: 15px;
  }

  .sidebar-logout .nav-label,
  .app.sidebar-collapsed .sidebar-logout .nav-label {
    font-size: 10px;
  }
}

@media (max-width: 380px) {
  .nav-btn span.nav-label {
    font-size: 0;
  }

  .nav-btn span.nav-label::after {
    content: attr(data-mobile-label);
    font-size: 10px;
  }

  #weeklyView .weekly-query-row .toolbar {
    grid-template-columns: 1fr;
  }

  #weeklyView .weekly-query-row .toolbar .grow,
  #weeklyView .weekly-query-row .toolbar > button {
    grid-column: 1;
    grid-row: auto;
  }

  #weeklyStats {
    grid-template-columns: 1fr;
  }

  .weekly-mobile-card-head {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .weekly-mobile-performance {
    grid-column: 2;
    grid-row: 2;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    text-align: left;
  }

  .weekly-mobile-performance-item {
    text-align: left;
  }
}
/* Explain unavailable analysis windows instead of leaving an empty panel. */
.empty-chart-message {
  color: var(--muted);
  text-align: center;
  padding: 4rem 1rem;
}
