/* LogiSight · สไตล์กลางของทุกหน้า (มือถือก่อน แล้วขยายถึงจอใหญ่) */
:root {
  --ink: #13233f;
  --ink-2: #3c4b66;
  --muted: #6b7890;
  --line: #dde3ec;
  --bg: #f3f5f9;
  --card: #ffffff;
  --brand: #12315c;
  --brand-2: #1d4f8f;
  --accent: #f0a20b;
  --ok: #17824f;
  --warn: #b26b00;
  --bad: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(19 35 63 / 6%), 0 4px 16px rgb(19 35 63 / 6%);
  --font: 'IBM Plex Sans Thai', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  min-height: 100dvh;
}
a { color: var(--brand-2); }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- แถบบน ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--brand); color: #fff;
}
.appbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .2px; }
.brand img { border-radius: 7px; }
.env-badge { font-size: .72rem; font-weight: 600; background: var(--accent); color: var(--ink); padding: 1px 8px; border-radius: 99px; }
.icon-btn { color: #fff; text-decoration: none; font-size: 1.8rem; line-height: 1; padding: 0 6px 4px 0; }
.user-btn {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  background: rgb(255 255 255 / 10%); border: 0; color: #fff; border-radius: 99px; padding: 4px 12px 4px 4px; cursor: pointer;
}
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--ink); display: grid; place-items: center; font-weight: 700; flex: none; }
.user-meta { display: flex; flex-direction: column; text-align: left; min-width: 0; }
.user-name, .user-role { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.user-name { font-size: .88rem; font-weight: 600; }
.user-role { font-size: .72rem; opacity: .8; }
.menu {
  position: absolute; right: 12px; top: calc(100% - 4px);
  background: var(--card); color: var(--ink); border-radius: 12px; box-shadow: var(--shadow);
  min-width: 230px; padding: 6px; display: flex; flex-direction: column; border: 1px solid var(--line);
}
.menu-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: .85rem; color: var(--muted); }
.menu-head strong { color: var(--ink); font-size: .95rem; }
.menu button { background: none; border: 0; text-align: left; padding: 10px; border-radius: 8px; cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--bg); }
.menu .danger { color: var(--bad); }
.offline-bar { position: absolute; left: 0; right: 0; top: 100%; background: var(--warn); color: #fff; text-align: center; font-size: .85rem; padding: 4px; }

/* ---------- โครงหน้า ---------- */
.page { max-width: 1080px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px); }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-end { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.section-title { margin: 24px 0 10px; font-size: 1rem; color: var(--ink-2); }
.muted { color: var(--muted); }
.hint { font-size: .85rem; color: var(--muted); margin: 0; }

/* ---------- ฟอร์ม ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 500; color: var(--ink-2); }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 1rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: .88rem; }
.btn.danger { background: #fff; border-color: #f0c9c4; color: var(--bad); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }

/* ---------- หน้า Login ---------- */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(1200px 500px at 10% -10%, #24508a 0%, transparent 60%), var(--brand); }
.auth-card { width: min(420px, 100%); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; color: #fff; margin-bottom: 18px; text-align: center; }
.auth-brand img { border-radius: 18px; box-shadow: 0 6px 24px rgb(0 0 0 / 25%); }
.auth-brand h1 { font-size: 1.6rem; }
.auth-brand p { margin: 0; opacity: .8; font-size: .92rem; }
.auth-links { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; }
.auth-links button { background: none; border: 0; color: var(--brand-2); text-decoration: underline; cursor: pointer; padding: 0; }
.notice { padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
.notice.info { background: #e8f0fb; color: #1d3f6e; }
.notice.error { background: #fdecea; color: #8e2a1f; }
.notice.success { background: #e6f4ec; color: #145c38; }

/* ---------- เมนูหลัก ---------- */
.tile {
  display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ink);
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; border: 1px solid transparent;
}
a.tile:hover { border-color: var(--brand-2); }
.tile .tile-title { font-weight: 700; }
.tile .tile-desc { font-size: .88rem; color: var(--muted); }
.tile.soon { opacity: .6; }
.tag { align-self: flex-start; font-size: .72rem; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); }

/* ---------- ตัวเลขสรุป ---------- */
.stats { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.stat { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; }
.stat .n { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: .82rem; color: var(--muted); }

/* ---------- รายการ ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.mono { font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; font-size: .92rem; letter-spacing: .3px; }
.item .addr { font-size: .9rem; color: var(--ink-2); }
.item .meta { font-size: .82rem; color: var(--muted); }

.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; background: #fafbfd; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

/* ---------- ป้ายสถานะ ---------- */
.chip { display: inline-block; font-size: .78rem; font-weight: 600; padding: 2px 10px; border-radius: 99px; background: #eef1f6; color: var(--ink-2); white-space: nowrap; }
.chip-requested, .chip-confirmed { background: #eef1f6; color: #3c4b66; }
.chip-planned { background: #ece9fb; color: #4b3aa8; }
.chip-picked_up, .chip-at_hub, .chip-in_transit { background: #e3eefc; color: #1d4f8f; }
.chip-out_for_delivery { background: #fff3d9; color: #8a5300; }
.chip-delivered, .chip-closed { background: #e2f3ea; color: #145c38; }
.chip-failed_attempt, .chip-returning, .chip-returned { background: #fdeceb; color: #9b2c20; }
.chip-cancelled { background: #f0f0f0; color: #777; text-decoration: line-through; }
.chip-on_hold { background: #fff6cc; color: #7a5d00; }
.chip-on { background: #e2f3ea; color: #145c38; }
.chip-off { background: #f0f0f0; color: #777; }

/* ---------- Timeline (หน้า Track) ---------- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 14px 12px; }
.timeline li::before { content: ''; position: absolute; left: -25px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--line); border: 2px solid #fff; }
.timeline li:last-child::before { background: var(--accent); }
.timeline .t { font-size: .82rem; color: var(--muted); }

/* ---------- Dialog / Toast / State ---------- */
.dialog { border: 0; border-radius: var(--radius); padding: 20px; width: min(480px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgb(0 0 0 / 30%); }
.dialog::backdrop { background: rgb(19 35 63 / 45%); }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px); font-size: .92rem;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--bad); }
.toast-success { background: var(--ok); }
.state { padding: 24px 16px; text-align: center; color: var(--muted); background: var(--card); border-radius: var(--radius); }
.state-error { color: var(--bad); }

@media (min-width: 720px) {
  .page { padding-top: 24px; }
  h1 { font-size: 1.6rem; }
}
