/* ===== GGPS Tracking — app.css ===== */
:root {
  --ggps-header-h: 48px;
  --ggps-bottomnav-h: 56px;
  --ggps-blue: #1b4f8a;        /* neptune deep blue เดิม */
  --ggps-blue-dark: #143a66;
  --ggps-accent: #0d6efd;
  --ggps-panel-bg: #f5f7fa;
  --ggps-border: #d7dde5;
}
html, body { height: 100%; }
body.ggps-app {
  margin: 0; overflow: hidden; background: var(--ggps-panel-bg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", "Sarabun", Tahoma, sans-serif;
  font-size: 13px;
}
.ggps-app .form-control, .ggps-app .form-select, .ggps-app .btn { font-size: 13px; }
.ggps-app .form-control-sm, .ggps-app .form-select-sm, .ggps-app .btn-sm { font-size: 12px; }

/* ---------- header ---------- */
.ggps-header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--ggps-header-h); z-index: 1030;
  display: flex; align-items: center; gap: 12px; padding: 0 10px;
  background: linear-gradient(180deg, var(--ggps-blue) 0%, var(--ggps-blue-dark) 100%); color: #fff;
}
.ggps-logo img { display: block; }
.ggps-tabs { display: flex; gap: 2px; margin-left: 12px; height: 100%; }
.ggps-tabs .ggps-tab {
  background: transparent; border: 0; color: rgba(255,255,255,.8); padding: 0 14px; height: 100%;
  border-bottom: 3px solid transparent; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.ggps-tabs .ggps-tab:hover { color: #fff; background: rgba(255,255,255,.08); }
.ggps-tabs .ggps-tab.active { color: #fff; border-bottom-color: #ffc107; }
.ggps-header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.ggps-impersonate { display: inline-flex; gap: 4px; align-items: center; flex-wrap: wrap; max-width: 46vw; }
.ggps-impersonate .badge { font-weight: 500; }
.ggps-help { color: #fff; text-decoration: none; }
.ggps-help:hover { text-decoration: underline; color: #fff; }
.ggps-lang { width: 64px; padding: 2px 22px 2px 6px; }
.ggps-logout img { display: block; }

/* ---------- main / panes ---------- */
.ggps-main { position: fixed; top: var(--ggps-header-h); left: 0; right: 0; bottom: 0; }
.ggps-pane { display: none; position: absolute; inset: 0; }
.ggps-pane.active { display: block; }
.ggps-stub { height: 100%; display: flex; align-items: center; justify-content: center; font-size: 16px; }

/* ---------- bottom nav (mobile) ---------- */
.ggps-bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--ggps-bottomnav-h); z-index: 1030;
  background: #fff; border-top: 1px solid var(--ggps-border); padding-bottom: env(safe-area-inset-bottom);
}
.ggps-bottomnav .ggps-tab {
  flex: 1; border: 0; background: transparent; color: #6c757d; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: 11px; padding: 4px 0;
}
.ggps-bottomnav .ggps-tab.active { color: var(--ggps-accent); }
.ggps-ico { width: 22px; height: 22px; display: inline-block; background: currentColor;
  -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat; }
.ggps-ico-geo     { --ico: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10zm0-7a3 3 0 1 1 0-6 3 3 0 0 1 0 6z'/></svg>"); }
.ggps-ico-route   { --ico: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M3 1a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm10 10a2 2 0 1 0 0 4 2 2 0 0 0 0-4zM3.5 5v3.5A2.5 2.5 0 0 0 6 11h5.5v-1H6A1.5 1.5 0 0 1 4.5 8.5V5h-1z'/></svg>"); }
.ggps-ico-report  { --ico: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M4 0h5.5L14 4.5V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm5 1v3a1 1 0 0 0 1 1h3L9 1zM4.5 8h7v1h-7V8zm0 2h7v1h-7v-1zm0 2h5v1h-5v-1z'/></svg>"); }
.ggps-ico-chart   { --ico: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M1 15h14v1H1zM2 9h2v5H2zm4-4h2v9H6zm4 2h2v7h-2zm4-5h2v12h-2z'/></svg>"); }
.ggps-ico-polygon { --ico: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M2 3l6-2 6 2v8l-6 4-6-4V3zm1.2.8v6.7L8 13.8l4.8-3.3V3.8L8 2.2 3.2 3.8z'/></svg>"); }
.ggps-ico-gear    { --ico: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M9.4 1l.4 1.8 1.6.7 1.6-.9 1.4 1.4-.9 1.6.7 1.6L16 7.6v2l-1.8.4-.7 1.6.9 1.6-1.4 1.4-1.6-.9-1.6.7L9.4 16h-2l-.4-1.8-1.6-.7-1.6.9-1.4-1.4.9-1.6-.7-1.6L0 9.4v-2l1.8-.4.7-1.6-.9-1.6 1.4-1.4 1.6.9 1.6-.7L7.4 1h2zM8 5a3 3 0 1 0 0 6 3 3 0 0 0 0-6z'/></svg>"); }

/* ---------- Track tab layout ---------- */
.tk-layout { position: absolute; inset: 0; display: flex; }
.tk-left { width: 700px; min-width: 400px; max-width: 80%; display: flex; flex-direction: column; background: #fff; border-right: 1px solid var(--ggps-border); }
.tk-left.collapsed { width: 0 !important; min-width: 0; overflow: hidden; border-right: 0; }
.tk-splitter { width: 6px; cursor: col-resize; background: #e3e8ee; border-right: 1px solid var(--ggps-border); flex: 0 0 auto; position: relative; }
.tk-splitter:hover { background: #cfd8e3; }
.tk-splitter .tk-collapse-btn {
  position: absolute; top: 50%; left: -1px; transform: translateY(-50%); width: 8px; height: 48px;
  background: #9aa7b5; border: 0; border-radius: 0 3px 3px 0; padding: 0; cursor: pointer; color: #fff; font-size: 8px; line-height: 48px;
}
.tk-right { flex: 1; position: relative; min-width: 0; }
.tk-panel-title { padding: 6px 10px; background: var(--ggps-blue); color: #fff; font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.tk-toolbar { padding: 6px 8px; border-bottom: 1px solid var(--ggps-border); background: var(--ggps-panel-bg); display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.tk-toolbar .form-check { margin: 0; }
.tk-toolbar .form-check-label { cursor: pointer; }
.tk-search { position: relative; flex: 1; min-width: 160px; }
.tk-search .tk-search-clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: #888; padding: 0 6px; line-height: 1; }
.tk-grid-wrap { flex: 1; min-height: 0; position: relative; }
.tk-grid { height: 100%; }
.tk-pager { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-top: 1px solid var(--ggps-border); background: var(--ggps-panel-bg); font-size: 12px; }
.tk-pager .btn { padding: 0 8px; line-height: 24px; }
.tk-pager .tk-page-input { width: 52px; text-align: center; padding: 0 4px; height: 26px; }
.tk-pager .ms-auto { color: #555; }
.tk-address { border-top: 1px solid var(--ggps-border); background: #fff; }
.tk-address .tk-address-title { font-weight: 600; padding: 4px 10px; background: #eef2f6; border-bottom: 1px solid var(--ggps-border); display: flex; align-items: center; justify-content: space-between; }
.tk-address .tk-address-body { padding: 6px 10px; min-height: 40px; max-height: 90px; overflow: auto; line-height: 1.45; }

/* Tabulator ปรับ */
.tk-grid .tabulator { font-size: 12px; border: 0; }
.tk-grid .tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 4px 4px; font-size: 12px; }
.tk-grid .tabulator-row .tabulator-cell { padding: 3px 6px; }
.tk-grid .tabulator-row.tabulator-selected { background-color: #cfe2ff !important; }
.tk-grid .tabulator-row.tabulator-selectable:hover { background-color: #e9f1ff; }
.tk-grid .tabulator-cell img { vertical-align: middle; }
.tk-grid .tk-speed-cell { display: block; margin: -3px -6px; padding: 3px 6px; text-align: right; }
.tk-grid .tabulator-cell .tk-actions { display: flex; gap: 3px; align-items: center; justify-content: center; }
.tk-grid .tabulator-cell .tk-actions img, .tk-grid .tabulator-cell .tk-actions .tk-act { width: 16px; height: 16px; cursor: pointer; }
.tk-grid .tabulator-cell .tk-actions .tk-act-placeholder { width: 16px; height: 16px; display: inline-block; }

/* map toolbar */
.tk-maptool { position: absolute; top: 8px; left: 8px; right: 8px; z-index: 5; display: flex; gap: 6px; align-items: center; pointer-events: none; }
.tk-maptool > * { pointer-events: auto; }
.tk-maptool .btn-group .btn, .tk-maptool .btn.tk-tool { background: #fff; border-color: #c9d1da; padding: 3px 7px; }
.tk-maptool .btn.active { background: #cfe2ff; border-color: #9ec5fe; }
.tk-maptool .btn img { width: 16px; height: 16px; display: block; }
.tk-maptool .tk-measure { background: rgba(255,255,255,.95); border: 1px solid #c9d1da; border-radius: 4px; padding: 3px 8px; font-size: 12px; min-width: 150px; }
.tk-maptool .ms-auto { margin-left: auto; }
.tk-legend { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); z-index: 5; background: rgba(255,255,255,.9); padding: 3px 6px; border-radius: 4px; }
.tk-legend img { display: block; max-width: 100%; height: auto; }
.tk-layer-menu { min-width: 220px; font-size: 13px; max-height: 60vh; overflow-y: auto; }
.tk-layer-menu .dropdown-header { font-size: 11px; }
.tk-layer-menu .form-check { padding-left: 1.6em; margin: 2px 12px; }

/* OL overrides */
.tk-right .ol-zoom { top: auto; bottom: 36px; left: 8px; }
.tk-right .ol-scale-line { left: 8px; bottom: 8px; }
.tk-right .ol-attribution { font-size: 10px; }

/* popup */
.ggps-popup {
  position: absolute; background: #fff; border-radius: 6px; border: 1px solid #aab; box-shadow: 0 2px 10px rgba(0,0,0,.25);
  padding: 8px 10px; min-width: 190px; max-width: 280px; font-size: 12px; line-height: 1.45; bottom: 14px; left: -20px;
}
.ggps-popup:after, .ggps-popup:before { top: 100%; border: solid transparent; content: ''; height: 0; width: 0; position: absolute; pointer-events: none; }
.ggps-popup:after { border-top-color: #fff; border-width: 10px; left: 24px; margin-left: -10px; }
.ggps-popup:before { border-top-color: #aab; border-width: 11px; left: 24px; margin-left: -11px; }
.ggps-popup hr { margin: 4px 0; }
.ggps-popup .ggps-popup-close { position: absolute; top: 2px; right: 6px; border: 0; background: transparent; font-size: 16px; line-height: 1; color: #666; cursor: pointer; }
.ggps-popup .ggps-popup-close:hover { color: #000; }

/* detail modal */
.tk-detail .form-label { margin: 0; color: #555; }
.tk-detail .row { margin-bottom: 4px; }
.tk-detail fieldset { border: 1px solid var(--ggps-border); border-radius: 4px; padding: 8px 12px; margin-bottom: 10px; }
.tk-detail legend { float: none; width: auto; font-size: 13px; font-weight: 600; padding: 0 6px; margin: 0; }
.tk-detail .tk-val { word-break: break-word; }

/* in/out area offcanvas */
.tk-area-oc { --bs-offcanvas-width: 480px; }
.tk-area-oc .offcanvas-body { display: flex; flex-direction: column; padding: 0; }
.tk-area-oc .tk-toolbar { flex: 0 0 auto; }
.tk-area-oc .tk-grid-wrap { flex: 1; }

/* ---------- mobile ---------- */
.tk-drawer-handle { display: none; }
@media (max-width: 767.98px) {
  body.ggps-app { font-size: 14px; }
  .ggps-header { gap: 8px; }
  .ggps-main { bottom: var(--ggps-bottomnav-h); }
  .tk-layout { flex-direction: column; }
  .tk-splitter { display: none; }
  .tk-left {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto !important; min-width: 0; max-width: none;
    height: 55%; border-right: 0; border-top: 1px solid var(--ggps-border); border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 16px rgba(0,0,0,.2); z-index: 6; transition: transform .25s ease;
  }
  .tk-left.collapsed { transform: translateY(calc(100% - 38px)); width: auto !important; overflow: visible; }
  .tk-left.full { height: calc(100% - 8px); }
  .tk-drawer-handle { display: flex; align-items: center; justify-content: center; gap: 8px; height: 38px; cursor: pointer; background: #fff; border-radius: 12px 12px 0 0; font-weight: 600; user-select: none; }
  .tk-drawer-handle:before { content: ''; width: 40px; height: 4px; background: #c4ccd6; border-radius: 2px; }
  .tk-panel-title { display: none; }
  .tk-right { flex: 1; }
  .tk-legend { bottom: 44px; }
  .tk-right .ol-zoom { display: none; }
  .tk-right .ol-scale-line { bottom: 44px; }
  .tk-maptool { flex-wrap: wrap; }
  .tk-maptool .tk-measure { min-width: 0; }
  .tk-area-oc { --bs-offcanvas-width: 100%; }
  .tk-address .tk-address-body { max-height: 56px; }
  .tk-toolbar { padding: 4px 6px; gap: 4px 8px; }
}

/* ---------- login page ---------- */
body.ggps-login-page { background: #f2f4f7; min-height: 100vh; margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", Tahoma, sans-serif; }
.ggps-login-wrap { display: flex; flex-direction: column; align-items: center; padding: 40px 16px; gap: 28px; }
.ggps-login-logo { width: 300px; max-width: 80vw; height: auto; }
.ggps-login-card { width: 340px; max-width: 100%; }
.ggps-login-card .card-header { background: var(--ggps-blue); color: #fff; }
.ggps-login-bg { width: 300px; max-width: 70vw; height: auto; opacity: .95; }

/* ---------- Route tab ---------- */
.rt-form { padding: 8px 10px; border-bottom: 1px solid var(--ggps-border); background: var(--ggps-panel-bg); }
.rt-form .rt-lbl { width: 72px; flex: 0 0 auto; }
.rt-form .rt-dt { width: 170px; background: #fff; cursor: pointer; }
.flatpickr-calendar { font-size: 13px; }
@media (max-width: 767.98px) {
  .rt-form { padding: 6px 8px; }
  .rt-form .rt-lbl { width: 64px; }
}

/* ---------- Report tab ---------- */
.rp-layout { position: absolute; inset: 0; display: flex; flex-direction: column; background: #fff; }
.rp-subtabs { flex: 0 0 auto; padding: 6px 8px 0; background: var(--ggps-panel-bg); border-bottom: 1px solid var(--ggps-border); flex-wrap: nowrap; overflow-x: auto; }
.rp-subtabs .nav-link { white-space: nowrap; padding: 6px 12px; }
.rp-content { flex: 1; min-height: 0; position: relative; }
.rp-content > .rp-pane { position: absolute; inset: 0; display: none; flex-direction: column; }
.rp-content > .rp-pane.active { display: flex; }
.rp-toolbar { flex: 0 0 auto; }
.rp-toolbar .vr { height: 22px; opacity: .25; }
.rp-date { width: 118px; background: #fff; cursor: pointer; }
.rp-time { width: 92px; background: #fff; cursor: pointer; }
.rp-num { width: 74px; }
.rp-pane .tk-grid-wrap { flex: 1; }
.rp-grid .tabulator { font-size: 12px; border: 0; }
.rp-grid .tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 4px 4px; }
.rp-grid .tabulator .tabulator-header .tabulator-col.tabulator-col-group .tabulator-col-group-cols .tabulator-col .tabulator-col-content { font-weight: 400; color: #555; }
.rp-grid .tabulator-row .tabulator-cell { padding: 3px 6px; }
.rp-grid .tabulator-cell .tk-act { width: 16px; height: 16px; cursor: pointer; margin: 0 2px; }
.rp-day-dialog { max-width: 900px; }
.rp-day-dialog .modal-content { height: min(640px, 92vh); }
.rp-day-content { flex: 1; min-height: 0; position: relative; }
.rp-day-content > .tab-pane { position: absolute; inset: 0; overflow: auto; }
.rp-day-content > .tab-pane.rp-day-one { display: none; flex-direction: column; overflow: hidden; }
.rp-day-content > .tab-pane.rp-day-one.active { display: flex; }
.rp-day-one .tk-grid { flex: 1; min-height: 0; }
.rp-day-content > .tab-pane.rp-day-two { display: none; flex-direction: column; gap: 6px; overflow: hidden; }
.rp-day-content > .tab-pane.rp-day-two.active { display: flex; }
.rp-day-half { flex: 1; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--ggps-border); border-radius: 4px; }
.rp-day-half .tk-grid { flex: 1; min-height: 0; }
.rp-grid-title { padding: 4px 8px; background: #eef2f6; font-weight: 600; border-bottom: 1px solid var(--ggps-border); }
.rp-summary { background: #8899aa; padding: 15px; border-radius: 15px; font-size: 1.1em; color: #fff; max-width: 860px; margin: 0 auto; }
.rp-summary-title { font-weight: 700; text-align: center; font-size: 1.15em; }
.rp-summary-range { text-align: center; margin-bottom: 8px; }
.summaryReportTable { width: 100%; border-collapse: collapse; background: #E0FFFF; color: #000; }
.summaryReportTable td, .summaryReportTable th { padding: 6px 8px; border: #999 1px solid; }
.summaryReportTable tr:nth-child(even) td { background: #8899aa; color: #fff; }
.summaryReportTable tr:nth-child(odd) td { background: #EAF4FF; }
.summaryReportTable .rp-sum-head td { font-weight: 700; }
.rp-summary-note { color: #0000FF; background: #fff; padding: 8px; margin-top: 8px; border-radius: 6px; font-size: .9em; }
@media (max-width: 767.98px) {
  .rp-toolbar { gap: 4px 6px; }
  .rp-day-dialog .modal-content { height: 100vh; }
  .rp-summary { padding: 8px; border-radius: 8px; font-size: 1em; }
}

/* ---------- Analysis tab ---------- */
.an-left { width: 480px; }
.an-pie { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 8px; }
.an-chart-title { font-weight: 600; padding: 4px 8px; background: #eef2f6; border: 1px solid var(--ggps-border); border-radius: 4px 4px 0 0; }
.an-chart-wrap { flex: 1; min-height: 160px; position: relative; border: 1px solid var(--ggps-border); border-top: 0; padding: 8px; }
.an-right { display: flex; flex-direction: column; gap: 10px; padding: 10px; overflow: auto; background: var(--ggps-panel-bg); }
.an-chart { flex: 1; min-height: 220px; display: flex; flex-direction: column; background: #fff; }
@media (max-width: 767.98px) {
  .an-layout { flex-direction: column; }
  .an-left.tk-left { height: 70%; }
  .an-right { flex: 1; }
  .an-chart { min-height: 200px; }
}

/* ---------- Setting tab ---------- */
.st-layout { position: absolute; inset: 0; display: flex; background: var(--ggps-panel-bg); }
.st-menu { width: 200px; flex: 0 0 auto; background: #fff; border-right: 1px solid var(--ggps-border); display: flex; flex-direction: column; padding: 8px; gap: 4px; }
.st-menu-item { border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 10px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; color: #333; }
.st-menu-item img { width: 32px; height: 32px; }
.st-menu-item:hover { background: #eef2f6; }
.st-menu-item.active { background: #e7f0ff; border-color: #9ec5fe; color: var(--ggps-accent); font-weight: 600; }
.st-cards { flex: 1; min-width: 0; position: relative; }
.st-card { display: none; position: absolute; inset: 0; overflow: auto; padding: 14px; }
.st-card.active { display: block; }
.st-card-grid { display: none; flex-direction: column; padding: 0; background: #fff; overflow: hidden; }
.st-card-grid.active { display: flex; }
.st-card-grid .tk-grid-wrap { flex: 1; }
.st-fs { border: 1px solid var(--ggps-border); border-radius: 6px; padding: 10px 14px 6px; margin-bottom: 12px; background: #fff; }
.st-fs legend { float: none; width: auto; font-size: 13px; font-weight: 600; padding: 0 6px; margin: 0 0 4px; }
.st-fs-w { max-width: 560px; }
.st-vehform .st-fs { padding: 8px 10px 2px; }
.st-pics { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.st-pic { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.st-pic img { height: 24px; }
@media (max-width: 767.98px) {
  .st-layout { flex-direction: column; }
  .st-menu { width: auto; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--ggps-border); padding: 4px; }
  .st-menu-item { flex: 1; flex-direction: row; justify-content: center; padding: 6px 4px; font-size: 12px; }
  .st-menu-item img { width: 22px; height: 22px; }
  .st-card { padding: 8px; }
}
