/* Lånebok: calm, light, large touch targets (>= 44 px), follows the phone's light/dark mode. One accent colour (green);
   red/yellow are only status colours for frist. */
:root {
  --bg: #f7f6f2; --surface: #ffffff; --text: #1f2a28; --muted: #66726e; --border: #e3e1da;
  --accent: #2d6a5f; --accent-ink: #ffffff; --accent-soft: #e2efeb;
  --red: #a8231b; --red-bg: #fde7e4; --yellow: #755600; --yellow-bg: #fff1c2; --gray-bg: #eceae4;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --nav-h: 56px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615; --surface: #1c2220; --text: #e8ede9; --muted: #9aa5a0; --border: #2c3532;
    --accent: #6fc2af; --accent-ink: #0b1f1a; --accent-soft: #1f322d;
    --red: #ffb4a9; --red-bg: #4a1f1b; --yellow: #f5d57a; --yellow-bg: #463808; --gray-bg: #2a312f;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

#root { max-width: 640px; margin: 0 auto; min-height: 100vh; position: relative; }
.banner { background: var(--yellow-bg); color: var(--yellow); text-align: center; padding: 8px 12px; font-size: 14px; font-weight: 600; }

/* ---- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600; text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.big { min-height: 56px; font-size: 18px; width: 100%; }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.iconbtn { min-width: 44px; min-height: 44px; border: 0; background: transparent; border-radius: 12px; font-size: 22px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- home */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 14px 8px; border-bottom: 1px solid var(--border); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--gray-bg); padding: 4px; border-radius: 14px; }
.tabs button { min-height: 44px; border: 0; background: transparent; border-radius: 10px; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.search { width: 100%; min-height: 44px; margin-top: 8px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.personline { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 6px 6px 6px 12px; border-radius: 12px; background: var(--accent-soft); font-size: 14px; }
.personline span { flex: 1; }
.personline button { min-width: 44px; min-height: 44px; border: 0; background: transparent; font-size: 20px; }
.list { padding: 12px 14px calc(var(--nav-h) + 96px); display: grid; gap: 10px; }
.card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer; min-height: 64px; }
.card .what { font-size: 19px; font-weight: 700; word-break: break-word; padding-right: 36px; }
.card .meta { margin-top: 4px; color: var(--muted); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.who { border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 700; border-radius: 10px; padding: 0 10px; min-height: 36px; margin: -4px 0; }
.photoicon { position: absolute; top: 14px; right: 14px; font-size: 18px; opacity: .7; }
.amount { font-weight: 700; color: var(--text); }
.badge { display: inline-block; margin-top: 8px; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--gray-bg); color: var(--muted); }
.badge.over { background: var(--red-bg); color: var(--red); }
.badge.soon { background: var(--yellow-bg); color: var(--yellow); }
.empty { text-align: center; padding: 56px 24px; color: var(--muted); }
.empty .btn { margin-top: 18px; }
.fab { position: fixed; right: max(18px, calc(50% - 320px + 18px)); bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); width: 64px; height: 64px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 36px; line-height: 1; box-shadow: 0 4px 14px rgba(0,0,0,.28); z-index: 6; }
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; 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; justify-content: center; }
.bottomnav .in { width: 100%; max-width: 640px; display: grid; grid-template-columns: 1fr 1fr; }
.bottomnav button { border: 0; background: transparent; font-weight: 600; color: var(--muted); min-height: var(--nav-h); }

/* ---- sub screens */
.bar { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 6px; position: sticky; top: 0; background: var(--bg); z-index: 5; border-bottom: 1px solid var(--border); }
.bar h1 { font-size: 20px; flex: 1; }
.pad { padding: 14px 16px 40px; display: grid; gap: 14px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--gray-bg); padding: 4px; border-radius: 14px; }
.seg button { min-height: 48px; border: 0; background: transparent; border-radius: 10px; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
label.field { display: grid; gap: 6px; font-weight: 600; }
label.field small { font-weight: 400; color: var(--muted); }
input.in, textarea.in { width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-weight: 400; }
textarea.in { min-height: 96px; resize: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.sug { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
details.more { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); padding: 0 14px; }
details.more summary { min-height: 48px; display: flex; align-items: center; font-weight: 700; cursor: pointer; }
details.more[open] { padding-bottom: 14px; display: grid; gap: 14px; }
details.more[open] summary { margin-bottom: 0; }
.err { color: var(--red); background: var(--red-bg); border-radius: 12px; padding: 10px 14px; font-weight: 600; }
.thumb { max-width: 100%; max-height: 260px; border-radius: 12px; border: 1px solid var(--border); display: block; }
.actions { display: grid; gap: 10px; }
.actions.two { grid-template-columns: 1fr 1fr; }
dl.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 600; word-break: break-word; }
.photo-full { width: 100%; border-radius: 14px; border: 1px solid var(--border); display: block; }
.what-big { font-size: 26px; font-weight: 800; word-break: break-word; }
.section { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; display: grid; gap: 12px; }
.section h2 { font-size: 17px; }
.qr { background: #fff; padding: 12px; border-radius: 12px; justify-self: center; line-height: 0; }
.qr svg { width: 220px; height: 220px; display: block; }
.dev { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--border); }
.dev:first-of-type { border-top: 0; }
.dev .n { flex: 1; min-width: 0; }
.dev .n b { display: block; word-break: break-word; }
.linkbox { word-break: break-all; font-size: 13px; background: var(--gray-bg); border-radius: 10px; padding: 10px 12px; user-select: all; }

/* ---- private page */
.gate { padding: 72px 28px; text-align: center; display: grid; gap: 14px; justify-items: center; }
.gate h1 { font-size: 26px; }
.gate .logo { width: 72px; height: 72px; border-radius: 18px; }

/* ---- toast + dialog */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 100px + env(safe-area-inset-bottom)); z-index: 20; width: min(92vw, 460px);
  background: #26302d; color: #f2f5f3; border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.35); }
.toast span { flex: 1; }
.toast button { border: 0; background: transparent; color: #8fe0cc; font-weight: 800; min-height: 44px; padding: 0 10px; }
dialog { border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text); padding: 20px; width: min(92vw, 420px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { font-size: 19px; margin-bottom: 8px; }
dialog p { margin: 0 0 16px; color: var(--muted); }
dialog .actions { grid-template-columns: 1fr 1fr; }

@media (prefers-reduced-motion: no-preference) { .card, .btn, .chip { transition: transform .08s; } .card:active, .btn:active { transform: scale(.985); } }

.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); }
label.btn { position: relative; }
