/* VNC Mobile — โทรทวง / ลงพื้นที่ */
:root {
  --vnc-red: #d62828;
  --vnc-red-dark: #b71c1c;
  --vnc-gradient: linear-gradient(135deg, #d90000 0%, #8b0000 100%);
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1a202c;
  --muted: #718096;
  --border: #e2e8f0;
  --tier1: #eab308;
  --tier2: #ea580c;
  --tier3: #dc2626;
  --ok: #16a34a;
  --radius: 14px;
  --radius-sm: 10px;
  --nav-h: 56px;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: 'Prompt', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--vnc-red-dark);
  text-decoration: none;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: calc(10px + var(--safe-t)) 16px 12px;
  background: var(--vnc-gradient);
  color: #fff;
  box-shadow: 0 4px 20px rgba(214, 40, 40, 0.25);
}

.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-header p {
  margin: 4px 0 0;
  font-size: 0.75rem;
  opacity: 0.92;
  font-weight: 500;
  line-height: 1.35;
  max-width: 100%;
  word-break: break-word;
}

.main-scroll {
  padding: 14px 14px calc(var(--tab-h) + var(--safe-b) + 20px);
  max-width: 520px;
  margin: 0 auto;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.stat-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}

.stat-pill .n {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.1;
}

.stat-pill .l {
  font-size: 0.65rem;
  color: var(--muted);
  font-weight: 600;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.search-bar {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.95rem;
  margin-bottom: 12px;
  background: #fff;
}

.search-bar:focus {
  outline: none;
  border-color: var(--vnc-red);
}

.search-row {
  margin-bottom: 12px;
}

.search-row-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
  width: 100%;
}

.search-row-form .search-bar {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.search-row-form .btn-search {
  flex-shrink: 0;
  padding-left: 14px;
  padding-right: 14px;
}

.search-row-hint {
  margin: 6px 0 0;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.35;
}

.chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.chip {
  border: 1.5px solid var(--border);
  background: #fff;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
}

.chip.active {
  background: var(--vnc-gradient);
  color: #fff;
  border-color: transparent;
}

.case-card {
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.case-card:active {
  transform: scale(0.99);
}

.case-card .stripe {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.case-card h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
  font-weight: 800;
}

.case-card .sub {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.case-card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.badge.t1 {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

.badge.t2 {
  background: #ffedd5;
  color: #9a3412;
  border: 1px solid #fdba74;
}

.badge.t3 {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.badge.ok {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
}

.policy-banner {
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.45;
}

.policy-banner.t1 {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
}

.policy-banner.t2 {
  background: #ffedd5;
  border: 1px solid #fdba74;
  color: #9a3412;
}

.policy-banner.t3 {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}

.policy-banner.ok {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #166534;
}

.detail-top {
  background: linear-gradient(135deg, #0f172a 0%, #334155 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.detail-top h2 {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 800;
}

.detail-top .name {
  font-size: 0.88rem;
  font-weight: 600;
  opacity: 0.95;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.detail-tags span {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: none;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--vnc-gradient);
  color: #fff;
  box-shadow: 0 2px 10px rgba(214, 40, 40, 0.35);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.btn-outline {
  background: #fff;
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.75rem;
}

.contact-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.contact-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fafafa;
}

.contact-item .role {
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.contact-item .nm {
  font-weight: 700;
  font-size: 0.88rem;
  margin-top: 4px;
}

.contact-item .ph {
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 2px;
}

.label {
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

textarea.notes {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

textarea.notes:focus {
  outline: none;
  border-color: var(--vnc-red);
}

.field-card {
  border-left: 4px solid var(--vnc-red);
}

.field-map-wrap {
  margin: 10px 0 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #e5e7eb;
  line-height: 0;
}

.field-map-iframe {
  width: 100%;
  height: min(200px, 42vw);
  min-height: 140px;
  border: none;
  display: block;
}

.field-photo-inp {
  width: 100%;
  margin-top: 6px;
  font-size: 0.8rem;
}

.field-status {
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 8px;
}

.field-status.pending {
  color: #b45309;
}

.field-status.done {
  color: var(--ok);
}

.field-admin-banner {
  margin: 0 0 10px;
  padding: 10px 12px;
  background: #fef2f2;
  border-radius: 10px;
  border: 1px solid #fecaca;
  font-weight: 600;
  color: #991b1b;
  line-height: 1.45;
}

.field-list-card-inner {
  padding-left: 8px;
}

.field-list-snippet {
  margin: 8px 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
}

.field-list-date {
  margin: 4px 0 0;
  font-size: 0.72rem;
}

.field-detail-head {
  margin-bottom: 12px;
}

.field-detail-hero {
  margin-bottom: 12px;
}

.field-detail-hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.field-detail-case {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.25;
}

.field-detail-name {
  font-size: 0.88rem;
  font-weight: 600;
  margin-top: 6px;
  line-height: 1.35;
}

.field-assign {
  margin: 8px 0 0;
  font-size: 0.72rem;
}

.field-detail-addr {
  margin: 10px 0 0;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.4;
}

.field-album-hint {
  margin: 0 0 10px;
  font-size: 0.72rem;
  line-height: 1.45;
}

.field-album {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

@media (min-width: 400px) {
  .field-album {
    grid-template-columns: repeat(4, 1fr);
  }
}

.field-album-item {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  position: relative;
}

.field-album-item--saved {
  background: linear-gradient(145deg, #ecfdf5 0%, #d1fae5 100%);
  border-color: #6ee7b7;
}

.field-album-ico {
  font-size: 1.1rem;
  color: var(--ok);
  font-weight: 800;
}

.field-album-num {
  font-size: 0.7rem;
  font-weight: 700;
  color: #047857;
  margin-top: 2px;
}

.field-album-item--pending {
  padding: 0;
}

.field-album-item--pending img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.field-album-add {
  cursor: pointer;
  background: #fff;
  border: 2px dashed #cbd5e1;
  transition: border-color 0.15s, background 0.15s;
}

.field-album-add:active {
  background: #fef2f2;
  border-color: var(--vnc-red);
}

.field-album-inp {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

.field-album-plus {
  font-size: 1.6rem;
  font-weight: 300;
  color: var(--vnc-red);
  line-height: 1;
  pointer-events: none;
}

.field-album-add-txt {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.bottom-tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + var(--safe-b));
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.08);
}

.bottom-tabs button {
  border: none;
  background: none;
  font: inherit;
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 6px 4px;
}

.bottom-tabs button .ico {
  font-size: 1.35rem;
  line-height: 1;
}

.bottom-tabs button.active {
  color: var(--vnc-red);
}

.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}

.back-fab {
  margin-bottom: 10px;
}

.muted {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.rec-hint {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.45;
  margin: 0 0 10px;
}

.rec-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.rec-timer {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--vnc-red);
  min-width: 3.2em;
}

.btn-rec {
  background: #0f172a;
  color: #fff;
}

.btn-rec-call {
  background: #c2410c;
  color: #fff;
}

.btn-rec-stop {
  background: #991b1b;
  color: #fff;
}

.btn-rec:disabled,
.btn-rec-call:disabled,
.btn-rec-stop:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.rec-status {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  flex: 1 1 100%;
}

select.call-result {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.9rem;
  margin-bottom: 10px;
  background: #fff;
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1.5px solid var(--border);
}

/* ── Login OTP (แบบต้นแบบ) ── */
/* [hidden] ใน UA มักถูกทับด้วย display:flex ของคลาสนี้ (specificity เท่ากัน) — ต้องบังคับซ่อน */
.auth-screen[hidden],
.app-shell[hidden] {
  display: none !important;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 300;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  padding-top: calc(20px + var(--safe-t));
  padding-bottom: calc(20px + var(--safe-b));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(135deg, #d90000 0%, #8b0000 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 22px;
  padding: 32px 28px 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.auth-logo-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 12px;
  min-height: 72px;
}

.auth-logo-img {
  display: block;
  max-width: min(200px, 55vw);
  width: auto;
  height: auto;
  max-height: 72px;
  object-fit: contain;
  object-position: center;
}

.auth-title {
  margin: 0;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
}

.auth-sub {
  margin: 6px 0 22px;
  text-align: center;
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 500;
}

.auth-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.auth-input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 1rem;
  margin-bottom: 14px;
  box-sizing: border-box;
}

.auth-input:focus {
  outline: none;
  border-color: var(--vnc-red);
}

.auth-otp-input {
  letter-spacing: 0.35em;
  text-align: center;
  font-weight: 700;
  font-size: 1.25rem;
}

.auth-otp-wrap {
  margin-bottom: 4px;
}

.auth-otp-hint {
  margin: -6px 0 14px;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
  text-align: center;
}

.auth-msg {
  min-height: 1.4em;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.auth-msg.err {
  color: #b91c1c;
}

.auth-msg.ok {
  color: #15803d;
}

.auth-submit {
  margin-top: 4px;
}

.auth-hint {
  margin: 14px 0 0;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
  word-break: break-all;
}

.app-shell {
  min-height: 100vh;
}

.app-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.app-header-row > div:first-child {
  flex: 1;
  min-width: 0;
}

.btn-logout {
  flex-shrink: 0;
  margin-top: 2px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-logout:active {
  opacity: 0.85;
}
