:root {
  --brand: #0f766e;
  --brand-dark: #134e4a;
  --brand-mid: #115e59;
  --brand-soft: #ccfbf1;
  --brand-softer: #f0fdfa;
  --ink: #14201f;
  --muted: #5f6f6d;
  --line: #dfe9e8;
  --bg: #f5f8f8;
  --card: #ffffff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(10, 40, 40, .06), 0 4px 16px rgba(10, 40, 40, .05);
  font-family: "Noto Sans Thai", "Sarabun", "Thonburi", "Leelawadee UI", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 15px; line-height: 1.55; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--brand-dark), var(--brand-mid));
  color: #ccfbf1; padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; color: #fff; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; background: #5eead4; color: var(--brand-dark);
  display: grid; place-items: center; font-weight: 800;
}
.brand strong { display: block; font-size: 1.05rem; }
.brand span { font-size: .75rem; opacity: .75; }
.nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav a, .nav .soon {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: #99f6e4; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.nav a.active { background: #fff; color: var(--brand-dark); }
.nav .soon { opacity: .5; cursor: default; justify-content: space-between; }
.nav .soon em { font-style: normal; font-size: .7rem; background: rgba(255,255,255,.15); padding: 1px 6px; border-radius: 6px; }
.nav-section { margin: 16px 12px 6px; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; opacity: .6; }
.nav-icon { width: 20px; text-align: center; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 14px 28px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.search { flex: 1; max-width: 460px; }
.search input { width: 100%; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.avatar.lg { width: 88px; height: 88px; font-size: 1.8rem; }
.avatar.xl { width: 180px; height: 180px; font-size: 3.4rem; }
/* Large avatars sit on the lavender profile header: solid brand colour + white ring so the circle is visible. */
.avatar.lg, .avatar.xl {
  background: linear-gradient(135deg, var(--brand), #5eead4); color: #fff;
  border: 4px solid #fff; box-shadow: 0 6px 18px rgba(17, 94, 89, .22);
}
img.avatar.photo { object-fit: cover; background: #fff; }
.avatar-block { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: none; }
.avatar-link { position: relative; display: block; border-radius: 50%; text-decoration: none; }
.avatar-overlay {
  position: absolute; inset: 4px; border-radius: 50%; display: grid; place-items: center; text-align: center;
  background: rgba(19, 78, 74, .62); color: #fff; font-size: .74rem; font-weight: 600; line-height: 1.3;
  opacity: 0; transition: opacity .15s;
}
.avatar-link:hover .avatar-overlay, .avatar-link:focus-visible .avatar-overlay { opacity: 1; }
.avatar-caption {
  font-size: .78rem; font-weight: 600; color: var(--brand); background: #fff; border: 1px solid #99f6e4;
  padding: 3px 10px; border-radius: 999px; text-decoration: none; white-space: nowrap;
}
.avatar-caption:hover { border-color: var(--brand); }
.photo-edit { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 8px 0 18px; }
.photo-edit .small { text-align: center; }
.content { padding: 24px 28px 48px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.breadcrumb { font-size: .82rem; color: var(--muted); margin-bottom: 6px; }

/* Cards & grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-title { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-title .icon { width: 32px; height: 32px; border-radius: 9px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.9rem; font-weight: 700; color: var(--brand-dark); }
.stat.highlight { background: var(--brand-softer); border-color: #99f6e4; }

.kv { display: grid; grid-template-columns: minmax(120px, 42%) 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; text-align: right; overflow-wrap: anywhere; }

.profile-head {
  display: flex; align-items: center; gap: 20px; padding: 22px; border-radius: var(--radius);
  background: linear-gradient(90deg, var(--brand-soft), var(--brand-softer)); margin-bottom: 16px; flex-wrap: wrap;
}
.profile-head .meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: .9rem; }
.profile-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .82rem; color: var(--muted); font-weight: 600; background: var(--brand-softer); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: #f6fefc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 28px; }

/* Badges & buttons */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.grey { background: #e6eeed; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { text-decoration: none; border-color: #5eead4; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #115e59; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.link-btn { background: none; border: 0; color: #99f6e4; font: inherit; cursor: pointer; padding: 0; }

/* Forms */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); }
input, select, textarea {
  font: inherit; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #5eead4; border-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.field { display: grid; gap: 5px; }
.field label { font-size: .85rem; font-weight: 600; }
.field.full { grid-column: 1 / -1; }
.field input, .field select, .field textarea { width: 100%; }
.field .err { color: var(--bad); font-size: .82rem; }
/* Checkboxes sit in front of their text on the same line (owner request 2026-10-20), never
   stretched to the full field width like text inputs. */
input[type="checkbox"], input[type="radio"] {
  width: 18px; height: 18px; padding: 0; margin: 0; flex: none; accent-color: var(--brand); cursor: pointer;
}
.field input[type="checkbox"], .field input[type="radio"] { width: 18px; }
label.check-row { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; line-height: 1.4; }
.field:has(> label.check-row) { align-self: center; padding: 6px 0; }
.field-title { font-size: .85rem; font-weight: 600; }
.check-list { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.check-list label.check-row { font-weight: 400; font-size: .92rem; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.notice { padding: 12px 16px; border-radius: 10px; background: var(--brand-softer); border: 1px solid #99f6e4; }
.notice.warn { background: var(--warn-soft); border-color: #fde68a; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.timeline .when { color: var(--muted); font-size: .85rem; }

/* Landing */
.landing { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand-dark), var(--brand)); }
.landing .card { width: min(420px, 92vw); text-align: center; padding: 36px; }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
  .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dd { text-align: left; }
}
.center-mark { margin: 0 auto 14px; }
.grid > .card + .card { margin-top: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 16px; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--brand); }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.flash { margin-bottom: 14px; }
tr.inactive td { opacity: .55; }
.nav .count { font-style: normal; margin-left: auto; background: #f43f5e; color: #fff; font-size: .72rem; padding: 1px 7px; border-radius: 999px; }
.schedule-table td, .schedule-table th { padding: 6px; text-align: center; }
.schedule-table td:first-child, .schedule-table th:first-child { text-align: left; white-space: nowrap; }
.schedule-table select { width: 100%; min-width: 108px; padding: 5px 6px; font-size: .85rem; }
.schedule-table td.weekend { background: #f6fefc; }
.schedule-table .cell-note { display: block; font-size: .72rem; color: var(--muted); }
.schedule-table td.draft select { border-style: dashed; }
.net-banner { display: flex; justify-content: space-between; align-items: center; gap: 16px; background: var(--brand); color: #fff; flex-wrap: wrap; }
.net-banner strong { font-size: 1.6rem; }
@media print {
  .sidebar, .topbar, .no-print, .flash { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}
.link-code { font-size: 1.6rem; letter-spacing: .2em; }
/* public invite pages (no sidebar) */
body.public { background: var(--bg, #f6f5fb); }
.public-main { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; }
.public-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; color: #1f2937; padding: 0; }
.public-brand span { display: block; color: #6b7280; font-size: .9rem; }
.steps li { margin: 12px 0; }
.steps .btn { margin-top: 8px; }
label.check { display: flex; gap: 10px; align-items: flex-start; margin: 8px 0 16px; }
label.check input[type="checkbox"] { margin-top: 3px; }
.invite-url { font-family: ui-monospace, monospace; word-break: break-all; }
.nav li.sub a { padding-left: 34px; font-size: .92rem; }
.invite-row { border-top: 1px solid #eee; padding: 10px 0; display: grid; gap: 4px; }
.invite-row:first-of-type { border-top: 0; }
.chat-preview { white-space: normal; max-width: 520px; background: #e8f9ee; border-color: #b7ebc6; }
.templates li { margin-bottom: 10px; }
td.narrow input { width: 60px; }
form.inline { display: inline; }
.preview-img { max-width: 240px; margin-top: 8px; border-radius: 8px; }
.join-card { text-align: left; }
.join-card .lead { font-size: 1.05rem; }
.btn.big { display: block; text-align: center; font-size: 1.15rem; padding: 16px 20px; margin: 16px 0; background: #06c755; border-color: #06c755; }
.steps-simple li { margin: 6px 0; }
.step-card { display: flex; gap: 14px; align-items: flex-start; border: 1px solid #e5e7eb; border-radius: 12px; padding: 14px; margin: 12px 0; }
.step-no { flex: none; width: 34px; height: 34px; border-radius: 50%; background: #0f766e; color: #fff; display: grid; place-items: center; font-weight: 700; }
.btn.armed { background: #b45309; border-color: #b45309; color: #fff; }
.confirm-note { margin-top: 8px; }
.import-form { display: grid; gap: 6px; min-width: 260px; margin-top: 8px; }
.import-form label { display: grid; gap: 2px; font-size: .9rem; }
/* Terminal-admin page: small stacked forms inside a row's "จัดการ…" panel */
.stack { display: grid; gap: 6px; padding: 10px 0; min-width: 220px; border-top: 1px solid var(--line); }
.stack label { display: grid; gap: 2px; font-size: .85rem; }
.card.narrow { max-width: 560px; }
.card-title .push-right { margin-left: auto; }

/* Schedule: bulk assign over a date range */
.bulk-card summary { cursor: pointer; display: flex; gap: 10px; align-items: baseline; }
.bulk-form { margin-top: 14px; }
.bulk-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1.4fr; gap: 14px 18px; align-items: start; }
.bulk-grid .field:first-child, .bulk-grid .field:nth-child(5), .bulk-grid .field:nth-child(6) { grid-column: span 2; }
@media (max-width: 980px) { .bulk-grid { grid-template-columns: 1fr 1fr; } .bulk-grid .field { grid-column: 1 / -1; } }

/* ---- FIX additions ---- */
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.quick-actions .btn { padding: 12px 18px; }
.btn.report { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn.report:hover { background: #b91c1c; }
.stat a { color: inherit; }
.stat.bad { background: var(--bad-soft); border-color: #fecaca; }
.stat.bad .value { color: var(--bad); }
.stat.warn { background: var(--warn-soft); border-color: #fde68a; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 160px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.panel { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--brand); padding: 6px 0; }
details.more[open] summary { margin-bottom: 8px; }
.thumbs { display: flex; gap: 10px; flex-wrap: wrap; }
.thumbs figure { margin: 0; width: 120px; }
.thumbs img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.thumbs figcaption { font-size: .75rem; color: var(--muted); }
.thumbs .pdf { width: 120px; height: 120px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.asset-photo { max-width: 220px; border-radius: 12px; border: 1px solid var(--line); }
.checklist-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.checklist-row .choices { display: flex; gap: 12px; flex-wrap: wrap; }
.checklist-row input[type="text"] { grid-column: 1 / -1; width: 100%; }
.progress { display: flex; gap: 8px; flex-wrap: wrap; }
.progress .pill { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: .85rem; }
.hidden-new[hidden] { display: none; }
.warn-text { color: var(--bad); font-weight: 600; }
.money { font-variant-numeric: tabular-nums; }
.sticky-actions { position: sticky; bottom: 0; background: var(--card); padding: 12px 0; border-top: 1px solid var(--line); }

/* QR stickers: A4, 3 per row, 5.5 cm squares + text */
.stickers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6mm; }
.sticker { border: 1px dashed #999; border-radius: 6px; padding: 4mm; text-align: center; break-inside: avoid; background: #fff; }
.sticker img { width: 40mm; height: 40mm; }
.sticker .code { font-size: 14pt; font-weight: 700; display: block; }
.sticker .name { font-size: 9pt; display: block; }
.sticker .hint { font-size: 7.5pt; color: #555; display: block; }

/* Out-of-service sign: A5 landscape-ish */
.sign { border: 6px solid #dc2626; border-radius: 16px; padding: 24px; text-align: center; max-width: 720px; margin: 0 auto; background: #fff; }
.sign h1 { font-size: 3rem; color: #dc2626; margin: 0 0 8px; }
.sign .big { font-size: 1.6rem; font-weight: 700; }
.print-sheet { background: #fff; padding: 16px; }
.print-sheet table { font-size: .9rem; }
.sign-line { display: inline-block; min-width: 200px; border-bottom: 1px solid #333; margin: 24px 12px 0; }

@media (max-width: 640px) {
  .quick-actions .btn { flex: 1; justify-content: center; }
  .stickers { grid-template-columns: repeat(2, 1fr); }
  .checklist-row { grid-template-columns: 1fr; }
  table.responsive thead { display: none; }
  table.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 4px; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }
}
@media print {
  @page { size: A4; margin: 10mm; }
  .stickers { grid-template-columns: repeat(3, 1fr); }
}
.pager { margin-top: 12px; }
.mt { margin-top: 16px; }
.right { text-align: right; }
input.narrow { width: 80px; }

/* Phones: the menu becomes one row that scrolls sideways, so the page content starts on screen. */
@media (max-width: 980px) {
  .sidebar { padding: 8px 10px; display: flex; align-items: center; gap: 6px; overflow-x: auto; position: sticky; top: 0; z-index: 6; }
  .sidebar .brand { padding: 0 6px 0 0; flex: none; }
  .sidebar .brand div:last-child { display: none; }
  .sidebar .brand-mark { width: 32px; height: 32px; }
  .sidebar .nav { display: flex; gap: 2px; flex: none; }
  .sidebar .nav a { padding: 7px 10px; white-space: nowrap; font-size: .9rem; }
  .sidebar .nav-section { display: none; }
  .topbar { position: static; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  .topbar .search { order: 2; flex-basis: 100%; max-width: none; }
}
.sticker img { max-width: 100%; height: auto; aspect-ratio: 1; }
