/* ============================================================
   GPS BM — ระบบเช็คอินภาคสนาม
   Design tokens: clean / minimal / corporate (TH)
   ============================================================ */

:root {
  /* neutrals — cool slate */
  --ink:      #15181E;
  --ink-2:    #4A5462;
  --ink-3:    #828D9C;
  --line:     #E7EBF0;
  --line-2:   #F0F3F7;
  --surface:  #FFFFFF;
  --bg:       #F3F5F8;
  --bg-2:     #EBEEF3;

  /* brand — corporate blue (trust / fleet) */
  --brand:      #1B4DB3;
  --brand-700:  #163F92;
  --brand-tint: #EAF0FB;
  --brand-tint2:#DCE7FA;

  /* semantics */
  --start:      #0E7C56;   /* เริ่มต้น / ออกเดินทาง */
  --start-tint: #E4F3EC;
  --end:        #1B4DB3;   /* สิ้นสุด / ถึงที่หมาย (brand) */
  --end-tint:   #EAF0FB;
  --warn:       #A65A12;   /* NA / ยังไม่สิ้นสุด */
  --warn-tint:  #FBF0E3;
  --danger:     #B5342B;
  --danger-tint:#FBEAE8;
  --ok:         #0E7C56;

  --shadow-1: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.07);
  --shadow-2: 0 4px 12px rgba(16,24,40,.06), 0 2px 6px rgba(16,24,40,.05);
  --shadow-3: 0 18px 48px rgba(16,24,40,.14), 0 6px 18px rgba(16,24,40,.08);

  --r-xs: 8px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 24px;

  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: "IBM Plex Sans Thai", system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--sans);
  color: var(--ink);
  background: #DFE3EA;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }
::selection { background: var(--brand-tint2); }

/* numbers / data */
.num { font-family: var(--mono); font-feature-settings: "tnum" 1; letter-spacing: -.01em; }

/* ---- generic helpers ---- */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; }
.gap-10 { gap: 10px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.grow { flex: 1; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }

/* ============================================================
   STAGE — showcase shell
   ============================================================ */
#root { min-height: 100vh; }

.stage {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 600px at 80% -10%, #EAEFF6 0%, transparent 60%),
    linear-gradient(180deg, #E4E8EF 0%, #DCE1E9 100%);
}

.stage-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid rgba(21,24,30,.07);
  background: rgba(255,255,255,.55);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 40;
}
.brandmark { display: flex; align-items: center; gap: 12px; }
.brandmark .glyph {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(150deg, var(--brand) 0%, var(--brand-700) 100%);
  display: grid; place-items: center; color: #fff;
  box-shadow: var(--shadow-1), inset 0 1px 0 rgba(255,255,255,.25);
}
.brandmark .title { font-weight: 600; font-size: 16px; letter-spacing: .01em; white-space: nowrap; }
.brandmark .sub { font-size: 12.5px; color: var(--ink-3); margin-top: -1px; white-space: nowrap; }

.seg {
  display: inline-flex; background: var(--bg-2); border-radius: 999px;
  padding: 4px; gap: 2px; border: 1px solid rgba(21,24,30,.05);
}
.seg button {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 500;
  color: var(--ink-2); transition: all .16s ease;
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

.stage-body { flex: 1; display: grid; place-items: start center; padding: 40px 20px 80px; }

/* ============================================================
   MOBILE APP
   ============================================================ */
.m-app {
  position: relative; height: 100%; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
}
.m-scroll { flex: 1; overflow-y: auto; padding-top: 54px; }
.m-scroll::-webkit-scrollbar { width: 0; }

.m-header { padding: 14px 20px 6px; }
.m-greeting { font-size: 13px; color: var(--ink-3); }
.m-name { font-size: 22px; font-weight: 600; letter-spacing: .005em; margin-top: 1px; }

.avatar {
  border-radius: 50%; display: grid; place-items: center;
  font-weight: 600; color: #fff; flex-shrink: 0;
  background: linear-gradient(150deg, #4D6FBF, #2B4F9E);
  letter-spacing: .02em;
}

.m-card {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1); border: 1px solid var(--line);
}
.m-sectiontitle {
  font-size: 12px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-3);
  padding: 4px 4px 10px;
}

/* status / open-trip card */
.statuscard { padding: 18px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px 5px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; letter-spacing: .01em;
}
.pill.start { background: var(--start-tint); color: var(--start); }
.pill.end   { background: var(--end-tint); color: var(--end); }
.pill.open  { background: var(--warn-tint); color: var(--warn); }
.pill.dot::before { content:""; width:7px; height:7px; border-radius:50%; background: currentColor; }

.bigbtn {
  width: 100%; padding: 17px; border-radius: var(--r-md);
  font-size: 16.5px; font-weight: 600; color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: var(--shadow-2); transition: transform .12s ease, filter .12s ease;
}
.bigbtn:active { transform: scale(.985); filter: brightness(.97); }
.bigbtn.start { background: linear-gradient(160deg, #14935F, var(--start)); }
.bigbtn.end   { background: linear-gradient(160deg, #2A5EC6, var(--brand-700)); }
.bigbtn:disabled { background: #C4CCD6; color: #fff; box-shadow: none; cursor: not-allowed; }

.statline { display: flex; gap: 10px; }
.statbox {
  flex: 1; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 13px 14px;
}
.statbox .k { font-size: 11.5px; color: var(--ink-3); font-weight: 500; }
.statbox .v { font-size: 22px; font-weight: 600; margin-top: 3px; }
.statbox .v small { font-size: 12px; color: var(--ink-3); font-weight: 500; }

/* bottom tab bar */
.m-tabs {
  display: flex; border-top: 1px solid var(--line);
  background: rgba(255,255,255,.86); backdrop-filter: blur(14px);
  padding: 8px 12px calc(8px + 22px);
}
.m-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--ink-3); font-size: 10.5px; font-weight: 500; padding: 4px;
}
.m-tab.on { color: var(--brand); }

/* trip card (history) */
.tripcard { padding: 14px 16px; }
.route { display: flex; gap: 12px; }
.route .timeline { display: flex; flex-direction: column; align-items: center; padding-top: 4px; }
.route .node { width: 11px; height: 11px; border-radius: 50%; border: 2.5px solid var(--start); background: #fff; }
.route .node.end { border-color: var(--end); }
.route .stalk { width: 2px; flex: 1; background: linear-gradient(var(--start), var(--end)); margin: 2px 0; min-height: 18px; }
.route .stalk.na { background: repeating-linear-gradient(var(--ink-3) 0 4px, transparent 4px 8px); }
.route .stop { padding-bottom: 14px; }
.route .stop:last-child { padding-bottom: 0; }
.route .stop .t { font-size: 12.5px; color: var(--ink-3); }
.route .stop .p { font-size: 15px; font-weight: 600; margin-top: 1px; }

.kmtag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  background: var(--line-2); padding: 5px 10px; border-radius: 999px;
}
.kmtag.na { color: var(--warn); background: var(--warn-tint); }

/* ---- check-in sheet ---- */
.sheet-scrim { position: absolute; inset: 0; background: rgba(16,20,28,.42); z-index: 80;
  opacity: 0; transition: opacity .25s ease; }
.sheet-scrim.show { opacity: 1; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 90;
  background: var(--bg); border-radius: 26px 26px 0 0;
  box-shadow: 0 -12px 40px rgba(16,24,40,.22);
  transform: translateY(100%); transition: transform .32s cubic-bezier(.32,.72,0,1);
  max-height: 94%; display: flex; flex-direction: column;
}
.sheet.show { transform: translateY(0); }
.sheet-grip { width: 38px; height: 5px; border-radius: 999px; background: #CFD6DF; margin: 9px auto 2px; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 8px 18px 14px; }
.sheet-body { overflow-y: auto; padding: 0 18px 14px; }
.sheet-body::-webkit-scrollbar { width: 0; }
.sheet-foot { padding: 14px 18px calc(14px + 22px); border-top: 1px solid var(--line); background: var(--surface); }

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; }
.field .req { color: var(--danger); margin-left: 2px; }
.field .hint { font-size: 11.5px; color: var(--ink-3); font-weight: 400; margin-left: 6px; }
.inp {
  width: 100%; padding: 13px 14px; border-radius: var(--r-sm);
  border: 1.5px solid var(--line); background: var(--surface);
  font-size: 15px; color: var(--ink); transition: border-color .15s ease;
}
.inp:focus { outline: none; border-color: var(--brand); }
.inp::placeholder { color: var(--ink-3); }
.inp.err { border-color: var(--danger); background: var(--danger-tint); }
.inp.odo { font-family: var(--mono); font-size: 18px; font-weight: 600; letter-spacing: .02em; }
textarea.inp { resize: none; line-height: 1.5; }

.errmsg { font-size: 12px; color: var(--danger); margin-top: 6px; display: flex; gap: 5px; align-items: center; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.chip {
  padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: var(--surface); border: 1.5px solid var(--line); color: var(--ink-2);
  transition: all .14s ease;
}
.chip:active { transform: scale(.96); }
.chip.on { background: var(--brand-tint); border-color: var(--brand); color: var(--brand-700); }

/* mini map */
.minimap {
  position: relative; height: 132px; border-radius: var(--r-md); overflow: hidden;
  border: 1.5px solid var(--line); background: #E8EDF1;
}
.minimap .grid { position: absolute; inset: 0; opacity: .5;
  background-image:
    linear-gradient(rgba(120,140,160,.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120,140,160,.18) 1px, transparent 1px);
  background-size: 26px 26px; }
.minimap .road { position: absolute; background: #fff; opacity: .85; }
.minimap .pin {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-100%);
  filter: drop-shadow(0 4px 6px rgba(16,24,40,.28));
}
.minimap .pulse {
  position: absolute; left: 50%; top: 50%; width: 22px; height: 22px;
  transform: translate(-50%,-50%); border-radius: 50%;
  background: rgba(27,77,179,.28); animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(27,77,179,.32); } 100% { box-shadow: 0 0 0 22px rgba(27,77,179,0); } }
@keyframes spin { to { transform: rotate(360deg); } }
.minimap .coordbar {
  position: absolute; left: 8px; bottom: 8px; right: 8px;
  display: flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,.92); backdrop-filter: blur(6px);
  border-radius: 9px; padding: 7px 10px; font-size: 11.5px; box-shadow: var(--shadow-1);
}
.minimap .locating {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(232,237,241,.7); font-size: 13px; color: var(--ink-2); gap: 8px;
}

.photo-slot {
  height: 92px; border-radius: var(--r-md); border: 1.5px dashed var(--line);
  background: var(--surface); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; color: var(--ink-3);
  font-size: 13px; transition: all .15s ease;
}
.photo-slot:active { transform: scale(.99); }
.photo-slot.filled { border-style: solid; border-color: var(--start); color: var(--start); position: relative; overflow: hidden; }
.photo-slot .thumb { position: absolute; inset: 0; }

/* success */
.success-ico {
  width: 72px; height: 72px; border-radius: 50%; margin: 12px auto 4px;
  display: grid; place-items: center; color: #fff;
}

/* ============================================================
   DESKTOP REPORT
   ============================================================ */
.rpt { background: var(--bg); min-height: 100%; color: var(--ink); }
.rpt-head {
  padding: 22px 30px; border-bottom: 1px solid var(--line); background: var(--surface);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 20px;
}
.rpt-title { font-size: 21px; font-weight: 600; }
.rpt-sub { font-size: 13px; color: var(--ink-3); margin-top: 3px; }

.monthsel {
  display: inline-flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 8px 7px 14px;
  font-size: 14px; font-weight: 500; background: var(--surface);
}
.monthsel button { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; color: var(--ink-2); }
.monthsel button:hover { background: var(--bg-2); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 15px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  transition: all .14s ease;
}
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--brand-700); }
.btn-primary:disabled { background: #C4CCD6; cursor: not-allowed; box-shadow: none; }
.btn-ghost { border: 1px solid var(--line); color: var(--ink-2); background: var(--surface); }
.btn-ghost:hover { background: var(--bg-2); }

.roleseg { display: inline-flex; background: var(--bg-2); border-radius: 9px; padding: 3px; gap: 2px; }
.roleseg button { padding: 6px 13px; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.roleseg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

.rpt-body { padding: 24px 30px 40px; }

.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 24px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 16px 18px; box-shadow: var(--shadow-1);
}
.kpi .k { font-size: 12px; color: var(--ink-3); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 27px; font-weight: 600; margin-top: 8px; line-height: 1; }
.kpi .v small { font-size: 13px; color: var(--ink-3); font-weight: 500; margin-left: 3px; }
.kpi .delta { font-size: 12px; margin-top: 7px; font-weight: 600; }
.kpi.accent { background: linear-gradient(160deg, #1E54BD, var(--brand-700)); border: none; color: #fff; }
.kpi.accent .k, .kpi.accent .v small { color: rgba(255,255,255,.78); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); overflow: hidden; }
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 600; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-weight: 600; color: var(--ink-3); font-size: 11.5px;
  letter-spacing: .03em; text-transform: uppercase; padding: 11px 16px;
  border-bottom: 1px solid var(--line); background: var(--line-2);
}
table.tbl th.r, table.tbl td.r { text-align: right; }
table.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
.personrow { cursor: pointer; transition: background .12s; }
.personrow:hover { background: var(--bg); }
.personrow.open { background: var(--brand-tint); }

.tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
}
.tag.sales { background: #EAF0FB; color: var(--brand-700); }
.tag.project { background: #F0ECF9; color: #6B3FA0; }
.tag.na { background: var(--warn-tint); color: var(--warn); }

.detailwrap { background: var(--bg); padding: 4px 16px 16px; }
.detailwrap table.sub { width: 100%; border-collapse: collapse; font-size: 12.5px; background: var(--surface); border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.detailwrap .sub th { background: transparent; border-bottom: 1px solid var(--line); padding: 9px 14px; }
.detailwrap .sub td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); }

.diffbar { display: inline-flex; align-items: center; gap: 8px; }
.diffbar .track { width: 60px; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.diffbar .fill { height: 100%; border-radius: 999px; }

.wp { display: flex; gap: 8px; align-items: flex-start; padding: 12px 16px; background: var(--warn-tint); border-radius: 12px; font-size: 12.5px; color: #6B3D0E; }

.tooltip-wrap { position: relative; display: inline-flex; }
.tooltip {
  position: absolute; bottom: calc(100% + 8px); right: 0; width: 220px;
  background: var(--ink); color: #fff; font-size: 12px; font-weight: 400; line-height: 1.5;
  padding: 9px 12px; border-radius: 9px; box-shadow: var(--shadow-2);
  opacity: 0; pointer-events: none; transform: translateY(4px); transition: all .16s ease; z-index: 10;
}
.tooltip-wrap:hover .tooltip { opacity: 1; transform: translateY(0); }

/* ============================================================
   REAL APP — shell, login, responsive
   ============================================================ */
html, body, #root { height: 100%; }
body { background: var(--bg); }

.gpsapp { height: 100%; display: flex; flex-direction: column; }

.demo-banner {
  background: #FBF0E3; color: #6B3D0E; font-size: 12.5px; font-weight: 500;
  padding: 8px 16px; display: flex; align-items: center; gap: 8px; justify-content: center;
  border-bottom: 1px solid #F0DEC4; text-align: center; flex-wrap: wrap;
}
.demo-banner b { font-weight: 700; }

/* ---------- Login ---------- */
.login-wrap {
  flex: 1; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 80% -10%, #EAEFF6 0%, transparent 60%),
    linear-gradient(180deg, #EEF1F6 0%, #E4E8EF 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border-radius: var(--r-xl); box-shadow: var(--shadow-3); padding: 32px 28px;
}
.login-logo {
  width: 56px; height: 56px; border-radius: 16px; margin-bottom: 18px;
  background: linear-gradient(150deg, var(--brand), var(--brand-700));
  display: grid; place-items: center; color: #fff;
  box-shadow: var(--shadow-1), inset 0 1px 0 rgba(255,255,255,.25);
}
.login-card h1 { font-size: 22px; font-weight: 600; margin: 0 0 3px; }
.login-card .sub { color: var(--ink-3); font-size: 13.5px; margin-bottom: 24px; }
.pin-input { letter-spacing: .3em; }

/* ---------- Employee app ---------- */
.emp { flex: 1; width: 100%; max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; min-height: 0; position: relative; background: var(--bg); box-shadow: 0 0 0 1px var(--line); }
.app-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.app-top .who { display: flex; align-items: center; gap: 11px; min-width: 0; }
.app-top .who .nm { font-weight: 600; font-size: 15px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-top .who .rl { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.iconbtn { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; color: var(--ink-2); background: var(--bg-2); flex-shrink: 0; }
.iconbtn:hover { background: var(--line); }

.emp-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.emp-tabs { display: flex; border-top: 1px solid var(--line); background: var(--surface); }
.emp-tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--ink-3); font-size: 11px; font-weight: 500; padding: 10px 4px; }
.emp-tab.on { color: var(--brand); }

/* ---------- check-in overlay (bottom sheet) ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; }
.overlay .sheet { max-height: 92%; }
.overlay .sheet-foot { padding: 14px 18px; }
.emp-tabs { padding-bottom: env(safe-area-inset-bottom, 0); }

/* real google map */
.gmap { height: 150px; border-radius: var(--r-md); overflow: hidden; border: 1.5px solid var(--line); background: #E8EDF1; }

/* ---------- Admin report responsive ---------- */
.rpt-shell { flex: 1; overflow-y: auto; background: var(--bg); }
.tbl-scroll { overflow-x: auto; }
@media (max-width: 720px) {
  .kpis { grid-template-columns: repeat(2, 1fr) !important; }
  .rpt-head { flex-direction: column; align-items: stretch !important; }
  .rpt-head .row { flex-wrap: wrap; }
  .rpt-body { padding: 18px 16px 32px !important; }
  table.tbl { min-width: 680px; }
}
@media (max-width: 440px) {
  .kpis { grid-template-columns: 1fr !important; }
}

/* spinner */
.spin { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.spin.dark { border-color: #C3CEDC; border-top-color: var(--brand); }
