/* ── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background: #0e0e1a;
  color: #e0e0e0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
}

/* ── App shell ─────────────────────────────────────────────────────────── */
.app {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.app > h1 {
  font-size: 1.4rem;
  color: #fff;
}

/* ── Accordion stack ──────────────────────────────────────────────────── */
.accordion-stack {
  background: #1a1a2e;
  border-radius: 10px;
  overflow: hidden;
}

.accordion-step {
  border-top: 1px solid #252540;
}

.accordion-step:first-child {
  border-top: none;
}

.accordion-header {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 1rem 1.2rem;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  gap: 0.6rem;
  text-align: left;
}

.accordion-header:hover {
  background: rgba(255, 255, 255, 0.03);
}

.accordion-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  flex-shrink: 0;
}

.step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5em;
  height: 1.5em;
  background: #6c5ce7;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.accordion-summary {
  color: #888;
  font-size: 0.85rem;
  white-space: nowrap;
}

.accordion-chevron {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #888;
  flex-shrink: 0;
  transition: transform 0.3s ease;
  margin-left: auto;
}

.accordion-step[data-state="expanded"] .accordion-chevron {
  transform: rotate(180deg);
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  padding: 0 1.2rem;
  transition: max-height 0.3s ease;
}

.accordion-step[data-state="expanded"] .accordion-body {
  max-height: none;
  overflow: visible;
  padding: 0 1.2rem 1.2rem;
}

/* Summary visible only when collapsed */
.accordion-step[data-state="expanded"] .accordion-summary {
  display: none;
}

/* Disabled step */
.accordion-step[data-enabled="false"] .accordion-header {
  opacity: 0.35;
  cursor: not-allowed;
}

.accordion-step[data-enabled="false"] .accordion-header:hover {
  background: none;
}

/* ── Typography ────────────────────────────────────────────────────────── */
h3 { font-size: 0.95rem; color: #fff; margin-top: 1rem; margin-bottom: 0.4rem; }
h4 { font-size: 0.85rem; color: #aaa; margin-top: 0.6rem; margin-bottom: 0.3rem; }
label { font-size: 0.85rem; color: #aaa; display: block; }
.optional { color: #666; font-weight: normal; }
.muted { color: #555; font-size: 0.8rem; }

/* ── Upload row ───────────────────────────────────────────────────────── */
.currency-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.currency-row label {
  font-size: 0.85rem;
  color: #aaa;
  display: inline;
}

.currency-row select {
  width: auto;
}

.currency-inline {
  width: auto;
  padding: 0.35rem 0.5rem;
  font-size: 0.75rem;
  color: #888;
  background: #1a1a2e;
  border: 1px solid #333;
  border-radius: 6px;
  margin-left: auto;
}

.upload-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.upload-or {
  color: #666;
  font-size: 0.8rem;
}

/* ── Form controls ─────────────────────────────────────────────────────── */
select,
input[type="text"] {
  width: 100%;
  padding: 0.5rem;
  background: #0e0e1a;
  border: 1px solid #333;
  border-radius: 6px;
  color: #e0e0e0;
  font-size: 0.85rem;
}

input[type="range"] {
  width: 100%;
  accent-color: #6c5ce7;
}

/* ── Uploaded file list ─────────────────────────────────────────────────── */
.file-list {
  list-style: none;
  font-size: 0.8rem;
  color: #888;
}

.file-list li::before {
  content: '\1F4CE\00a0';
}

.file-x {
  cursor: pointer;
  opacity: 0.4;
  font-weight: bold;
  margin-left: 0.3rem;
}

.file-x:hover { opacity: 1; }

/* ── Theme editor ──────────────────────────────────────────────────────── */
.alloc-total {
  text-align: right;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  margin-bottom: 0.1rem;
}

.alloc-ok { color: #00b894; }
.alloc-off { color: #fdcb6e; }

.theme-table th { font-size: 0.75rem; }
.theme-table td { vertical-align: middle; }

.category-row td {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6e9ecf;
  padding: 0.5rem 0.6rem 0.15rem;
  border-bottom: none;
  border-top: 0.5rem solid #1a1a2e;
}

.category-weight {
  font-variant-numeric: tabular-nums;
}

.theme-name-cell {
  font-weight: 500;
  color: #e0e0e0;
  padding-left: 1.2rem;
}

.theme-basis {
  font-size: 0.7rem;
  font-style: italic;
  color: #777;
  font-weight: normal;
  white-space: normal;
}

.theme-weight-value {
  cursor: pointer;
  font-weight: 600;
  color: #fff;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  text-decoration-color: #556;
}

.theme-weight-value:hover {
  text-decoration-color: #6c5ce7;
}

.cash-weight-value {
  cursor: pointer;
  font-weight: 600;
  color: #888;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  text-decoration-color: #556;
}

.cash-weight-value:hover {
  text-decoration-color: #6c5ce7;
  color: #bbb;
}

/* ── Cash row ─────────────────────────────────────────────────────────── */
.cash-row {
  border-top: 0.5rem solid #1a1a2e;
}

.cash-name {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6e9ecf;
}

/* ── Delta redistribution buttons ─────────────────────────────────── */
.theme-weight-cell {
  white-space: nowrap;
}

.take-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  cursor: pointer;
  background: #2d2d44;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 0.2rem;
  vertical-align: middle;
  line-height: 1.4;
}

.take-btn svg {
  flex-shrink: 0;
}

/* Over → decrease → orange */
.take-btn.take-decrease {
  color: #fdcb6e;
  border-color: #555;
}
.take-btn.take-decrease:hover {
  background: #3d3d54;
  border-color: #fdcb6e;
}

/* Short → increase → green */
.take-btn.take-increase {
  color: #00b894;
  border-color: #555;
}
.take-btn.take-increase:hover {
  background: #3d3d54;
  border-color: #00b894;
}

/* Proportional variant — dimmer */
.take-btn.take-prop {
  opacity: 0.65;
  font-size: 0.65rem;
}
.take-btn.take-prop:hover {
  opacity: 1;
}

.delta-banner {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  margin-bottom: 0.3rem;
}

.delta-over {
  background: #3a0000;
  color: #ff7675;
  border-left: 3px solid #d63031;
}

.delta-short {
  background: #3a3000;
  color: #fdcb6e;
  border-left: 3px solid #fdcb6e;
}

.theme-weight-input {
  background: #0e0e1a;
  border: 1px solid #6c5ce7;
  border-radius: 3px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.1rem 0.2rem;
  width: 4.5em;
  outline: none;
  text-align: center;
}

.theme-tickers-cell {
  line-height: 1.8;
}

.theme-ticker {
  display: inline-block;
  white-space: nowrap;
  background: #2d2d44;
  border: 1px solid #444;
  border-radius: 999px;
  padding: 0.1rem 0.4rem;
  font-size: 0.7rem;
  color: #aaa;
  margin: 0.1rem;
}

.theme-ticker.ticker-warn {
  border-color: #b8860b;
}

.theme-ticker.ticker-overlap {
  border-color: #6c5ce7;
}

.ticker-overlap-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
  margin-left: 0.25em;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: #6c5ce7;
  border-radius: 50%;
  vertical-align: 0.05em;
}

.ticker-warn-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
  margin-left: 0.25em;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  color: #000;
  background: #fdcb6e;
  border-radius: 2px;
  vertical-align: 0.05em;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
  padding-top: 0.2em;
}

.theme-actions-cell {
  white-space: nowrap;
  text-align: right;
  width: 5rem;
}

.theme-action-btn {
  cursor: pointer;
  opacity: 0.35;
  padding: 0 0.2rem;
  vertical-align: middle;
  display: inline-block;
  line-height: 1;
}

.theme-action-btn svg {
  display: block;
}

.theme-action-btn:hover { opacity: 1; }

.theme-remove-btn:hover { color: #e74c3c; opacity: 1; }

/* ── Theme overflow menu ─────────────────────────────────────────────── */
.theme-overflow-btn {
  display: none;
  cursor: pointer;
  opacity: 0.35;
  vertical-align: middle;
  line-height: 1;
}

.theme-overflow-btn:hover { opacity: 1; }

.overflow-label { display: none; }

.take-btns-row { display: inline; }

/* ── Merge icon states ────────────────────────────────────────────────── */
.theme-merge-btn.active { opacity: 1; color: #6c5ce7; }
.theme-merge-btn.merge-target { opacity: 0.85; color: #6c5ce7; animation: pulse-merge 1s ease-in-out infinite; }
tr.merge-selected { background: rgba(108, 92, 231, 0.1); }

@keyframes pulse-merge {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ── Inline split mode ───────────────────────────────────────────────── */
.theme-split-btn.active { opacity: 1; color: #6c5ce7; }

.theme-ticker.split-selectable {
  cursor: pointer;
  animation: pulse-split 1s ease-in-out infinite;
  border-color: #6c5ce7;
}

.theme-ticker.split-selectable:hover {
  background: #3d3d54;
  color: #fff;
}

.theme-ticker.split-selected {
  background: #6c5ce7;
  border-color: #6c5ce7;
  color: #fff;
  animation: none;
}

@keyframes pulse-split {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.theme-add-row {
  margin-top: 0.6rem;
  display: flex;
  gap: 0.4rem;
}

.theme-add-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.btn-theme-apply {
  display: none;
  padding: 0.5rem 0.8rem;
  background: #6c5ce7;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-theme-apply:hover { background: #5b4bd5; }

/* ── Rules row ─────────────────────────────────────────────────────────── */
.rules-row {
  margin-top: 0.6rem;
  margin-bottom: 0.8rem;
}

/* ── Rule chips ────────────────────────────────────────────────────────── */
#rule-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  min-height: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #2d2d44;
  border: 1px solid #444;
  border-radius: 16px;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  line-height: 1.4;
  word-break: break-word;
}

.rule-chip {
  background: #1e3a5f;
  border-color: #2a5a8a;
}

#rule-tip {
  position: fixed;
  background: #16213e;
  border: 1px solid #2a5a8a;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  color: #ccc;
  line-height: 1.5;
  max-width: 300px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 100;
  pointer-events: none;
  display: none;
}

#rule-tip.tip-clickable {
  pointer-events: auto;
}

.tip-links {
  margin-top: 0.3rem;
  padding-top: 0.3rem;
  border-top: 1px solid #2a5a8a;
  display: flex;
  gap: 0.6rem;
}

.tip-links a {
  color: #6e9ecf;
  text-decoration: none;
  font-size: 0.7rem;
}

.tip-links a:hover {
  color: #fff;
  text-decoration: underline;
}

.rule-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid #4a7ab5;
  background: transparent;
  color: #8ab4f8;
  font-size: 0.6rem;
  font-weight: bold;
  flex-shrink: 0;
  line-height: 1;
}

.rule-label {
  color: #8ab4f8;
  font-size: 0.75rem;
}

.rule-value {
  cursor: pointer;
  text-decoration: underline dashed;
  text-underline-offset: 2px;
  text-decoration-color: #556;
}

.rule-value:hover {
  text-decoration-color: #8ab4f8;
}

.rule-input {
  background: #0e0e1a;
  border: 1px solid #2a5a8a;
  border-radius: 3px;
  color: #e0e0e0;
  font-size: 0.78rem;
  padding: 0 0.2rem;
  width: 4em;
  outline: none;
}

.chip-revert {
  cursor: pointer;
  opacity: 0.5;
  font-size: 0.85rem;
  line-height: 1;
}

.chip-revert:hover { opacity: 1; }

.hidden { display: none; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn-upload {
  padding: 0.5rem 1rem;
  background: #2d2d44;
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-upload:hover { background: #3d3d54; }

.btn-sample {
  border-style: dashed;
  color: #aaa;
}
.btn-sample:hover { color: #e0e0e0; }

.btn-export {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: #00cec9;
  color: #0e0e1a;
  text-decoration: none;
  border-radius: 6px;
  font-weight: bold;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.btn-export:hover { background: #00b5b0; }

/* ── App footer & clear link ──────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.link-clear {
  background: none;
  border: none;
  color: #555;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-clear:hover { color: #888; }

.footer-link {
  color: #555;
  font-size: 0.8rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer-link:hover { color: #888; }

.footer-sep {
  color: #444;
  font-size: 0.8rem;
  margin: 0 0.3rem;
}

/* ── Privacy note ─────────────────────────────────────────────────────── */
.privacy-note {
  font-size: 0.75rem;
  color: #666;
  margin: 0.4rem 0 0.2rem;
  line-height: 1.5;
}

.privacy-note a {
  color: #a29bfe;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.privacy-note a:hover { color: #6c5ce7; }

/* ── About page ───────────────────────────────────────────────────────── */
.about-page {
  max-width: 680px;
}

.about-page h2 {
  font-size: 1.1rem;
  color: #a29bfe;
  margin-top: 1.8rem;
  margin-bottom: 0.5rem;
}

.about-page p,
.about-page li {
  font-size: 0.88rem;
  line-height: 1.7;
  color: #c0c0c0;
  margin-bottom: 0.4rem;
}

.about-page ol,
.about-page ul {
  padding-left: 1.2rem;
  margin-bottom: 0.6rem;
}

.about-page .disclaimer {
  background: #1a1a2e;
  border-left: 3px solid #fdcb6e;
  border-radius: 6px;
  padding: 0.8rem 1rem;
}

.about-page .back-link {
  display: inline-block;
  margin-top: 2rem;
  color: #a29bfe;
  font-size: 0.85rem;
  text-decoration: none;
}

.about-page .back-link:hover {
  color: #6c5ce7;
  text-decoration: underline;
}

/* ── Metrics row ───────────────────────────────────────────────────────── */
.metrics {
  display: flex;
  gap: 0.6rem;
  margin: 0.5rem 0;
}

.metric {
  flex: 1;
  background: #16213e;
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  text-align: center;
}

.metric-value {
  font-size: 1rem;
  font-weight: bold;
  color: #fff;
}

.metric-label {
  font-size: 0.75rem;
  color: #888;
}

/* ── Data tables ───────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin: 0.3rem 0;
}

.data-table th {
  text-align: left;
  padding: 0.4rem 0.6rem;
  color: #888;
  border-bottom: 1px solid #333;
}

.data-table td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid #1e1e30;
}

.positive { color: #00b894; }
.negative { color: #d63031; }
.buy      { color: #00b894; font-weight: bold; }
.sell     { color: #d63031; font-weight: bold; }

.trade-theme-header {
  font-size: 0.8rem;
  color: #8ab4f8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.8rem;
}

/* ── Status boxes ──────────────────────────────────────────────────────── */
.error-box {
  background: #d63031;
  color: #fff;
  padding: 0.6rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
}

.info-box {
  background: #16213e;
  color: #74b9ff;
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.warning-box {
  background: #fdcb6e;
  color: #0e0e1a;
  padding: 0.5rem;
  border-radius: 6px;
  margin: 0.3rem 0;
  font-size: 0.85rem;
}

/* ── htmx spinner ─────────────────────────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-indicator.htmx-request { display: inline-flex; }

.spinner-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.spinner-ring {
  width: 24px;
  height: 24px;
  border: 3px solid #333;
  border-top-color: #6c5ce7;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Full-page loader overlay ─────────────────────────────────────────── */
.page-loader {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(14, 14, 26, 0.75);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.page-loader.active {
  display: flex;
}

.loader-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}

.loader-content .spinner-ring {
  width: 36px;
  height: 36px;
}

.loader-text {
  color: #aaa;
  font-size: 0.9rem;
}

.loader-track {
  width: min(200px, 60vw);
  height: 3px;
  background: #333;
  border-radius: 2px;
  overflow: hidden;
}

.loader-bar {
  height: 100%;
  width: 0%;
  background: #6c5ce7;
  border-radius: 2px;
  transition: width 0.2s linear;
}

/* ── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ── Overlap section ──────────────────────────────────────────────────── */
.overlap-section {
  margin-top: 0.6rem;
}

.overlap-section h4 {
  color: #a29bfe;
  font-size: 0.8rem;
  margin-bottom: 0.3rem;
}

.overlap-box {
  background: #1e1538;
  color: #a29bfe;
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  border-left: 3px solid #6c5ce7;
  margin-bottom: 0.3rem;
}

/* ── Overlap picker ──────────────────────────────────────────────────── */
.overlap-picker {
  margin-top: 0.8rem;
  background: #1e1538;
  border: 1px solid #6c5ce7;
  border-radius: 8px;
  padding: 1rem;
}

.overlap-picker h4 {
  color: #a29bfe;
  font-size: 0.9rem;
  margin-bottom: 0.6rem;
}

.picker-cluster {
  margin-bottom: 0.6rem;
}

.picker-table {
  font-size: 0.8rem;
}

.picker-table th {
  font-size: 0.7rem;
  color: #888;
}

.picker-row {
  cursor: pointer;
  transition: background 0.15s;
}

.picker-row:hover {
  background: rgba(108, 92, 231, 0.1);
}

.picker-selected {
  background: rgba(108, 92, 231, 0.2);
}

.picker-selected td {
  color: #fff;
}

.picker-also-adding {
  font-size: 0.8rem;
  color: #888;
  margin: 0.5rem 0;
}

.picker-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.btn-confirm-picker {
  padding: 0.4rem 1.2rem;
  background: #6c5ce7;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-confirm-picker:hover { background: #5b4bd5; }

.btn-cancel-picker {
  padding: 0.4rem 1.2rem;
  background: transparent;
  color: #888;
  border: 1px solid #444;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-cancel-picker:hover { color: #e0e0e0; border-color: #666; }

/* ── Suggestion movement styles ──────────────────────────────────────── */
.suggestion-reduce { color: #d63031; font-weight: 600; }
.suggestion-add    { color: #00b894; font-weight: 600; }

/* ── Comparison table ─────────────────────────────────────────────── */
.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 0.3rem 0;
}

.comparison-table thead th {
  text-align: left;
  padding: 0.4rem 0.6rem;
  color: #888;
  font-size: 0.75rem;
  font-weight: 600;
  border-bottom: 1px solid #333;
}

.comparison-table thead th:nth-child(n+2) {
  text-align: right;
}

.comparison-table td {
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid #1e1e30;
  font-variant-numeric: tabular-nums;
}

.comparison-table td:first-child {
  color: #aaa;
}

.comparison-table td.has-tip,
.comparison-table .section-row td.has-tip,
.detail-card h4.has-tip {
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  text-decoration-color: #555;
}

.comparison-table td:nth-child(n+2) {
  text-align: right;
  color: #e0e0e0;
  font-weight: 500;
}

.comparison-table .section-row td {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8ab4f8;
  padding: 0.6rem 0.6rem 0.2rem;
  border-bottom: 1px solid #2a3a5e;
  background: none;
}

.metric-improved { color: #00b894 !important; }
.metric-degraded { color: #d63031 !important; }

/* ── Detail cards grid ───────────────────────────────────────────── */
.detail-cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.detail-card {
  background: #131a2e;
  border: 1px solid #1e2a44;
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
  overflow-x: auto;
}

.detail-card-wide {
  grid-column: 1 / -1;
}

.detail-card h4 {
  font-size: 0.8rem;
  color: #8ab4f8;
  margin: 0 0 0.4rem;
}

.detail-card .data-table {
  margin: 0;
}

.detail-card .corr-heatmap {
  margin: 0;
}

.detail-card .info-box {
  margin: 0;
}

.detail-card .btn-export {
  margin-top: 0.6rem;
}

.detail-card-desc {
  font-size: 0.78rem;
  color: #778;
  line-height: 1.5;
  margin-bottom: 0.5rem;
}

/* ── BL advisory table ───────────────────────────────────────────── */
.bl-table td:nth-child(n+2),
.bl-table th:nth-child(n+2) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bl-deviation {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.78rem;
}

.bl-info {
  color: #74b9ff;
  background: rgba(116, 185, 255, 0.1);
}

.bl-warning {
  color: #fdcb6e;
  background: rgba(253, 203, 110, 0.1);
}

.bl-alert {
  color: #ff7675;
  background: rgba(255, 118, 117, 0.15);
}

.bl-row-muted td {
  color: #556 !important;
}

.bl-deviation-muted {
  color: #556;
  font-size: 0.78rem;
}

/* ── Risk contribution bar ────────────────────────────────────────── */
.risk-contrib-bar {
  height: 6px;
  background: #6c5ce7;
  border-radius: 3px;
  min-width: 2px;
}

/* ── Correlation heatmap ──────────────────────────────────────────── */
.corr-heatmap {
  overflow-x: auto;
  margin: 0.4rem 0;
}

.corr-table {
  border-collapse: collapse;
  font-size: 0.65rem;
}

.corr-table th,
.corr-table td {
  padding: 0.2rem 0.3rem;
  text-align: center;
  min-width: 2.8rem;
}

.corr-header {
  color: #888;
  font-weight: 500;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  height: 3.5rem;
  vertical-align: bottom;
  font-size: 0.6rem;
}

.corr-row-label {
  color: #888;
  font-weight: 500;
  text-align: right !important;
  padding-right: 0.4rem !important;
  white-space: nowrap;
  font-size: 0.6rem;
}

.corr-header a,
.corr-row-label a {
  color: #888;
  text-decoration: none;
}

.corr-header a:hover,
.corr-row-label a:hover {
  color: #aac8ff;
  text-decoration: underline;
}

.corr-cell {
  color: #ccc;
  font-variant-numeric: tabular-nums;
  border: 1px solid #1a1a2e;
}

.corr-cell a {
  color: #ccc;
  text-decoration: none;
  display: block;
}

.corr-cell a:hover {
  color: #fff;
  text-decoration: underline;
}

/* ── Table scroll wrapper ─────────────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Scroll shadow hint for heatmap ──────────────────────────────────── */
.corr-heatmap {
  background:
    linear-gradient(to right, #131a2e 30%, transparent) left / 1rem 100% no-repeat,
    linear-gradient(to left, #131a2e 30%, transparent) right / 1rem 100% no-repeat,
    linear-gradient(to right, rgba(0,0,0,0.3), transparent) left / 0.5rem 100% no-repeat,
    linear-gradient(to left, rgba(0,0,0,0.3), transparent) right / 0.5rem 100% no-repeat;
  background-attachment: local, local, scroll, scroll;
}

/* ── Responsive: tablet (≤768px) ─────────────────────────────────────── */
@media (max-width: 768px) {
  .app {
    padding: 0.75rem;
  }

  .detail-cards-grid {
    grid-template-columns: 1fr;
  }

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

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

  .upload-row > * {
    width: 100%;
  }

  .upload-row .upload-or {
    text-align: left;
  }

  .metrics {
    flex-wrap: wrap;
  }

  .metric {
    flex: 1 1 calc(50% - 0.6rem);
    min-width: 0;
  }

  .accordion-summary {
    white-space: normal;
    font-size: 0.75rem;
  }
}

/* ── Responsive: phone (≤640px) ──────────────────────────────────────── */
@media (max-width: 640px) {
  .app > h1 {
    font-size: 1.1rem;
  }

  .accordion-header {
    padding: 0.75rem 0.8rem;
    font-size: 1rem;
  }

  .currency-row {
    flex-direction: column;
    align-items: stretch;
  }

  .currency-inline {
    margin-left: 0;
  }

  .picker-actions {
    flex-direction: column;
  }

  .picker-actions button {
    width: 100%;
  }

  .overlap-picker {
    padding: 0.6rem;
  }

  .btn-theme-apply {
    display: block;
  }

  /* ── Theme table: card layout ───────────────────────────────────── */
  .theme-table thead { display: none; }

  .theme-table tbody tr:not(.category-row) {
    display: grid;
    grid-template-columns: 1fr auto;
    row-gap: 0;
    column-gap: 0.4rem;
    padding: 0.5rem 0.6rem;
    padding-right: 2.5rem;
    border-bottom: 1px solid #1e1e30;
    align-items: baseline;
    position: relative;
  }

  .theme-table tbody tr:not(.category-row) > td {
    border-bottom: none;
    padding: 0;
  }

  /* Dissolve cells so children become direct grid items */
  .theme-name-cell {
    display: contents;
  }

  .theme-weight-cell {
    display: contents;
  }

  /* Row 1: title + percentage */
  .theme-name {
    grid-column: 1;
    grid-row: 1;
    font-weight: 500;
    color: #e0e0e0;
  }

  .theme-weight-value,
  .cash-weight-value {
    grid-column: 2;
    grid-row: 1;
    text-align: right;
    font-size: 0.85rem;
  }

  /* Cash row: no right padding for actions */
  .cash-row {
    padding-right: 0.6rem;
  }

  /* Row 2: redistribution actions */
  .take-btns-row {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
    margin-top: 0.15rem;
  }

  .take-btns-row:empty {
    display: none;
  }

  /* Row 3: description */
  .theme-basis {
    grid-column: 1 / -1;
    grid-row: 3;
    margin-top: 0.1rem;
  }

  /* Row 4: tickers */
  .theme-tickers-cell {
    grid-column: 1 / -1;
    grid-row: 4;
    margin-top: 0.15rem;
  }

  /* Let overflow menu escape the scroll wrapper on mobile */
  .theme-table-scroll {
    overflow: visible;
  }

  /* "..." button vertically centered on the right */
  .theme-actions-cell {
    position: absolute;
    right: 0.3rem;
    top: 50%;
    transform: translateY(-50%);
  }

  /* Category rows */
  .theme-table .category-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.1rem 0.4rem;
    border-top: 0.5rem solid #1a1a2e;
    padding: 0.5rem 0.6rem 0.15rem;
  }

  .theme-table .category-row > td {
    border-bottom: none;
    border-top: none;
    padding: 0;
  }

  .theme-table .category-row td[colspan] {
    display: none;
  }

  .theme-table .category-row:first-child {
    border-top: none;
  }

  /* ── Overflow menu for theme actions ────────────────────────── */
  .theme-overflow-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
  }

  .theme-actions-cell > .theme-overflow-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: #2d2d44;
    border: 1px solid #555;
    border-radius: 8px;
    padding: 0.3rem;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  }

  .theme-actions-cell > .theme-overflow-menu.open {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
  }

  .theme-overflow-menu .theme-action-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0.7;
  }

  .theme-overflow-menu .theme-action-btn:hover,
  .theme-overflow-menu .theme-action-btn:active {
    background: #3d3d54;
    opacity: 1;
  }

  .theme-overflow-menu .overflow-label {
    display: inline;
    font-size: 0.78rem;
    color: #ccc;
  }

  .theme-overflow-menu .theme-remove-btn .overflow-label {
    color: #e74c3c;
  }
}

/* ── Touch targets (≥44px hit area) ──────────────────────────────────── */
@media (pointer: coarse) {
  .take-btn {
    padding: 0.4rem 0.6rem;
    min-height: 44px;
    font-size: 0.75rem;
  }

  .theme-action-btn {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem;
  }

  .file-x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 10px;
    font-size: 1rem;
  }

  .rule-help {
    width: 20px;
    height: 20px;
    padding: 12px;
    font-size: 0.65rem;
  }

  .chip {
    padding: 0.35rem 0.6rem;
    min-height: 36px;
  }

  .btn-upload,
  .btn-sample,
  .btn-confirm-picker,
  .btn-cancel-picker {
    min-height: 44px;
  }
}

