:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --field: #ffffff;
  --field-border: #b6bcc6;
  --ink: #1f2430;
  --muted: #5c636e;
  --line: #e3e6ea;
  --brand: #0f766e;
  --brand-dark: #0b5850;
  --danger: #b91c1c;
  --warn: #b45309;
  --ok: #15803d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a; --card: #22262e; --field: #0e1013; --field-border: #4b5563;
    --ink: #f1f3f5; --muted: #aab2bd;
    --line: #333a44; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; min-width: 0; }
[hidden] { display: none !important; }
html, body { margin: 0; max-width: 100%; overflow-x: hidden; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
img, svg, table, pre { max-width: 100%; }
h1, h2, h3, h4, p, span, b, div, dd, li, code { overflow-wrap: anywhere; word-break: break-word; }
.view { width: 100%; max-width: 720px; margin: 0 auto; padding: 14px; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.hint { color: var(--brand-dark); border-left: 3px solid var(--brand); padding: 4px 0 4px 10px; font-size: 13px; margin: 8px 0 0; }
@media (prefers-color-scheme: dark) { .hint { color: #6ee7b7; border-left-color: #34d399; } }
.error { color: #fca5a5; font-size: 13px; font-weight: 600; }
@media (prefers-color-scheme: light) { .error { color: var(--danger); } }
.msg { font-size: 13px; margin-left: 8px; }

/* ---------- login ---------- */
#view-login { display: flex; min-height: 90vh; align-items: center; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; width: 100%;
}
.brand { font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 10px; line-height: 1.2; }
.brand small { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--brand); color: #fff; font-size: 18px; flex: none;
}
.brand-mark.sm { width: 26px; height: 26px; font-size: 14px; border-radius: 8px; }
.who-txt { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who-txt #me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 14px; }
input, select, textarea {
  width: 100%; margin-top: 6px; padding: 13px 12px; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--field); border: 1.5px solid var(--field-border); border-radius: 10px;
}
input::placeholder { color: var(--muted); opacity: 1; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
#login-pin { letter-spacing: 3px; text-align: center; }
textarea { resize: vertical; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 10px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.block { width: 100%; margin-top: 16px; padding: 12px; font-size: 16px; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); border-color: #fca5a5; }

/* ---------- top bar / tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  background: var(--bg); padding: 4px 0 10px;
}
.who { flex: 1; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.pill { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  background: var(--brand); color: #fff; padding: 2px 7px; border-radius: 999px; }
.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  width: 38px; height: 38px; border-radius: 10px; font-size: 17px; cursor: pointer;
}
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--muted);
  padding: 8px 12px; border-radius: 999px; font: inherit; font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ---------- task cards ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; cursor: pointer;
}
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--muted); }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid transparent; }
.s-Pending { background: #fff7ed; color: #9a3412; }
.s-InProgress { background: #eff6ff; color: #1d4ed8; }
.s-Submitted { background: #f5f3ff; color: #6d28d9; }
.s-UnderReview { background: #ecfeff; color: #0e7490; }
.s-Approved, .s-Completed { background: #ecfdf5; color: #15803d; }
.s-OnHold { background: #f3f4f6; color: #4b5563; }
.s-Rework { background: #fef2f2; color: #b91c1c; }
.tag-overdue { background: #fef2f2; color: var(--danger); }
.tag-prio-High { color: var(--danger); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------- full-screen detail sheet ---------- */
.sheet { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: stretch;
  z-index: 20; }
.sheet-body {
  background: var(--card); width: 100%; max-width: 720px; margin: 0 auto;
  height: 100%; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  position: relative; padding: 0 14px 40px;
}
.sheet-bar {
  position: sticky; top: 0; z-index: 6; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; background: var(--card); margin: 0 -14px 6px; padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-bar #sheet-back-btn { flex: none; font-weight: 700; white-space: nowrap; }
.sheet-bar #sheet-close { flex: none; }
.sheet-bar .spacer { flex: 1; min-width: 0; text-align: center; font-weight: 700; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet h2 { margin: 4px 0 10px; font-size: 18px; }
.kv { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 4px 10px; font-size: 13px; margin: 10px 0; }
.kv dt { color: var(--muted); }
.status-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.status-row .btn.small.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.review-callout {
  background: #fef2f2; border: 1px solid #fecaca; border-left: 4px solid #ef4444;
  border-radius: 10px; padding: 10px 12px; margin: 10px 0 14px; color: #7f1d1d;
}
@media (prefers-color-scheme: dark) {
  .review-callout { background: #2a1414; border-color: #7f1d1d; color: #fecaca; }
}
.review-callout b { display: block; font-size: 13px; }
.review-callout p { margin: 6px 0 4px; font-size: 13.5px; white-space: pre-wrap; }

.rework-box { border-color: #fecaca; }
.rework-box summary { color: #b91c1c; }
@media (prefers-color-scheme: dark) { .rework-box summary { color: #fca5a5; } }

.file-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.file-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dropzone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 16px; text-align: center;
  color: var(--muted); font-size: 13px; margin-top: 8px;
}

/* ---------- manage ---------- */
details { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; }
summary { font-weight: 700; cursor: pointer; }
.stack { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
form.inline { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
form.inline input { flex: 1; min-width: 140px; margin: 0; }
form.inline select { width: auto; margin: 0; }
.staff-list { display: flex; flex-direction: column; gap: 6px; }
.staff-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 13px; padding: 9px 0; border-top: 1px solid var(--line); }
.staff-row .grow { flex: 1 1 100%; }
.staff-row .btn.small { padding: 5px 9px; font-size: 12px; }
.nopin { color: var(--warn); font-size: 11px; font-weight: 700; }
.role-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); border: 1px solid var(--line); padding: 1px 6px; border-radius: 999px; }
.role-tag.is-admin { color: #fff; background: var(--brand); border-color: var(--brand); }

@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- dashboard ---------- */
.dash-hero {
  background: linear-gradient(135deg, #0f766e 0%, #0b5850 55%, #134e4a 100%);
  color: #fff; border-radius: 16px; padding: 16px;
  box-shadow: 0 6px 18px rgba(15,118,110,.22);
}
.dash-hero-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dash-hero-title { font-size: 17px; font-weight: 800; letter-spacing: .2px; }
.dash-hero-sub { font-size: 12px; opacity: .85; margin-top: 2px; }
.dash-ring { flex: none; }
.dash-hero-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 14px; }
.dash-hero-stats > div {
  background: rgba(255,255,255,.12); border-radius: 10px; padding: 9px 4px; text-align: center;
}
.dash-hero-stats b { display: block; font-size: 20px; font-weight: 800; line-height: 1; }
.dash-hero-stats span { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; opacity: .85; }
.dash-hero-stats > div.warn { background: rgba(251,191,36,.28); }

/* sites directory on the dashboard */
.site-list { display: flex; flex-direction: column; gap: 2px; }
.site-row {
  appearance: none; border: 0; background: none; width: 100%; text-align: left; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 6px; border-top: 1px solid var(--line); color: var(--ink); font: inherit;
}
.site-row:first-child { border-top: 0; }
.site-row:active { background: var(--bg); }
.site-name { font-weight: 600; font-size: 13.5px; flex: 1; min-width: 0; }
.site-counts { flex: none; display: flex; align-items: center; gap: 6px; font-size: 12px; white-space: nowrap; }
.site-counts b { font-size: 14px; }
.sc-over { color: #fff; background: #ef4444; border-radius: 999px; padding: 1px 7px; font-size: 10px; font-weight: 700; }
.site-arrow { color: var(--muted); font-size: 18px; line-height: 1; }

.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.dash-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 14px 16px;
}
.dash-card.wide { grid-column: 1 / -1; }
.dash-card h4 { margin: 0 0 12px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.donut-wrap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.donut { flex: none; width: 140px; height: 140px; max-width: 46vw; }
.donut-num { fill: var(--ink); font-size: 24px; font-weight: 800; }
.donut-lbl { fill: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; flex: 1 1 120px; min-width: 120px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink); }
.legend i { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend b { margin-left: auto; }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 84px minmax(0, 1fr) 26px; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 8px; }
.bar-row.clickable { cursor: pointer; }
.bar-row.clickable:hover { background: var(--bg); }
.bar-row.clickable:active { opacity: .55; }
.bar-row.clickable .bar-label { color: var(--brand); font-weight: 600; text-decoration: underline; text-decoration-color: var(--field-border); text-underline-offset: 2px; }
@media (prefers-color-scheme: dark) { .bar-row.clickable .bar-label { color: #5eead4; } }
.tap-hint { margin-left: auto; font-size: 10px; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--muted); opacity: .8; }
.sheet-back { margin-bottom: 10px; }
.bar-label { font-size: 12px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--line); border-radius: 999px; height: 12px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.bar-val { font-size: 12px; font-weight: 700; color: var(--muted); text-align: right; }

/* person / project mini-profile in the sheet */
.grp-head { display: flex; align-items: center; gap: 12px; margin: 2px 0 14px; }
.grp-avatar {
  flex: none; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-size: 20px; font-weight: 800;
}
.mini-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 6px 0 10px; }
.mini-stats .ms {
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 4px; text-align: center;
}
.mini-stats .ms b { display: block; font-size: 20px; font-weight: 800; line-height: 1; color: var(--ink); }
.mini-stats .ms span { font-size: 9.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.mini-stats .ms.amber b { color: #b45309; }
.mini-stats .ms.blue b { color: #1d4ed8; }
.mini-stats .ms.green b { color: #15803d; }
@media (prefers-color-scheme: dark) {
  .mini-stats .ms.amber b { color: #fbbf24; }
  .mini-stats .ms.blue b { color: #60a5fa; }
  .mini-stats .ms.green b { color: #4ade80; }
}
.mini-prog { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--line); }
.mini-prog span { display: block; min-width: 0; }
.mp-amber { background: #f59e0b; }
.mp-blue { background: #3b82f6; }
.mp-green { background: #22c55e; }
.grp-h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
@media (max-width: 360px) { .mini-stats { grid-template-columns: 1fr 1fr; } }

.due-list { display: flex; flex-direction: column; gap: 4px; }
.due-row { display: flex; align-items: center; gap: 8px; padding: 9px 6px; border-radius: 10px; cursor: pointer; }
.due-row:active { background: var(--bg); }
.due-desc { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.due-meta { font-size: 11px; color: var(--muted); flex: none; }

@media (max-width: 560px) {
  .dash-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 76px minmax(0, 1fr) 24px; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600; z-index: 50; box-shadow: var(--shadow);
}
