:root {
  --bg: #f7f8f6;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --ink: #202522;
  --muted: #66706a;
  --line: #dce3de;
  --accent: #087f5b;
  --accent-2: #2563eb;
  --warn: #b7791f;
  --bad: #c2412d;
  --good: #13795b;
  --shadow: 0 16px 40px rgba(30, 44, 35, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px clamp(18px, 4vw, 44px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(24px, 4vw, 36px);
  line-height: 1.05;
}

h2 {
  font-size: 16px;
}

.actions,
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

button,
select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  min-height: 38px;
}

button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-color: transparent;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

button:disabled {
  opacity: 0.65;
  cursor: wait;
}

select {
  padding: 0 34px 0 12px;
}

input[type="search"] {
  min-width: min(420px, 100%);
  padding: 0 12px;
}

input[type="text"],
input[type="password"],
input[type="number"] {
  padding: 0 12px;
}

textarea {
  padding: 12px;
}

.icon-button {
  justify-content: center;
  width: 38px;
  min-width: 38px;
  padding: 0;
}

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

.login-card,
.settings-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card {
  display: grid;
  gap: 12px;
  padding: 24px;
}

.login-card h1 {
  margin-bottom: 8px;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--bad);
  font-size: 13px;
  font-weight: 700;
}

.form-error.success {
  color: var(--good);
}

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

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
}

.switch input {
  accent-color: var(--accent);
}

.layout {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 34px) 42px;
}

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

.metric,
.panel,
.cash-section,
.grand-total,
.analysis-section,
.history-section,
.notes-section,
.table-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
  min-height: 118px;
}

.metric span,
.metric small,
.panel-title span,
.badge,
.empty {
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
}

.metric small {
  display: block;
  margin-top: 8px;
  min-height: 18px;
}

.metric-main {
  background: linear-gradient(135deg, #ffffff 0%, #eff8f2 100%);
}

.panels {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.65fr);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  min-height: 236px;
  padding: 18px;
}

.cash-section {
  margin-top: 14px;
  padding: 18px;
}

.analysis-section {
  margin-top: 14px;
  padding: 18px;
}

.history-section {
  margin-top: 14px;
  padding: 18px;
}

.notes-section {
  margin-top: 14px;
  padding: 18px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: start end;
  padding: 84px clamp(18px, 4vw, 44px) 24px;
  background: rgba(32, 37, 34, 0.28);
}

.settings-card {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.settings-section {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.settings-section h3 {
  margin: 0;
  font-size: 14px;
}

.settings-copy {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.settings-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

.bars {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(140px, 1fr) 132px;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
}

.bar-fill {
  width: var(--w);
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.broker-value {
  display: grid;
  gap: 2px;
  justify-items: end;
}

.broker-value small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.broker-value small.positive {
  color: var(--good);
}

.broker-value small.negative {
  color: var(--bad);
}

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

.alert {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.alert strong {
  font-size: 14px;
}

.cash-form {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(180px, 1fr) minmax(130px, 0.7fr) 100px auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.cash-list {
  display: grid;
  gap: 8px;
}

.cash-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) minmax(170px, 1fr) minmax(120px, 0.7fr) 96px 102px 84px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.cash-row input,
.cash-row select {
  width: 100%;
}

.table-section {
  margin-top: 14px;
  overflow: hidden;
}

.table-toolbar {
  justify-content: space-between;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 360px);
  min-height: 360px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f3f6f4;
  color: #3b433e;
  font-size: 12px;
  text-transform: uppercase;
  cursor: pointer;
}

td:first-child {
  min-width: 260px;
  white-space: normal;
}

.manual-controls {
  display: grid;
  grid-template-columns: 98px 78px auto;
  gap: 6px;
  align-items: center;
  min-width: 258px;
}

.manual-controls input,
.manual-controls select {
  width: 100%;
  min-height: 32px;
}

.manual-controls button,
.cash-row button {
  min-height: 32px;
  padding: 0 10px;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

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

.badge {
  display: inline-flex;
  align-items: center;
  max-width: 220px;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fbfcfb;
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge.good {
  border-color: rgba(19, 121, 91, 0.25);
  background: #edf8f3;
  color: var(--good);
}

.badge.warn {
  border-color: rgba(183, 121, 31, 0.25);
  background: #fff8e8;
  color: var(--warn);
}

.badge.manual {
  border-color: rgba(37, 99, 235, 0.25);
  background: #eef4ff;
  color: var(--accent-2);
}

.badge.bad {
  border-color: rgba(194, 65, 45, 0.25);
  background: #fff0ed;
  color: var(--bad);
}

.empty {
  height: 160px;
  text-align: center;
}

.grand-total {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin-top: 14px;
  overflow: hidden;
}

.grand-total article {
  min-height: 118px;
  padding: 18px;
  border-right: 1px solid var(--line);
}

.grand-total article:last-child {
  border-right: 0;
}

.grand-total span,
.grand-total small {
  display: block;
  color: var(--muted);
}

.grand-total strong {
  display: block;
  margin-top: 10px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
}

.grand-total small {
  margin-top: 8px;
}

.grand-total-main {
  background: linear-gradient(135deg, #ffffff 0%, #eef4ff 100%);
}

.asset-mix {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.asset-mix-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.asset-mix-card span,
.asset-mix-card small,
.asset-mix-card em {
  color: var(--muted);
}

.asset-mix-card strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  line-height: 1.05;
}

.asset-mix-grid {
  display: grid;
  grid-template-columns: minmax(80px, 0.7fr) minmax(120px, 1fr);
  gap: 8px 12px;
  margin-top: 14px;
  align-items: baseline;
}

.asset-mix-grid b {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.asset-mix-card em {
  display: block;
  margin-top: 12px;
  font-size: 12px;
  font-style: normal;
}

.snapshot-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.snapshot-form input[type="date"] {
  width: 150px;
}

.snapshot-form input[type="text"] {
  width: min(260px, 100%);
}

.snapshot-chart {
  min-height: 330px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 14px;
}

.snapshot-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 6px;
}

.chart-summary strong {
  font-size: 24px;
}

.chart-summary span {
  font-weight: 800;
}

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

.chart-grid text,
.chart-date {
  fill: var(--muted);
  font-size: 12px;
}

.chart-line {
  fill: none;
  stroke: var(--accent-2);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-point circle {
  fill: var(--surface);
  stroke: var(--accent-2);
  stroke-width: 3;
  cursor: pointer;
}

.chart-point.selected circle {
  fill: var(--accent-2);
}

.snapshot-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.45fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.snapshot-list {
  display: grid;
  align-content: start;
  gap: 8px;
}

.snapshot-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 8px;
}

.snapshot-item.selected {
  border-color: rgba(37, 99, 235, 0.45);
  background: #eef4ff;
}

.snapshot-select {
  display: grid;
  justify-items: start;
  gap: 4px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.snapshot-select span,
.snapshot-select small {
  color: var(--muted);
}

.snapshot-detail {
  min-width: 0;
}

.snapshot-assets-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.snapshot-assets-wrap table {
  font-size: 13px;
}

.notes-input {
  width: 100%;
  min-height: 190px;
  resize: vertical;
}

@media (max-width: 980px) {
  .topbar,
  .actions {
    align-items: flex-start;
  }

  .topbar {
    flex-direction: column;
  }

  .summary-grid,
  .panels,
  .grand-total,
  .asset-mix,
  .snapshot-layout {
    grid-template-columns: 1fr;
  }

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

  .cash-form,
  .cash-row,
  .snapshot-form {
    grid-template-columns: 1fr;
  }

  .settings-inline {
    align-items: stretch;
  }

  .settings-inline > * {
    width: 100%;
  }

  .snapshot-form {
    justify-content: stretch;
  }

  .snapshot-form > * {
    width: 100% !important;
  }

  .grand-total article {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .grand-total article:last-child {
    border-bottom: 0;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .actions,
  .table-toolbar,
  .actions > *,
  .table-toolbar > * {
    width: 100%;
  }

  button {
    justify-content: center;
  }

  .metric {
    min-height: 106px;
  }
}
