:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-dark: #1d4ed8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0,0,0,.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Leelawadee UI', 'Tahoma', 'Noto Sans Thai', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

#app { min-height: 100dvh; }

.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  gap: 1rem;
  color: var(--muted);
}

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--surface2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.shell {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.user-strip {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .4rem .75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  font-size: .72rem;
  flex-wrap: wrap;
}

.strip-logo {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  object-fit: contain;
  background: #fff;
}

.strip-user { font-weight: 600; color: var(--text); }
.strip-role {
  padding: .1rem .45rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: .65rem;
}
.role-admin .strip-role { background: #7c2d12; color: #ffedd5; }
.role-reviewer .strip-role { background: #1e3a5f; color: #bfdbfe; }
.role-technician .strip-role { background: #14532d; color: #bbf7d0; }
.strip-tenant { color: var(--muted); margin-left: auto; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15,23,42,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--surface2);
  padding: .65rem .85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-width: 0;
}

.topbar-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
  flex-shrink: 0;
}

.topbar h1 {
  font-size: .95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .sub {
  font-size: .72rem;
  color: var(--muted);
}

.login-logo {
  width: 72px;
  height: 72px;
  display: block;
  margin: 0 auto .75rem;
  border-radius: 12px;
  background: #fff;
  padding: 4px;
}

.view-only-banner {
  background: #1e3a5f !important;
  border-color: #3b82f6 !important;
  font-size: .85rem;
  text-align: center;
  padding: .65rem !important;
}

.review-mode-banner {
  background: #713f12 !important;
  border-color: var(--warning) !important;
  font-size: .85rem;
  text-align: center;
  padding: .65rem !important;
}

.card-hint {
  font-size: .75rem;
  color: var(--primary);
  margin-top: .35rem;
}

.zone-editor-row {
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: 10px;
  padding: .75rem;
  margin-bottom: .65rem;
}

.zone-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem;
}

.btn-zone-del {
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
  border-radius: 6px;
  padding: .2rem .5rem;
  font-size: .72rem;
  cursor: pointer;
}

.zone-required-check {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  color: var(--muted);
  margin-top: .25rem;
}

.zone-required-check input { width: auto; }

.admin-tabs {
  display: flex;
  gap: .35rem;
  margin-bottom: .75rem;
  flex-wrap: wrap;
}

.admin-tab.active {
  background: var(--primary-dark) !important;
  color: #fff !important;
  border-color: var(--primary) !important;
}

.btn-job-del {
  margin-top: .5rem;
  width: 100%;
  padding: .45rem;
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
  border-radius: 8px;
  font-size: .78rem;
  cursor: pointer;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .65rem;
}

.stats-grid > div {
  background: var(--bg);
  border-radius: 10px;
  padding: .75rem;
  text-align: center;
}

.stats-num {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
}

.stats-lbl {
  font-size: .72rem;
  color: var(--muted);
}

.log-list {
  max-height: 320px;
  overflow-y: auto;
}

.log-row {
  border-bottom: 1px solid var(--surface2);
  padding: .55rem 0;
  font-size: .78rem;
}

.log-time { color: var(--muted); font-size: .7rem; }
.log-action { font-weight: 600; margin: .15rem 0; }
.log-user { color: var(--muted); }
.log-meta { font-size: .68rem; color: var(--primary); }

.btn-icon {
  background: var(--surface);
  border: 1px solid var(--surface2);
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 10px;
  font-size: 1.1rem;
  cursor: pointer;
}

.content {
  flex: 1;
  padding: 1rem;
  padding-bottom: 5rem;
}

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(30,41,59,.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--surface2);
  display: flex;
  justify-content: center;
  gap: .25rem;
  padding: .5rem;
  max-width: 520px;
  margin: 0 auto;
}

.nav-item {
  flex: 1;
  text-align: center;
  padding: .55rem .25rem;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: .7rem;
  border: none;
  background: transparent;
  cursor: pointer;
}

.nav-item.active {
  background: var(--primary-dark);
  color: #fff;
}

.nav-item span { display: block; font-size: 1.2rem; margin-bottom: .15rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: .85rem;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1rem;
  margin-bottom: .35rem;
}

.card p, .muted { color: var(--muted); font-size: .875rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  width: 100%;
  padding: .9rem 1rem;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  margin-top: .5rem;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #052e16; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--surface2);
  color: var(--text);
}

.btn:disabled { opacity: .45; cursor: not-allowed; }

.rework-hint {
  font-size: .85rem;
  color: #fdba74;
  background: rgba(154, 52, 18, .25);
  border-radius: 8px;
  padding: .6rem .75rem;
  margin-bottom: .75rem;
}

.form-group { margin-bottom: .85rem; }
.form-group label {
  display: block;
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: .35rem;
}

input, select, textarea {
  width: 100%;
  padding: .75rem .85rem;
  border-radius: 10px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

textarea { min-height: 80px; resize: vertical; }

.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
}

.badge-draft { background: #475569; }
.badge-before_done, .badge-in_progress { background: #854d0e; color: #fef3c7; }
.badge-after_done { background: #1e40af; }
.badge-submitted { background: #7c2d12; color: #ffedd5; }
.badge-approved { background: #14532d; color: #bbf7d0; }
.badge-rejected { background: #7f1d1d; color: #fecaca; }
.badge-needs_rework { background: #9a3412; color: #ffedd5; }
.badge-cab-idle { background: #475569; }
.badge-cab-working { background: #854d0e; color: #fef3c7; }
.badge-cab-pending_review { background: #7c2d12; color: #ffedd5; }
.badge-cab-rework { background: #9a3412; color: #ffedd5; }
.badge-cab-approved { background: #14532d; color: #bbf7d0; }
.badge-cab-rejected { background: #7f1d1d; color: #fecaca; }
.badge-zone-pending { background: #854d0e; color: #fef3c7; }
.badge-zone-passed { background: #14532d; color: #bbf7d0; }
.badge-zone-failed { background: #7f1d1d; color: #fecaca; }

.zone-list { display: flex; flex-direction: column; gap: .65rem; }

.zone-item {
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: 12px;
  padding: .85rem;
}

.zone-item.done { border-color: var(--success); }

.zone-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .35rem;
}

.zone-head strong { font-size: .95rem; }

.hint {
  font-size: .78rem;
  color: var(--warning);
  margin-bottom: .5rem;
}

.phase-block { margin-top: .5rem; }
.phase-label {
  font-size: .75rem;
  color: var(--muted);
  margin-bottom: .35rem;
  font-weight: 600;
}

.photo-gallery {
  display: flex;
  gap: .45rem;
  overflow-x: auto;
  padding-bottom: .25rem;
  margin-bottom: .35rem;
  -webkit-overflow-scrolling: touch;
}

.gallery-item {
  flex: 0 0 88px;
  width: 88px;
  height: 66px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  background: var(--surface2);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-num {
  position: absolute;
  top: 2px; left: 2px;
  background: rgba(0,0,0,.7);
  font-size: .6rem;
  padding: 1px 4px;
  border-radius: 4px;
}

.gallery-del {
  position: absolute;
  top: 2px; right: 2px;
  width: 20px; height: 20px;
  border: none;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: .85rem;
  line-height: 1;
  cursor: pointer;
}

.gallery-empty {
  font-size: .78rem;
  color: var(--muted);
  padding: .35rem 0 .5rem;
}

.compare-picker {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
  margin-top: .5rem;
}

.picker-btn {
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--muted);
  border-radius: 8px;
  padding: .3rem .55rem;
  font-size: .72rem;
  cursor: pointer;
}

.picker-btn.active {
  background: var(--primary-dark);
  color: #fff;
  border-color: var(--primary);
}

.thumb-row {
  display: flex;
  gap: .5rem;
  margin-top: .5rem;
}

.thumb {
  flex: 1;
  aspect-ratio: 4/3;
  border-radius: 8px;
  background: var(--surface2);
  overflow: hidden;
  position: relative;
}

.thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
}

.thumb-label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.65);
  font-size: .65rem;
  text-align: center;
  padding: .2rem;
}

.photo-input { display: none; }

.capture-btn {
  font-size: .85rem;
  padding: .55rem;
}

.compare-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}

.compare-pane {
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.compare-pane img {
  width: 100%;
  display: block;
  transform-origin: center center;
}

.compare-label {
  position: absolute;
  top: .35rem; left: .35rem;
  background: rgba(0,0,0,.7);
  font-size: .65rem;
  padding: .15rem .4rem;
  border-radius: 4px;
}

.compare-controls {
  display: flex;
  gap: .5rem;
  margin: .75rem 0;
  flex-wrap: wrap;
}

.compare-controls .btn { width: auto; flex: 1; min-width: 100px; margin: 0; font-size: .85rem; padding: .6rem; }

.overlay-mode .compare-wrap {
  grid-template-columns: 1fr;
  position: relative;
}

.overlay-mode .compare-pane.after {
  position: absolute;
  inset: 0;
  opacity: var(--overlay-opacity, .5);
}

.thumb-strip {
  display: flex;
  gap: .35rem;
  overflow-x: auto;
  margin-top: .35rem;
  padding-bottom: .2rem;
  -webkit-overflow-scrolling: touch;
}

.cmp-thumb {
  flex: 0 0 52px;
  width: 52px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  opacity: .85;
}

.cmp-thumb:hover { opacity: 1; border-color: var(--primary); }

.cmp-main { cursor: zoom-in; }

.zone-review-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem;
}

.zone-review-head h2 { margin: 0; font-size: .95rem; }

.zone-review-btns {
  display: flex;
  gap: .5rem;
  margin-top: .5rem;
}

.zone-review-btns .btn { flex: 1; margin: 0; font-size: .85rem; padding: .65rem; }

.zone-review-card.zone-st-passed { border-color: #22c55e55; }
.zone-review-card.zone-st-failed { border-color: #ef444455; }

.zone-zone-controls { margin-top: .35rem; }

.review-mode-banner {
  background: #1e3a5f44;
  border-color: var(--primary);
  font-size: .85rem;
}

.view-only-banner {
  background: #33415544;
  font-size: .85rem;
}

.rework-banner {
  background: #9a341222;
  border-color: #f97316;
  font-size: .85rem;
}

.zone-failed { border-color: #ef4444 !important; }
.zone-passed-lock { opacity: .85; }
.zone-fail-note {
  font-size: .78rem;
  color: #fecaca;
  background: #7f1d1d33;
  border-radius: 8px;
  padding: .45rem .6rem;
  margin-bottom: .5rem;
}

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, .92);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 1rem;
}

.lightbox.open { display: flex; }

.lightbox img {
  max-width: 100%;
  max-height: 85dvh;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox .lb-label {
  color: #fff;
  font-size: .85rem;
  margin-bottom: .75rem;
  text-align: center;
}

.lightbox .lb-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
}

.gallery-item img { cursor: zoom-in; }

.cmp-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .5rem;
}

.cmp-nav-label {
  font-size: .78rem;
  color: var(--muted);
  flex: 1;
  text-align: center;
}

.filter-card .form-group { margin-bottom: .65rem; }

.station-chip {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  padding: .15rem .35rem;
  margin: .15rem .2rem .15rem 0;
  font-size: .75rem;
}

.chip-edit, .chip-del {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .75rem;
  padding: 0 .15rem;
}

.chip-del { color: var(--danger); }

.qr-box {
  text-align: center;
  padding: 1rem;
}

.qr-box canvas, .qr-box img, .qr-box table {
  max-width: 200px;
  margin: .5rem auto;
  background: #fff;
  padding: 8px;
  border-radius: 8px;
}

.qr-canvas-wrap {
  display: inline-block;
}

.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  color: var(--text);
  padding: .65rem 1rem;
  border-radius: 10px;
  font-size: .875rem;
  z-index: 100;
  max-width: 90%;
  box-shadow: var(--shadow);
}

.toast.error { background: var(--danger); }
.toast.success { background: var(--success); color: #052e16; }

.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: .25rem;
}

.status-steps {
  display: flex;
  gap: .35rem;
  margin: .75rem 0;
}

.step {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--surface2);
}

.step.active { background: var(--primary); }
.step.done { background: var(--success); }

@media (min-width: 521px) {
  body { background: #020617; }
  .shell { border-left: 1px solid var(--surface2); border-right: 1px solid var(--surface2); }
}