:root {
  color-scheme: light;
  font-family: "Noto Sans Thai", "Leelawadee UI", Tahoma, system-ui, sans-serif;
  color: #14251e;
  background: #edf1ed;
  --ink: #14251e;
  --muted: #53665c;
  --line: #d8e1db;
  --panel: #fff;
  --field: #f9fbf8;
  --green: #17684e;
  --green-deep: #104b3a;
  --green-light: #e5f3eb;
  --gold: #825008;
  --gold-light: #fff2da;
  --danger: #ac352d;
  --shadow: 0 2px 9px #172c2210;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; line-height: 1.55; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button { color: inherit; }
button:disabled { cursor: default; opacity: .58; }
[hidden] { display: none !important; }
a { color: var(--green-deep); }
:focus-visible { outline: 3px solid #1f805e; outline-offset: 3px; }
h1, h2, h3, p, dl, dd { margin: 0; }
h1, h2, h3 { line-height: 1.32; }
button { -webkit-tap-highlight-color: transparent; }
.initial-message, .offline { max-width: 550px; padding: 30px; margin: 12vh auto; }
.offline p { margin: .5rem 0 1rem; }

.btn {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 700;
  text-decoration: none;
  background: transparent;
  line-height: 1.45;
}
.btn.primary { color: white; background: var(--green); }
.btn.primary:hover:not(:disabled) { background: var(--green-deep); }
.btn.secondary { color: var(--ink); border-color: #c9d6ce; background: white; }
.btn.secondary:hover:not(:disabled) { background: #f1f6f1; }
.btn.text { color: var(--green-deep); min-height: 32px; padding: 4px 8px; background: var(--green-light); font-size: .8rem; white-space: nowrap; }
.btn.danger { color: white; background: var(--danger); }
.btn.danger:hover:not(:disabled) { background: #872720; }
.btn.ghost { color: #e6f3ea; border-color: #577266; }
.btn.ghost:hover { background: #ffffff16; }
.btn.wide { width: 100%; }
.btn.compact { min-height: 36px; padding: 5px 11px; font-size: .85rem; }
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  color: var(--ink);
  font-weight: 700;
  font-size: .91rem;
}
.field input, .field select, .field textarea {
  display: block;
  width: 100%;
  border: 1px solid #bfcfc4;
  background: var(--field);
  color: var(--ink);
  padding: 9px 11px;
  border-radius: 8px;
  min-height: 43px;
  font-size: 1rem;
  font-weight: 500;
}
.field input::placeholder, .field textarea::placeholder { color: #677970; }
.field textarea { resize: vertical; }
.field-label { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.field-optional { color: var(--muted); font-size: .82rem; font-weight: 400; }
.form-error { margin: 10px 0; background: #fdebe8; color: #822a23; padding: 9px 12px; border-radius: 7px; }

.brand { display: inline-flex; align-items: center; gap: 11px; color: white; text-align: left; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; color: #123b2d; background: #b9e5a8; font-size: 1.4rem; font-weight: 900; }
.brand strong { display: block; line-height: 1.08; font-size: 1.22rem; letter-spacing: -.035em; }
.brand small { color: #bcd2c3; font-size: .74rem; }
.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(330px, 43%) minmax(380px, 1fr);
}
.login-side {
  display: flex;
  flex-direction: column;
  color: white;
  justify-content: space-between;
  gap: 40px;
  background-color: #142e25;
  background-image: radial-gradient(ellipse at 24% 78%, #28513e, transparent 63%),
    linear-gradient(90deg, #ffffff07 1px, transparent 1px), linear-gradient(#ffffff07 1px, transparent 1px);
  background-size: auto, 31px 31px, 31px 31px;
  padding: clamp(27px, 5vw, 92px) clamp(25px, 6vw, 95px);
}
.login-side-body { margin: auto 0; padding: 5vh 0 6vh; }
.login-tag { color: #c4edb6; display: inline-block; font-size: .87rem; font-weight: 700; margin-bottom: 15px; }
.login-side h1 { font-size: clamp(1.8rem, 3.4vw, 3.7rem); letter-spacing: -.047em; }
.login-content { background: #f6f8f4; display: grid; place-items: center; padding: 36px 30px; }
.login-card { width: min(100%, 465px); padding: 32px; border: 1px solid var(--line); border-radius: 16px; background: white; box-shadow: var(--shadow); }
.login-card h2 { font-size: 1.9rem; margin-bottom: 22px; }
.login-card form { display: grid; gap: 16px; }
.role-group { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; }
.role-group legend { padding: 0; font-size: .91rem; font-weight: 700; margin-bottom: 8px; }
.role-option { display: flex; gap: 12px; min-height: 61px; cursor: pointer; align-items: center; border: 1px solid var(--line); background: #fcfdfc; padding: 9px 12px; border-radius: 8px; position: relative; }
.role-option input { position: absolute; width: 1px; height: 1px; inset-inline-start: 14px; opacity: 0; }
.role-option:has(input:checked) { border-color: #3d825f; background: #edf7ef; }
.role-option:has(input:focus-visible) { outline: 3px solid #1f805e; outline-offset: 2px; }
.role-option-copy { display: grid; gap: 2px; }
.role-option-copy strong { font-size: .97rem; }
.role-option-copy small { color: var(--muted); font-size: .8rem; }
.role-radio { margin-left: auto; flex: 0 0 auto; height: 18px; width: 18px; border-radius: 50%; border: 1px solid #a2b6a9; background: white; display: grid; place-items: center; }
.role-option input:checked ~ .role-radio { border-color: var(--green); }
.role-option input:checked ~ .role-radio::after { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--green); }

.topbar { min-height: 69px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px max(5vw, calc((100vw - 1420px) / 2)); background: #142e25; }
.topbar-account { display: flex; align-items: center; gap: 17px; color: white; }
.account { min-width: 0; text-align: right; }
.account strong, .account small { display: block; }
.account strong { max-width: 225px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .94rem; }
.account small { color: #bbd0c1; font-size: .76rem; }
.topbar-leave { min-height: 36px; min-width: max-content; font-size: .84rem; white-space: nowrap; }
.workspace { width: min(100% - 10vw, 1420px); margin: 0 auto; padding: 31px 0 45px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 15px; margin-bottom: 22px; }
.page-head h1 { font-size: clamp(1.6rem, 3vw, 2.3rem); letter-spacing: -.04em; }
.page-head p { color: var(--muted); margin-top: 4px; font-size: .95rem; }
.workspace-grid { display: grid; grid-template-columns: minmax(260px, 325px) minmax(0, 1fr); gap: 18px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); min-width: 0; }
.queue-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 11px; }
.queue-head h2 { font-size: 1rem; }
.count { display: grid; place-items: center; min-width: 25px; min-height: 25px; padding: 0 5px; border-radius: 8px; background: #ecf1ec; color: #405a4d; font-size: .83rem; font-variant-numeric: tabular-nums; font-weight: 700; }
.queue-filters { display: flex; padding: 0 15px 12px; gap: 6px; border-bottom: 1px solid var(--line); }
.filter { padding: 5px 9px; min-height: 34px; border: 1px solid transparent; border-radius: 7px; background: transparent; font-size: .82rem; font-weight: 700; color: var(--muted); }
.filter.selected { background: var(--green-light); color: var(--green-deep); }
.queue-item { width: 100%; border: 0; background: transparent; border-bottom: 1px solid #e0e8e1; display: grid; text-align: left; gap: 4px; padding: 12px 15px; min-height: 97px; }
.queue-item:last-child { border-bottom: 0; border-bottom-left-radius: 13px; border-bottom-right-radius: 13px; }
.queue-item:hover { background: #f6faf6; }
.queue-item.current { background: #edf6ed; box-shadow: inset 3px 0 #318361; }
.queue-item strong { font-size: .99rem; }
.queue-line { display: flex; justify-content: space-between; word-break: break-word; gap: 8px; align-items: flex-start; }
.queue-location { color: #455c51; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .86rem; }
.queue-footer { color: var(--muted); margin-top: 1px; gap: 5px; font-size: .73rem; line-height: 1.5; }
.queue-footer time, .wait-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.wait-time { color: #77500d; }
.queue-empty { color: var(--muted); padding: 29px 15px; text-align: center; font-size: .9rem; }
.ticket-ref { color: #52695d; font-weight: 700; font-size: .79rem; letter-spacing: .015em; }
.badge { display: inline-flex; align-items: center; gap: 5px; min-height: 23px; padding: 3px 7px; border-radius: 6px; font-size: .72rem; line-height: 1.35; font-weight: 700; }
.badge-dot { background: currentColor; border-radius: 50%; width: 5px; height: 5px; flex: none; }
.badge-success { color: #215a3b; background: #e1f2e3; }
.badge-caution { color: #77480a; background: var(--gold-light); }
.badge-active { color: #24558a; background: #e6f0ff; }
.badge-neutral { color: #4c6256; background: #e9eeea; }
.work-panel { min-height: 405px; padding: clamp(16px, 2.8vw, 30px); }
.ticket-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; padding-bottom: 14px; }
.ticket-top h2 { font-size: clamp(1.27rem, 2vw, 1.74rem); overflow-wrap: anywhere; }
.ticket-top p { margin-top: 6px; color: var(--muted); font-size: .9rem; }
.ticket-top .badge { align-self: start; white-space: nowrap; }
.mobile-back { display: none; }
.detail-tabs { display: flex; gap: 19px; border-bottom: 1px solid var(--line); margin-bottom: 17px; }
.tab { padding: 8px 2px 10px; min-height: 42px; background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); font-size: .88rem; font-weight: 700; }
.tab.active-tab { border-bottom-color: var(--green); color: var(--green-deep); }
.empty-detail { display: grid; place-content: center; justify-items: center; gap: 17px; min-height: 342px; text-align: center; color: var(--muted); }
.empty-detail h2 { font-size: 1.12rem; }

.editor-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 15px; row-gap: 13px; }
.editor-grid .primary-field { grid-column: 1 / -1; }
#review-form > .editor-grid .field:nth-child(2) { grid-column: 1 / -1; }
.route-form { margin: 17px 0 0; display: grid; gap: 8px; }
.action-bar { display: flex; justify-content: flex-end; gap: 8px; margin-top: 17px; flex-wrap: wrap; }
.quiet-actions { justify-content: flex-start; }
.extra-fields { margin-top: 13px; }
.extra-fields summary { color: var(--green-deep); cursor: pointer; font-size: .88rem; font-weight: 700; padding: 4px 0; }
.extra-fields .editor-grid { margin-top: 8px; }
.audio-block { margin-top: 15px; border-radius: 8px; padding: 10px 11px; background: #f0f5f0; display: grid; gap: 6px; }
.audio-block strong { font-size: .82rem; }
.audio-block audio { width: 100%; min-width: 0; height: 39px; }
.notice { margin-bottom: 13px; padding: 10px 12px; background: #eef6f0; border: 1px solid #d5e6db; border-radius: 8px; display: grid; gap: 3px; font-size: .88rem; }
.notice strong, .notice span { display: block; }
.notice.notice-warning { background: #fff7e7; border-color: #f0dfba; }
.notice-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.route-form .notice { margin-bottom: 0; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.fact { background: #f3f7f3; border-radius: 8px; min-width: 0; padding: 10px 12px; overflow-wrap: anywhere; }
.fact.place { grid-column: 1 / -1; background: #eaf5ec; border: 1px solid #d4e6da; }
.fact.place dd { font-size: 1.17rem; }
.fact dt { color: var(--muted); font-size: .8rem; }
.fact dd { font-weight: 700; margin-top: 3px; }
.return-form { padding: 13px; border: 1px solid #e7bfb9; background: #fff9f8; border-radius: 9px; margin-top: 15px; display: grid; gap: 11px; }
.return-form h3 { font-size: 1rem; }
.return-form .action-bar { margin-top: 3px; }

.audio-capture { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; margin-top: 8px; }
.capture-choice { display: grid; grid-template-rows: auto 1fr auto; gap: 7px; border: 1px solid #d5e2d8; border-radius: 8px; padding: 14px; background: #f5f8f4; min-width: 0; }
.capture-choice p { display: block; color: var(--muted); margin: 0; overflow-wrap: anywhere; font-size: .87rem; }
.capture-choice .btn { justify-self: start; margin-top: 6px; }
.upload-label { cursor: pointer; position: relative; }
.upload-label input { width: 1px; height: 1px; position: absolute; opacity: 0; inset: 0; }
.upload-label:has(input:focus-visible) { outline: 3px solid #1f805e; outline-offset: 3px; }
.call-time { display: block; margin-top: 15px; }
.call-time input { max-width: 310px; margin-top: 5px; }

.location-card { display: flex; align-items: center; gap: 12px; margin-bottom: 15px; border: 1px solid #cee0d4; border-radius: 11px; background: #eaf4eb; padding: 12px 15px; }
.location-icon { width: 36px; height: 36px; display: grid; place-items: center; background: white; color: #3b724f; border-radius: 8px; font-size: 1.35rem; flex: none; }
.location-card h2 { font-size: .98rem; }
.location-card p { color: var(--muted); font-size: .83rem; margin-top: 2px; }
.location-actions { margin-left: auto; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.location-card .btn { flex: 0 0 auto; }
.dispatch { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 17px; }
.dispatch-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 11px; }
.dispatch-header h3 { font-size: 1.02rem; }
.dispatch-header p, .section-help { color: var(--muted); font-size: .84rem; margin-top: 4px; }
.patrol-map {
  position: relative;
  isolation: isolate;
  height: 360px;
  width: 100%;
  background-color: #e4ede8;
  background-image: repeating-linear-gradient(0deg, #a8c0b64d 0, #a8c0b64d 1px, transparent 1px, transparent 28px),
    repeating-linear-gradient(90deg, #a8c0b64d 0, #a8c0b64d 1px, transparent 1px, transparent 28px);
  border: 1px solid #c2d2c7;
  border-radius: 9px;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}
.patrol-map:active { cursor: grabbing; }
.patrol-map.map-picking { cursor: crosshair; }
.map-tiles, .map-markers { position: absolute; inset: 0; pointer-events: none; }
.map-tile { position: absolute; inset: 0 auto auto 0; max-width: none; user-select: none; }
.map-marker { display: grid; place-content: center; width: 32px; height: 32px; position: absolute; pointer-events: none; transform: translate(-50%, -50%); border: 2px solid white; border-radius: 50%; background: #17684e; color: white; box-shadow: 0 2px 6px #1a262a6b; padding: 0; font-weight: 800; font-size: .8rem; }
button.map-marker { pointer-events: auto; }
.map-marker-incident { background: #b84033; z-index: 2; width: 35px; height: 35px; }
.map-marker-station { background: #365a78; z-index: 0; }
.map-marker-demo { background: #53764a; border-style: dashed; }
.map-marker-label { color: #152820; background: white; border: 1px solid #a9c2b1; border-radius: 6px; padding: 3px 6px; font-size: .73rem; white-space: nowrap; position: absolute; top: 29px; left: 50%; transform: translateX(-50%); }
.map-controls { position: absolute; z-index: 3; top: 9px; right: 9px; display: grid; overflow: hidden; border-radius: 6px; border: 1px solid #a9beb1; box-shadow: var(--shadow); }
.map-control { border: 0; border-bottom: 1px solid var(--line); background: white; width: 36px; height: 36px; font-weight: 700; font-size: 1rem; }
.map-control:last-child { border: 0; }
.map-control:hover { background: #ecf3e9; }
.map-attribution { position: absolute; right: 0; bottom: 0; background: #fff; padding: 2px 6px; z-index: 3; font-size: .72rem; }
.map-tile-status { position: absolute; z-index: 3; top: 9px; left: 9px; max-width: calc(100% - 64px); padding: 3px 7px; color: #345146; background: #fffffff2; border-radius: 5px; pointer-events: none; font-size: .72rem; }
.map-legend { display: flex; flex-wrap: wrap; gap: 9px 15px; color: var(--muted); font-size: .8rem; margin-top: 6px; }
.map-legend span { display: flex; align-items: center; gap: 5px; }
.map-legend i { width: 8px; height: 8px; border-radius: 50%; background: #17684e; }
.map-legend .legend-incident { background: #b84033; }
.map-legend .legend-station { background: #365a78; }
.pin-form { margin-top: 9px; padding: 8px 11px 11px; background: #f3f7f3; border: 1px solid var(--line); border-radius: 8px; }
.pin-form .editor-grid { margin-top: 7px; }
.pin-form .action-bar { margin-top: 9px; }
.candidate-list { margin-top: 8px; display: grid; gap: 6px; }
.candidate { width: 100%; display: flex; justify-content: space-between; gap: 12px; align-items: center; border: 1px solid #d0ddd3; background: white; border-radius: 8px; padding: 8px 11px; text-align: left; min-height: 52px; }
.candidate-selected { border-color: var(--green); background: var(--green-light); box-shadow: inset 2px 0 var(--green); }
.candidate-info { min-width: 0; overflow-wrap: anywhere; }
.candidate-info strong { font-size: .9rem; }
.candidate-info small { display: block; font-size: .79rem; color: var(--muted); }
.candidate-rec { display: inline-block; background: #deeedc; color: #28543a; border-radius: 6px; padding: 2px 5px; font-size: .69rem; white-space: nowrap; }
.candidate-distance { white-space: nowrap; font-size: .89rem; font-weight: 700; }

.timeline-total { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.timeline-total > div { display: grid; gap: 3px; border: 1px solid #d5e5d8; background: #eef6ef; padding: 10px 12px; border-radius: 8px; min-width: 0; }
.timeline-total span { color: var(--muted); font-size: .82rem; }
.timeline-total strong { font-size: clamp(.9rem, 1.9vw, 1.17rem); font-variant-numeric: tabular-nums; line-height: 1.5; }
.timeline-wrap { max-width: 100%; overflow-x: auto; }
.timeline { border-collapse: collapse; width: 100%; text-align: left; font-size: .88rem; }
.timeline th { background: #f3f6f3; color: #41584b; font-size: .77rem; }
.timeline th, .timeline td { padding: 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
.timeline th:last-child, .timeline td:last-child { min-width: 6em; }
.timeline time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.timeline small { display: block; color: var(--muted); font-size: .76rem; }
.toast { position: fixed; z-index: 10; inset: auto 17px 17px auto; max-width: min(90vw, 440px); color: white; padding: 10px 15px; border-radius: 8px; background: #174e3b; box-shadow: 0 2px 14px #162b2452; font-size: .94rem; pointer-events: none; }
.toast.toast-error { background: #8d3529; }

@media (min-width: 1250px) {
  .workspace-grid { grid-template-columns: minmax(310px, 355px) minmax(0, 1fr); gap: 22px; }
}

@media (min-width: 1160px) {
  .station-active-layout { display: grid; grid-template-columns: minmax(185px, .65fr) minmax(345px, 1.35fr); gap: 20px; align-items: start; }
  .station-active-layout .facts { grid-template-columns: 1fr; }
  .station-active-layout .dispatch { border-left: 1px solid var(--line); border-top: 0; padding: 0 0 0 18px; margin: 0; min-width: 0; }
  .station-active-layout .patrol-map { height: 320px; }
}

@media (max-width: 800px) {
  .topbar { padding-inline: 13px; }
  .workspace { width: min(100% - 26px, 590px); padding-top: 20px; }
  .workspace-grid { display: block; }
  .workspace-grid .work-panel { display: none; }
  .workspace.mobile-detail .work-panel { display: block; }
  .workspace.mobile-detail .queue { display: none; }
  .mobile-back { display: inline-flex; }
  .mobile-detail .page-head { margin-bottom: 12px; }
  .work-panel { min-height: 350px; }
  .ticket-top { flex-wrap: wrap; gap: 6px 9px; }
  .ticket-top > div { flex: 1 1 65%; }
  .ticket-top .mobile-back { flex: 0 0 auto; }
  .patrol-map { height: 310px; }
  .login-shell { grid-template-columns: 1fr; }
  .login-side { padding: 17px 24px; }
  .login-side-body { display: none; }
  .login-content { place-items: start center; padding: 21px 15px; }
}

@media (max-width: 500px) {
  .login-card { padding: 18px; }
  .topbar-account { gap: 8px; }
  .account strong { max-width: 94px; font-size: .8rem; }
  .account small { font-size: .68rem; }
  .topbar-leave { padding-inline: 7px; font-size: .73rem; }
  .brand-mark { width: 34px; height: 34px; font-size: 1.14rem; border-radius: 8px; }
  .brand { gap: 6px; }
  .brand strong { font-size: 1.05rem; }
  .brand small { font-size: .65rem; }
  .page-head { align-items: start; flex-wrap: wrap; }
  .page-head h1 { font-size: 1.53rem; }
  .page-head .btn { min-height: 38px; font-size: .82rem; padding-inline: 8px; }
  .work-panel { padding: 13px; }
  .editor-grid { gap: 9px; }
  .editor-grid .field { grid-column: 1 / -1; }
  .pin-form .editor-grid .field { grid-column: auto; }
  .audio-capture { grid-template-columns: 1fr; }
  .location-card { flex-wrap: wrap; gap: 7px; padding: 11px; }
  .location-copy { flex: 1 1 170px; }
  .location-actions { margin-left: 42px; }
  .location-card .btn { min-height: 37px; }
  .timeline { font-size: .8rem; }
  .timeline th, .timeline td { padding: 7px 5px; }
  .timeline-total { grid-template-columns: 1fr; }
}
.summary-stages { margin-bottom: 15px; }
.summary-stages h3 { font-size: .98rem; margin: 7px 0 8px; }
.map-marker-stale { background: #687570; border-style: dashed; }
