:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --text: #1c2430;
  --text-muted: #6b7280;
  --accent: #b8935f;
  --accent-soft: #f0e6d8;
  --border: #e8e3da;
  --danger: #c0503f;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* The HTML `hidden` attribute works by applying `display: none` from
   the browser's default stylesheet — which means ANY author CSS rule
   setting `display` on the same element silently overrides it. That
   caused a real bug: `.actions-row` and `.switcher` both set
   `display: flex`, so `hidden` was being ignored and the Add entry /
   Transfer buttons stayed visible to read-only users even though the
   JavaScript was correctly setting the attribute. This rule makes
   `hidden` authoritative everywhere, permanently. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  /* Keeps content clear of the notch/status bar and the home
     indicator when running full-screen from the Home Screen — without
     this, content renders underneath those areas and becomes both
     invisible and untappable. */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.screen {
  /* dvh (not vh) so this matches the *visible* viewport on mobile
     Safari — plain vh includes the area behind the browser's URL bar,
     which pushes content off-screen. The safe-area subtraction stops
     body's inset padding from adding extra scroll height on top. */
  min-height: 100vh;
  min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}

.card h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 4px;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 28px;
  font-size: 0.95rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 16px;
}

input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  width: 100%;
  padding: 13px;
  margin-top: 24px;
  border: none;
  border-radius: 10px;
  background: var(--text);
  color: var(--surface);
  font-size: 1rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}

button:active {
  opacity: 0.85;
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 12px;
  display: none;
}

.error.visible {
  display: block;
}

.lang-toggle {
  position: absolute;
  /* calc() keeps this clear of the notch/status bar when the login
     page is opened full-screen from the Home Screen. */
  top: calc(20px + env(safe-area-inset-top));
  right: calc(20px + env(safe-area-inset-right));
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px;
}

.lang-toggle button {
  width: auto;
  margin: 0;
  padding: 6px 14px;
  border-radius: 16px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.lang-toggle button.active {
  background: var(--accent-soft);
  color: var(--text);
}

.balance-figure {
  font-size: 2.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 4px 0 0;
}

.balance-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: none;
}

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

.dash-wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 20px 100px;
}

.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 10px;
  margin-bottom: 20px;
}

.dash-title {
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 0;
}

.dash-greeting {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.version-tag {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.6;
  margin-top: 24px;
  padding-bottom: 8px;
}

/* On the login page the card is vertically centred in a full-height
   container, so the version tag is pinned to the bottom instead of
   sitting below the fold and requiring a scroll to reach. */
.version-tag-fixed {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(8px + env(safe-area-inset-bottom));
  margin-top: 0;
}

.dash-header-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.icon-btn {
  width: auto;
  margin: 0;
  padding: 8px 14px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.switcher {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
}

.switcher button {
  flex: 1;
  width: auto;
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.switcher button.active {
  background: var(--accent-soft);
  color: var(--text);
}

.balance-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.actions-row {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.actions-row button {
  margin: 0;
  font-size: 0.9rem;
  padding: 12px;
}

.actions-row .secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.tx-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.tx-row:last-child {
  border-bottom: none;
}

.tx-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tx-category {
  font-size: 0.95rem;
  font-weight: 500;
}

.tx-note {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.tx-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.tx-edit-actions {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}

.tx-edit-btn {
  width: auto;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-decoration: underline;
}

.tx-edit-btn-danger {
  color: var(--danger);
}

.tx-amount {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
}

.tx-amount.positive {
  color: #3f7a4d;
}

.tx-amount.negative {
  color: var(--text);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-size: 0.9rem;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(28, 36, 48, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 28px 24px 32px;
  width: 100%;
  max-width: 420px;
  /* dvh so this measures the *visible* viewport — plain vh on mobile
     Safari includes the area behind the URL bar, which is what pushed
     the top of long modals (Settings especially) up out of view. The
     safe-area subtraction keeps it clear of the notch too. */
  max-height: 85vh;
  max-height: calc(88dvh - env(safe-area-inset-top));
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-close {
  /* Sticky + float keeps the × pinned to the top of the card even
     while a long modal scrolls, so there's always a visible way out. */
  position: sticky;
  top: 0;
  float: right;
  width: 32px;
  height: 32px;
  margin: -8px -4px 0 0;
  padding: 0;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.modal-card h2 {
  font-size: 1.15rem;
  margin: 0 0 20px;
}

.save-feedback {
  display: inline-block;
  margin-left: 10px;
  font-size: 0.85rem;
  color: #3f7a4d;
  opacity: 0;
  transition: opacity 0.2s;
}

.save-feedback.visible {
  opacity: 1;
}

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

.modal-actions button {
  margin: 0;
}

.modal-actions .secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}

.import-warning {
  background: #fbeee9;
  border: 1px solid #e8c4b8;
  color: var(--danger);
  font-size: 0.85rem;
  line-height: 1.4;
  padding: 10px 14px;
  border-radius: 10px;
  margin: 6px 0 14px;
}

/* Makes it explicit which account a screen is acting on, instead of
   silently inheriting whichever tab was selected on the dashboard. */
.scope-banner {
  background: var(--accent-soft);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: 10px;
  margin: 0 0 18px;
}

/* ---- Possible duplicate flagging (v2.7.0) ---- */
.dup-banner {
  background: #fdf3e1;
  border: 1px solid #ecd3a3;
  color: #8a5a12;
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.4;
  padding: 12px 14px;
  border-radius: 12px;
  margin: 0 0 16px;
}

.tx-row-flagged {
  background: #fdf8ee;
  border-left: 3px solid #d9a441;
  padding-left: 10px;
  margin-left: -13px;
}

.dup-badge {
  display: inline-block;
  align-self: flex-start;
  background: #f6e2b8;
  color: #8a5a12;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 4px;
}

/* Locked while a save is in progress */
button:disabled {
  opacity: 0.55;
  cursor: default;
}

/* Checkbox row (recurring rule "Amount varies each month") */
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 4px;
  color: var(--text);
  font-size: 0.92rem;
  cursor: pointer;
}
.check-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  flex: none;
}

/* Month shown on each recurring reminder card */
.reminder-month {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 2px;
}
.reminder-month.late {
  color: var(--danger);
}

/* Reminder count on account tabs */
.tab-badge {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  padding: 0 5px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  text-align: center;
  vertical-align: 1px;
}

/* Small technical code under an error, so a screenshot shows the cause */
.error-code {
  color: var(--text-muted);
  font-size: 0.72rem;
  margin-top: 6px;
  word-break: break-word;
}
.error-code:empty {
  display: none;
}
