/* ============================================================
   Matching Service — design system
   สีและโครงยกมาจาก mockup ตอนออกแบบ ซึ่งถูกลบทิ้งไปแล้ว
   ไฟล์นี้เป็นแหล่งเดียวของ design system ตอนนี้
   ============================================================ */

:root {
  --bg: #EEF2F1;
  --panel: #FFFFFF;
  --panel-2: #F7F9F8;
  --ink: #0E1A1C;
  --muted: #566A6B;
  --faint: #7C8E8E;
  --line: #D8E1DF;
  --line-soft: #E7EDEB;
  --dep: #0E7C7B;
  --dep-soft: #E2F0EF;
  --wdr: #A9501B;
  --wdr-soft: #F7EAE0;
  --alert: #A83A3A;
  --alert-soft: #F7E6E5;
  --ok: #2F7A4A;
  --ok-soft: #E4F1E8;
  --sidebar: #0E1A1C;
  --sidebar-ink: #B9C9C7;
  --sidebar-hi: #FFFFFF;

  --f-text: "Sukhumvit Set", "IBM Plex Sans Thai", "Noto Sans Thai", "Thonburi", -apple-system, system-ui, sans-serif;
  --f-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --r: 4px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0A1213;
    --panel: #111C1E;
    --panel-2: #0E1719;
    --ink: #E7EFED;
    --muted: #94A7A6;
    --faint: #7A8D8D;
    --line: #223134;
    --line-soft: #1A2628;
    --dep: #3FBDB7;
    --dep-soft: #123230;
    --wdr: #E08A45;
    --wdr-soft: #2E2114;
    --alert: #E4706F;
    --alert-soft: #2F1A1A;
    --ok: #6FB57F;
    --ok-soft: #16291D;
    --sidebar: #071012;
    --sidebar-ink: #90A4A2;
    --sidebar-hi: #FFFFFF;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--dep); }

/* ---------- app shell ---------- */

.app { display: grid; grid-template-columns: 1fr; min-height: 100vh; }

@media (min-width: 900px) {
  .app { grid-template-columns: 15rem minmax(0, 1fr); }
}

.side {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  padding: 1.5rem 0.9rem;
  display: grid;
  gap: 1.4rem;
  align-content: start;
}

@media (min-width: 900px) {
  .side { position: sticky; top: 0; height: 100vh; overflow-y: auto; }
}

.brand { display: grid; gap: 0.15rem; padding: 0 0.4rem; }
.brand b { color: var(--sidebar-hi); font-size: 0.95rem; letter-spacing: -0.01em; }

.brand span {
  font-family: var(--f-mono);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #6E8583;
}

.navgroup { display: grid; gap: 0.5rem; }

.navlabel {
  font-family: var(--f-mono);
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #5E7472;
  padding: 0 0.4rem;
}

.nav { display: grid; gap: 0.12rem; }

.nav a, .nav button {
  all: unset;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.55rem;
  border-radius: var(--r);
  font-size: 0.86rem;
  color: var(--sidebar-ink);
}

.nav a:hover, .nav button:hover { background: rgba(255, 255, 255, 0.06); color: var(--sidebar-hi); }
.nav a[aria-current="true"], .nav button[aria-current="true"] { background: rgba(63, 189, 183, 0.16); color: var(--sidebar-hi); }

.nav .idx { font-family: var(--f-mono); font-size: 0.62rem; color: #5E7472; width: 1.1rem; }
.nav [aria-current="true"] .idx { color: #3FBDB7; }

.badge-count {
  margin-left: auto;
  font-family: var(--f-mono);
  font-size: 0.62rem;
  background: rgba(224, 138, 69, 0.2);
  color: #E8A76C;
  padding: 0.05rem 0.35rem;
  border-radius: 100px;
}

.badge-count.calm { background: rgba(63, 189, 183, 0.16); color: #6FD3CD; }

.main { min-width: 0; display: grid; align-content: start; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 { font-size: 1.02rem; font-weight: 700; margin: 0; }

.endpoint {
  font-family: var(--f-mono);
  font-size: 0.68rem;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 0.12rem 0.45rem;
  border-radius: var(--r);
  white-space: nowrap;
  overflow-x: auto;
  max-width: 100%;
}

.live-flag {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--f-mono);
  font-size: 0.63rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dep);
  background: var(--dep-soft);
  border: 1px solid var(--dep);
  padding: 0.15rem 0.5rem;
  border-radius: 100px;
}

.live-flag i { width: 6px; height: 6px; border-radius: 100px; background: var(--dep); display: inline-block; }
.live-flag.down { color: var(--alert); background: var(--alert-soft); border-color: var(--alert); }
.live-flag.down i { background: var(--alert); }

.view { padding: 1.5rem; display: grid; gap: 1.25rem; align-content: start; }

/* ---------- panels ---------- */

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
  padding: 0.7rem 0.95rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.panel-head h2 { font-size: 0.9rem; font-weight: 700; margin: 0; }
.panel-head .sub { font-size: 0.78rem; color: var(--muted); }
.panel-body { padding: 0.95rem; display: grid; gap: 0.9rem; }

.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); }

.tiles { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0.85rem 0.95rem;
  display: grid;
  gap: 0.15rem;
  align-content: start;
}

.tile .k {
  font-family: var(--f-mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

.tile .v { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.tile .d { font-size: 0.76rem; color: var(--muted); }
.tile.accent { border-left: 3px solid var(--dep); }
.tile.warn { border-left: 3px solid var(--wdr); }
.tile.bad { border-left: 3px solid var(--alert); }

/* ---------- tables ---------- */

.tablewrap { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; min-width: 44rem; font-size: 0.84rem; }

thead th {
  text-align: left;
  font-family: var(--f-mono);
  font-size: 0.63rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 500;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: var(--panel-2);
}

tbody td { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--panel-2); }

.mono { font-family: var(--f-mono); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.amt { font-family: var(--f-mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.dim { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---------- pills ---------- */

/* ขยายป้ายสถานะทั้งชุดให้อ่านง่าย (สั่ง 21 ส.ค.) */
.pill {
  display: inline-block;
  font-family: var(--f-mono);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.6rem;
  border-radius: 100px;
  white-space: nowrap;
}

.p-ok { background: var(--ok-soft); color: var(--ok); }
.p-dep { background: var(--dep-soft); color: var(--dep); }
.p-wdr { background: var(--wdr-soft); color: var(--wdr); }
.p-bad { background: var(--alert-soft); color: var(--alert); }
.p-mute { background: var(--line-soft); color: var(--muted); }
/* เหลือง — สถานะส่งต่อระบบอื่น (สั่ง 21 ส.ค.) */
.p-warn { background: rgba(202, 158, 22, 0.16); color: #9a7207; }
/* ป้ายชื่อเว็บใหญ่กว่าป้ายสถานะ อ่านง่ายจากระยะไกล (สั่ง 21 ส.ค.) */
.p-site {
  background: transparent; color: var(--muted); border: 1.5px solid var(--line);
  font-size: 0.82rem; font-weight: 700; letter-spacing: 0.05em;
  padding: 0.22rem 0.7rem;
}
/* สีประจำเว็บ (สั่ง 20 ส.ค.) — lsm65 น้ำเงิน · s65win ส้ม · berlin777 แดง · lsm789up ทอง · เว็บอื่นใช้สีกลางข้างบน */
.p-site-lsm65     { background: rgba(37, 99, 235, 0.12);  color: #1d4ed8; border-color: rgba(37, 99, 235, 0.45); }
.p-site-s65win    { background: rgba(234, 121, 22, 0.14); color: #c2590a; border-color: rgba(234, 121, 22, 0.5); }
.p-site-berlin777 { background: rgba(220, 38, 38, 0.12);  color: #b91c1c; border-color: rgba(220, 38, 38, 0.5); }
.p-site-lsm789up  { background: rgba(202, 158, 22, 0.16); color: #9a7207; border-color: rgba(202, 158, 22, 0.55); }

/* ref ที่คลิกข้ามหน้าได้ (สั่ง 23 ส.ค.) — กดแล้วเด้งไปหน้ารายการนั้นพร้อมกรองให้ */
.reflink { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
.reflink:hover { color: var(--dep); }

/* ตัวนับถอยหลังกว้างคงที่ — ตัวเลขเปลี่ยนทุกวิแล้วคอลัมน์ต้องไม่ยืดหด (สั่ง 22 ส.ค.) */
[data-countdown] {
  display: inline-block;
  min-width: 15ch;
  font-variant-numeric: tabular-nums;
}

/* ปุ่มดู log รายแถว — superadmin/audit/headadmin (25 ส.ค.) · actions.js เติม class ที่ body หลังรู้ role */
.sa-only { display: none; }
body.can-logs .sa-only { display: inline-block; }

.tier {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 100px;
  font-family: var(--f-mono);
  font-size: 0.66rem;
  background: var(--dep-soft);
  color: var(--dep);
}

.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.chip {
  all: unset;
  cursor: pointer;
  font-size: 0.76rem;
  padding: 0.22rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 100px;
  color: var(--muted);
  background: var(--panel);
}

.chip:hover { border-color: var(--dep); color: var(--dep); }
.chip[aria-pressed="true"] { background: var(--dep); border-color: var(--dep); color: #FFF; }

/* ---------- buttons ---------- */

.btn {
  all: unset;
  cursor: pointer;
  font-size: 0.78rem;
  padding: 0.3rem 0.7rem;
  border-radius: var(--r);
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--panel);
  white-space: nowrap;
  text-align: center;
}

.btn:hover { border-color: var(--dep); color: var(--dep); }
.btn-primary { background: var(--dep); border-color: var(--dep); color: #FFF; }
.btn-primary:hover { color: #FFF; opacity: 0.9; }
.btn-warn { background: var(--wdr); border-color: var(--wdr); color: #FFF; }
.btn-warn:hover { color: #FFF; opacity: 0.9; }
.btn-danger { color: var(--alert); border-color: var(--alert); }
.btn-danger:hover { background: var(--alert-soft); color: var(--alert); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.35rem; }

/* ---------- toggle ---------- */

.toggle {
  all: unset;
  cursor: pointer;
  width: 2.1rem;
  height: 1.15rem;
  border-radius: 100px;
  background: var(--line);
  position: relative;
  display: inline-block;
  vertical-align: middle;
}

.toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.15rem - 4px);
  height: calc(1.15rem - 4px);
  border-radius: 100px;
  background: var(--panel);
  transition: transform 0.15s ease;
}

.toggle[aria-pressed="true"] { background: var(--dep); }
.toggle[aria-pressed="true"]::after { transform: translateX(0.95rem); }

/* ---------- meter ---------- */

.meter { height: 5px; border-radius: 100px; background: var(--line-soft); overflow: hidden; min-width: 5rem; }
.meter i { display: block; height: 100%; background: var(--dep); }
.meter i.hot { background: var(--wdr); }
.meter i.over { background: var(--alert); }

/* ---------- forms ---------- */

/* ชิดบน ไม่ใช่ชิดล่าง — ไม่งั้นช่องที่มีคำอธิบายใต้ช่องจะดันตัวเองสูงกว่าช่องที่ไม่มี */
.form { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); align-items: start; }

/* ให้ทุกช่องในฟอร์มสูงเท่ากัน ตัวควบคุมจะได้อยู่แนวเดียวกันทุกคอลัมน์ */
.form .field { align-content: start; }
.form .field > label { min-height: 1.05rem; }
.form .field .hint { min-height: 1.1rem; }

.field { display: grid; gap: 0.25rem; }

.field label {
  font-family: var(--f-mono);
  font-size: 0.63rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

.field .hint { font-size: 0.72rem; color: var(--muted); }

.field input, .field select {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel-2);
  color: var(--ink);
  width: 100%;
}

.field input:focus, .field select:focus { outline: 2px solid var(--dep); outline-offset: 1px; }

/* ---------- code ---------- */

.code {
  background: #0B1618;
  color: #CFDEDC;
  border-radius: var(--r);
  padding: 0.8rem 0.9rem;
  overflow-x: auto;
  font-family: var(--f-mono);
  font-size: 0.72rem;
  line-height: 1.65;
  white-space: pre;
  margin: 0;
}

.code.wrap { white-space: pre-wrap; word-break: break-word; }
.code .s { color: #7ED0CA; }
.code .n { color: #E8A76C; }
.code .k2 { color: #93A9A7; }
.code .c { color: #7F9694; }

/* ---------- drawer ---------- */

.scrim { position: fixed; inset: 0; background: rgba(6, 16, 18, 0.45); z-index: 40; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(30rem, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 50;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.drawer-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.drawer-head b { font-size: 0.9rem; }
.drawer-body { padding: 1rem; overflow-y: auto; display: grid; gap: 1rem; align-content: start; }

.kv { display: grid; gap: 0.45rem; margin: 0; }
.kv div { display: grid; grid-template-columns: 8.5rem 1fr; gap: 0.6rem; font-size: 0.83rem; }

.kv dt {
  color: var(--faint);
  font-family: var(--f-mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding-top: 0.15rem;
}

.kv dd { margin: 0; }

.timeline { display: grid; gap: 0.55rem; }

.timeline div {
  display: grid;
  grid-template-columns: 4.6rem 1fr;
  gap: 0.6rem;
  font-size: 0.8rem;
  padding-left: 0.7rem;
  border-left: 2px solid var(--line);
}

.timeline div.hit { border-left-color: var(--dep); }
.timeline .t { font-family: var(--f-mono); font-size: 0.72rem; color: var(--faint); }

.section-title {
  font-family: var(--f-mono);
  font-size: 0.63rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ---------- member simulator ---------- */

.ticket {
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0.8rem 0.9rem;
  display: grid;
  gap: 0.5rem;
  background: var(--panel);
}

.ticket.hot { border-left: 3px solid var(--dep); }
.ticket.wait { border-left: 3px solid var(--wdr); }
.ticket.done { border-left: 3px solid var(--ok); }
.ticket.dead { border-left: 3px solid var(--line); opacity: 0.65; }

.ticket .head { display: flex; flex-wrap: wrap; gap: 0.4rem 0.6rem; align-items: center; }
.ticket .head .id { font-family: var(--f-mono); font-size: 0.76rem; }
.ticket .head .big { font-family: var(--f-mono); font-size: 1rem; font-weight: 700; margin-left: auto; }

.chan { background: var(--panel-2); border-radius: var(--r); padding: 0.55rem 0.65rem; display: grid; gap: 0.15rem; }
.chan .no { font-family: var(--f-mono); font-size: 1rem; letter-spacing: 0.02em; }
.chan .cap { font-size: 0.74rem; color: var(--faint); }

.count { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.count.low { color: var(--alert); }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 60;
  display: grid;
  gap: 0.5rem;
  max-width: min(26rem, calc(100vw - 2rem));
}

.toast {
  background: #0B1618;
  color: #E2EDEB;
  border: 1px solid #24393B;
  border-left: 3px solid #3FBDB7;
  border-radius: var(--r);
  padding: 0.6rem 0.8rem;
  display: grid;
  gap: 0.15rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.toast.bad { border-left-color: #E4706F; }
.toast b { font-size: 0.8rem; }
.toast span { font-family: var(--f-mono); font-size: 0.68rem; color: #8FA6A4; word-break: break-all; }

.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); font-size: 0.85rem; }

:focus-visible { outline: 2px solid var(--dep); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- ปฏิทินเลือกวัน ---------- */

.datebtn {
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel-2);
  color: var(--ink);
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.datebtn:hover { border-color: var(--dep); }
.datebtn[aria-expanded="true"] { border-color: var(--dep); outline: 2px solid var(--dep); outline-offset: 1px; }
.datebtn .ph { color: var(--faint); }
.datebtn .ico { margin-left: auto; color: var(--faint); font-size: 0.9rem; }

.cal {
  position: absolute;
  z-index: 70;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  padding: 0.6rem;
  width: 17.5rem;
  display: grid;
  gap: 0.5rem;
}

.cal-head { display: flex; align-items: center; gap: 0.4rem; }

.cal-head b {
  flex: 1;
  text-align: center;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

.cal-nav {
  all: unset;
  cursor: pointer;
  width: 1.7rem;
  height: 1.7rem;
  display: grid;
  place-items: center;
  border-radius: var(--r);
  color: var(--muted);
  border: 1px solid var(--line);
}

.cal-nav:hover { border-color: var(--dep); color: var(--dep); }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }

.cal-dow {
  font-family: var(--f-mono);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: var(--faint);
  text-align: center;
  padding: 0.2rem 0;
}

.cal-day {
  all: unset;
  cursor: pointer;
  text-align: center;
  padding: 0.35rem 0;
  border-radius: var(--r);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.cal-day:hover { background: var(--dep-soft); color: var(--dep); }
.cal-day.other { color: var(--faint); opacity: 0.55; }
.cal-day.today { box-shadow: inset 0 0 0 1px var(--dep); }
.cal-day.inrange { background: var(--dep-soft); }
.cal-day.selected { background: var(--dep); color: #FFF; }
.cal-day[disabled] { opacity: 0.3; cursor: not-allowed; }
.cal-day[disabled]:hover { background: none; color: var(--ink); }

.cal-foot { display: flex; gap: 0.35rem; justify-content: space-between; }

/* ปุ่มที่วางในฟอร์มให้สูงเท่าช่องกรอก จะได้อยู่แนวเดียวกัน */
.form .field > .btn { padding-top: 0.4rem; padding-bottom: 0.4rem; }

/* ---------- แถวในตัวแก้เส้นทางของกลุ่ม ---------- */

.route-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--line-soft);
}

.route-row:last-child { border-bottom: none; }

.route-row select {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel-2);
  color: var(--ink);
  max-width: 100%;
}

/* ---------- รหัสที่กดได้ ---------- */

.ref {
  all: unset;
  cursor: pointer;
  font-family: var(--f-mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--dep);
  border-bottom: 1px dotted currentColor;
  white-space: nowrap;
}

.ref:hover { background: var(--dep-soft); border-bottom-style: solid; }
.ref:focus-visible { outline: 2px solid var(--dep); outline-offset: 2px; }
