:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-strong: #eef4f2;
  --ink: #17211f;
  --muted: #64716d;
  --line: #dbe4e1;
  --teal: #0f766e;
  --cyan: #0e7490;
  --coral: #e4574f;
  --gold: #b7791f;
  --violet: #6d5bd0;
  --green: #2f8f58;
  --danger: #c2413a;
  --shadow: 0 24px 70px rgba(23, 33, 31, 0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(14, 116, 144, 0.12), transparent 32rem),
    linear-gradient(135deg, #f7faf9 0%, #eef3f7 100%);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(440px, 100%);
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(219, 228, 225, 0.92);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #17211f;
  color: #fff;
  font-weight: 800;
  margin-bottom: 20px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.auth-panel h1 {
  font-size: 32px;
  line-height: 1.05;
}

.muted,
.status-text {
  color: var(--muted);
}

.status-text {
  min-height: 22px;
  margin-top: 16px;
}

.auth-form,
.entry-form,
.settings-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.primary-action,
.secondary-action,
.file-action,
.danger-action {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 16px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-action {
  background: var(--ink);
  color: #fff;
}

.secondary-action,
.file-action {
  background: var(--surface-strong);
  color: var(--ink);
  border: 1px solid var(--line);
}

.danger-action {
  background: rgba(194, 65, 58, 0.1);
  color: var(--danger);
  border: 1px solid rgba(194, 65, 58, 0.18);
}

.file-action {
  position: relative;
  overflow: hidden;
}

.file-action input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 22px;
}

.topbar h1 {
  font-size: 34px;
  line-height: 1;
}

.eyebrow {
  color: var(--teal);
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.compact-field {
  min-width: 126px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 800;
}

.tabbar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  position: sticky;
  top: 0;
  z-index: 4;
  backdrop-filter: blur(12px);
}

.tab-button {
  flex: 0 0 auto;
  min-height: 38px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab-button.active {
  background: var(--ink);
  color: #fff;
}

main {
  padding-top: 22px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 18px;
}

.hero-panel,
.chart-panel,
.settings-panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 14px 40px rgba(23, 33, 31, 0.07);
}

.hero-panel {
  padding: 28px;
  min-height: 360px;
  display: grid;
  align-content: space-between;
  gap: 24px;
}

.total-label {
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 8px;
}

.total-value {
  font-size: clamp(38px, 6vw, 76px);
  line-height: 0.96;
  font-weight: 900;
}

.total-subvalue {
  color: var(--muted);
  font-size: clamp(20px, 2.4vw, 30px);
  font-weight: 900;
  margin-top: 10px;
}

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

.metric-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fff;
  text-align: left;
  color: inherit;
  display: block;
  min-height: 92px;
}

.metric-card.active,
.metric-card:hover {
  border-color: rgba(15, 118, 110, 0.55);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
}

.metric-value {
  font-size: 18px;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.metric-value small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 5px;
}

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

.metric-value.negative {
  color: var(--danger);
}

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

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

.chart-panel {
  padding: 22px;
  display: grid;
  gap: 18px;
}

.metric-detail {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 16px;
}

.detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.metric-detail h3 {
  font-size: 16px;
  margin-bottom: 5px;
}

.metric-detail p,
.metric-detail span {
  color: var(--muted);
  font-size: 13px;
}

.detail-heading > strong {
  text-align: right;
  white-space: nowrap;
}

.detail-heading > strong small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.detail-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.detail-row strong,
.detail-row b {
  font-size: 14px;
}

.detail-row b {
  text-align: right;
  white-space: nowrap;
}

.compact-heading {
  margin-bottom: 0;
}

.segmented-control {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.segmented-control button {
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--muted);
  min-width: 42px;
  height: 32px;
  font-weight: 900;
}

.segmented-control button.active {
  background: #fff;
  color: var(--ink);
}

.history-panel {
  margin-top: 18px;
}

.history-chart {
  display: grid;
  gap: 10px;
}

.history-chart svg {
  width: 100%;
  min-height: 260px;
  overflow: visible;
}

.grid-line {
  stroke: var(--line);
  stroke-width: 1;
}

.axis-label,
.x-label {
  fill: var(--muted);
  font-size: 12px;
}

.x-label {
  text-anchor: middle;
}

.history-line {
  fill: none;
  stroke: var(--teal);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-dot {
  fill: #fff;
  stroke: var(--teal);
  stroke-width: 3;
}

.chart-wrap {
  min-height: 270px;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  align-items: center;
  gap: 20px;
}

.donut {
  width: 220px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--line) 0deg 360deg);
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(23, 33, 31, 0.05);
}

.donut::after {
  content: "";
  position: absolute;
  inset: 22%;
  background: #fff;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--line);
}

.legend {
  display: grid;
  gap: 10px;
}

.legend-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.legend-row small {
  grid-column: 2 / -1;
  color: var(--muted);
  font-size: 12px;
  margin-top: -5px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

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

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

.section-heading h2 {
  font-size: 28px;
}

.entry-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.entry-form .wide-field {
  grid-column: span 2;
}

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

.data-row {
  display: grid;
  grid-template-columns: minmax(210px, 1.25fr) repeat(4, minmax(120px, 0.7fr)) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.data-row.product-row {
  grid-template-columns: minmax(210px, 1.25fr) repeat(6, minmax(110px, 0.7fr)) auto;
}

.row-title {
  min-width: 0;
}

.row-title strong {
  display: block;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.row-title span,
.row-cell span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.row-cell {
  min-width: 0;
  font-weight: 800;
  overflow-wrap: anywhere;
}

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

.small-icon-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.small-icon-button.danger {
  color: var(--danger);
}

.empty-state,
.status-strip {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.status-strip {
  margin-bottom: 14px;
  display: none;
}

.status-strip.active {
  display: block;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.settings-panel {
  padding: 20px;
}

.settings-panel h3 {
  font-size: 18px;
}

.button-row {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  max-width: min(360px, calc(100vw - 44px));
  z-index: 10;
}

@media (max-width: 1040px) {
  .dashboard-grid,
  .holdings-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

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

  .data-row,
  .data-row.product-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .row-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

@media (max-width: 680px) {
  body {
    background: #f5f7f8;
  }

  .app-shell {
    padding: 14px;
  }

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

  .topbar h1 {
    font-size: 30px;
  }

  .topbar-actions {
    width: 100%;
    align-items: end;
  }

  .compact-field {
    flex: 1;
  }

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

  .entry-form .wide-field {
    grid-column: auto;
  }

  .chart-wrap {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .detail-heading,
  .detail-row,
  .compact-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .detail-heading > strong,
  .detail-row b {
    text-align: left;
  }

  .segmented-control {
    width: 100%;
    justify-content: space-between;
  }

  .segmented-control button {
    flex: 1;
  }

  .donut {
    width: min(220px, 72vw);
  }

  .auth-panel,
  .hero-panel,
  .chart-panel,
  .settings-panel {
    padding: 18px;
  }

  .data-row,
  .data-row.product-row {
    grid-template-columns: 1fr;
  }
}
