:root {
  color-scheme: dark; /* native checkboxes and the date picker follow the dark theme */
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #21252e;
  --border: #2c313c;
  --text: #e8eaed;
  --muted: #9aa2b1;
  --accent: #34d399;
  --accent-ink: #05291d;
  --danger: #f87171;
  --radius: 14px;
  --tap: 44px;
}

* { box-sizing: border-box; }

/* The root paints the canvas, so overscroll past the app shell stays --bg
 * instead of flashing white behind the translucent status bar. */
html { -webkit-text-size-adjust: 100%; background: var(--bg); }

body {
  margin: 0;
  /* First declaration is the fallback for engines without env()/dvh; the
   * second wins where they are supported. Insets keep the shell clear of the
   * status bar, the home indicator and the landscape notch. */
  padding: 16px 16px 32px;
  padding:
    calc(16px + env(safe-area-inset-top, 0px))
    calc(16px + env(safe-area-inset-right, 0px))
    calc(32px + env(safe-area-inset-bottom, 0px))
    calc(16px + env(safe-area-inset-left, 0px));
  max-width: 640px;
  margin-inline: auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}

[hidden] { display: none !important; }

.muted { color: var(--muted); font-weight: 400; }

/* ---------- Buttons & inputs ---------- */

.btn {
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { color: var(--danger); }
.btn-ghost { background: none; border-color: transparent; min-width: var(--tap); padding: 0 10px; }
.btn-block { width: 100%; }
/* Visually lighter only — height stays at .btn's 44px touch target. */
.btn-sm { padding: 0 12px; font-size: 15px; }

input, 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);
  font: inherit;
}
textarea { min-height: 64px; resize: vertical; }
input:focus, textarea:focus, .btn:focus-visible, .total-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field { display: block; margin-bottom: 14px; }
.label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }

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

.form-error { margin: 0 0 12px; color: var(--danger); font-size: 14px; }

/* ---------- Segmented toggles ---------- */

.segmented { display: flex; gap: 8px; }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-weight: 600;
  cursor: pointer;
}
.segmented input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ---------- Login ---------- */

.login-view { display: flex; align-items: center; min-height: 80vh; }
.login-card { width: 100%; }
.login-title { margin: 0 0 20px; font-size: 22px; text-align: center; }

/* ---------- Totals ---------- */

.totals { display: flex; gap: 12px; margin-bottom: 16px; }
.total-card {
  flex: 1;
  min-height: 92px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.total-card.active { border-color: var(--accent); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--accent); }
.total-label { font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.total-card.active .total-label { color: var(--accent); }
.total-value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; }

/* ---------- Controls ---------- */

.controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.switch { display: flex; align-items: center; gap: 8px; min-height: var(--tap); font-size: 15px; cursor: pointer; }
.switch input { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--accent); }

.filter-note { margin: 0 0 12px; font-size: 14px; color: var(--accent); }
.offline-note {
  margin: 0 0 12px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 14px;
}
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

/* ---------- Entry list ---------- */

.entry-list { display: flex; flex-direction: column; gap: 12px; }

.entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.entry.completed { opacity: .5; }

.entry-main { cursor: pointer; }
.entry-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.entry-date { font-size: 14px; color: var(--muted); }
.entry-amount { font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
.entry-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}
.badge.investment { color: var(--accent); border-color: var(--accent); }
.entry-payment { font-size: 14px; color: var(--muted); }

.entry-flags { display: flex; gap: 18px; margin-top: 12px; }

.entry-details { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.detail-row { display: flex; gap: 8px; font-size: 15px; margin-bottom: 6px; }
.detail-row .label { margin: 0; min-width: 92px; }
.detail-row a { color: var(--accent); }

.remarks { margin: 14px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.remark { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 15px; }
.remark time { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }

.remark-add { display: flex; gap: 8px; margin-top: 12px; }
.remark-add input { flex: 1; }

.entry-actions { display: flex; gap: 8px; margin-top: 14px; }

/* ---------- Form overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, .6);
  overflow-y: auto;
  /* Fixed to the viewport, so it needs its own insets — the body's do not
   * apply. Keeps the close button and Save clear of the status bar and the
   * home indicator. */
  padding: 16px;
  padding:
    calc(16px + env(safe-area-inset-top, 0px))
    calc(16px + env(safe-area-inset-right, 0px))
    calc(16px + env(safe-area-inset-bottom, 0px))
    calc(16px + env(safe-area-inset-left, 0px));
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.form-card { width: 100%; max-width: 608px; margin: auto; }
.form-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.form-head h2 { margin: 0; font-size: 19px; }
