:root {
  --bg: #eff4f1;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: #ffffff;
  --panel-muted: #f5f8f6;
  --ink: #112119;
  --muted: #5f7367;
  --line: rgba(17, 33, 25, 0.08);
  --accent: #18382b;
  --accent-soft: #d9efe3;
  --gain: #168a52;
  --gain-soft: rgba(22, 138, 82, 0.12);
  --loss: #cc4d42;
  --loss-soft: rgba(204, 77, 66, 0.12);
  --warning: #bf8a18;
  --shadow: 0 12px 28px rgba(19, 39, 29, 0.05);
  --radius: 26px;
  --radius-sm: 18px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgba(130, 186, 155, 0.22), transparent 26%),
    radial-gradient(circle at right top, rgba(23, 56, 43, 0.08), transparent 24%),
    linear-gradient(180deg, #f8fbf9 0%, var(--bg) 100%);
}

body.auth-only {
  overflow: hidden;
}

.app-hidden {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  background:
    radial-gradient(circle at top left, rgba(130, 186, 155, 0.22), transparent 26%),
    radial-gradient(circle at right top, rgba(23, 56, 43, 0.08), transparent 24%),
    linear-gradient(180deg, #f8fbf9 0%, var(--bg) 100%);
}

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 998;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(130, 186, 155, 0.22), transparent 26%),
    radial-gradient(circle at right top, rgba(23, 56, 43, 0.08), transparent 24%),
    linear-gradient(180deg, #f8fbf9 0%, var(--bg) 100%);
}

.boot-card {
  width: min(440px, 100%);
  padding: 28px;
  border-radius: 32px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.72);
}

.boot-card h1,
.boot-card p {
  margin-top: 0;
}

.auth-card {
  width: min(980px, 100%);
  padding: 28px;
  border-radius: 32px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.72);
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 22px;
}

.auth-single {
  grid-template-columns: 1fr;
}

.auth-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 22px;
  padding: 6px;
  border-radius: 18px;
  background: var(--panel-muted);
  border: 1px solid var(--line);
}

.auth-toggle-button {
  border: 0;
  padding: 12px 18px;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.auth-toggle-button.is-active {
  background: var(--accent);
  color: #fff;
}

.auth-form {
  padding: 22px;
  border-radius: 24px;
  background: var(--panel-muted);
  border: 1px solid var(--line);
  display: grid;
  gap: 14px;
}

.auth-panel {
  display: none;
}

.auth-panel.is-active {
  display: grid;
}

.backend-form {
  margin-top: 22px;
}

.backend-form .button-secondary {
  background: var(--accent);
  color: #ffffff;
}

.backend-status {
  margin: 0;
  color: var(--muted);
}

.backend-status.is-ready {
  color: var(--gain);
  font-weight: 700;
}

.auth-form h2,
.auth-copy h1 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
}

.muted-dark {
  color: var(--muted);
}

.auth-message {
  margin: 16px 4px 0;
}

.auth-inline-message {
  margin: 0;
  min-height: 20px;
}

.auth-switch {
  margin: 0;
  color: var(--muted);
}

.auth-inline-actions {
  margin-top: -6px;
}

.text-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  overflow-y: auto;
  padding: 28px 22px;
  background: rgba(16, 34, 26, 0.96);
  color: #f5faf6;
  display: flex;
  flex-direction: column;
  gap: 26px;
  min-width: 0;
  z-index: 20;
}

.sidebar-mobile-bar {
  display: block;
}

.sidebar-menu {
  display: grid;
  gap: 26px;
}

.mobile-menu-toggle {
  display: none;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  padding: 0;
  cursor: pointer;
}

.mobile-menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 4px auto;
  background: #f5faf6;
  border-radius: 999px;
}

.account-chip {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.06);
}

.account-chip strong {
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.brand-block h1,
.topbar h2,
.panel-head h3,
.summary-card strong {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
}

.brand-wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 0.02em;
  letter-spacing: -0.04em;
  line-height: 0.95;
  font-size: clamp(2rem, 4vw, 2.8rem);
}

.brand-wordmark span {
  color: #9fd1b4;
  text-shadow: 0 0 20px rgba(159, 209, 180, 0.12);
}

.mobile-brand-header {
  display: none;
}

.mobile-utility-toggle,
.mobile-utility-menu {
  display: none;
}

.muted,
.brand-block .muted {
  color: rgba(245, 250, 246, 0.72);
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 800;
  color: #7ca38f;
}

.nav-list {
  display: grid;
  gap: 10px;
}

.nav-item,
.button {
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.nav-item {
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  font-weight: 600;
}

.nav-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.nav-item-icon svg {
  width: 18px;
  height: 18px;
}

.nav-item.is-active,
.nav-item:hover {
  background: #f5faf6;
  color: var(--accent);
  transform: translateX(4px);
}

.sidebar-actions {
  display: grid;
  gap: 10px;
}

.account-chip {
  margin-top: auto;
}

.button {
  padding: 13px 16px;
  font-weight: 700;
}

.button-primary {
  background: var(--accent);
  color: #fff;
}

.button-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #f5faf6;
}

.main-content {
  margin-left: 280px;
  padding: 28px;
  min-width: 0;
}

.topbar,
.summary-grid,
.content-grid,
.analytics-grid,
.rebalancing-grid {
  display: grid;
  gap: 18px;
}

.topbar {
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-bottom: 20px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-status-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.currency-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.currency-switch span {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.currency-switch select {
  min-width: 84px;
  padding: 10px 12px;
}

.status-pill {
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  box-shadow: var(--shadow);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--accent);
  box-shadow: var(--shadow);
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.icon-button svg {
  width: 22px;
  height: 22px;
  transition: transform 0.16s ease;
}

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

.icon-button:active {
  transform: translateY(0) scale(0.94);
  box-shadow: 0 6px 16px rgba(19, 39, 29, 0.08);
  background: rgba(24, 56, 43, 0.08);
}

.icon-button:active svg {
  transform: rotate(-18deg) scale(0.94);
}

.icon-button.is-pressed {
  transform: translateY(0) scale(0.94);
  box-shadow: 0 6px 16px rgba(19, 39, 29, 0.08);
  background: rgba(24, 56, 43, 0.08);
}

.icon-button.is-pressed svg {
  transform: rotate(-18deg) scale(0.94);
}

.chat-toggle-button {
  min-width: 88px;
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-weight: 800;
}

.chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 90;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 62px;
  height: 62px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent);
  box-shadow: 0 18px 40px rgba(19, 39, 29, 0.18);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.chat-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 44px rgba(19, 39, 29, 0.22);
}

.chat-fab:active {
  transform: translateY(0) scale(0.97);
}

.chat-fab:focus-visible {
  outline: 2px solid rgba(34, 117, 78, 0.35);
  outline-offset: 3px;
}

.chat-fab-icon {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(24, 56, 43, 0.08);
}

.chat-fab-icon svg {
  width: 18px;
  height: 18px;
}

.chat-fab-label {
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  white-space: nowrap;
  font-size: 0.94rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  transform: translateX(-4px);
  transition: max-width 0.18s ease, opacity 0.16s ease, margin-left 0.16s ease, transform 0.16s ease;
}

@media (hover: hover) and (pointer: fine) {
  .chat-fab:hover,
  .chat-fab:focus-visible {
    justify-content: flex-start;
    gap: 10px;
    width: auto;
    min-width: 62px;
    padding: 0 18px 0 14px;
  }

  .chat-fab:hover .chat-fab-label,
  .chat-fab:focus-visible .chat-fab-label {
    max-width: 160px;
    margin-left: 2px;
    opacity: 1;
    transform: translateX(0);
  }
}

.chat-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 20px;
}

.chat-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(9, 19, 14, 0.38);
  backdrop-filter: blur(6px);
}

.chat-modal {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(80vh, 760px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 18px;
  padding: 24px;
  border-radius: 32px;
  background:
    radial-gradient(circle at top left, rgba(130, 186, 155, 0.12), transparent 28%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(248, 251, 249, 0.94));
  border: 1px solid rgba(255, 255, 255, 0.92);
  box-shadow:
    0 28px 70px rgba(10, 22, 16, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.chat-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 4px;
}

.chat-close-button {
  width: 42px;
  height: 42px;
}

.chat-messages {
  min-height: 280px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 4px 6px 4px 0;
}

.chat-bubble {
  max-width: min(82%, 520px);
  padding: 14px 16px 15px;
  border-radius: 24px;
  display: grid;
  gap: 8px;
  border: 1px solid rgba(17, 33, 25, 0.08);
  box-shadow: 0 10px 24px rgba(17, 33, 25, 0.04);
}

.chat-bubble strong,
.chat-bubble-body p {
  margin: 0;
}

.chat-bubble strong {
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.chat-provider-badge {
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #7e9289;
  margin-top: -4px;
}

.chat-bubble-body {
  display: grid;
  gap: 10px;
  line-height: 1.55;
  color: #25352e;
}

.chat-bubble-body p {
  line-height: 1.55;
  color: #25352e;
}

.chat-bubble-body ul {
  margin: 0;
  padding-left: 1.15rem;
  display: grid;
  gap: 0.45rem;
}

.chat-bubble-body li {
  margin: 0;
}

.chat-bubble-body code {
  padding: 0.14rem 0.4rem;
  border-radius: 999px;
  background: rgba(24, 56, 43, 0.08);
  color: #193126;
  font-size: 0.92em;
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

.chat-bubble-body em {
  color: #345445;
}

.chat-bubble.is-assistant {
  background: linear-gradient(180deg, rgba(245, 248, 246, 0.98), rgba(238, 244, 240, 0.9));
  justify-self: start;
}

.chat-bubble.is-user {
  background: linear-gradient(180deg, rgba(222, 236, 227, 0.96), rgba(212, 229, 219, 0.9));
  justify-self: end;
}

.chat-form {
  display: grid;
  gap: 14px;
}

.chat-input-wrap {
  display: grid;
}

.chat-input-wrap textarea {
  width: 100%;
  min-height: 82px;
  resize: vertical;
  padding: 16px 18px;
  border-radius: 22px;
  border: 1px solid rgba(17, 33, 25, 0.14);
  background: rgba(255, 255, 255, 0.98);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

.chat-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-status {
  min-height: 0;
  margin: 0;
}

.chat-form .button-primary {
  min-width: 112px;
}

body.chat-open {
  overflow: hidden;
}

.summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.summary-card,
.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  max-width: 100%;
  overflow: hidden;
}

.summary-card {
  padding: 20px;
  display: grid;
  gap: 8px;
}

.summary-card span,
.summary-card small,
.panel-head,
label span,
th,
.form-message,
.insight-item small {
  color: var(--muted);
}

.summary-card strong {
  font-size: 1.7rem;
}

.content-grid {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  overflow: hidden;
}

.content-main,
.analytics-grid,
.rebalancing-grid {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.content-main {
  gap: 28px;
  overflow-x: hidden;
}

.panel {
  padding: 22px;
  min-width: 0;
  width: 100%;
}

.holdings-panel {
  width: 100%;
  max-width: 100%;
  inline-size: 100%;
  max-inline-size: 100%;
  overflow: hidden;
  margin-bottom: 0;
}

.portfolio-insights-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  align-items: start;
}

.portfolio-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  margin-top: 14px;
}

.portfolio-detail-grid + .analytics-grid {
  margin-top: 14px;
}

.asset-chart-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 18px;
}

.asset-chart-selector {
  display: grid;
  gap: 8px;
  max-width: 320px;
}

.asset-chart-ranges {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border-radius: 18px;
  background: rgba(24, 56, 43, 0.04);
  border: 1px solid rgba(17, 33, 25, 0.06);
}

.asset-chart-range-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  padding: 8px 13px;
  border-radius: 14px;
  cursor: pointer;
}

.asset-chart-range-button.is-active {
  background: var(--accent);
  color: #fff;
}

.asset-chart-range-button.is-disabled,
.asset-chart-range-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.asset-chart-frame {
  min-height: 440px;
  border-radius: 24px;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
  padding: 18px 18px 14px;
}

.asset-chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.asset-chart-symbol {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.asset-chart-price {
  color: var(--ink);
  font-size: clamp(2rem, 4vw, 2.6rem);
  font-weight: 800;
  line-height: 1;
}

.asset-chart-change {
  display: grid;
  justify-items: end;
  gap: 4px;
  padding-top: 8px;
  text-align: right;
}

.asset-chart-change strong {
  font-size: 1.4rem;
  line-height: 1;
}

.asset-chart-change span {
  font-size: 1rem;
  font-weight: 700;
}

.asset-chart-canvas-wrap {
  position: relative;
  min-height: 500px;
}

.asset-purchase-history {
  margin-top: 18px;
}

.asset-purchase-history .panel-head {
  margin-bottom: 12px;
}

.asset-chart-loading {
  min-height: 340px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.portfolio-performance-panel,
.portfolio-mix-panel {
  width: 100%;
  margin-inline: 0;
}

#portfolio-performance-chart {
  min-height: 320px;
}

@media (max-width: 820px) {
  .holdings-panel {
      width: 100%;
      max-width: 100%;
      inline-size: 100%;
      max-inline-size: 100%;
    margin: 0;
  }

  .asset-chart-controls {
    align-items: stretch;
  }

  .asset-chart-selector {
    max-width: 100%;
  }

  .asset-chart-ranges {
    width: 100%;
    justify-content: space-between;
  }

  .asset-chart-header {
    grid-template-columns: 1fr;
    display: grid;
  }

  .asset-chart-change {
    justify-items: start;
    text-align: left;
    padding-top: 0;
  }

  .portfolio-mix-panel {
      width: 100%;
    }

  .portfolio-insights-grid {
    grid-template-columns: 1fr;
  }
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-select {
  width: auto;
  min-width: 132px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
}

.legend-row {
  display: flex;
  gap: 16px;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.gain {
  background: var(--gain);
}

.loss {
  background: var(--loss);
}

.view-section {
  display: none;
}

.view-section.is-active {
  display: block;
}

.view-section[data-section="assets"].is-active {
  display: grid;
  gap: 18px;
}

.table-wrap {
  overflow: auto;
  min-width: 0;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 14px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 0.94rem;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.holding-row.is-clickable {
  cursor: pointer;
}

.holding-row.is-clickable:hover td {
  background: rgba(24, 56, 43, 0.03);
}

.lot-row td {
  background: rgba(24, 56, 43, 0.035);
}

.lot-row td:first-child {
  padding-left: 28px;
}

.asset-name {
  font-weight: 700;
}

.asset-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  min-width: 0;
}

.expand-indicator {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 700;
}

.asset-sub {
  display: inline;
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 700;
}

.pill.gain {
  background: var(--gain-soft);
  color: var(--gain);
}

.pill.loss {
  background: var(--loss-soft);
  color: var(--loss);
}

.pill.neutral {
  background: rgba(24, 56, 43, 0.08);
  color: var(--accent);
}

.form-grid,
.targets-grid {
  display: grid;
  gap: 16px;
}

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

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

label {
  display: grid;
  gap: 8px;
}

input,
select {
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--ink);
}

input:focus,
select:focus {
  outline: 2px solid rgba(24, 56, 43, 0.14);
  border-color: rgba(24, 56, 43, 0.22);
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.settings-card + .settings-card {
  margin-top: 14px;
}

.view-section[data-section="settings"] .panel > .settings-card {
  max-width: 760px;
}

.settings-grid {
  max-width: 420px;
}

.settings-logout-card .settings-actions {
  margin: 0;
}

.settings-account-row {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.settings-account-row span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.settings-account-row strong {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.view-section[data-section="settings"] .settings-card {
  background: rgba(24, 56, 43, 0.04);
}

.view-section[data-section="settings"] .settings-card label span {
  color: var(--ink);
}

.view-section[data-section="settings"] .settings-logout-card .button-secondary {
  background: rgba(24, 56, 43, 0.08);
  color: var(--ink);
  border: 1px solid rgba(24, 56, 43, 0.08);
}

.row-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.table-action.compact {
  padding: 4px 8px;
  font-size: 0.78rem;
  flex: 0 0 auto;
}

.table-action {
  border: 0;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(24, 56, 43, 0.08);
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

.form-message {
  min-height: 20px;
}

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

.metric-panel {
  grid-column: 1 / -1;
}

#analytics-panel-popular-movers,
#analytics-panel-insights,
#portfolio-page-panel-popular-movers,
#portfolio-page-panel-insights {
  grid-column: span 1;
}

#portfolio-page-panel-asset-mix,
#portfolio-page-panel-best-worst-day {
  grid-column: span 1;
}

canvas {
  width: 100%;
  max-height: 320px;
}

#portfolio-allocation-chart {
  min-height: 320px;
}

.inner-panel {
  background: var(--panel-muted);
  box-shadow: none;
}

.asset-manager-panel {
  margin-top: 12px;
}

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

.allocation-overview,
.insight-list,
.snapshot-report,
.simulator-results {
  display: grid;
  gap: 12px;
}

.asset-manager-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.asset-manager-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.table-action.is-danger {
  background: rgba(204, 77, 66, 0.12);
  color: var(--loss);
}

.allocation-item,
.insight-item,
.snapshot-card,
.scenario-card {
  padding: 14px 16px;
  border-radius: 18px;
  background: var(--panel-muted);
  border: 1px solid var(--line);
}

.mover-item .insight-top strong {
  font-size: 1.02rem;
}

.movers-toggle {
  margin-top: 8px;
  justify-self: start;
  background: var(--accent);
  color: #ffffff;
}

.side-panel .allocation-item,
.side-panel .insight-item {
  padding: 16px 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(17, 33, 25, 0.07);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.allocation-top,
.insight-top,
.snapshot-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.allocation-bar {
  margin-top: 10px;
  height: 9px;
  border-radius: 999px;
  background: rgba(24, 56, 43, 0.08);
  overflow: hidden;
}

.allocation-bar-stacked {
  display: flex;
  gap: 2px;
  margin-top: 0;
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
}

.allocation-segment {
  height: 100%;
  min-width: 6px;
  border-radius: 999px;
}

.side-panel .allocation-top strong,
.side-panel .insight-item strong {
  font-size: 1.12rem;
  color: var(--accent);
}

.side-panel .allocation-top span,
.side-panel .insight-item small,
.side-panel .allocation-item small {
  color: var(--muted);
}

.allocation-fill {
  height: 100%;
  background: linear-gradient(90deg, #2c6b4d, #5fb282);
  border-radius: 999px;
}

.allocation-item-compact {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 10px;
  align-items: center;
  padding: 4px 0;
}

.allocation-item-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.allocation-item-compact small {
  grid-column: 1 / -1;
  font-size: 0.84rem;
}

.allocation-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.empty-state {
  padding: 20px;
  border-radius: 18px;
  border: 1px dashed rgba(24, 56, 43, 0.18);
  background: rgba(24, 56, 43, 0.02);
  color: var(--muted);
}

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

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

.warning {
  color: var(--warning);
}

@media (max-width: 1180px) {
  .auth-grid,
  .app-shell,
  .content-grid,
  .summary-grid,
  .analytics-grid,
  .rebalancing-grid,
  .portfolio-detail-grid,
  .transaction-grid,
  .targets-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1600px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) and (orientation: landscape) {
  .app-shell,
  .content-grid,
  .portfolio-detail-grid,
  .analytics-grid,
  .rebalancing-grid,
  .transaction-grid,
  .targets-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
  }

  .summary-card {
    padding: 16px;
    gap: 6px;
  }

  .summary-card strong {
    font-size: 1.45rem;
  }

  .sidebar {
    position: fixed;
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: auto;
    z-index: 30;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 14px;
    gap: 14px;
    border-radius: 24px;
    box-shadow: 0 16px 36px rgba(9, 19, 14, 0.18);
    backdrop-filter: blur(14px);
    overflow: visible;
  }

  .sidebar-mobile-bar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
  }

  .sidebar-mobile-bar .brand-block {
    min-width: 0;
  }

  .sidebar-mobile-bar .brand-block .muted {
    display: none;
  }

  .mobile-menu-toggle {
    display: block;
    flex: 0 0 auto;
  }

  .sidebar-menu {
    display: none;
    gap: 14px;
  }

  .sidebar-menu.is-open {
    display: grid;
  }

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

  .sidebar-actions {
    margin-top: 0;
    grid-template-columns: 1fr;
  }

  .main-content {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
  }

  .topbar {
    margin-top: 84px;
  }
}

@media (max-width: 820px) {
  input,
  select,
  textarea,
  button {
    font-size: 16px;
  }

  .app-shell {
    overflow-x: hidden;
  }

  body {
    background:
      radial-gradient(circle at top center, rgba(31, 74, 55, 0.34), transparent 26%),
      linear-gradient(180deg, #07110d 0%, #0a1712 100%);
    color: #eef7f1;
  }

  .auth-card,
  .main-content {
    padding: 18px 14px;
  }

  .content-grid,
  .summary-grid,
  .analytics-grid,
  .rebalancing-grid,
  .portfolio-detail-grid {
    gap: 12px;
    width: 100%;
    max-width: 100%;
  }

  .content-main,
  .view-section,
  .summary-card,
  .panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
  }

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

  .topbar {
    grid-template-columns: 1fr;
    margin-top: 0;
    margin-bottom: 16px;
    gap: 14px;
  }

  .mobile-brand-header {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    align-items: center;
    margin: 0 0 14px;
    padding: 12px 14px;
    min-height: 62px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    box-sizing: border-box;
    position: relative;
  }

  .mobile-brand-center {
    display: grid;
    justify-items: center;
    text-align: center;
    gap: 2px;
    min-width: 0;
  }

  .mobile-brand-header .eyebrow {
    margin-bottom: 0;
    color: rgba(238, 247, 241, 0.66);
    font-size: 0.68rem;
    display: none;
  }

  .mobile-brand-header .brand-wordmark {
    justify-self: center;
    font-size: clamp(1.2rem, 5.2vw, 1.55rem);
    color: #f7fbf8;
    line-height: 1;
    letter-spacing: 0.16em;
    text-transform: lowercase;
  }

  .mobile-utility-toggle {
    display: inline-grid;
    place-items: center;
    position: relative;
    top: auto;
    right: auto;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
  }

  .mobile-utility-toggle span {
    display: block;
    width: 16px;
    height: 2px;
    margin: 2px auto;
    border-radius: 999px;
    background: #f7fbf8;
  }

  .mobile-utility-menu {
    display: grid;
    gap: 10px;
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    width: min(240px, calc(100vw - 16px));
    padding: 12px;
    background: rgba(11, 22, 17, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.24);
    z-index: 50;
  }

  .mobile-utility-button,
  .mobile-status-pill {
    width: 100%;
    box-sizing: border-box;
  }

  .mobile-chat-toggle {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: #f7fbf8;
    cursor: pointer;
    justify-self: end;
  }

  .mobile-chat-toggle-icon {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
  }

  .mobile-chat-toggle-icon svg {
    width: 18px;
    height: 18px;
  }

  .sidebar {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    background: rgba(16, 34, 26, 0.96);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -12px 30px rgba(9, 19, 14, 0.18);
    backdrop-filter: blur(12px);
    overflow: visible;
  }

  .sidebar-mobile-bar,
  .account-chip {
    display: none;
  }

  .mobile-menu-toggle {
    display: none;
  }

  .sidebar-menu,
  .sidebar-menu.is-open {
    display: block;
    gap: 0;
  }

  .nav-list {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    align-items: center;
  }

  .nav-item[data-view="settings"] {
    display: none;
  }

  .nav-item {
    min-width: 0;
    padding: 10px 6px;
    border-radius: 18px;
    justify-content: center;
    text-align: center;
    white-space: nowrap;
    line-height: 1;
    gap: 0;
  }

  .nav-item span:last-child {
    display: none;
  }

  .nav-item-icon svg {
    width: 22px;
    height: 22px;
  }

  .nav-item.is-active,
  .nav-item:hover {
    transform: none;
  }

  .main-content {
    margin-left: 0;
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }

  .topbar > div:first-child .eyebrow {
    color: rgba(238, 247, 241, 0.56);
  }

  .topbar h2 {
    color: #f7fbf8;
    font-size: clamp(1.7rem, 6vw, 2rem);
    letter-spacing: -0.04em;
  }

  .topbar-actions,
  .topbar-status-group {
    display: none;
  }

  .currency-switch,
  .status-pill {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: none;
    color: rgba(238, 247, 241, 0.82);
  }

  .currency-switch span,
  .status-pill,
  .summary-card span,
  .summary-card small,
  .panel-head,
  label span,
  th,
  .form-message,
  .insight-item small {
    color: rgba(238, 247, 241, 0.64);
  }

  .currency-switch select,
  .panel-select,
  .chat-input-wrap textarea,
  input,
  select,
  textarea {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.1);
    color: #f7fbf8;
  }

  .view-section[data-section="settings"] .settings-logout-card .button-secondary {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.1);
    color: #f7fbf8;
  }

  .view-section[data-section="settings"] .settings-account-row span {
    color: rgba(238, 247, 241, 0.64);
  }

  .view-section[data-section="settings"] .settings-account-row strong {
    color: #f7fbf8;
  }

  .summary-card,
  .panel {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: none;
    backdrop-filter: blur(10px);
  }

  .summary-card strong,
  .panel h3,
  .panel strong,
  .asset-name,
  .snapshot-top strong,
  td,
  .insight-item {
    color: #f7fbf8;
  }

  .table-wrap,
  .holdings-table tr,
  .asset-manager-item,
  .insight-item,
  .quick-add-chips,
  .chat-modal {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
  }

  .holdings-table tr,
  .asset-manager-item,
  .insight-item {
    box-shadow: none;
  }

  .dot.loss,
  .negative {
    color: #ff8777;
  }

  .dot.gain,
  .positive {
    color: #58d68b;
  }

  .chat-modal {
    width: 100%;
    max-height: min(86vh, 760px);
    padding: 18px 16px;
    border-radius: 24px;
  }

  .chat-fab {
    display: none;
  }

  .chat-fab-icon {
    width: 32px;
    height: 32px;
  }

  .chat-fab-label {
    display: none;
  }

  .chat-bubble {
    max-width: 100%;
  }

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

  .chat-form .button-primary {
    width: 100%;
  }

  .main-content {
    margin-left: 0;
  }

  .currency-switch,
  .status-pill {
    width: 100%;
    box-shadow: none;
  }

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

  .summary-card {
    padding: 16px;
  }

  .summary-card strong {
    font-size: 1.35rem;
  }

  .panel {
    padding: 16px 14px;
  }

  .main-content {
    width: 100%;
    max-width: 100%;
    margin: 0;
    overflow-x: hidden;
  }

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .legend-row {
    gap: 10px;
    font-size: 0.84rem;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0;
    border-collapse: separate;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--panel-muted);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: minmax(100px, 42%) 1fr;
    gap: 10px;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--line);
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .lot-row td:first-child {
    padding-left: 12px;
  }

  .empty-row {
    background: transparent;
    border: 0;
  }

  .empty-row td {
    display: block;
    padding: 0;
    border: 0;
  }

  .empty-row td::before {
    content: none;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .button,
  .form-actions .button,
  .account-chip .button,
  .sidebar-actions .button {
    width: 100%;
    text-align: center;
  }

  .asset-manager-item,
  .allocation-top,
  .insight-top,
  .snapshot-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .holdings-table-wrap {
    display: block;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    inline-size: 100%;
    max-inline-size: 100%;
    min-width: 0;
    margin: 0;
    padding-bottom: 0;
    scrollbar-width: none;
  }

  .holdings-table-wrap::-webkit-scrollbar {
    display: none;
  }

  .holdings-panel,
  .holdings-panel .holdings-table-wrap {
    width: 100%;
    max-width: 100%;
  }

  .holdings-panel .table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .holdings-table,
  .holdings-table thead,
  .holdings-table tbody,
  .holdings-table tr,
  .holdings-table th,
  .holdings-table td {
    width: auto;
  }

  .holdings-table {
    display: table;
    width: max-content;
    min-width: 560px;
    border-collapse: collapse;
    max-width: none;
  }

  .holdings-table thead {
    display: table-header-group;
  }

  .holdings-table tbody {
    display: table-row-group;
  }

  .holdings-table tr {
    display: table-row;
    border: 0;
    background: transparent;
  }

  .holdings-table th,
  .holdings-table td {
    display: table-cell;
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
  }

  .holdings-table .asset-name {
    display: block;
    white-space: nowrap;
  }

  .holdings-table .asset-sub {
    display: block;
    margin-top: 2px;
    font-size: 0.74rem;
    white-space: nowrap;
  }

  .holdings-table td::before {
    content: none;
  }

  .holdings-table .asset-inline {
    white-space: nowrap;
  }

  .holdings-table .lot-row-mobile td {
    padding: 0 0 12px;
    border-bottom: 0;
  }

  .lot-mobile-card {
    padding: 14px;
    border-radius: 18px;
    background: rgba(24, 56, 43, 0.04);
    border: 1px solid rgba(17, 33, 25, 0.08);
  }

  .lot-mobile-head {
    display: grid;
    gap: 4px;
    margin-bottom: 12px;
  }

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

  .lot-mobile-item {
    display: grid;
    gap: 2px;
    min-width: 0;
  }

  .lot-mobile-item span {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .lot-mobile-item strong {
    font-size: 0.94rem;
    color: var(--ink);
    word-break: break-word;
  }
}

@media (max-width: 560px) {
  html {
    font-size: 14px;
  }

  .main-content {
    padding: 14px 8px calc(92px + env(safe-area-inset-bottom));
  }

  .summary-card {
    padding: 14px 12px;
  }

  .panel {
    padding: 14px 12px;
  }

  .nav-list {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
  }

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

  td {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  td::before {
    margin-bottom: 2px;
  }

  .holdings-table-wrap,
  .holdings-panel .table-wrap {
    overflow-x: visible;
  }

  .holdings-table {
    min-width: 0;
    width: 100%;
  }
}
