:root {
  --ink: #1E2528; --ground: #F3F4F2; --surface: #FFFFFF; --border: #DADFDD; --muted: #4F5A5E;
  --accent: #B4530F; --tint: #FBEADC; --accent-ink: #6B2F05; --ok: #1F6B57; --ok-tint: #E2EFE9;
  --grey: #6F7A7E; --map: #E9ECEA; --grid: #DCE1DE;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: 'Noto Sans Thai', system-ui, 'Leelawadee UI', Tahoma, sans-serif;
  font-size: 15px; line-height: 1.6;
}
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; line-height: 1.5; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2 { margin: 0; line-height: 1.4; }
h1 { font-size: 18px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 700; }
.muted { color: var(--muted); }
.sm { font-size: 13px; }
.ok { color: var(--ok); font-weight: 600; }
.grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.warn { margin: 0; color: var(--accent-ink); background: var(--tint); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.warn[hidden] { display: none; }

/* top bar */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 8px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
}
.brand { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; flex: 1 1 auto; min-width: 0; }
.brand .name { font-size: 20px; font-weight: 700; color: var(--accent); }
.badge { font-size: 12px; color: var(--muted); background: var(--ground); border: 1px solid var(--border); border-radius: 999px; padding: 0 10px; }
.tabs { display: flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.tabs button { min-height: 44px; min-width: 88px; padding: 0 18px; border: 0; background: var(--surface); font-weight: 600; }
.tabs button[aria-current="true"] { background: var(--accent); color: #fff; }
.reset { min-height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-size: 14px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }
@media (max-width: 560px) {
  .tabs { order: 3; flex: 1 1 100%; }
  .tabs button { flex: 1; }
}

/* customer phone column */
.custwrap { padding: 16px; }
.phone { max-width: 420px; margin: 0 auto; background: var(--ground); border: 1px solid var(--border); border-radius: 18px; overflow: clip; display: flex; flex-direction: column; }
.phead { background: var(--surface); padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.back { width: 44px; height: 44px; border: 0; border-radius: 10px; background: var(--ground); font-size: 24px; line-height: 1; }
.body { padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.lab { font-size: 14px; font-weight: 600; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.dates { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.chip {
  min-height: 44px; padding: 4px 6px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface);
  font-size: 14px; font-weight: 600; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.chip small { font-size: 11px; font-weight: 400; }
.chip.on { border-color: var(--accent); background: var(--tint); color: var(--accent-ink); }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.seg .chip { border: 0; border-radius: 0; }
.seg .chip.on { background: var(--accent); color: #fff; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.card.nopad { padding: 0; overflow: hidden; gap: 0; }
textarea { width: 100%; border: 0; resize: vertical; min-height: 76px; padding: 0; background: transparent; line-height: 1.6; }
textarea:focus-visible { outline-offset: 6px; }
.photos { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.addphoto { position: relative; min-height: 44px; min-width: 96px; padding: 0 12px; border: 1.5px dashed var(--grey); border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; cursor: pointer; }
.addphoto:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.addphoto input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.mapfoot { padding: 8px 12px; display: flex; flex-direction: column; }
.est { background: var(--tint); border-radius: 12px; padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; color: #5E3A1E; }
.est > div { display: flex; flex-direction: column; }
.est b { font-size: 22px; color: var(--accent-ink); line-height: 1.4; }
.est .note { max-width: 140px; text-align: right; line-height: 1.5; }
.cta { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 8px; margin-top: auto; z-index: 10; }
.cta .row { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.primary { min-height: 52px; border: 0; border-radius: 14px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 600; padding: 4px 16px; }
.primary:disabled { background: #E3E7E5; color: var(--muted); }

/* maps */
.map {
  position: relative; width: 100%; aspect-ratio: 1; overflow: hidden; background: var(--map);
  background-image: linear-gradient(var(--grid) 2px, transparent 2px), linear-gradient(90deg, var(--grid) 2px, transparent 2px);
  background-size: 20% 20%;
}
#cmap { cursor: crosshair; }
.road { position: absolute; background: #fff; pointer-events: none; }
.road.h { left: 0; right: 0; height: 12px; }
.road.v { top: 0; bottom: 0; width: 12px; }
.road.thin.h { height: 8px; }
.road.thin.v { width: 8px; }
.center { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border: 2px solid var(--grey); border-radius: 50%; pointer-events: none; }
.maptip { position: absolute; left: 8px; bottom: 8px; background: #fff; border-radius: 8px; padding: 2px 10px; font-size: 12px; color: var(--muted); pointer-events: none; }
.range { position: absolute; aspect-ratio: 1; border-radius: 50%; border: 2px dashed rgba(180, 83, 15, 0.55); background: rgba(180, 83, 15, 0.07); pointer-events: none; }
.pin { position: absolute; width: 44px; height: 44px; transform: translate(-50%, -100%); padding: 0; border: 0; background: none; z-index: 3; }
span.pin { pointer-events: none; }
.pin i {
  position: absolute; left: calc(50% - var(--s) / 2); top: calc(44px - var(--s) * 1.207); width: var(--s); height: var(--s);
  border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--c); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.pin.big { z-index: 4; }
.pin.big i { outline: 3px solid rgba(180, 83, 15, 0.35); }
.dot { position: absolute; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%; border: 2px solid var(--grey); background: #fff; z-index: 1; }
.dot.free { background: var(--ok); border-color: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); }
.dot.rec { outline: 3px solid rgba(31, 107, 87, 0.35); outline-offset: 2px; }
.num { width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; line-height: 1; }
.num.onmap { position: absolute; margin: -14px 0 0 -14px; z-index: 2; border: 2px solid #fff; }
.num.onmap.sel { background: var(--accent); outline: 3px solid rgba(180, 83, 15, 0.35); }
.legend { margin: 0; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); font-size: 12px; line-height: 1.6; }
.legend .k { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin: 0 6px 0 10px; vertical-align: middle; }
.legend .k:first-child { margin-left: 0; }
.k.pk { background: var(--accent); }
.k.pg { background: var(--grey); }
.k.dg { background: var(--ok); }
.k.dw { background: #fff; border: 1.5px solid var(--grey); }

/* step 2 + 3 */
.listhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.techs { display: flex; flex-direction: column; gap: 10px; }
.tech { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: var(--surface); border: 1.5px solid var(--border); text-align: left; width: 100%; }
.tech.on { background: var(--tint); border-color: var(--accent); }
.tinfo { display: flex; flex-direction: column; flex: 1; min-width: 0; gap: 2px; }
.tinfo b { font-size: 15px; }
.tdist { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; text-align: right; }
.tdist b { font-size: 15px; }
.empty { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.done { border-color: var(--ok); background: var(--ok-tint); }
.jobno { font-size: 26px; color: var(--ok); line-height: 1.4; }
dl { margin: 0; display: flex; flex-direction: column; gap: 6px; }
dl > div { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
dt { color: var(--muted); flex-shrink: 0; }
dd { margin: 0; text-align: right; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { position: relative; padding-left: 28px; color: var(--muted); }
.timeline li::before { content: ''; position: absolute; left: 2px; top: 6px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); background: #fff; }
.timeline li.active { color: var(--ink); font-weight: 700; }
.timeline li.active::before { border-color: var(--ok); background: var(--ok); }

/* admin */
.admin { max-width: 1280px; margin: 0 auto; }
.ahead { background: var(--ink); color: #fff; padding: 10px 24px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 24px; }
.ahead span { color: #B9C2C5; }
.stats { display: flex; flex-wrap: wrap; gap: 4px 24px; font-size: 14px; }
.stats span { color: #fff; }
.stats b { color: #F2A766; font-size: 17px; }
.agrid { display: grid; grid-template-columns: 400px minmax(0, 1fr); align-items: stretch; }
.jobs { background: var(--surface); border-right: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.jobs .listhead { padding: 2px 4px 4px; }
.job { text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1.5px solid #E3E7E5; width: 100%; }
.job.on { background: var(--tint); border-color: var(--accent); }
.jtop { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.jtop b { flex: 1; min-width: 0; font-size: 14px; }
.pill { font-size: 11px; font-weight: 600; padding: 0 8px; border-radius: 10px; white-space: nowrap; background: var(--tint); color: var(--accent-ink); }
.pill.done { background: var(--ok-tint); color: var(--ok); border: 0; }
.newtag { font-size: 11px; font-weight: 700; padding: 0 8px; border-radius: 10px; background: var(--accent); color: #fff; }
.amap { padding: 16px; display: flex; flex-direction: column; gap: 0; }
.amap .map { max-width: 520px; margin: 0 auto; border: 1px solid var(--border); border-radius: 12px 12px 0 0; }
.amap .legend { max-width: 520px; width: 100%; margin: 0 auto; border: 1px solid var(--border); border-top: 0; }
.selbar { max-width: 520px; width: 100%; margin: 12px auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.selbar .grow { min-width: 200px; }
.seltitle { font-size: 16px; line-height: 1.5; }
.selbar .primary { font-size: 15px; min-height: 48px; border-radius: 12px; }
@media (max-width: 860px) {
  .agrid { grid-template-columns: minmax(0, 1fr); }
  .jobs { border-right: 0; border-bottom: 1px solid var(--border); }
  .amap { padding: 12px; }
  .ahead { padding: 10px 16px; }
  .selbar .primary { width: 100%; }
}
