/* SPX Agency Bot settings PWA. Palette: Siam Dessert (design only). Phone-first, table at >= 900px. */
:root {
  --orange: #DE632A; --orange-h: #A8441A; --orange-a: #8F3913;
  --cocoa: #21140B; --pink: #FAE1D8; --coral: #FF7F50; --cream: #FFF8F4;
  --n1: #F1F1F1; --n2: #F3F3F3; --n3: #CCCCCC;
  --line: #E5D3CA; --line2: #EFE3DD; --muted: #5C4A3F; --green: #2F7D45; --red: #B42318;
  --warn-bg: #FFF1D6; --warn-bd: #E9B44C; --warn-tx: #5A3B00;
  --ease: cubic-bezier(.4, 0, .2, 1);
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--cream); color: var(--cocoa); font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 15px; line-height: 1.45; }
a { color: var(--cocoa); }
a:hover { color: var(--cocoa); }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; user-select: none; touch-action: manipulation; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
p { margin: 0; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.slot { display: contents; }
.loading { padding: 40px 18px; text-align: center; color: var(--muted); }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); }
.foot { font-size: 13px; padding: 4px 2px 0; }

button, a, input, select { transition: background-color .24s var(--ease), border-color .24s var(--ease), color .24s var(--ease), box-shadow .24s var(--ease), transform .12s ease; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 20px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--cocoa); font-weight: 600; text-decoration: none; }
.btn.sm { padding: 0 14px; font-size: 14px; }
.btn.lg { min-height: 52px; font-size: 16px; }
.btn.icon { padding: 0; width: 44px; font-size: 12px; }
.btn-primary { background: var(--orange); border-color: var(--orange); color: var(--cocoa); font-weight: 700; }
.btn-primary:hover:not(:disabled) { background: var(--orange-h); border-color: var(--orange-h); color: #fff; box-shadow: 0 10px 24px rgba(168, 68, 26, .45); transform: translateY(-2px); }
.btn-primary:active:not(:disabled) { background: var(--orange-a); color: #fff; box-shadow: 0 3px 8px rgba(168, 68, 26, .35); transform: translateY(0) scale(.98); }
.btn-primary:disabled { background: var(--n3); border-color: var(--n3); color: #4a3d34; }
.btn-secondary:hover:not(:disabled) { background: var(--cocoa); border-color: var(--cocoa); color: #fff; box-shadow: 0 8px 18px rgba(33, 20, 11, .25); transform: translateY(-2px); }
.btn-secondary:active:not(:disabled) { background: #000; color: #fff; transform: translateY(0) scale(.97); }
.btn-secondary:disabled { opacity: .45; }
.btn-ink { background: var(--cocoa); border-color: var(--cocoa); color: var(--pink); font-weight: 700; }
.btn-ink:hover { background: var(--orange-h); border-color: var(--orange-h); color: #fff; box-shadow: 0 8px 18px rgba(168, 68, 26, .4); transform: translateY(-2px); }
.btn-ink:active { background: var(--orange-a); transform: translateY(0) scale(.97); }
.btn-danger:hover { background: var(--red); border-color: var(--red); color: #fff; box-shadow: 0 8px 18px rgba(180, 35, 24, .35); transform: translateY(-2px); }
.btn-danger:active { background: #8E1B12; color: #fff; transform: translateY(0) scale(.97); }
.btn-danger-solid { background: var(--red); border-color: var(--red); color: #fff; font-weight: 700; }
.btn-danger-solid:hover { background: #8E1B12; border-color: #8E1B12; }
.btn-ghost-dark { min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid #5A4537; background: transparent; color: var(--pink); font-size: 13px; font-weight: 600; }
.btn-ghost-dark:hover { background: var(--orange); border-color: var(--orange); color: var(--cocoa); box-shadow: 0 0 0 4px rgba(222, 99, 42, .3); }
.btn-link { min-height: 44px; padding: 0 12px; border: 0; background: transparent; color: var(--orange-h); font-size: 13px; font-weight: 600; border-radius: 999px; }
.btn-link:hover { background: var(--red); color: #fff; }
.btn-add { min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px dashed var(--orange); background: #fff; color: var(--orange-h); font-weight: 600; }
.btn-add:hover { background: var(--cocoa); border-color: var(--cocoa); color: #fff; transform: translateY(-2px); }
.btn.dry { padding: 0 18px; font-size: 14px; font-weight: 700; border-color: transparent; color: var(--cocoa); }
.btn.dry.sim { background: var(--pink); }
.btn.dry.live { background: var(--orange); }
.btn.dry:hover { background: var(--orange); border-color: var(--orange); color: var(--cocoa); box-shadow: 0 0 0 4px rgba(222, 99, 42, .3); }

/* pill toggle buttons (vehicles, date/time modes, filters) */
.pill { min-height: 48px; padding: 0 8px; border-radius: 12px; border: 2px solid var(--line); background: #fff; color: var(--muted); font-weight: 600; font-size: 14px; }
.pill.sm { min-height: 44px; }
.pill.tall { min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 10px; }
.pill.tall small { font-weight: 400; font-size: 12px; }
.pill[aria-pressed="true"] { background: var(--orange); border-color: var(--orange); color: var(--cocoa); font-weight: 700; }
.pill[aria-pressed="false"]:hover { border-color: var(--orange); color: var(--cocoa); background: var(--pink); box-shadow: 0 6px 14px rgba(222, 99, 42, .25); transform: translateY(-2px); }
.pill[aria-pressed="true"]:hover { background: var(--orange-h); border-color: var(--orange-h); color: #fff; box-shadow: 0 8px 18px rgba(168, 68, 26, .45); transform: translateY(-2px); }
.pill:active { transform: translateY(0) scale(.96); }
.pill[aria-pressed="true"]:active { background: var(--orange-a); color: #fff; }

/* ---- switch ---- */
.switch { position: relative; flex: none; width: 52px; height: 32px; padding: 3px; border-radius: 999px; border: 0; background: var(--n3); display: flex; justify-content: flex-start; }
.switch::after { content: ''; position: absolute; inset: -6px -4px; }
.switch[aria-checked="true"] { background: var(--green); justify-content: flex-end; }
.switch .knob { width: 26px; height: 26px; border-radius: 50%; background: #fff; display: block; }
.switch:hover:not(:disabled) { box-shadow: 0 0 0 4px rgba(47, 125, 69, .18); }
.switch:disabled { opacity: .55; }
.tbl-wrap .switch { width: 48px; height: 28px; }
.tbl-wrap .switch .knob { width: 22px; height: 22px; }

/* ---- quota stepper ---- */
.step { border-radius: 999px; background: #fff; border: 1px solid var(--line); color: var(--cocoa); }
.step.sm { width: 40px; height: 40px; font-size: 18px; }
.step.md { width: 44px; height: 44px; font-size: 20px; }
.step.lg { width: 56px; height: 56px; font-size: 26px; border: 0; background: var(--pink); }
.step:hover:not(:disabled) { background: var(--orange-h); border-color: var(--orange-h); color: #fff; box-shadow: 0 6px 14px rgba(168, 68, 26, .4); transform: scale(1.06); }
.step:active:not(:disabled) { background: var(--orange-a); color: #fff; transform: scale(.94); }
.step:disabled { opacity: .35; cursor: not-allowed; }
.qty { border: 1px solid transparent; border-radius: 10px; background: transparent; text-align: center; font-weight: 700; color: var(--cocoa); -moz-appearance: textfield; appearance: textfield; }
.qty::-webkit-outer-spin-button, .qty::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty.sm { width: 48px; height: 40px; font-size: 16px; }
.qty.md { width: 52px; height: 44px; font-size: 20px; }
.qty.lg { width: 96px; height: 52px; font-size: 28px; border-radius: 12px; }
.qty:hover { border-color: var(--line); }
.qty:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px rgba(222, 99, 42, .22); background: #fff; }
.qgrp { display: inline-flex; align-items: center; gap: 2px; }
@keyframes bumpA { 0% { transform: scale(1); } 40% { transform: scale(1.2); } 100% { transform: scale(1); } }
.bumpA { animation: bumpA .22s ease; }

/* ---- inputs ---- */
.field { min-height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--cocoa); min-width: 0; }
.field::placeholder { color: #75655b; }
.field:hover:not(:disabled) { border-color: #D9B7A8; }
.field:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px rgba(222, 99, 42, .22); }
.field:disabled { background: var(--n2); color: #6b5e55; }
input.field[type="text"], input.field[type="email"], input.field[type="password"] { flex: 1; width: 100%; }
.field.sel { padding-right: 6px; }
.lbl { font-size: 14px; font-weight: 600; }
.chk { width: 22px; height: 22px; accent-color: var(--orange); cursor: pointer; flex: none; }
.chk:hover { transform: scale(1.12); }

/* ---- layout helpers ---- */
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 10px; }
.row.start { align-items: flex-start; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.gap6 { gap: 6px; }
.row.gap8 { gap: 8px; }
.row.gap8 .field[type="date"], .row.gap8 .field[type="time"] { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid { display: grid; gap: 8px; }
.grid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.veh-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
.grid.wk { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }

/* ---- top bar ---- */
.top { background: var(--cocoa); color: #fff; padding: 20px 18px 14px; padding-top: max(20px, env(safe-area-inset-top)); }
.top-in { display: flex; flex-direction: column; gap: 12px; max-width: 1240px; margin: 0 auto; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.top h1 { font-size: 22px; font-weight: 700; }
.bot-status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--pink); }
.bot-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #7BD389; }
.bot-status.warn .dot { background: #F2B84B; }
.bot-status.off .dot { background: var(--coral); }
.tabs { display: flex; gap: 6px; }
.tab { flex: 1; text-align: center; min-height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 999px; border: 1px solid #5A4537; color: var(--pink); text-decoration: none; font-size: 14px; font-weight: 600; }
.tab:hover { background: var(--orange); border-color: var(--orange); color: var(--cocoa); }
.tab[aria-current="page"] { background: var(--pink); border-color: var(--pink); color: var(--cocoa); }
.top-ctl { display: flex; flex-direction: column; gap: 10px; }
.run { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 600; color: var(--pink); }
.ed-top { padding: 14px; padding-top: max(14px, env(safe-area-inset-top)); }
.top-in.ed { flex-direction: row; align-items: center; gap: 10px; }
.top-in.ed h1 { flex: 1; font-size: 20px; }
.back { width: 44px; height: 44px; border-radius: 12px; background: #33241A; display: flex; align-items: center; justify-content: center; }
.back:hover { background: var(--orange); }
.back:hover svg { stroke: var(--cocoa); }

/* ---- pages ---- */
.page { padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.cta-bar { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 12px 0 22px; padding-bottom: max(22px, env(safe-area-inset-bottom)); background: var(--cream); margin: 0 -14px -14px; padding-left: 14px; padding-right: 14px; }
.cta-bar .btn { flex: 1; }
.cta-bar .grow2 { flex: 2; }

/* ---- route card ---- */
.card { background: #fff; border: 2px solid var(--line2); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; transition: box-shadow .24s var(--ease), transform .24s var(--ease), border-color .24s ease; }
.card.route:not(.live) { opacity: .85; }
.card.live { border-color: var(--orange); }
.card:hover { box-shadow: 0 8px 22px rgba(33, 20, 11, .10); transform: translateY(-2px); }
.title-link { flex: 1; min-width: 0; text-decoration: none; display: flex; flex-direction: column; gap: 2px; min-height: 44px; justify-content: center; }
.title-link .sub { font-size: 12px; color: var(--muted); }
.title-link .ttl { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-link:hover .ttl { color: var(--orange-h); text-decoration: underline; text-underline-offset: 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag { padding: 4px 10px; border-radius: 8px; background: var(--n2); font-size: 13px; }
.tag.veh { background: var(--pink); font-weight: 600; }
.note { padding: 6px 10px; border-radius: 8px; background: var(--warn-bg); border: 1px solid var(--warn-bd); font-size: 13px; color: var(--warn-tx); display: block; }
.used { font-size: 14px; color: var(--muted); }
.used strong { color: var(--cocoa); }
.acts { display: grid; grid-template-columns: 1fr 1fr 44px 44px; gap: 6px; }

/* ---- desktop table ---- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tbl-wrap { overflow-x: auto; border-radius: 16px; background: #fff; border: 1px solid var(--line2); }
table { width: 100%; min-width: 980px; border-collapse: collapse; }
th { padding: 12px 14px; background: var(--pink); text-align: left; font-size: 13px; font-weight: 600; }
td { padding: 12px 14px; border-top: 1px solid #F3E6E0; vertical-align: middle; }
th.c, td.c { text-align: center; }
th.narrow, td.narrow { padding-left: 8px; padding-right: 8px; }
.sm-t { font-size: 14px; }
.badge { padding: 2px 8px; border-radius: 6px; background: var(--n2); font-size: 12px; font-weight: 700; }
tbody tr { transition: background-color .15s ease; }
tbody tr:hover { background: #FFF4EE; }
tbody tr.dim { opacity: .75; }
tbody tr:hover td:nth-child(2) a, tbody tr:hover td:nth-child(3) a { color: var(--orange-h); }
td a { text-decoration: none; }
td a:hover { text-decoration: underline; text-underline-offset: 3px; }
.status-t { margin-top: 4px; font-size: 12px; color: #7a4d00; }
td .btn { margin: 0 2px; }

/* ---- editor ---- */
.ed-body { gap: 18px; max-width: 760px; width: 100%; margin: 0 auto; }
.sec { display: flex; flex-direction: column; gap: 8px; }
.sec-t { font-size: 15px; font-weight: 700; }
.sec-t .hint { font-weight: 400; }
.alert { padding: 10px 12px; border-radius: 12px; background: var(--warn-bg); border: 1px solid var(--warn-bd); font-size: 14px; color: var(--warn-tx); }
.chipbox { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; min-height: 44px; border-radius: 14px; background: #fff; border: 1px solid var(--line); }
.chip { display: inline-flex; align-items: center; gap: 2px; padding: 2px 2px 2px 9px; border-radius: 8px; background: var(--pink); font-size: 13px; font-weight: 600; }
.chip.dst { background: var(--cocoa); color: var(--pink); }
.chip.date { font-size: 14px; padding-left: 10px; }
.chip-x { width: 26px; height: 26px; border: 0; background: transparent; color: #7A4A33; font-size: 16px; line-height: 1; border-radius: 999px; }
.chip.dst .chip-x { color: var(--pink); }
.chip-x:hover { background: var(--red); color: #fff; transform: scale(1.1); }
.qbox { display: flex; align-items: center; justify-content: space-between; padding: 8px; border-radius: 14px; background: #fff; border: 1px solid var(--line); }
.qmid { display: inline-flex; align-items: baseline; gap: 4px; font-size: 16px; font-weight: 500; }
.summary { padding: 12px 14px; border-radius: 14px; background: #FDF0EA; border: 1px dashed #E8B9A3; font-size: 14px; line-height: 1.6; }
.rules { font-size: 14px; color: var(--muted); }
.rules summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; color: var(--orange-h); }
.rules ul { margin: 0 0 4px; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.pause { min-height: 48px; border-width: 2px; font-size: 14px; }
.pause.on { background: var(--warn-bg); border-color: var(--warn-bd); }
.ed-bar { border-top: 1px solid #F0E2DB; max-width: 760px; width: 100%; margin: 0 auto; }
.ed-bar .btn-danger { background: #fff; }

/* ---- events ---- */
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.chip-f { white-space: nowrap; flex: none; padding: 0 14px; }
.ev-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ev { background: #fff; border: 1px solid var(--line2); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.ev .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; background: var(--n3); }
.ev.good .dot { background: var(--green); }
.ev.warn .dot { background: var(--orange); }
.ev.bad .dot { background: var(--red); }
.ev time { font-size: 13px; white-space: nowrap; }
.ev-meta { font-size: 14px; }
.ev-detail { font-size: 13px; }
.more { display: flex; justify-content: center; padding: 4px 0 20px; }

/* ---- settings ---- */
.set { gap: 12px; }
.set h2 { font-size: 16px; font-weight: 700; }
.types { border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px 10px; margin: 0; display: flex; flex-direction: column; }
.types legend { padding: 0 6px; font-size: 14px; font-weight: 600; }
.chk-row { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.steps { margin: 0; padding-left: 20px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }

/* ---- login ---- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 18px; }
.login-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line2); border-radius: 20px; padding: 24px 20px; display: flex; flex-direction: column; gap: 10px; }
.login-card h1 { font-size: 24px; font-weight: 700; }
.form-err { color: var(--red); font-size: 14px; min-height: 20px; }

/* ---- dialog + toast ---- */
.dlg { border: 0; border-radius: 20px; padding: 22px 20px 18px; max-width: min(400px, calc(100vw - 32px)); background: #fff; color: var(--cocoa); box-shadow: 0 20px 50px rgba(33, 20, 11, .35); }
.dlg::backdrop { background: rgba(33, 20, 11, .55); }
.dlg h2 { font-size: 18px; margin-bottom: 8px; }
.dlg p { font-size: 14px; line-height: 1.6; margin-bottom: 8px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 90px); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 14px; pointer-events: none; z-index: 50; }
.toast { background: var(--cocoa); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 14px; max-width: 460px; box-shadow: 0 8px 24px rgba(33, 20, 11, .3); animation: toastIn .2s ease; }
.toast.err { background: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- >= 900px : table layout, one-row header ---- */
@media (min-width: 900px) {
  .top { padding: 14px 20px; }
  .top-in { flex-direction: row; align-items: center; gap: 20px; }
  .top-row { gap: 16px; }
  .tabs { margin-left: 8px; }
  .tab { flex: none; padding: 0 18px; }
  .top-ctl { flex-direction: row; align-items: center; margin-left: auto; gap: 16px; }
  .top-row { flex: none; }
  .page { max-width: 1240px; width: 100%; margin: 0 auto; padding: 24px 20px; gap: 16px; }
  .page.settings { max-width: 760px; }
  .page.wide { max-width: 1240px; }
  .cta-bar.ed-bar { margin: 0 auto; }
}
@media (min-width: 600px) and (max-width: 899px) {
  .page, .top-in { max-width: 640px; margin-left: auto; margin-right: auto; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; transform: none !important; }
}

h1:focus { outline: none; }
.card.set:hover { transform: none; box-shadow: none; }
.card.set { opacity: 1; }

/* desktop table readability */
table { min-width: 1100px; }
.sm-t { white-space: nowrap; }
td:nth-child(2) { min-width: 230px; }
td:nth-child(3) { min-width: 110px; }
