/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg:          #f5f1eb;
  --surface:     #ffffff;
  --surface2:    #ede8e0;
  --border:      #ddd8cf;
  --text:        #1a1814;
  --muted:       #857870;
  --green:       #2e7a52;
  --green-dk:    #245f40;
  --green-bg:    rgba(46,122,82,.10);
  --amber:       #b8762a;
  --amber-bg:    rgba(184,118,42,.12);
  --red:         #b04040;
  --red-bg:      rgba(176,64,64,.10);
  --blue:        #4a7fc1;
  --radius:      12px;
  --radius-sm:   8px;
  --header-h:    52px;
  --nav-h:       60px;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  min-height: 100dvh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
  border: none;
  outline: none;
  background: none;
}
button { cursor: pointer; }

/* ── Layout ────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Header */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  padding: 0 1rem;
  padding-top: env(safe-area-inset-top);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
}
.app-name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--green);
}
.logout-btn {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: color .15s;
}
.logout-btn:hover { color: var(--text); }

/* Main content */
.app-main {
  flex: 1;
  margin-top: calc(var(--header-h) + env(safe-area-inset-top));
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 1.5rem);
  padding-top: 1.5rem;
  padding-left: 1rem;
  padding-right: 1rem;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 500;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--green); }
.nav-item:hover { color: var(--text); }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  border: 1px solid var(--border);
}
.card + .card { margin-top: 0.75rem; }
.card-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.card-value {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.card-value.green  { color: var(--green); }
.card-value.red    { color: var(--red); }
.card-value.amber  { color: var(--amber); }

.card-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  border: 1px solid var(--border);
}
.stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.stat-value.green { color: var(--green); }
.stat-value.red   { color: var(--red); }
.stat-value.amber { color: var(--amber); }

/* ── Progress bar ──────────────────────────────────────── */
.progress-track {
  height: 8px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.6rem 0;
}
.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width .4s ease;
}
.progress-fill.warn { background: var(--amber); }
.progress-fill.low  { background: var(--red); }

.progress-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Deadline pill ─────────────────────────────────────── */
.deadline-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--amber-bg);
  color: var(--amber);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
}
.deadline-badge.urgent { background: var(--red-bg); color: var(--red); }
.deadline-badge.ok     { background: var(--green-bg); color: var(--green); }

/* ── Forms ─────────────────────────────────────────────── */
.field {
  margin-bottom: 1rem;
}
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  color: var(--text);
  transition: border-color .15s;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--green);
}
.field textarea {
  resize: vertical;
  min-height: 70px;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--green);
  color: #fff;
  width: 100%;
}
.btn-primary:hover { opacity: 0.9; }
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { opacity: 0.85; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
}
.btn-ghost:hover { color: var(--text); }
.btn-danger-ghost {
  background: transparent;
  color: var(--red);
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
}
.btn-danger-ghost:hover { opacity: 0.8; }
.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.45; pointer-events: none; }

/* ── Calculator output ─────────────────────────────────── */
.calc-output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 1rem;
}
.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}
.calc-row:last-child { border-bottom: none; }
.calc-row-label { font-size: 0.9rem; color: var(--muted); }
.calc-row-value { font-size: 1.2rem; font-weight: 700; }
.calc-row-value.green { color: var(--green); }
.calc-row-value.red   { color: var(--red); }

/* Rate adjuster */
.rate-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
}
.rate-row input[type="number"] {
  width: 5rem;
  background: none;
  border: none;
  text-align: right;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  padding: 0;
}
.rate-row span { color: var(--muted); }

/* ── Payment log ───────────────────────────────────────── */
.payment-entry {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 0.9rem 1rem;
  margin-bottom: 0.6rem;
  position: relative;
}
.payment-entry.editing { border-color: var(--green); }
.entry-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.4rem;
}
.entry-date {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}
.entry-gross {
  font-size: 1.1rem;
  font-weight: 700;
}
.entry-aside {
  font-size: 0.85rem;
  color: var(--green);
  font-weight: 600;
}
.entry-notes {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.2rem;
  font-style: italic;
}
.entry-actions {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.5rem;
  justify-content: flex-end;
}
.entry-edit-form {
  display: none;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.entry-edit-form.open { display: block; }

/* ── Quarterly ─────────────────────────────────────────── */
.deadline-group {
  margin-bottom: 1.25rem;
}
.deadline-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.deadline-date {
  font-size: 0.95rem;
  font-weight: 700;
}
.q-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.q-item.paid {
  opacity: 0.65;
  border-color: var(--green-dk);
}
.q-jurisdiction {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface2);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  color: var(--muted);
  min-width: 54px;
  text-align: center;
}
.q-amount {
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1;
}
.q-paid-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--green);
  background: var(--green-bg);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.pay-form-inline {
  display: none;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.pay-form-inline.open { display: block; }

/* ── Settings ──────────────────────────────────────────── */
.settings-section {
  margin-bottom: 1.5rem;
}
.settings-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.75rem;
}
.q-edit-row {
  display: grid;
  grid-template-columns: auto 1fr 1fr auto;
  gap: 0.4rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.q-edit-row:last-child { border-bottom: none; }
.q-edit-row input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  color: var(--text);
}
.q-edit-row input:focus { border-color: var(--green); }
.q-edit-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
}

/* ── Login ─────────────────────────────────────────────── */
.login-wrap {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 60% 20%, rgba(46,122,82,.07) 0%, transparent 60%);
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 360px;
}
.login-logo {
  font-size: 2rem;
  font-weight: 800;
  color: var(--green);
  text-align: center;
  margin-bottom: 0.25rem;
  letter-spacing: -0.04em;
}
.login-tagline {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 1.75rem;
}
.error-msg {
  background: var(--red-bg);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.success-msg {
  background: var(--green-bg);
  color: var(--green);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* ── Totals bar ────────────────────────────────────────── */
.totals-bar {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.totals-item { text-align: center; }
.totals-item .label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.totals-item .value {
  font-size: 1rem;
  font-weight: 700;
  margin-top: 0.1rem;
}
.totals-item .value.green { color: var(--green); }
.totals-divider {
  width: 1px;
  height: 2rem;
  background: var(--border);
}

/* ── FAB (floating add button) ─────────────────────────── */
.fab-container {
  margin-bottom: 1rem;
}

/* ── Bottom sheet overlay ──────────────────────────────── */
.sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 200;
}
.sheet-overlay.open { display: block; }
.sheet {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding: 1.25rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
  z-index: 201;
  max-width: 480px;
  margin: 0 auto;
  transform: translateY(100%);
  transition: transform .25s ease;
}
.sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--surface2);
  border-radius: 999px;
  margin: 0 auto 1.25rem;
}
.sheet-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

/* ── Misc ──────────────────────────────────────────────── */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1rem;
  font-size: 0.9rem;
}
.divider {
  height: 1px;
  background: var(--border);
  margin: 1rem 0;
}
.text-muted { color: var(--muted); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-amber  { color: var(--amber); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }

/* ── Tablet+ ───────────────────────────────────────────── */
@media (min-width: 600px) {
  .app-main {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}
