:root {
  --bg: #f4f5f7; --surface: #ffffff; --text: #1c2330; --muted: #667085; --line: #e3e6ec;
  --accent: #d96c00; --accent-ink: #ffffff; --accent-soft: #fff1e0;
  --good: #14804a; --good-soft: #e1f5ea; --warn: #9a6700; --warn-soft: #fff4d6; --info: #1a5fb4; --info-soft: #e4effc;
  --danger: #c0302b; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 2px 8px rgba(16,24,40,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --surface: #1b1f27; --text: #e8ebf0; --muted: #98a2b3; --line: #2b313c;
    --accent: #f08a1c; --accent-ink: #1a1206; --accent-soft: #3a2711;
    --good: #4cc38a; --good-soft: #173626; --warn: #e5b440; --warn-soft: #3a2f10; --info: #6ea8f0; --info-soft: #172a45;
    --danger: #f2706b; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.topbar { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1040px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand i { width: 24px; height: 24px; border-radius: 6px; background: var(--accent); display: inline-block; }
.spacer { flex: 1; }
.navlink { color: var(--muted); text-decoration: none; padding: 6px 8px; border-radius: 6px; }
.navlink:hover { background: var(--bg); color: var(--text); }
.who { color: var(--muted); font-size: 13px; }
main { max-width: 1040px; margin: 0 auto; padding: 16px; }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 8px; cursor: pointer; min-height: 40px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.pad { padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); font-size: 14px; min-height: 1.3em; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

label.f { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
label.f > input, label.f > select, label.f > textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; color: var(--text); }
input[type=text], input[type=password], input[type=date], select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-height: 40px;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

/* login */
.login { max-width: 360px; margin: 12vh auto 0; padding: 0 16px; }
.login .card { padding: 22px; }
.login h1 { font-size: 22px; margin-bottom: 4px; }

/* projects */
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.pcard { display: block; color: inherit; text-decoration: none; overflow: hidden; }
.pcard:hover { border-color: var(--muted); }
.cover { height: 150px; background: var(--bg) center / cover no-repeat; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.pcard .body { padding: 12px 14px 14px; }
.pcard h3 { font-size: 16px; }
.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.chip.in_progress { background: var(--info-soft); color: var(--info); }
.chip.completed { background: var(--good-soft); color: var(--good); }
.chip.on_hold { background: var(--warn-soft); color: var(--warn); }
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.done > span { background: var(--good); }
.pct { font-weight: 700; font-variant-numeric: tabular-nums; }

/* project page */
.phead { padding: 16px; }
.phead h1 { font-size: 22px; }
.phead .meta { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 6px; color: var(--muted); font-size: 14px; }
.big-progress { margin-top: 14px; }
.big-progress .bar { height: 12px; margin-top: 6px; }

.update { padding: 14px 16px; }
.update .who-line { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; flex: none; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.note { white-space: pre-wrap; word-break: break-word; margin: 8px 0 0; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin-top: 10px; }
.photos button { padding: 0; border: 0; background: var(--bg); border-radius: 8px; overflow: hidden; aspect-ratio: 4 / 3; cursor: zoom-in; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.comments { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.comment { font-size: 14px; padding: 4px 0; }
.comment b { font-weight: 600; }
.cform { display: flex; gap: 8px; margin-top: 6px; }
.cform input { flex: 1; min-width: 0; }

.composer { padding: 14px 16px; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; }
.preview { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; background: var(--bg); }
.preview img { width: 100%; height: 100%; object-fit: cover; }
.preview button { position: absolute; top: 2px; right: 2px; border: 0; border-radius: 50%; width: 22px; height: 22px; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; line-height: 1; }
.preview.done::after { content: "✓"; position: absolute; inset: auto 4px 4px auto; background: var(--good); color: #fff; border-radius: 50%; width: 20px; height: 20px; text-align: center; font-size: 13px; line-height: 20px; }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* modal + lightbox */
.overlay { position: fixed; inset: 0; background: rgba(10,12,18,.55); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 12px; overflow: auto; z-index: 20; }
.modal { width: 100%; max-width: 480px; padding: 20px; }
.modal h2 { margin-bottom: 14px; font-size: 18px; }
.checks { max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--bg); }
.checks label { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.lightbox img { max-width: 96vw; max-height: 82vh; object-fit: contain; }
.lightbox .cap { color: #ddd; margin-top: 10px; text-align: center; padding: 0 16px; min-height: 1.4em; }
.lightbox button { position: absolute; background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 50%; width: 44px; height: 44px; font-size: 22px; cursor: pointer; }
.lightbox .x { top: 14px; right: 14px; } .lightbox .prev { left: 10px; top: 45%; } .lightbox .next { right: 10px; top: 45%; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1c2330; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; max-width: 90vw; }
#toast.show { opacity: 1; }
table.users { width: 100%; border-collapse: collapse; }
table.users td, table.users th { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.users th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
table.users tr:last-child td { border-bottom: 0; }
.scroll-x { overflow-x: auto; }

.composer > b { display: block; }
.composer textarea { display: block; width: 100%; }
.row input[type=range] { flex: 1; width: auto; min-width: 0; }
.pcard h3 { min-width: 0; overflow-wrap: anywhere; }
.brand, .navlink { white-space: nowrap; }
@media (max-width: 480px) { .topbar-in { gap: 4px; padding: 8px 10px; } .brand { font-size: 15px; } .navlink { padding: 6px 6px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; } }

/* project categories */
.chip.cat.solar { background: var(--warn-soft); color: var(--warn); }
.chip.cat.cctv { background: var(--info-soft); color: var(--info); }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.tab { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; cursor: pointer; white-space: nowrap; min-height: 36px; }
.tab:hover { border-color: var(--muted); }
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.tab .n { opacity: .75; font-variant-numeric: tabular-nums; margin-left: 2px; }

/* project list: search, view toggle, list view */
.tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.search { flex: 1; min-width: 180px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-height: 40px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg-b { border: 0; background: transparent; padding: 8px 14px; min-height: 40px; cursor: pointer; color: var(--muted); }
.seg-b + .seg-b { border-left: 1px solid var(--line); }
.seg-b.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.plist { overflow: hidden; }
.prow { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) 48px; gap: 14px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
a.prow:hover { background: var(--bg); }
.prow:last-child { border-bottom: 0; }
.prow.phead-row { padding-top: 9px; padding-bottom: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: 12px; }
.pname { font-weight: 600; overflow-wrap: anywhere; }
.prow .pct { text-align: right; }
@media (max-width: 560px) {
  .prow { grid-template-columns: minmax(0, 1fr) 44px; gap: 6px 10px; }
  .prow .pname { grid-column: 1 / -1; }
  .prow .pbar { grid-column: 1; }
  .prow.phead-row { display: none; }
}
