:root {
  --bg: #f5f2ec;
  --card: #ffffff;
  --ink: #1b1a17;
  --muted: #7b746a;
  --line: #e6e0d6;
  --accent: #8f6f43;
  --accent-soft: #f1e8da;
  --ok: #2f7a52;
  --ok-soft: #e3f1e8;
  --warn: #b5701f;
  --warn-soft: #fbeedd;
  --bad: #b3443a;
  --bad-soft: #f8e4e1;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--sans); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }

/* ---------- Layout ---------- */
.topbar { position: sticky; top: 0; z-index: 5; background: rgba(245, 242, 236, 0.92); backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 10px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { font-family: var(--serif); font-size: 1.05rem; }
.brand small { display: block; font-family: var(--sans); font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
main { max-width: 680px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-bottom)); }
.section { margin: 22px 0 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.section h2 { font-size: 1.05rem; }
.section .count { color: var(--muted); font-size: .85rem; }

nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr); padding-bottom: var(--safe-bottom); }
nav.tabs a { text-decoration: none; color: var(--muted); font-size: .72rem; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 0 10px; }
nav.tabs a svg { width: 23px; height: 23px; }
nav.tabs a.active { color: var(--ink); }
nav.tabs a.new svg { background: var(--ink); color: #fff; border-radius: 50%; padding: 4px; width: 30px; height: 30px; margin-top: -4px; }

/* ---------- Cards & lists ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.card.tap { display: block; text-decoration: none; color: inherit; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack > * + * { margin-top: 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.strong { font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; border: 1px dashed var(--line); border-radius: var(--radius); font-size: .92rem; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: .94rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.chip { display: inline-block; font-size: .72rem; padding: 3px 9px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.grey { background: #eeebe5; color: var(--muted); }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font-family: var(--serif); font-size: 1.45rem; }
.stat span { font-size: .74rem; color: var(--muted); }

/* ---------- Buttons & forms ---------- */
.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: 600 .9rem var(--sans);
  padding: 10px 14px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.wa { background: #1f8f4e; border-color: #1f8f4e; color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 6px 10px; font-size: .8rem; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }

form .field { margin-bottom: 12px; }
label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea { width: 100%; font: 16px var(--sans); color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; }
textarea { min-height: 90px; resize: vertical; }
textarea.tall { min-height: 360px; font-size: 14px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; font-size: .95rem; color: var(--ink); font-weight: 500; margin: 0; }
.check input { width: 22px; height: 22px; accent-color: var(--ok); flex: none; }
.search { position: sticky; top: 64px; z-index: 4; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg label { margin: 0; color: var(--ink); font-weight: 600; font-size: .92rem; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: block; text-align: center; padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--card); cursor: pointer; }
.seg input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

/* ---------- Reminders ---------- */
.rem { display: flex; gap: 12px; align-items: flex-start; }
.rem .when { flex: none; width: 62px; text-align: center; border-radius: 10px; padding: 6px 0; background: var(--accent-soft); color: var(--accent); font-size: .72rem; font-weight: 700; line-height: 1.2; }
.rem .when.over { background: var(--bad-soft); color: var(--bad); }
.rem .when.today { background: var(--ok-soft); color: var(--ok); }
.rem .body { flex: 1; min-width: 0; }
.rem .msg { font-size: .85rem; color: var(--muted); margin-top: 4px; white-space: pre-wrap; }
.rem.done { opacity: .5; }
.rem.done .title { text-decoration: line-through; }

/* ---------- Pipeline ---------- */
.pipeline { list-style: none; padding: 0; margin: 4px 0 12px; }
.pipeline li { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: .92rem; color: var(--muted); }
.pipeline li::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.pipeline li.done { color: var(--ink); }
.pipeline li.done::before { background: var(--ok); border-color: var(--ok); }
.pipeline li.current { color: var(--ink); font-weight: 700; }
.pipeline li.current::before { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Contract ---------- */
.contract { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 20px; font-size: .95rem; line-height: 1.6; }
.contract h2 { font-size: 1.45rem; margin-bottom: 10px; }
.contract h3 { margin: 20px 0 6px; font-size: 1.02rem; }
.contract p { margin: 8px 0; }
.contract ul { margin: 6px 0; padding-left: 20px; }
.sigbox { border: 1.5px dashed var(--muted); border-radius: 12px; background: #fff; position: relative; }
.sigbox canvas { display: block; width: 100%; height: 180px; touch-action: none; border-radius: 12px; }
.sigbox .hint { position: absolute; left: 14px; bottom: 10px; color: var(--muted); font-size: .8rem; pointer-events: none; }
.sigimg { max-width: 280px; width: 100%; border-bottom: 1px solid var(--ink); display: block; }

.share { background: var(--accent-soft); border-radius: 12px; padding: 12px; margin-top: 10px; }
.share code { display: block; font-size: .75rem; word-break: break-all; margin: 6px 0 10px; color: var(--ink); }

/* ---------- Misc ---------- */
.toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 99px; font-size: .88rem; z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.login { max-width: 380px; margin: 12vh auto 0; padding: 0 20px; }
.login h1 { margin-bottom: 4px; }
.err { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 10px; font-size: .9rem; margin: 10px 0; }
.hide { display: none !important; }

@media print {
  .topbar, nav.tabs, .no-print, .btn { display: none !important; }
  body, html { background: #fff; }
  main { padding: 0; max-width: none; }
  .contract { border: 0; padding: 0; }
}
