:root {
  --bg: #F2F5F8; --surface: #FFFFFF; --surface2: #E8EEF3; --line: rgba(18,40,66,0.10); --line2: rgba(18,40,66,0.18);
  --text: #0B1E33; --muted: #556579; --faint: #99A6B4;
  --primary: #0C3B66; --on-primary: #FFFFFF; --accent: #B84A2A; --warn: #B98400; --ok: #2E6B58; --info: #2F6FA3;
  --radius: 14px; --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0B1622; --surface: #13212F; --surface2: #1B2C3D; --line: rgba(255,255,255,0.08); --line2: rgba(255,255,255,0.16);
          --text: #E6EDF3; --muted: #93A4B5; --faint: #5F7082;
          --primary: #6FA8DC; --on-primary: #0B1622; --accent: #E07A5F; --warn: #E0B04A; --ok: #6FBF9F; --info: #7FB2E0; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif; overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
[hidden] { display: none !important; }

/* ---- top bar */
#bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
       padding: calc(10px + var(--safe-top)) 12px 10px; background: var(--surface); border-bottom: 1px solid var(--line); }
#title { flex: 1; font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { background: none; border: 0; width: 40px; height: 40px; border-radius: 10px; font-size: 18px; color: var(--primary); cursor: pointer; }
.pill { border: 1px solid var(--line2); background: var(--surface2); border-radius: 999px; padding: 6px 10px; font-size: 13px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.pill i { font-size: 8px; vertical-align: 2px; }
.pill.ok i { color: var(--ok); } .pill.wait i { color: var(--warn); } .pill.off i { color: var(--faint); } .pill.err i { color: var(--accent); }

main { max-width: 720px; margin: 0 auto; padding: 12px 12px calc(96px + var(--safe-bottom)); }

/* ---- blocks */
.hello { font-size: 22px; font-weight: 700; margin: 6px 2px 2px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 2px 12px; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; text-align: left; cursor: pointer; }
.tile b { display: block; font-size: 24px; }
.tile span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tile.alert b { color: var(--accent); }
.tile.on { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.seg { display: flex; background: var(--surface2); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 6px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line2); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.search { width: 100%; padding: 10px 12px; border: 1px solid var(--line2); border-radius: 12px; background: var(--surface); margin-bottom: 10px; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 2px 8px; }

/* ---- task cards, with swipe */
.card-wrap { position: relative; margin-bottom: 8px; border-radius: var(--radius); overflow: hidden; }
.card-actions { position: absolute; inset: 0; display: flex; justify-content: flex-end; }
.card-actions button { border: 0; width: 84px; color: #fff; font-weight: 600; font-size: 13px; }
.card-actions .prog { background: var(--info); } .card-actions .done { background: var(--ok); }
.card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; cursor: pointer;
        transition: transform .2s; touch-action: pan-y; }
.card .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.card .txt { margin: 4px 0 6px; font-weight: 500; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.card.done .txt { color: var(--muted); text-decoration: line-through; }
.badge { border-radius: 6px; padding: 2px 7px; background: var(--surface2); color: var(--muted); font-weight: 600; }
.badge.late { background: rgba(184,74,42,.14); color: var(--accent); }
.badge.p1 { background: rgba(184,74,42,.14); color: var(--accent); }
.badge.s2 { background: rgba(47,111,163,.14); color: var(--info); } .badge.s3 { background: rgba(185,132,0,.16); color: var(--warn); }
.badge.s4, .badge.s5 { background: rgba(46,107,88,.15); color: var(--ok); }
.badge.wait { background: rgba(185,132,0,.16); color: var(--warn); }

.villa-row { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.villa-row img, .villa-row .ph { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--surface2); flex: none; }
.villa-row .name { flex: 1; font-weight: 600; }
.villa-row .count { color: var(--muted); font-size: 13px; text-align: right; }
.villa-row .count b { color: var(--accent); }

/* ---- detail */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.field { width: 100%; padding: 10px 12px; border: 1px solid var(--line2); border-radius: 10px; background: var(--surface); }
textarea.field { min-height: 90px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
label.l { display: block; font-size: 12px; color: var(--muted); margin: 0 2px 4px; text-transform: uppercase; letter-spacing: .04em; }
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; }
.status-grid button { border: 1px solid var(--line2); background: var(--surface); border-radius: 10px; padding: 10px 4px; font-size: 13px; font-weight: 600; cursor: pointer; }
.status-grid button.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.photo-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photo-btns label { display: block; text-align: center; border: 1px dashed var(--line2); border-radius: 10px; padding: 10px 4px; font-size: 13px; cursor: pointer; }
.photo-btns input { display: none; }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.gallery figure { margin: 0; position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface2); }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery figcaption { position: absolute; left: 4px; bottom: 4px; font-size: 11px; background: rgba(0,0,0,.55); color: #fff; padding: 1px 6px; border-radius: 6px; }
.gallery .del { position: absolute; right: 4px; top: 4px; border: 0; background: rgba(0,0,0,.55); color: #fff; width: 28px; height: 28px; border-radius: 8px; }
.gallery .wait { position: absolute; right: 4px; bottom: 4px; color: #fff; text-shadow: 0 0 4px #000; }
.ba { position: relative; aspect-ratio: 4/3; border-radius: 12px; overflow: hidden; margin-top: 8px; background: var(--surface2); }
.ba img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ba .after { clip-path: inset(0 0 0 50%); }
.ba input { position: absolute; inset: auto 0 8px; width: 90%; margin: 0 5%; }
.comment { border-top: 1px solid var(--line); padding: 8px 0; font-size: 14px; }
.comment .who { color: var(--muted); font-size: 12px; }
.send { display: flex; gap: 6px; margin-top: 8px; }
.send input { flex: 1; }
.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; padding: 10px 12px calc(10px + var(--safe-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.bottom .in { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; }
.btn { border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 700; cursor: pointer; background: var(--surface2); color: var(--text); width: 100%; }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.danger { background: none; color: var(--accent); border: 1px solid var(--accent); }
.btn:disabled { opacity: .5; }
.fab { position: fixed; right: 16px; bottom: calc(18px + var(--safe-bottom)); z-index: 8; width: 58px; height: 58px; border-radius: 18px; border: 0;
       background: var(--primary); color: var(--on-primary); font-size: 22px; box-shadow: 0 6px 18px rgba(12,59,102,.35); cursor: pointer; }
.fab.second { right: 84px; background: var(--ok); color: #fff; box-shadow: 0 6px 18px rgba(46,107,88,.35); }

/* ---- info */
.info-line { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.info-line:first-child { border-top: 0; }
.info-line i { width: 18px; color: var(--muted); padding-top: 3px; text-align: center; }
.info-line .k { color: var(--muted); font-size: 12px; }
.pre { white-space: pre-wrap; }
.copy { border: 1px solid var(--line2); background: var(--surface2); border-radius: 8px; padding: 2px 8px; font-size: 12px; margin-left: 6px; }
details.instr { border-top: 1px solid var(--line); padding: 8px 0; }
details.instr summary { font-weight: 600; cursor: pointer; }
details.instr img { max-width: 100%; border-radius: 10px; margin-top: 6px; }

/* ---- sheet, toast, lightbox */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; }
.sheet-body { width: 100%; max-height: 88vh; overflow: auto; background: var(--bg); border-radius: 18px 18px 0 0; padding: 16px 14px calc(16px + var(--safe-bottom)); }
.sheet-body h2 { margin: 0 0 12px; font-size: 18px; }
.sheet-body .field { margin-bottom: 10px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-bottom)); z-index: 30; background: var(--text); color: var(--bg);
         padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; pointer-events: none; }
.lightbox { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100%; max-height: 100%; }
.missing { border-color: var(--accent) !important; box-shadow: 0 0 0 1px var(--accent); }
.login { max-width: 360px; margin: 10vh auto 0; }
.login img { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 16px; }
.err-box { background: rgba(184,74,42,.12); color: var(--accent); border-radius: 10px; padding: 10px 12px; margin: 8px 0; font-size: 14px; }
