/* styles.css — Gastos. Mobile-first (375px baseline), dark mode via
   prefers-color-scheme, safe-area insets, tap targets >= 44px. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef1;
  --text: #0f172a;
  --text-dim: #64748b;
  --border: #d9dde3;
  --accent: #059669;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
  --radius: 14px;
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #131c31;
    --surface-2: #1c2740;
    --text: #e8edf5;
    --text-dim: #94a3b8;
    --border: #26324d;
    --accent: #34d399;
    --accent-text: #06281c;
    --danger: #f87171;
    --danger-bg: #2a1416;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  line-height: 1.4;
}

[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------- layout --- */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

#views {
  flex: 1;
  padding: 16px 16px calc(96px + var(--safe-bottom));
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.view {
  animation: fade 0.15s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------------------------------------- tab bar --- */

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}

.tab {
  flex: 1;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.tab-icon {
  font-size: 20px;
  line-height: 1;
}

.tab[aria-current="page"] {
  color: var(--accent);
}

/* -------------------------------------------------------------- cards ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.section-title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

.total-hero {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  padding: 20px 16px;
}

.total-hero .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

.total-hero .value {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

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

.totals-row .stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
}

.totals-row .stat .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  display: block;
}

.totals-row .stat .value {
  font-size: 16px;
  font-weight: 700;
  margin-top: 4px;
}

/* --------------------------------------------------------------- forms --- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

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

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}

textarea {
  min-height: 60px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  min-height: var(--tap);
  padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.btn:active {
  transform: translateY(1px);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  min-height: var(--tap);
  padding: 8px;
}

.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  border: none;
  background: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  border-radius: 10px;
}

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

.inline-actions .btn {
  width: auto;
  flex: 1;
}

/* --------------------------------------------------------------- lists --- */

.entry-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.entry:last-child {
  border-bottom: none;
}

.entry .swatch {
  width: 10px;
  height: 34px;
  border-radius: 4px;
  flex: none;
}

.entry .entry-main {
  flex: 1;
  min-width: 0;
}

.entry .entry-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry .entry-sub {
  font-size: 12px;
  color: var(--text-dim);
}

.entry .entry-amount {
  font-weight: 700;
  white-space: nowrap;
}

.entry .entry-buttons {
  display: flex;
  gap: 2px;
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 24px 8px;
  font-size: 14px;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px;
}

.chip .del {
  border: none;
  background: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
}

.chip.seed {
  opacity: 0.7;
}

/* -------------------------------------------------------------- report --- */

.picker-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.picker-row .field {
  flex: 1;
  margin: 0;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.report-table th,
.report-table td {
  padding: 10px 6px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.report-table th:first-child,
.report-table td:first-child {
  text-align: left;
}

.report-table .cat-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.report-table .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
}

.report-table tfoot td {
  font-weight: 800;
  border-top: 2px solid var(--border);
  border-bottom: none;
}

.pie-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
}

.pie-wrap svg {
  width: 220px;
  height: 220px;
  max-width: 70vw;
  max-height: 70vw;
}

/* Subtle stroke between slices; theme-aware so thin slices stay separable. */
.pie-wrap svg path,
.pie-wrap svg circle {
  stroke: var(--surface);
  stroke-width: 0.7;
}

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  width: 100%;
}

.legend .item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.legend .dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
}

.legend .pct {
  margin-left: auto;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.readonly-banner {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 12px;
  text-align: center;
}

/* --------------------------------------------------------------- modal --- */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 200; /* above the lock screen (z-index 100) */
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(2, 6, 23, 0.55);
  padding: 0;
}

.modal {
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.25);
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions .btn {
  flex: 1;
}

/* ---------------------------------------------------------- lock screen --- */

.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px);
}

.lock-inner {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.lock-logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 800;
}

.lock-title {
  margin: 0;
  font-size: 22px;
}

.lock-hint {
  margin: 0;
  color: var(--text-dim);
  min-height: 20px;
  font-size: 14px;
}

.lock-hint.error {
  color: var(--danger);
}

.pin-dots {
  display: flex;
  gap: 16px;
  margin: 4px 0 8px;
}

.pin-dots .dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--text-dim);
}

.pin-dots .dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
}

.keypad button {
  min-height: 64px;
  min-width: var(--tap);
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 24px;
  font-weight: 600;
  cursor: pointer;
}

.keypad button:active {
  background: var(--surface-2);
}

.keypad button.blank {
  border: none;
  background: none;
  cursor: default;
}

/* ------------------------------------------------------------ utilities --- */

.muted {
  color: var(--text-dim);
  font-size: 13px;
}

.stack > * + * {
  margin-top: 12px;
}

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

.toggle-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap);
}

/* ---------------------------------------------------------------- toast --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translate(-50%, 12px);
  z-index: 300;
  max-width: 88%;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
