:root {
  color-scheme: light;
  --ink: #15211b;
  --muted: #65716b;
  --line: #d8dfda;
  --paper: #f8faf7;
  --panel: #ffffff;
  --accent: #126b50;
  --accent-strong: #0c4d3a;
  --blue: #285c9f;
  --amber: #9a6a10;
  --wash: #eef4ef;
  --danger: #b43f2c;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

button,
a,
select,
input,
label {
  font: inherit;
}

button,
a,
select,
input[type="radio"],
label:has(input[type="radio"]) {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

a[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.6;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  gap: 16px;
  align-items: center;
  padding: 14px 24px;
  background: rgba(248, 250, 247, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
  width: max-content;
}

.brand img {
  border-radius: 8px;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1;
}

.brand strong {
  font-size: 1.15rem;
}

.brand small {
  margin-top: 4px;
  color: var(--muted);
}

.mode-tabs,
.auth-mode {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.mode-tab,
.auth-mode label {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
}

.mode-tab.is-active,
.auth-mode label:has(input:checked) {
  background: var(--accent);
  color: #fff;
}

.auth-mode input {
  position: absolute;
  opacity: 0;
}

.account-strip {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  min-width: 0;
}

main {
  width: min(1460px, 100%);
  margin: 0 auto;
  padding: 18px 24px 44px;
}

.notice-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  min-height: 44px;
  padding: 10px 0 18px;
  color: var(--muted);
}

.notice-row p {
  margin: 0;
}

.notice-row span,
.weight-status {
  color: var(--accent-strong);
  white-space: nowrap;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 300px minmax(0, 1.35fr) minmax(320px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.account-panel,
.simulator-panel,
.results-panel,
.history-view {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 12px 30px rgba(37, 52, 43, 0.06);
}

.panel-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}

.panel-heading.wide {
  flex-direction: row;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.panel-heading strong {
  font-size: 1.05rem;
}

.auth-form,
.controls-grid,
.holdings-tools {
  display: grid;
  gap: 12px;
}

.auth-form label,
.controls-grid label,
.holdings-tools label {
  display: grid;
  gap: 6px;
}

.auth-form span,
.controls-grid span,
.holdings-tools span {
  color: var(--muted);
  font-size: 0.86rem;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  min-height: 42px;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(40, 92, 159, 0.22);
  outline-offset: 2px;
}

.primary-button,
.ghost-button,
.google-button,
.template-card,
.snapshot-item,
.icon-button {
  border-radius: 8px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.primary-button,
.ghost-button,
.google-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid transparent;
  text-decoration: none;
  font-weight: 700;
}

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

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button,
.google-button {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.ghost-button:hover,
.google-button:hover,
.template-card:hover,
.snapshot-item:hover {
  border-color: var(--accent);
}

.compact {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 0.9rem;
}

.form-status,
.source-line,
.empty-state {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.controls-grid {
  grid-template-columns: minmax(180px, 1fr) minmax(140px, 0.7fr) auto auto;
  align-items: end;
  margin-bottom: 16px;
}

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

.template-card {
  min-height: 112px;
  border: 1px solid var(--line);
  background: var(--wash);
  color: var(--ink);
  padding: 12px;
  text-align: left;
}

.template-card strong,
.template-card span {
  display: block;
}

.template-card strong {
  margin-bottom: 8px;
}

.template-card span {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.holdings-tools {
  grid-template-columns: minmax(210px, 1fr) auto auto minmax(120px, auto);
  align-items: end;
  margin-bottom: 12px;
}

.weight-status {
  justify-self: end;
  padding-bottom: 10px;
  font-weight: 700;
}

.weight-status.warn {
  color: var(--amber);
}

.holdings-table {
  display: grid;
  gap: 8px;
}

.holding-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.1fr) minmax(135px, 0.9fr) 122px 42px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.holding-row.heading {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
  background: transparent;
  border-style: dashed;
}

.holding-row strong {
  display: grid;
  gap: 2px;
}

.holding-row small {
  color: var(--muted);
  font-weight: 500;
}

.holding-row label {
  position: relative;
}

.holding-row input {
  padding-right: 28px;
}

.holding-row em {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-style: normal;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--danger);
  font-weight: 800;
}

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

.metric-grid div,
.holding-result {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.metric-grid span,
.holding-result small {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.metric-grid strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(1rem, 1.6vw, 1.45rem);
}

.history-chart {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 7;
  min-height: 220px;
  margin-bottom: 12px;
}

.history-chart rect {
  fill: #f4f7f5;
}

.history-chart line {
  stroke: #c9d3cc;
  stroke-width: 1;
}

.history-chart path {
  fill: none;
  stroke: var(--blue);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-chart text {
  fill: var(--muted);
  font-size: 15px;
}

.holding-results,
.snapshot-list {
  display: grid;
  gap: 8px;
}

.holding-result {
  display: grid;
  grid-template-columns: 66px 1fr;
  gap: 4px 10px;
  align-items: center;
}

.holding-result span {
  justify-self: end;
  color: var(--accent-strong);
  font-weight: 800;
}

.holding-result small {
  grid-column: 1 / -1;
}

.history-view {
  min-height: 420px;
}

.snapshot-item {
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 12px;
  text-align: left;
}

.snapshot-item span {
  color: var(--muted);
}

[hidden] {
  display: none !important;
}

@media (max-width: 1180px) {
  .workspace-grid {
    grid-template-columns: minmax(240px, 0.8fr) minmax(0, 1.2fr);
  }

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

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

@media (max-width: 820px) {
  .topbar {
    position: static;
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .mode-tabs,
  .account-strip {
    justify-self: stretch;
  }

  .account-strip {
    justify-content: space-between;
  }

  main {
    padding: 14px;
  }

  .notice-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace-grid,
  .controls-grid,
  .holdings-tools {
    grid-template-columns: 1fr;
  }

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

  .holding-row {
    grid-template-columns: minmax(0, 1fr) 88px 38px;
  }

  .holding-row.heading {
    display: none;
  }

  .holding-row > span {
    display: none;
  }

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

  .panel-heading.wide {
    flex-direction: column;
  }

  .weight-status {
    justify-self: start;
    padding-bottom: 0;
  }
}
