:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f8f6f2;
  --text: #1d1b18;
  --muted: #6b665e;
  --line: #e3ded5;
  --brand: #1f2a24;
  --brand-text: #ffffff;
  --accent: #c8781e;
  --accent-soft: #fbefe0;
  --ok: #1f7a4d;
  --ok-soft: #e3f3ea;
  --warn: #a86200;
  --warn-soft: #fff1d6;
  --bad: #b3261e;
  --bad-soft: #fde7e4;
  --info: #2457a6;
  --info-soft: #e6eefb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 10px rgba(0,0,0,.05);
  --tap: 52px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121412; --surface: #1c1f1c; --surface-2: #232723; --text: #eceae6; --muted: #a29d94; --line: #333833;
    --brand: #0c0f0d; --accent: #e8953a; --accent-soft: #3a2a17; --ok: #4cc38a; --ok-soft: #173326; --warn: #f0a640;
    --warn-soft: #3a2c12; --bad: #ff7b72; --bad-soft: #3d1a18; --info: #79a8ff; --info-soft: #18263d;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121412; --surface: #1c1f1c; --surface-2: #232723; --text: #eceae6; --muted: #a29d94; --line: #333833;
  --brand: #0c0f0d; --accent: #e8953a; --accent-soft: #3a2a17; --ok: #4cc38a; --ok-soft: #173326; --warn: #f0a640;
  --warn-soft: #3a2c12; --bad: #ff7b72; --bad-soft: #3d1a18; --info: #79a8ff; --info-soft: #18263d;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--info); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: var(--brand-text);
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); display: flex; align-items: center; gap: 12px;
}
.topbar .title { font-weight: 700; letter-spacing: .02em; }
.topbar .sub { opacity: .75; font-size: .85rem; }
.topbar .title, .topbar .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar > .row { flex: none; gap: 6px; }
@media (max-width: 600px) {
  .topbar { padding-left: 12px; padding-right: 12px; gap: 8px; }
  .topbar .hide-sm { display: none; }
  .topbar .logo { width: 26px; height: 26px; }
  .topbar select { max-width: 120px; }
}
.topbar button.ghost { color: var(--brand-text); border-color: rgba(255,255,255,.25); }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; font-weight: 800; color: #1d1b18; flex: none; }

.page { max-width: 1100px; margin: 0 auto; padding: 16px; padding-bottom: 120px; }
.page.narrow { max-width: 760px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600;
  text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1d1b18; }
.btn.dark { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.btn.danger { color: var(--bad); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { min-height: 56px; font-size: 1.05rem; padding: 0 22px; }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: .9rem; border-radius: 10px; }
.btn[disabled] { opacity: .5; cursor: default; }
.iconbtn { width: 44px; height: 44px; padding: 0; border-radius: 12px; }

label.field { display: block; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.checkline { display: flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; }
.checkline input { width: 20px; height: 20px; accent-color: var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap; font-size: .92rem;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.daypick { display: flex; gap: 6px; flex-wrap: wrap; }
.daypick .chip { padding: 6px 10px; min-width: 44px; text-align: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* ---------- status pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.late { background: var(--warn-soft); color: var(--warn); }
.pill.missed, .pill.overdue_started, .pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.in_progress, .pill.info { background: var(--info-soft); color: var(--info); }
.pill.open { background: var(--accent-soft); color: var(--accent); }
.pill.upcoming, .pill.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.pill.signoff { background: var(--warn-soft); color: var(--warn); }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .2s; }
.progress.ok > i { background: var(--ok); }

/* ---------- lock screen ---------- */
.lock { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 420px) 1fr; }
.lock-left { background: var(--brand); color: var(--brand-text); padding: 24px 28px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; overflow: auto; }
@media (max-height: 760px) { .pinpad button { height: 56px; font-size: 1.5rem; } .lock-clock { font-size: 2.4rem; } }
.lock-clock { font-size: 3.2rem; font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: auto; }
.pinpad button {
  height: 74px; border-radius: 18px; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.06);
  color: var(--brand-text); font-size: 1.8rem; font-weight: 600; cursor: pointer;
}
.pinpad button:active { background: rgba(255,255,255,.18); }
.pindots { display: flex; gap: 14px; justify-content: center; min-height: 22px; }
.pindots i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,.6); }
.pindots i.on { background: var(--accent); border-color: var(--accent); }
.pinmsg { min-height: 24px; text-align: center; color: #ffb4a9; font-weight: 600; }
.lock-right { padding: 28px; overflow: auto; }
@media (max-width: 820px) {
  .lock { grid-template-columns: 1fr; }
  .lock-left { min-height: 100vh; }
  .pinpad button { height: 68px; }
}

/* ---------- today list ---------- */
.tasklist { display: grid; gap: 10px; }
.task {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; padding: 14px 16px; cursor: pointer;
  border-left: 5px solid var(--line);
}
.task.missed, .task.overdue_started { border-left-color: var(--bad); }
.task.open, .task.in_progress { border-left-color: var(--accent); }
.task.done { border-left-color: var(--ok); }
.task.late { border-left-color: var(--warn); }
.task .name { font-weight: 700; font-size: 1.05rem; }
.task .meta { grid-column: 1 / -1; display: flex; gap: 12px; align-items: center; }
.task .meta .progress { flex: 1; }
.dept-tag { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- run (checklist) ---------- */
.runhead { position: sticky; top: 52px; z-index: 15; background: var(--bg); padding: 12px 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.section-title { margin: 22px 0 8px; font-size: .82rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; justify-content: space-between; }
.items { display: grid; gap: 8px; }
.item { padding: 12px 14px; display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; align-items: start; scroll-margin-top: 170px; }
.item.attention { outline: 3px solid var(--bad); }
.item .txt { font-weight: 600; padding-top: 10px; overflow-wrap: anywhere; }
.item.is-done .txt { color: var(--muted); }
.item .body { grid-column: 2; min-width: 0; }
.item .more { width: 40px; height: 40px; margin: 2px -6px 0 0; font-size: 1.3rem; flex: none; border-color: transparent; }
.helpdot { margin-left: 8px; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: .8rem; cursor: pointer; vertical-align: 1px; }
.item .help { white-space: pre-wrap; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; margin-top: 6px; font-size: .9rem; }
.item .who { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.item .tools { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tick {
  width: var(--tap); height: var(--tap); border-radius: 14px; border: 2px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; font-size: 1.6rem; color: transparent; flex: none;
}
.tick.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.tick.na { background: var(--surface-2); color: var(--muted); font-size: .9rem; font-weight: 800; }
.tick.fail { background: var(--bad); border-color: var(--bad); color: #fff; }
.tick.blank { visibility: hidden; }
.pf { display: flex; gap: 8px; margin-top: 8px; }
.pf button { flex: 1; min-height: 48px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; }
.pf button.ok.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.pf button.fail.on { background: var(--bad); border-color: var(--bad); color: #fff; }
.numrow { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.numrow input { max-width: 160px; font-size: 1.2rem; font-weight: 700; }
.numrow input.out { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.tag { font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.tag.req { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thumb { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); cursor: zoom-in; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .x { position: absolute; top: 3px; right: 3px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.thumb.pending::after { content: "Uploading…"; position: absolute; inset: auto 0 0 0; font-size: .7rem; background: rgba(0,0,0,.6); color: #fff; text-align: center; padding: 2px; }
.note-box { margin-top: 8px; }
.issue-note { background: var(--bad-soft); color: var(--bad); padding: 6px 10px; border-radius: 8px; margin-top: 6px; font-size: .9rem; }

.footerbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--surface); border-top: 1px solid var(--line);
  padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); display: flex; gap: 12px; align-items: center; justify-content: center;
}
.footerbar .inner { max-width: 760px; width: 100%; display: flex; gap: 12px; align-items: center; }
.banner { border-radius: 12px; padding: 12px 14px; font-weight: 600; }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.info { background: var(--info-soft); color: var(--info); }

/* ---------- admin ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; background: var(--brand); padding: 0 12px; scrollbar-width: none; }
.tabs a { color: var(--brand-text); opacity: .7; padding: 10px 12px; text-decoration: none; font-weight: 600; white-space: nowrap; border-bottom: 3px solid transparent; }
.tabs a.on { opacity: 1; border-bottom-color: var(--accent); }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 1.8rem; font-weight: 800; letter-spacing: -.02em; }
.kpi .l { color: var(--muted); font-size: .85rem; font-weight: 600; }
.kpi.bad .v { color: var(--bad); } .kpi.ok .v { color: var(--ok); } .kpi.warn .v { color: var(--warn); }
table.data { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.data th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tablewrap { overflow-x: auto; }
.bar-mini { width: 90px; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 8px; border: 1px solid var(--line); }
.bar-mini i { display: block; height: 100%; background: var(--ok); }
.filters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
.chart { width: 100%; height: 200px; display: block; }
.legend { display: flex; gap: 14px; font-size: .82rem; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.edit-item { padding: 12px; display: grid; gap: 8px; }
.edit-item .r1 { display: grid; grid-template-columns: 1fr 150px auto; gap: 8px; align-items: center; }
.edit-item .r2 { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.edit-item .r3 { display: grid; grid-template-columns: repeat(3, minmax(80px, 1fr)); gap: 8px; }
.edit-section { margin: 18px 0 8px; display: flex; gap: 8px; align-items: center; }
.edit-section input { font-weight: 800; text-transform: uppercase; letter-spacing: .05em; font-size: .85rem; }
@media (max-width: 640px) { .edit-item .r1 { grid-template-columns: 1fr; } }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 18px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal .mh { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal .mb { padding: 18px; }
.modal .mf { padding: 12px 18px 18px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 200; display: grid; place-items: center; }
.lightbox img { max-width: 96vw; max-height: 88vh; border-radius: 8px; }
.lightbox .cap { color: #ddd; margin-top: 10px; text-align: center; font-size: .9rem; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 300; background: #222; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.3); max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad); }
.sync { font-size: .8rem; padding: 3px 10px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(420px, 100%); }

@media print {
  .topbar, .tabs, .footerbar, .noprint, .item .tools, .toast { display: none !important; }
  body { background: #fff; color: #000; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  .runhead { position: static; }
  .tick { width: 28px; height: 28px; font-size: 1rem; border-radius: 6px; }
  .thumb { width: 120px; height: 120px; }
}
