:root {
  --bg: #f7f4f4;
  --card: #ffffff;
  --ink: #2a1215;
  --muted: #6b5f61;
  --line: #ece4e4;
  --brand: #8e0b13;
  --brand-2: #b3141e;
  --brand-soft: #f9e6e7;
  --accent: #f59e0b;
  --accent-soft: #fff4dc;
  --ok: #16a34a;
  --ok-soft: #e7f7ec;
  --danger: #8f1111;
  --danger-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 4px 14px rgba(20, 33, 61, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand-2); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 10px 16px; min-height: 44px;
  background: var(--brand); color: #fff; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: var(--card); color: var(--brand); border-color: var(--line); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: var(--danger); }
.btn.danger-ghost { background: var(--card); color: var(--danger); border-color: #f5c2c2; }
.btn.accent { background: var(--accent); color: #1f1300; }
.btn.sm { padding: 6px 12px; min-height: 36px; font-size: 14px; border-radius: 9px; }
.btn.block { width: 100%; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer;
  width: 40px; height: 40px; border-radius: 10px; font-size: 18px;
  display: inline-grid; place-items: center; color: inherit;
}
.icon-btn:hover { background: rgba(0,0,0,.06); }

label.field { display: block; }
.field > span:first-child { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field > span:first-child .req { color: var(--danger); }
input[type=text], input[type=password], input[type=url], input[type=date], input[type=time],
input[type=number], input[type=search], input[type=tel], input[type=month], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; padding: 10px 12px; min-height: 44px; outline: none;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(142, 11, 19, .14); }

/* date field: วว/ดด/ปปปป text + calendar button (the real date picker sits invisibly over the 📅) */
.datein { display: flex; gap: 6px; align-items: stretch; }
.datein .date-text { flex: 1; min-width: 0; letter-spacing: .03em; }
.datein .date-text.bad { border-color: var(--danger); background: var(--danger-soft); }
.date-cal { position: relative; flex: none; width: 46px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: #fff; display: grid; place-items: center; font-size: 18px; cursor: pointer; overflow: hidden; }
.date-cal .date-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; min-height: 0; }
.datein.ro .date-text { background: var(--bg); color: var(--muted); }
.datein.ro .date-cal { opacity: .4; pointer-events: none; }
.timein { display: flex; align-items: center; gap: 6px; }
.timein select { width: auto; flex: 1; min-width: 68px; text-align: center; font-variant-numeric: tabular-nums; }
.timein b { color: var(--muted); }
.num-unit { display: flex; gap: 6px; }
.num-unit input { flex: 1; min-width: 0; }
.num-unit select { width: auto; flex: none; min-width: 84px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .icon-btn:hover { background: rgba(255,255,255,.15); }
.who { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.who b { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 420px) { .who b { display: none; } }
.role { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: rgba(255,255,255,.18); text-transform: uppercase; letter-spacing: .03em; }
.role.owner { background: var(--accent); color: #1f1300; }
.role.admin { background: #fff; color: var(--brand); }

.page { max-width: 980px; margin: 0 auto; padding: 16px 16px 120px; }
.page.wide { max-width: 1400px; }
.banner {
  background: var(--accent-soft); color: #7a4b00; border: 1px solid #f7d58c;
  border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-bottom: 16px;
}
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 14px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-h h2, .card-h h3 { margin: 0; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 180px; }
.toolbar select { width: auto; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 500px at 50% -10%, #b3141e 0%, #8e0b13 55%, #4a0508 100%); }
.login { width: 100%; max-width: 400px; background: var(--card); border-radius: 20px; padding: 28px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.brand { text-align: center; margin: -6px 0 18px; }
.brand img { width: 96px; height: auto; display: block; margin: 0 auto 12px; }
.brand h1 { margin: -6px 0 0; font-size: 22px; line-height: 1.2; color: var(--brand); letter-spacing: .02em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.home-logo { display: block; width: 64px; height: auto; margin: 0 0 10px; mix-blend-mode: multiply; }
.login form { display: grid; gap: 14px; }
.steps { display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--line); }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 12px; color: var(--muted); }
.step i { font-style: normal; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--line); color: var(--muted); font-weight: 700; transition: .2s; }
.step.active i { background: var(--brand); color: #fff; box-shadow: 0 0 0 4px var(--brand-soft); }
.step.active { color: var(--ink); font-weight: 600; }
.step.done i { background: var(--ok); color: #fff; }
.arrow { color: #cbd5e1; font-size: 18px; margin-bottom: 18px; }

/* ---------- home tiles ---------- */
.home-bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .80) 0%, rgba(247, 244, 244, .86) 55%, rgba(247, 244, 244, .92) 100%),
    url("bg-solar.webp") 40% center / cover no-repeat;
}
.hello { margin: 4px 0 18px; }
.hello h2 { margin: 0; font-size: 22px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  position: relative; text-align: left; cursor: pointer;
  border: 0; border-radius: 18px; padding: 18px 16px; min-height: 150px;
  background: var(--card); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px; transition: transform .12s, box-shadow .12s;
}
.tile:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(20,33,61,.12); }
.tile .ico { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; }
.tile .ico svg { width: 28px; height: 28px; }
.tile b { font-size: 18px; }
.tile small { color: var(--muted); font-size: 13px; line-height: 1.35; }
.tile .num { position: absolute; top: 14px; right: 16px; font-weight: 700; color: #cbd5e1; font-size: 20px; }
.tile .lock { position: absolute; bottom: 14px; right: 16px; font-size: 14px; color: var(--muted); }

/* ---------- list cards ---------- */
.list { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); } /* long addresses get "…" instead of widening the page */
.item {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  background: var(--card); border: 0; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; cursor: pointer;
}
.item:hover { box-shadow: 0 6px 20px rgba(20,33,61,.1); }
.item .thumb { width: 56px; height: 56px; border-radius: 10px; background: var(--brand-soft); flex: none; object-fit: cover; display: grid; place-items: center; color: var(--brand); font-size: 22px; }
.item .body { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .m { color: var(--muted); font-size: 12px; margin-top: 2px; }
.chev { color: #cbd5e1; font-size: 20px; }
.progress { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--ok); border-radius: 99px; }

/* ---------- forms ---------- */
.q { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px; }
.q-h { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.q-no { flex: none; font-weight: 700; color: var(--brand); background: var(--brand-soft); border-radius: 8px; padding: 1px 8px; font-size: 14px; }
.q-t { font-weight: 600; }
.q .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
.q + .q { margin-top: 0; }
.row2 { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .row2 { grid-template-columns: 1fr 1fr; } }
.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }

details.q > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; }
details.q > summary::-webkit-details-marker { display: none; }
details.q > summary .q-t { flex: 1; }
details.q > summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
details.q[open] > summary::after { transform: rotate(180deg); }
details.q[open] > summary { margin-bottom: 12px; }
.q-h .topic-rm { margin-left: auto; width: 36px; height: 36px; font-size: 16px; opacity: .7; align-self: center; }
.q-h .topic-rm:hover { opacity: 1; background: var(--danger-soft); }
.topic-foot { display: flex; justify-content: flex-end; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.add-topic { border-style: dashed; border-width: 2px; margin-bottom: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--ok); }
.cnt { font-size: 12px; color: var(--muted); }

.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.files:empty { display: none; }
.f { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); cursor: pointer; }
.f img { width: 100%; height: 100%; object-fit: cover; display: block; }
.f .doc { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px; font-size: 11px; text-align: center; word-break: break-all; color: var(--muted); }
.f .doc b { font-size: 24px; }
.f .rm { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 13px; display: grid; place-items: center; }
.f .by {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #fff;
  font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.f.loading { display: grid; place-items: center; color: var(--muted); font-size: 12px; cursor: default; }
.file-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.file-actions label { cursor: pointer; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  background: rgba(255,255,255,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.savebar > div { max-width: 980px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.savebar .grow { flex: 1; }

/* ---------- PM table ---------- */
.year { margin-bottom: 22px; }
.year-h { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.year-h h2 { margin: 0; font-size: 22px; color: var(--brand); }
.year-h .grow { flex: 1; }
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table.pm { border-collapse: collapse; width: 100%; min-width: 1100px; font-size: 14px; }
table.pm th, table.pm td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.pm th { background: #f8fafc; font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
table.pm tbody tr { cursor: pointer; }
table.pm tbody tr:hover td { background: #fff8f8; }
table.pm td.no { font-weight: 700; color: var(--brand); width: 48px; position: sticky; left: 0; background: var(--card); }
table.pm th:first-child { position: sticky; left: 0; z-index: 1; }
table.pm td.wrap { max-width: 240px; white-space: pre-wrap; }
.maint-cell { display: flex; align-items: flex-start; gap: 8px; min-width: 150px; }
.maint-cell > div { flex: 1; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.tag.red { background: var(--danger-soft); color: var(--danger); }
.tag.amber { background: var(--accent-soft); color: #9a5b00; }
.tag.green { background: var(--ok-soft); color: var(--ok); }

.maint-list { display: grid; gap: 8px; }
.maint { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; gap: 10px; }
.maint .body { flex: 1; min-width: 0; }
.maint .when { font-size: 13px; color: var(--brand); font-weight: 600; }
.maint .what { white-space: pre-wrap; }
.maint-form { background: var(--bg); border-radius: 12px; padding: 12px; display: grid; gap: 10px; margin-top: 10px; }

/* ---------- users ---------- */
.urow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.urow:last-child { border-bottom: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }
.urow .body { flex: 1; min-width: 140px; }
.urow .acts { display: flex; gap: 6px; }
.pw { font-family: ui-monospace, Consolas, monospace; letter-spacing: .08em; color: var(--ink); }
.pw.shown { background: var(--accent-soft); padding: 0 6px; border-radius: 6px; font-weight: 600; }
.pw-eye { border: 0; background: none; cursor: pointer; font-size: 15px; padding: 0 4px; vertical-align: middle; }
.tag:not(.red):not(.amber):not(.green) { background: var(--bg); color: var(--muted); font-weight: 500; }

/* ---------- PM alerts / schedule / install ---------- */
.alerts { position: relative; isolation: isolate; margin-bottom: 18px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border-left: 4px solid var(--brand); padding: 4px 12px 4px 14px; }
/* folded: only the most urgent alert shows, with paper "cards" peeking out underneath */
.alerts.stacked:not(.open) { margin-bottom: 30px; }
.alerts.stacked:not(.open)::before, .alerts.stacked:not(.open)::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -7px; height: 12px; z-index: -1;
  background: var(--card); border-radius: 0 0 12px 12px; box-shadow: var(--shadow); opacity: .9;
}
.alerts.stacked:not(.open)::after { left: 20px; right: 20px; bottom: -13px; opacity: .7; }
.alerts:not(.open) .alert-item ~ .alert-item { display: none; }
.alerts-head { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; padding: 8px 0; font-weight: 700; font-size: 16px; text-align: left; cursor: pointer; color: var(--ink); }
.alerts-head:disabled { cursor: default; }
.alerts-count { min-width: 26px; height: 26px; padding: 0 8px; border-radius: 99px; background: var(--brand); color: #fff; font-size: 13px; display: grid; place-items: center; }
.alerts-chev { color: var(--muted); transition: transform .15s; }
.alerts.open .alerts-chev { transform: rotate(180deg); }
.alert-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border-top: 1px solid var(--line); padding: 10px 0; cursor: pointer; }
.alert-item:hover { background: #fff8f8; }
.alert-x { flex: none; width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--bg); color: var(--muted); cursor: pointer; font-size: 14px; }
.alert-x:hover { background: var(--danger-soft); color: var(--danger); }
.alerts-more { width: 100%; border: 0; border-top: 1px dashed var(--line); background: none; padding: 8px 0 6px; color: var(--brand); font-weight: 600; font-size: 14px; cursor: pointer; }
.alert-item .grow, .sched-row .grow, .installed .grow { flex: 1; min-width: 0; }
.tile .badge { position: absolute; top: 10px; right: 40px; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 99px; background: var(--brand); color: #fff; font-size: 13px; font-weight: 700; display: grid; place-items: center; box-shadow: 0 0 0 3px #fff; }
.sched { display: grid; gap: 6px; }
.sched-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.sched-row input { width: 20px; height: 20px; accent-color: var(--ok); flex: none; }
.sched-row.done { background: var(--ok-soft); border-color: #bfe6cb; }
.sched-row.done .grow { color: var(--muted); }
.sched-row.filling { border-color: var(--ok); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.tick-form { display: grid; gap: 10px; margin-top: -6px; padding: 12px; border: 1px solid var(--ok); border-top: 0; border-radius: 0 0 10px 10px; background: var(--ok-soft); }
.tick-form .req { color: var(--danger); font-style: normal; }
.btn.ok { background: var(--ok); }
.installed { display: flex; align-items: center; gap: 10px; }
.q.install { border: 2px dashed #bfe6cb; }

/* ---------- loading ---------- */
.loading { position: fixed; inset: 0; z-index: 70; background: rgba(255, 255, 255, .45); display: grid; place-items: center; animation: fade .15s ease-out; }
.loading-bar { position: fixed; top: 0; left: 0; height: 3px; width: 40%; background: var(--accent); animation: bar 1s ease-in-out infinite; }
.loading-box { display: flex; align-items: center; gap: 12px; background: var(--card); padding: 14px 20px; border-radius: 14px; box-shadow: var(--shadow); font-weight: 500; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bar { 0% { left: -40%; } 100% { left: 100%; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- modal / toast / lightbox ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(8, 20, 45, .5); display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal-wrap { align-items: center; padding: 20px; } }
.modal { background: var(--card); width: 100%; max-width: 460px; max-height: 92vh; display: flex; flex-direction: column; border-radius: 18px 18px 0 0; box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: up .18s ease-out; }
@media (min-width: 640px) { .modal { border-radius: 18px; } }
.modal.wide { max-width: 760px; }
.modal-h { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-h h3 { flex: 1; margin: 0; font-size: 17px; }
.modal-b { padding: 16px; overflow: auto; display: grid; gap: 12px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.modal-f { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; flex-wrap: wrap; }
@keyframes up { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; z-index: 80; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: up .18s ease-out; font-size: 15px; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 86vh; border-radius: 8px; }
.lightbox .bar { position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px; display: flex; gap: 8px; }
.lightbox .bar { left: 12px; align-items: center; }
.lightbox .lb-count { color: #fff; font-weight: 600; margin-right: auto; padding-left: 4px; }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.18); color: #fff; font-size: 34px; line-height: 1;
  display: grid; place-items: center; padding-bottom: 4px;
}
.lb-nav:hover { background: rgba(255,255,255,.3); }
.lb-nav.prev { left: 10px; }
.lb-nav.next { right: 10px; }
.lightbox .bar a, .lightbox .bar button { background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 10px; padding: 8px 14px; cursor: pointer; text-decoration: none; font-size: 15px; }

/* PDF progress box */
.pdfprog { position: fixed; inset: 0; z-index: 80; background: rgba(8, 20, 45, .45); display: grid; place-items: center; padding: 16px; animation: fade .15s ease-out; }
.pdfprog-card { background: var(--card); width: 100%; max-width: 360px; border-radius: 16px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); display: grid; gap: 10px; }
.pdfprog-bar { height: 10px; border-radius: 99px; background: var(--brand-soft); overflow: hidden; }
.pdfprog-bar i { display: block; height: 100%; width: 0; background: var(--brand); border-radius: 99px; transition: width .3s ease; }
.pdfprog-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; color: var(--muted); }
.pdfprog-row b { color: var(--brand); font-size: 18px; }
.pdfprog-card .btn { justify-self: end; }
/* photo editor (rotate / crop) */
.imged { position: fixed; inset: 0; z-index: 95; background: #111; color: #fff; display: flex; flex-direction: column; animation: fade .15s ease-out; }
.imged-bar { display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; background: #000; }
.imged-bar .grow { flex: 1; }
.imged-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 16px; }
.imged-stage canvas { touch-action: none; cursor: crosshair; display: block; }
.imged-tools { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px 4px; }
.imged-hint { text-align: center; font-size: 13px; color: rgba(255,255,255,.6); padding: 4px 12px calc(12px + env(safe-area-inset-bottom)); }

/* ---- Daily report ---- */
.daily-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 16px; margin-bottom: 12px; }
.daily-head > div { display: flex; flex-direction: column; gap: 2px; }
.drow { display: grid; grid-template-columns: 26px 1fr 1fr 36px; gap: 8px; align-items: start; margin-bottom: 8px; }
.drow.one { grid-template-columns: 26px 1fr 36px; }
.drow textarea { min-height: 58px; }
.drow-no { padding-top: 10px; text-align: center; color: var(--muted); font-size: 14px; }
.drow-rm { grid-column: -2; grid-row: 1; width: 36px; height: 36px; opacity: .6; }
.drow-rm:hover { opacity: 1; background: var(--danger-soft); }
.drow-h { margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.ot-time { margin: 0 0 10px; }
@media (max-width: 560px) {
  .drow, .drow.one { grid-template-columns: 22px 1fr 32px; }
  .drow textarea { grid-column: 2; }
  .drow-h { display: none; }
}
.dcopy { display: block; width: 100%; text-align: left; margin-bottom: 10px; padding: 11px 14px; border-radius: 12px; border: 1.5px dashed #e0a100; background: #fff7e6; color: #8a5b00; font-weight: 600; cursor: pointer; }
.dcopy:hover { background: #fff1d1; }
.dnote { margin-bottom: 10px; padding: 10px 14px; border-radius: 12px; font-size: 14px; }
.dnote.draft { background: #eef4ff; color: #2457c5; }
.dnote.sent { background: #e7f7ec; color: #16803c; }
.dnote.late { background: #fdecec; color: #7a0a10; }
.dtag { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; vertical-align: middle; }
.dtag.draft { background: #eef4ff; color: #2457c5; }
.dtag.sent { background: #e7f7ec; color: #16803c; }
.dtag.late { background: #fdecec; color: var(--brand); }
.dpick { display: block; width: 100%; text-align: left; margin-bottom: 8px; padding: 11px 14px; border-radius: 12px; border: 1.5px solid #ddd; background: #fff; cursor: pointer; }
.dpick b { display: block; font-size: 15px; }
.dpick small { color: var(--muted); }
.dpick.main { border-color: var(--brand); background: var(--brand-soft); }
.dpick:hover { border-color: var(--brand); }
.dslot { border: 1px solid #f0e4e4; border-radius: 12px; padding: 10px 12px; margin-top: 10px; }
.dslot h4 { margin: 0 0 8px; font-size: 14px; color: var(--brand); }
.dseg { display: flex; gap: 8px; }
.dseg button { flex: 1; padding: 9px; border-radius: 10px; border: 1.5px solid #ddd; background: #fff; cursor: pointer; font-weight: 500; }
.dseg button.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 600; }
/* ===== 5. แผนงาน ===== */
.pseg { display: flex; background: #f1eded; border-radius: 12px; padding: 4px; margin-bottom: 10px; }
.pseg button { flex: 1; border: 0; background: none; padding: 8px 0; border-radius: 9px; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.pseg button.on { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.pwho { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 6px; scrollbar-width: none; }
.pwho::-webkit-scrollbar { display: none; }
.pwho button { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 12px; font: inherit; font-size: 14px; cursor: pointer; color: var(--ink); }
.pwho button.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pnav { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; }
.pnav b { flex: 1; text-align: center; font-size: 16px; }
.pnav .icon-btn { color: var(--brand); font-size: 24px; }
.pweek { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 6px; }
.pweek table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.pweek th, .pweek td { padding: 3px 1px; vertical-align: middle; }
.pweek thead th { font-size: 12px; color: var(--muted); font-weight: 500; text-align: center; cursor: pointer; }
.pweek thead th small { display: block; font-size: 13px; color: var(--ink); font-weight: 600; }
.pweek thead th:first-child { width: 58px; cursor: default; }
.pweek thead th.today small { color: #fff; background: var(--brand); border-radius: 99px; width: 24px; margin: 0 auto; }
.pweek tbody th { text-align: left; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 4px; }
.pweek tbody th.me { color: var(--brand); }
.pweek tbody tr + tr > * { border-top: 1px solid var(--line); }
.pweek tbody td { height: 44px; cursor: pointer; }
.pweek td.today { background: #fff6f6; }
.pchip { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; background: var(--pc); color: #fff; border-radius: 6px; font-size: 10px; letter-spacing: -.2px; line-height: 1.35; padding: 0 1px; border-block: 3px solid var(--pc); margin: 1px 0; text-align: center; overflow: hidden; overflow-wrap: anywhere; position: relative; }
.pchip.done { opacity: .5; }
.pchip.done::before { content: '✓'; }
.pchip.flag::after { content: ''; position: absolute; top: 1px; right: 1px; width: 6px; height: 6px; border-radius: 50%; background: #fbbf24; box-shadow: 0 0 0 1px #fff; }
.plegend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--muted); margin: 10px 2px 0; }
.plegend b { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.pcard { display: block; width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--pc); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; font: inherit; color: inherit; cursor: pointer; box-shadow: var(--shadow); }
.pc-t { font-weight: 700; }
.pc-m { color: var(--muted); font-size: 13px; margin-top: 2px; }
.pc-p { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.pav { background: var(--pc); color: #fff; font-size: 12px; padding: 2px 9px; border-radius: 99px; }
.pav.done { opacity: .6; }
.psum { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.psum div { background: #fff; border-radius: 12px; padding: 8px 2px; text-align: center; font-size: 12.5px; color: var(--muted); box-shadow: var(--shadow); }
.psum b { display: block; font-size: 20px; color: var(--ink); }
.psum .r b { color: var(--brand); }
.pfree-h { margin: 12px 0 6px; }
.pfree { display: flex; flex-wrap: wrap; gap: 6px; }
.pfree button { border: 1px dashed #cfc4c5; background: #fff; border-radius: 99px; padding: 5px 12px; font: inherit; font-size: 14px; cursor: pointer; }
.pday { margin-bottom: 10px; }
.pday-h { display: block; border: 0; background: none; padding: 4px 2px; font: inherit; font-weight: 700; color: var(--ink); cursor: pointer; }
.pday.today .pday-h { color: var(--brand); }
.pnone { padding: 2px 4px 6px; }
.pmonth { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.pm-h { text-align: center; font-size: 12px; color: var(--muted); padding-bottom: 2px; }
.pm-d { position: relative; height: 58px; border: 0; border-radius: 9px; background: #fff; font: inherit; font-size: 14px; padding: 8px 2px 0; text-align: center; cursor: pointer; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.pm-d.out { background: transparent; color: #c9bfc0; box-shadow: none; }
.pm-d.today { outline: 2px solid var(--brand); font-weight: 700; color: var(--brand); }
.pm-d i { position: absolute; left: 2px; right: 2px; bottom: 9px; display: flex; justify-content: center; gap: 3px; }
.pm-d i b { width: 7px; height: 7px; border-radius: 50%; }
.pnew { margin-top: 14px; }
fieldset.pform { border: 0; margin: 0; min-width: 0; }
.pform { display: grid; gap: 14px; }
.pform .req { color: var(--danger); font-style: normal; }
.pchips { display: flex; flex-wrap: wrap; gap: 6px; }
.ptype, .pteam { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 6px 12px; font: inherit; font-size: 14px; cursor: pointer; color: var(--ink); }
.ptype.on { background: var(--pc); border-color: var(--pc); color: #fff; font-weight: 600; }
.pteam.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
fieldset[disabled] .ptype, fieldset[disabled] .pteam { cursor: default; }
.pgrid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .pgrid2 { grid-template-columns: 1fr; } }
.pdone { display: flex; align-items: center; gap: 10px; background: var(--ok-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.pdone span { flex: 1; font-weight: 600; color: #166534; }
.phist { margin-top: 10px; }
.phist summary { cursor: pointer; font-weight: 600; }
.ph-row { border-top: 1px solid var(--line); padding: 8px 0; margin-top: 8px; font-size: 14px; }
/* ===== 6. ประวัติพนักงาน ===== */
.pcalc { display: block; margin-top: 4px; color: var(--brand); font-weight: 600; font-size: 13px; }
.pavatar { display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 18px; border-radius: 50%; }
.pavatar.big { width: 56px; height: 56px; font-size: 24px; flex: none; }
.pprof-h { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.pprof-h b { font-size: 18px; }
.pform + .card { margin-top: 14px; }
.plock { text-align: center; background: var(--brand-soft); border-radius: 12px; padding: 16px; display: grid; gap: 6px; justify-items: center; }
.plock-i { font-size: 28px; }
.plock b { color: var(--brand); }
.plock .btn { margin-top: 6px; }
.plock-h { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
[data-locked] { display: grid; gap: 14px; }
[data-locked] .plock-h { margin-bottom: 0; }
/* iPhone app: swipe from the left edge to go back */
.swipe-back { position: fixed; left: 0; z-index: 200; width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; font-size: 28px; pointer-events: none; transition: background .15s; }
.swipe-back.ready { background: var(--brand); }
/* ===== 7. สลิปเงินเดือน ===== */
.slip-up { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .slip-up { grid-template-columns: 1.2fr 1fr 1.4fr auto; align-items: end; } }
.slipview { display: grid; gap: 10px; user-select: none; -webkit-user-select: none; }
.slipview img, .slipview canvas { width: 100%; height: auto; display: block; border-radius: 10px; box-shadow: var(--shadow); background: #fff; -webkit-touch-callout: none; pointer-events: none; }
.slip-alert { box-shadow: inset 4px 0 0 #a16207, var(--shadow); margin-bottom: 14px; }
.slip-alert .alert-item { width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: none; font: inherit; color: inherit; cursor: pointer; }.pmine { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: linear-gradient(135deg, #fff, var(--brand-soft)); border: 1.5px solid #f1c9cc; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; font: inherit; color: inherit; cursor: pointer; }
.pmine .grow { flex: 1; display: grid; gap: 1px; min-width: 0; }
.pmine small { color: var(--brand); font-weight: 700; font-size: 12.5px; }
.pmine b { font-size: 17px; }
.pmine .chev { color: var(--brand); font-size: 22px; }
.psec { font-size: 15px; margin: 20px 2px 10px; color: var(--muted); }/* profile photo */
img.pavatar, img.avatar { object-fit: cover; padding: 0; }
.item .thumb.pavatar { border-radius: 50%; }
.pphoto { position: relative; flex: none; cursor: pointer; display: block; }
.pphoto .pavatar.big { width: 72px; height: 72px; font-size: 30px; }
.pcam { position: absolute; right: -2px; bottom: -2px; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 13px; box-shadow: 0 0 0 3px #fff; }
.pprof-h .grow { flex: 1; min-width: 0; display: grid; gap: 2px; justify-items: start; }
.pphoto-rm { margin-top: 6px; min-height: 30px; padding: 3px 10px; font-size: 13px; }

/* Daily: pick any earlier day */
.dpick-other { padding: 11px 14px; border-radius: 12px; border: 1.5px dashed #ddd; }
.dpick-other b { display: block; font-size: 15px; margin-bottom: 8px; }
.dpick-other .inline { display: flex; gap: 8px; align-items: center; }
.dpick-other .datein { flex: 1; min-width: 0; }
.dpick-other small { display: block; margin-top: 6px; }
