/* หน้าแอดมิน CCN — โต๊ะทำงาน: ตารางอ่านง่าย ตัวเลขชัด สีหลักแดง CCN */
:root {
  --brand: #C8102E; --brand-dark: #9E0B23; --brand-tint: #FDF2F4;
  --ink: #17191C; --ink-2: #414651; --muted: #6B7280;
  --line: #E3E6EB; --line-strong: #CFD4DC; --bg: #F5F6F8; --surface: #fff;
  --ok: #17803D; --ok-tint: #ECFDF3; --warn: #B54708; --warn-tint: #FFFAEB;
  --bad: #B42318; --bad-tint: #FEF3F2; --info: #175CD3; --info-tint: #EFF4FF;
  --r: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: 'IBM Plex Sans Thai', system-ui, sans-serif; font-size: 15px; line-height: 1.5; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2, h3 { letter-spacing: -.01em; }
a { color: var(--brand); }
.muted { color: var(--muted); } .small { font-size: 13px; } .b { font-weight: 700; }
.r { text-align: right; }
.ic { font-family: 'Material Symbols Rounded'; font-size: 22px; line-height: 1; vertical-align: -5px;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24; }
.ic.sm { font-size: 18px; vertical-align: -4px; }

/* เข้าสู่ระบบ */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 400px at 50% -10%, #fff, var(--bg)); }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 36px 32px;
  box-shadow: 0 8px 28px rgba(16,24,40,.08); text-align: center; display: grid; gap: 12px; justify-items: center; max-width: 380px; }
.login-card h1 { margin: 6px 0 0; font-size: 22px; }
.login-card p { margin: 0; }
.mark { background: var(--brand); color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .06em;
  padding: 6px 9px; border-radius: 8px; }
.notice { background: var(--bad-tint); color: var(--bad); border: 1px solid #FECDCA; padding: 8px 12px;
  border-radius: 8px; font-size: 14px; }

/* แถบบน */
.top { display: flex; align-items: center; gap: 14px; padding: 10px 20px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top h1 { font-size: 17px; margin: 0; }
.tabs { display: flex; gap: 4px; margin-left: 10px; }
.tab { padding: 8px 14px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.tab:hover { background: var(--bg); }
.tab.on { background: var(--brand-tint); color: var(--brand); font-weight: 600; }
.me { margin-left: auto; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.role { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 1px 10px; font-size: 12px; color: var(--muted); }
.iconbtn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 9px; color: var(--ink-2); }
.iconbtn:hover { background: var(--bg); }

.body { padding: 20px; max-width: 1400px; margin: 0 auto; display: grid; gap: 16px; }

/* ตัวกรอง */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); }
.filters label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
.filters label.grow { flex: 1; min-width: 220px; }
.filters input[type=date], .filters select, .filters input:not([type]), .search {
  height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 9px; background: #fff; font-size: 15px; }
.filters .search { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.filters .search input { border: 0; outline: none; flex: 1; height: 100%; }
.filters label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink-2); }
.quick { display: flex; gap: 6px; }
.chip { border: 1px solid var(--line-strong); border-radius: 999px; padding: 7px 14px; background: #fff; font-size: 14px; }
.chip:hover { border-color: var(--brand); color: var(--brand); }
.btn { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 16px; border-radius: 9px;
  border: 1px solid var(--line-strong); background: #fff; font-weight: 600; box-shadow: var(--shadow); }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { border-color: var(--line); color: var(--brand); }
.btn.small { height: 32px; padding: 0 12px; font-size: 14px; }

/* กล่องเตือน */
.alert { display: flex; align-items: center; gap: 12px; background: var(--warn-tint); border: 1px solid #FEDF89;
  color: var(--warn); border-radius: var(--r); padding: 12px 16px; font-weight: 500; }
.alert .btn { margin-left: auto; }

/* การ์ดสรุป */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px;
  box-shadow: var(--shadow); }
.stat dt { font-size: 13px; color: var(--muted); }
.stat dd { margin: 4px 0 0; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.bad dd { color: var(--bad); }

/* ตาราง */
.tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: auto;
  box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); background: #FAFBFC; padding: 11px 14px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; white-space: nowrap; }
th.r { text-align: right; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #FCFCFD; }
tbody tr.hidden-row { opacity: .55; }
td.empty { text-align: center; color: var(--muted); padding: 28px; }
.plate-cell { font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.warnnum { color: var(--bad); font-weight: 600; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: var(--bg); border: 1px solid var(--line-strong); color: var(--ink-2); white-space: nowrap; }
.pill.run { background: var(--info-tint); border-color: #B2CCFF; color: var(--info); }
.pill.done, .pill.ok { background: var(--ok-tint); border-color: #A9E5BE; color: var(--ok); }
.pill.warn { background: var(--warn-tint); border-color: #FEDF89; color: var(--warn); }
.pill.bad, .pill.closed { background: var(--bad-tint); border-color: #FECDCA; color: var(--bad); }
.cell { border-bottom: 1px dashed var(--line-strong); cursor: pointer; padding: 1px 2px; }
.cell:hover { background: var(--brand-tint); border-color: var(--brand); color: var(--brand); }

/* สองคอลัมน์ */
/* รูปที่ถูกลบตามอายุ (เก็บ 3 เดือน) */
.gone { display: inline-flex; align-items: center; justify-content: center; min-width: 96px; min-height: 72px; padding: 6px;
  border: 1px dashed var(--line, #ccc); border-radius: 8px; color: var(--ink-3, #888); font-size: 13px; }
.cell.addcust { color: var(--brand, #C8102E); font-weight: 600; border: 1px dashed currentColor; border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.custlist { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.custchip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border: 1px solid var(--line, #ccc); border-radius: 999px; background: var(--surface, #fff); font: inherit; }
.custlist.pick .custchip { cursor: pointer; }
.custchip .x { border: 0; background: none; cursor: pointer; font-size: 18px; line-height: 1; color: var(--ink-3, #888); padding: 0; }
.mfind { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-weight: 600; }
.mfind input { flex: 1; max-width: 420px; }
tr[hidden] { display: none !important; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 20px; align-items: start; }
.two h2 { font-size: 16px; margin: 0 0 10px; }
.addadmin { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.addadmin input { height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 9px; flex: 1; min-width: 180px; }

/* รูป */
.gallery, .photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.ph { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.ph img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: #111; }
.ph figcaption { padding: 7px 10px; font-size: 12.5px; color: var(--ink-2); }

/* แท็บรูปทั้งวัน: แยกศูนย์ → 1 เที่ยว 1 แถว · ช่องแดง = ประเภทที่ติ๊กไว้แต่เที่ยวนั้นไม่มีรูป */
.phtypes { align-items: center; }
.phtypes .lab { font-size: 13px; color: var(--muted); font-weight: 500; }
.phtypes label.check { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 14px; }
.ph-center { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.ph-center h2 { margin: 0; font-size: 18px; }
.ph-row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 12px; }
.ph-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.ph-head .plate-cell { font-size: 17px; }
.grow { flex: 1; }
.ph-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.ph[data-ph] { cursor: zoom-in; }
.ph[data-ph]:hover { border-color: var(--brand); }
.ph.missing { border-color: #F5C2BD; }
.ph.missing .miss { aspect-ratio: 4/3; display: grid; place-content: center; justify-items: center; gap: 4px;
  background: var(--bad-tint); color: var(--bad); font-size: 13px; font-weight: 500; }
.lb { display: flex; align-items: center; gap: 6px; background: #111; padding: 10px; min-height: 0; flex: 1; }
.lb img { flex: 1; min-width: 0; max-height: 70dvh; object-fit: contain; }
.lb .iconbtn { color: #fff; flex: none; }
.lb .iconbtn:hover { background: rgba(255,255,255,.12); }
.flip .ic { transform: scaleX(-1); }

/* กล่องกลางจอ */
.modal-wrap { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center;
  padding: 24px; z-index: 50; }
.modal { background: var(--surface); border-radius: 16px; width: min(560px, 100%); max-height: 88dvh;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 50px rgba(16,24,40,.25); }
.modal.wide { width: min(1000px, 100%); }
.modal-top { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-top h2 { margin: 0; font-size: 18px; flex: 1; }
.modal-body { padding: 18px; overflow: auto; display: grid; gap: 14px; }
.modal-body h3 { margin: 6px 0 0; font-size: 15px; color: var(--ink-2); }
.modal-body input, .modal-body select { height: 44px; padding: 0 12px; border: 1px solid var(--line-strong);
  border-radius: 9px; width: 100%; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line);
  background: #FAFBFC; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.kv div { background: var(--bg); border-radius: 10px; padding: 9px 12px; }
.kv dt { font-size: 12.5px; color: var(--muted); }
.kv dd { margin: 2px 0 0; font-weight: 500; }
.drop { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; }
.drop-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.drop-head .btn { margin-left: auto; }
.hist { font-size: 14px; }

/* แจ้งเตือนมุมจอ */
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: var(--ink);
  color: #fff; padding: 11px 18px; border-radius: 10px; opacity: 0; transition: .2s; z-index: 60; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); }

/* ---------- มือถือ ----------
   แอดมินเปิดจากมือถือได้จริง: ตัวกรองเรียงสองช่องต่อแถว ตารางเที่ยวกลายเป็นการ์ด
   (ชื่อคอลัมน์มาจาก data-label ของแต่ละช่อง) และกล่องรายละเอียดเต็มจอ */
@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .top h1 { font-size: 16px; }
  .tabs { order: 3; width: 100%; overflow: auto; margin-left: 0; }
  .tab { padding: 10px 14px; white-space: nowrap; flex: none; }
  .role { display: none; }
  .body { padding: 12px; gap: 12px; }

  .filters { padding: 12px; gap: 10px; }
  .filters label { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .filters label.grow, .filters label.check, .filters .quick { flex: 1 1 100%; min-width: 0; }
  .filters label.check { display: flex; align-items: center; gap: 8px; }   /* ไม่งั้นช่องติ๊กไปอยู่คนละบรรทัดกับข้อความ */
  .alert { flex-wrap: wrap; }
  .alert .btn { margin-left: 0; width: 100%; justify-content: center; }
  .filters input[type=date], .filters select, .filters input:not([type]), .search { height: 44px; width: 100%; }
  .filters .btn { flex: 1 1 calc(50% - 5px); justify-content: center; height: 44px; }
  .quick { justify-content: space-between; }
  .chip { flex: 1; padding: 10px 0; text-align: center; }

  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat dd { font-size: 22px; }

  .tablewrap { background: none; border: 0; box-shadow: none; overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
    box-shadow: var(--shadow); padding: 10px 12px; margin-bottom: 10px; }
  tbody td { border: 0; padding: 5px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  tbody td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; }
  tbody td.act { padding-top: 10px; }
  tbody td.act .btn { width: 100%; height: 40px; justify-content: center; }
  td.empty { text-align: center; }

  .modal-wrap { padding: 0; place-items: stretch; }
  .modal, .modal.wide { width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .kv { grid-template-columns: 1fr 1fr; }
  /* รูปที่ถูกลบตามอายุ (เก็บ 3 เดือน) */
.gone { display: inline-flex; align-items: center; justify-content: center; min-width: 96px; min-height: 72px; padding: 6px;
  border: 1px dashed var(--line, #ccc); border-radius: 8px; color: var(--ink-3, #888); font-size: 13px; }
.cell.addcust { color: var(--brand, #C8102E); font-weight: 600; border: 1px dashed currentColor; border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.custlist { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.custchip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border: 1px solid var(--line, #ccc); border-radius: 999px; background: var(--surface, #fff); font: inherit; }
.custlist.pick .custchip { cursor: pointer; }
.custchip .x { border: 0; background: none; cursor: pointer; font-size: 18px; line-height: 1; color: var(--ink-3, #888); padding: 0; }
.mfind { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-weight: 600; }
.mfind input { flex: 1; max-width: 420px; }
tr[hidden] { display: none !important; }
.two { grid-template-columns: 1fr; }
  .gallery, .photos { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .ph-strip { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .phtypes label.check { flex: 1 1 calc(50% - 5px); }
  .lb img { max-height: none; }
  .drop-head .btn { margin-left: 0; width: 100%; }
}

.job { margin-bottom: 18px; }
.job:last-child { margin-bottom: 0; }
.job h3 { font-size: 15px; margin: 0 0 4px; }
.jobrow { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.summarytext { margin: 0; padding: 16px 20px; white-space: pre-wrap; font: 15px/1.7 inherit; }

.drop-head .cell-wrap.shop { flex: 1 1 200px; min-width: 160px; }

/* บอกว่าตารางยังแสดงไม่ครบ + ปุ่มโหลดเพิ่ม */
.more { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--warn-tint); border: 1px solid #FEDF89; color: var(--warn); border-radius: var(--r); padding: 10px 14px; }
.more .btn { color: var(--ink); }

/* ---------- หน้าแผนที่ ---------- */
.mapnote { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; align-items: baseline; }
.mapwrap { display: grid; grid-template-columns: 1fr 240px; gap: 12px; }
.map { height: calc(100dvh - 330px); min-height: 460px; border: 1px solid var(--line); border-radius: var(--r);
  background: #E8ECEF; z-index: 0; }
.maplegend { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px;
  display: grid; gap: 6px; align-content: start; max-height: calc(100dvh - 330px); min-height: 460px; overflow: auto; }
.maplegend label { display: grid; grid-template-columns: auto auto 1fr auto; gap: 8px; align-items: center;
  font-size: 14px; cursor: pointer; padding: 3px 2px; border-radius: 6px; }
.maplegend label:hover { background: var(--bg); }
.maplegend label i { width: 14px; height: 14px; border-radius: 50%; display: block; }
.maplegend small { color: var(--muted); }
.legend-keys { display: grid; gap: 5px; margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 13px; color: var(--ink-2); }
.legend-keys span { display: flex; align-items: center; gap: 8px; }
.k { width: 12px; height: 12px; border-radius: 50%; display: inline-block; background: #9CA3AF; }
.k.start { background: #fff; border: 2px solid #111; }
.k.warn { border: 3px solid #D97706; }
.k.bad { border: 3px solid #DC2626; }
.mapthumb { display: block; width: 180px; max-width: 100%; margin-top: 6px; border-radius: 6px; }
.leaflet-popup-content { font-family: 'IBM Plex Sans Thai', system-ui, sans-serif; font-size: 13.5px; line-height: 1.5; }
@media (max-width: 760px) {
  .mapwrap { grid-template-columns: 1fr; }
  .map { height: 62vh; min-height: 360px; }
  .maplegend { min-height: 0; max-height: 260px; }
}
