:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #f8f6f2;
  --text: #1f1b16;
  --muted: #6b6258;
  --border: #e2dbd1;
  --accent: #8a3b12;
  --accent-ink: #ffffff;
  --accent-soft: #f6e6dc;
  --ok: #1d7a46;
  --ok-soft: #dff2e6;
  --ko: #b42318;
  --ko-soft: #fde4e1;
  --nv: #57534e;
  --nv-soft: #ebe7e2;
  --warn: #9a6400;
  --warn-soft: #fbefd5;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 2px 8px rgb(0 0 0 / 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120f;
    --surface: #211d19;
    --surface-2: #2a2520;
    --text: #f3eee8;
    --muted: #a99f94;
    --border: #3a332c;
    --accent: #e3824d;
    --accent-ink: #1a0f08;
    --accent-soft: #3d2516;
    --ok: #4cc17f;
    --ok-soft: #173525;
    --ko: #ff7a6b;
    --ko-soft: #42201c;
    --nv: #c9c2b9;
    --nv-soft: #34302b;
    --warn: #f0b64a;
    --warn-soft: #3a2c10;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
[hidden] { display: none !important; }

/* ---- Layout ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title span { font-size: 0.8rem; color: var(--muted); }
.sync {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 0.85rem; cursor: pointer;
}
.sync::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.sync.pending::before { background: var(--warn); }
.sync.offline::before { background: var(--ko); }

main { max-width: 860px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 10px; text-decoration: none; color: var(--muted); font-size: 0.75rem;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a.active { color: var(--accent); font-weight: 600; }

.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card.tight { padding: 12px 14px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 22px 2px 10px; }
.section-title h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-weight: 600; text-decoration: none; color: var(--text);
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--ko); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.5; cursor: default; }

.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hero .btn { min-height: 96px; flex-direction: column; font-size: 1.1rem; border-radius: var(--radius); }
.hero .btn svg { width: 30px; height: 30px; }
@media (max-width: 420px) { .hero { grid-template-columns: 1fr; } .hero .btn { min-height: 72px; flex-direction: row; } }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; text-decoration: none; color: inherit; }
.kpi b { display: block; font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 0.82rem; color: var(--muted); }
.kpi.ko b { color: var(--ko); }
.kpi.warn b { color: var(--warn); }

/* ---- Forms ---- */
label.field { display: block; }
label.field > span { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=search], input[type=password], input[type=datetime-local], input[type=number], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
textarea { min-height: 110px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .seg button:focus-visible, .chip:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); font-weight: 500;
}
.chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.check { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.check input { width: 26px; height: 26px; accent-color: var(--accent); }

/* Segmented Si / No / n.v. */
.seg { display: inline-grid; grid-template-columns: repeat(3, minmax(64px, 1fr)); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; flex-shrink: 0; }
.seg button { min-height: 48px; border: 0; background: var(--surface); cursor: pointer; font-weight: 600; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed=true][data-v=si] { background: var(--ok); color: #fff; }
.seg button[aria-pressed=true][data-v=no] { background: var(--ko); color: #fff; }
.seg button[aria-pressed=true][data-v=nv] { background: var(--nv); color: var(--surface); }
.seg.two { grid-template-columns: repeat(2, minmax(72px, 1fr)); }

.area { padding: 0; overflow: hidden; }
.area-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.area-head h3 { flex: 1; }
.q { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.q:last-child { border-bottom: 0; }
.q .text { flex: 1; min-width: 0; }
.q .text small { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.q.is-no { background: var(--ko-soft); }
@media (max-width: 560px) { .q { flex-direction: column; align-items: stretch; } .seg { width: 100%; } }

.sticky-actions {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; gap: 10px; padding: 12px 0 4px;
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}
.sticky-actions .btn { flex: 1; }

/* ---- Lists ---- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: block; width: 100%; text-align: left; text-decoration: none; color: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
}
.item .top { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; }
.item .top b { min-width: 0; overflow-wrap: anywhere; }
.item .sub { color: var(--muted); font-size: 0.86rem; margin-top: 2px; overflow-wrap: anywhere; }
.item.selected { border-color: var(--accent); background: var(--accent-soft); }
.day { margin: 18px 2px 8px; font-weight: 700; color: var(--muted); font-size: 0.9rem; text-transform: capitalize; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--nv-soft); color: var(--nv); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.ko { background: var(--ko-soft); color: var(--ko); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.photos { display: flex; flex-wrap: wrap; gap: 8px; }
.photo { position: relative; width: 92px; height: 92px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo button { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgb(0 0 0 / 0.6); color: #fff; cursor: pointer; }
.photo-add { display: inline-flex; align-items: center; justify-content: center; flex-direction: column; gap: 4px; width: 92px; height: 92px; border: 2px dashed var(--border); border-radius: 10px; color: var(--muted); cursor: pointer; font-size: 0.8rem; }
.photo-add input { display: none; }

.bar { height: 10px; border-radius: 999px; background: var(--ko-soft); overflow: hidden; margin: 8px 0 4px; }
.bar > i { display: block; height: 100%; background: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 50; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 600; box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
}

.login { max-width: 380px; margin: 12vh auto 0; }
.login h1 { margin-bottom: 4px; }

.selected-stand { display: flex; gap: 12px; align-items: center; }
.selected-stand .grow b { display: block; }
.pos { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 44px; padding: 0 8px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex-shrink: 0; font-variant-numeric: tabular-nums; }

.lightbox { position: fixed; inset: 0; z-index: 60; background: rgb(0 0 0 / 0.88); display: flex; align-items: center; justify-content: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
