/* ============================================================
   Rental Manager — Design System
   Handcrafted, prebuilt CSS. No build step, no CDN.
   Direction: a warm "paper ledger" with deep ink accents.
   Mobile-first; large tap targets; one-handed friendly.
   ============================================================ */

/* ---------- Design tokens ---------------------------------- */
:root {
  /* Palette — warm paper + ink + a single trustworthy green */
  --paper:        #F7F4EE;   /* app background */
  --card:         #FFFFFF;   /* surfaces */
  --ink:          #1E1B16;   /* primary text */
  --ink-soft:     #6B6459;   /* secondary text */
  --ink-faint:    #A79F92;   /* tertiary / captions */
  --line:         #E7E1D6;   /* hairlines, borders */
  --line-strong:  #D8D0C2;

  --brand:        #1F6F54;   /* deep ledger green (primary action) */
  --brand-ink:    #16523E;   /* pressed / hover */
  --brand-tint:   #E4EFEA;   /* soft green fill */

  --amber:        #B5760E;   /* rent due / warning */
  --amber-tint:   #FBEFD8;
  --red:          #B23B3B;   /* outstanding / destructive */
  --red-tint:     #F7E2E1;
  --blue:         #2A5DA8;   /* info / deposit */
  --blue-tint:    #E3ECF7;

  /* Radii, shadows, spacing */
  --r-sm: 10px;
  --r:    16px;
  --r-lg: 22px;
  --r-pill: 999px;

  --sh-1: 0 1px 2px rgba(30,27,22,.05), 0 1px 3px rgba(30,27,22,.04);
  --sh-2: 0 4px 14px rgba(30,27,22,.08);
  --sh-fab: 0 8px 24px rgba(31,111,84,.34);

  --nav-h: 64px;
  --space: 16px;

  --safe-b: env(safe-area-inset-bottom, 0px);

  /* Type */
  --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  --font-num: "SF Mono", ui-monospace, "Roboto Mono", Menlo, Consolas, monospace;
}

/* Dark mode via [data-theme="dark"] on <html> */
[data-theme="dark"] {
  --paper:        #17150F;
  --card:         #201D16;
  --ink:          #F1ECE1;
  --ink-soft:     #B4AC9C;
  --ink-faint:    #7C7566;
  --line:         #322D23;
  --line-strong:  #423B2E;

  --brand:        #4FB08C;
  --brand-ink:    #6BC3A2;
  --brand-tint:   #1C3A30;

  --amber:        #E0A64A;
  --amber-tint:   #3A2E17;
  --red:          #E07A7A;
  --red-tint:     #3A1F1F;
  --blue:         #7DA6E0;
  --blue-tint:    #1E2A3E;

  --sh-1: 0 1px 2px rgba(0,0,0,.3);
  --sh-2: 0 4px 16px rgba(0,0,0,.4);
}

/* ---------- Reset ------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1,h2,h3,h4,p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
img, svg { display: block; max-width: 100%; }
input, select, textarea { font-family: inherit; }

/* ---------- Layout scaffold -------------------------------- */
.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}
.page,
.wrap {
  padding: var(--space);
  /* room for fixed bottom nav + FAB + iOS home indicator */
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 88px);
}

/* App top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  padding: 14px var(--space) 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.topbar .sub { color: var(--ink-soft); font-size: 13px; font-weight: 500; }
.topbar .spacer { flex: 1; }
.topbar-back {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
}

/* ---------- Cards ------------------------------------------ */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--sh-1);
}
.card-pad { padding: 16px; }
.stack > * + * { margin-top: 12px; }
.stack-sm > * + * { margin-top: 8px; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-faint);
  margin: 22px 4px 10px;
}

/* Stat tiles (dashboard) */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 14px 16px;
  box-shadow: var(--sh-1);
}
.stat .label { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; }
.stat .value {
  font-size: 26px; font-weight: 750; letter-spacing: -0.02em;
  margin-top: 6px; font-variant-numeric: tabular-nums;
}
.stat .value.money { font-size: 22px; }
.stat.accent { background: var(--brand-tint); border-color: transparent; }
.stat.warn   { background: var(--amber-tint); border-color: transparent; }
.stat.bad    { background: var(--red-tint); border-color: transparent; }

/* ---------- List rows -------------------------------------- */
.list { display: flex; flex-direction: column; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--sh-1);
  min-height: 62px;
}
.row + .row { margin-top: 10px; }
.row .avatar {
  width: 44px; height: 44px; flex: none;
  border-radius: 14px;
  display: grid; place-items: center;
  background: var(--brand-tint); color: var(--brand-ink);
  font-weight: 700; font-size: 16px;
}
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 650; font-size: 15.5px; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { color: var(--ink-soft); font-size: 13px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { text-align: right; flex: none; }
.row .amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.row .chev { color: var(--ink-faint); flex: none; }

/* ---------- Badges / pills --------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 650;
  padding: 3px 9px; border-radius: var(--r-pill);
  line-height: 1.6;
}
.badge.ok    { background: var(--brand-tint); color: var(--brand-ink); }
.badge.due   { background: var(--amber-tint); color: var(--amber); }
.badge.bad   { background: var(--red-tint);   color: var(--red); }
.badge.info  { background: var(--blue-tint);  color: var(--blue); }
.badge.mute  { background: var(--line);       color: var(--ink-soft); }
.badge .dot  { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Buttons ---------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 20px;
  border-radius: var(--r);
  border: 1px solid transparent;
  font-size: 16px; font-weight: 650;
  background: var(--card); color: var(--ink);
  border-color: var(--line-strong);
  transition: transform .05s ease, background .15s ease;
  width: 100%;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--brand); color: #fff; border-color: transparent; }
.btn-primary:active { background: var(--brand-ink); }
.btn-danger  { background: var(--red); color: #fff; border-color: transparent; }
.btn-ghost   { background: transparent; border-color: var(--line-strong); }
.btn-sm { min-height: 42px; font-size: 14.5px; padding: 0 14px; width: auto; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 1; }

/* ---------- Forms ------------------------------------------ */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 13.5px; font-weight: 650;
  color: var(--ink-soft); margin-bottom: 7px;
}
.field .hint { font-size: 12.5px; color: var(--ink-faint); margin-top: 6px; }
.input, .select, .textarea {
  width: 100%;
  min-height: 52px;
  padding: 13px 15px;
  font-size: 16px;                     /* >=16px prevents iOS/Android zoom */
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236B6459' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 42px;
}
.field.invalid .input,
.field.invalid .select,
.field.invalid .textarea { border-color: var(--red); }
.field .error { color: var(--red); font-size: 12.5px; font-weight: 600; margin-top: 6px; }

.input-money { position: relative; }
.input-money .sym {
  position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
  color: var(--ink-soft); font-weight: 600; pointer-events: none;
}
.input-money .input { padding-left: 30px; }

/* Segmented control (e.g., payment method) */
.segment { display: flex; gap: 6px; background: var(--line); padding: 4px;
  border-radius: var(--r-sm); }
.segment label { flex: 1; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment span {
  display: block; text-align: center; padding: 10px 6px;
  border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--ink-soft);
}
.segment input:checked + span { background: var(--card); color: var(--ink);
  box-shadow: var(--sh-1); }

/* ---------- Bottom navigation ------------------------------ */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex;
}
.bottom-nav .inner {
  max-width: 520px; margin: 0 auto; width: 100%;
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--ink-faint); font-size: 10.5px; font-weight: 600;
  padding-top: 8px;
}
.nav-item svg { width: 23px; height: 23px; stroke-width: 2; }
.nav-item.active { color: var(--brand); }

/* ---------- Floating action button ------------------------- */
.fab {
  position: fixed; z-index: 45;
  right: max(18px, calc(50% - 260px + 18px));
  bottom: calc(var(--nav-h) + var(--safe-b) + 18px);
  width: 60px; height: 60px; border-radius: 20px;
  background: var(--brand); color: #fff; border: none;
  box-shadow: var(--sh-fab);
  display: grid; place-items: center;
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; transition: transform .2s; }
.fab.open svg { transform: rotate(45deg); }

/* ---------- Bottom sheet / action sheet -------------------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20,17,12,.42);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-width: 520px; margin: 0 auto;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 10px 16px calc(20px + var(--safe-b));
  transform: translateY(110%); transition: transform .26s cubic-bezier(.32,.72,0,1);
  box-shadow: 0 -8px 30px rgba(0,0,0,.18);
  /* never grow past the viewport — scroll inside instead */
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
/* grabber + title stay put while the form scrolls under them */
.sheet .grabber,
.sheet h3 { position: sticky; z-index: 1; background: var(--card); }
.sheet .grabber { top: 0; }
.sheet h3 { top: 10px; padding: 4px 0 8px; margin: 0 4px 8px; }
.sheet.show { transform: translateY(0); }
.sheet .grabber {
  width: 40px; height: 4px; border-radius: 999px; background: var(--line-strong);
  margin: 6px auto 14px;
  box-sizing: content-box; padding: 4px 0;
}
.sheet h3 { font-size: 16px; font-weight: 700; margin: 0 4px 12px; }
.sheet-action {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  padding: 15px 12px; border: none; background: transparent;
  border-radius: var(--r-sm); color: var(--ink); font-size: 16px; font-weight: 600;
}
.sheet-action:active { background: var(--paper); }
.sheet-action .ic {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center; background: var(--brand-tint); color: var(--brand-ink);
}
.sheet-action .ic svg { width: 21px; height: 21px; }

/* ---------- Ledger ----------------------------------------- */
.ledger-item {
  display: flex; gap: 12px; padding: 13px 4px;
  border-bottom: 1px solid var(--line);
}
.ledger-item:last-child { border-bottom: none; }
.ledger-item .lmark {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  display: grid; place-items: center;
}
.ledger-item .lmark.in  { background: var(--brand-tint); color: var(--brand-ink); }
.ledger-item .lmark.out { background: var(--red-tint); color: var(--red); }
.ledger-item .lmain { flex: 1; min-width: 0; }
.ledger-item .ltitle { font-weight: 600; font-size: 14.5px; }
.ledger-item .ldesc { color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }
.ledger-item .lright { text-align: right; flex: none; }
.ledger-item .lamt { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14.5px; }
.ledger-item .lamt.pos { color: var(--brand-ink); }
.ledger-item .lamt.neg { color: var(--red); }
.ledger-item .lbal { font-size: 11.5px; color: var(--ink-faint); margin-top: 2px;
  font-variant-numeric: tabular-nums; }

/* ---------- Flash / toast ---------------------------------- */
.flash-wrap {
  position: fixed; top: 12px; left: 0; right: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 0 16px; pointer-events: none;
}
.flash {
  max-width: 480px; width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-radius: var(--r);
  background: var(--ink); color: var(--paper);
  box-shadow: var(--sh-2); font-size: 14.5px; font-weight: 600;
  animation: flashIn .25s ease, flashOut .3s ease 3.4s forwards;
}
.flash.success { background: var(--brand-ink); color: #fff; }
.flash.error   { background: var(--red); color: #fff; }
.flash svg { width: 20px; height: 20px; flex: none; }
@keyframes flashIn  { from { transform: translateY(-14px); opacity: 0; } }
@keyframes flashOut { to   { transform: translateY(-14px); opacity: 0; } }

/* ---------- Empty state ------------------------------------ */
.empty {
  text-align: center; padding: 48px 24px; color: var(--ink-soft);
}
.empty .ic {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 20px;
  display: grid; place-items: center; background: var(--card);
  border: 1px solid var(--line); color: var(--ink-faint);
}
.empty h3 { font-size: 17px; color: var(--ink); margin-bottom: 6px; }
.empty p { font-size: 14px; }

/* ---------- Search ----------------------------------------- */
.searchbar { position: relative; margin-bottom: 4px; }
.searchbar svg {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; color: var(--ink-faint);
}
.searchbar .input { padding-left: 42px; }

/* ---------- Misc ------------------------------------------- */
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.num   { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.hidden { display: none !important; }

/* Login screen */
.login-wrap {
  min-height: 100dvh; display: flex; flex-direction: column;
  justify-content: center; padding: 32px 24px calc(40px + var(--safe-b));
  max-width: 420px; margin: 0 auto;
}
.brand-mark {
  width: 60px; height: 60px; border-radius: 18px; margin: 0 auto 18px;
  background: var(--brand); color: #fff; display: grid; place-items: center;
  box-shadow: var(--sh-fab);
}
.brand-mark svg { width: 30px; height: 30px; }
.login-wrap h1 { text-align: center; font-size: 24px; font-weight: 750;
  letter-spacing: -0.02em; }
.login-wrap .tag { text-align: center; color: var(--ink-soft); margin: 6px 0 28px;
  font-size: 14.5px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important;
    transition-duration: .001ms !important; }
}
