:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --ink: #15201f;
  --muted: #63706e;
  --line: #dce6e3;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --blue: #2563eb;
  --red: #dc2626;
  --orange: #ea580c;
  --green: #16a34a;
  --shadow: 0 12px 30px rgba(18, 31, 29, 0.12);
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  touch-action: manipulation;
}

.app {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 18px 14px 92px;
}

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

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

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

h1 {
  font-size: 1.9rem;
}

h2 {
  font-size: 1.45rem;
}

h3 {
  font-size: 1rem;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.filters label,
.field {
  display: grid;
  gap: 6px;
}

.filters span,
.field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

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

.primary,
.secondary,
.danger,
.small-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}

.helper-text {
  color: var(--muted);
  line-height: 1.45;
}

.small-help {
  font-size: 0.86rem;
}

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

.secondary {
  background: #dff2ef;
  color: var(--teal-dark);
}

.danger {
  background: #fee2e2;
  color: #991b1b;
}

.small-button {
  min-height: 38px;
  background: #e3eeeb;
  color: var(--teal-dark);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 12px;
}

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

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 18px rgba(18, 31, 29, 0.06);
}

.metric {
  display: grid;
  gap: 4px;
  padding: 13px;
}

.metric span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

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

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

.metric.negative strong {
  color: var(--red);
}

.panel {
  padding: 14px;
}

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

.compact-title {
  align-items: flex-start;
  margin-bottom: 0;
}

.panel-title span {
  color: var(--muted);
  font-size: 0.82rem;
}

.form-panel,
.stack {
  display: grid;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.last-entry-card {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
}

.last-entry-card span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.last-entry-card strong {
  font-size: 0.9rem;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  font-weight: 800;
}

.segmented input:checked + span {
  border-color: var(--teal);
  background: #dff2ef;
  color: var(--teal-dark);
}

.bar-list,
.history-list,
.legend {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.bar-line strong,
.history-main strong {
  overflow-wrap: anywhere;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf3f1;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--teal);
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.history-main {
  display: grid;
  gap: 4px;
}

.history-main span,
.history-item small {
  color: var(--muted);
  font-size: 0.82rem;
}

.amount-income {
  color: var(--green);
  font-weight: 850;
}

.amount-expense {
  color: var(--red);
  font-weight: 850;
}

.search {
  margin-bottom: 8px;
}

.backup-actions {
  display: grid;
  gap: 12px;
}

.file-restore {
  display: grid;
  place-items: center;
  min-height: 48px;
  text-align: center;
}

.file-restore input {
  display: none;
}

.backup-status {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
}

.backup-panel {
  display: grid;
  gap: 14px;
}

.backup-main {
  min-height: 52px;
}

.backup-status span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.9rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.legend-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.legend-label span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  padding: 7px max(8px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(18, 31, 29, 0.08);
}

.bottom-nav button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
}

.bottom-nav button.active {
  background: #dff2ef;
  color: var(--teal-dark);
}

.lock {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(180deg, #e8f3f0, #f8fbfa);
}

.lock[hidden] {
  display: none;
}

.login-card {
  width: min(390px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 900;
}

.message {
  min-height: 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

canvas {
  width: 100%;
  max-width: 100%;
}

@media (min-width: 760px) {
  .app {
    padding-bottom: 24px;
  }

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

  .view.active[data-view="dashboard"],
  .view.active[data-view="charts"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-grid,
  .view.active[data-view="dashboard"] .panel:first-of-type,
  .view.active[data-view="charts"] .panel:last-of-type {
    grid-column: 1 / -1;
  }

  .bottom-nav {
    width: min(520px, calc(100% - 24px));
    right: 12px;
    bottom: 12px;
    left: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
  }
}
