/* AGENTS — จอเฝ้า 15 ห้อง AI
   static ล้วน ไม่มี build ไม่มี framework — แก้ไฟล์นี้แล้ว rsync ขึ้นได้เลย */

:root {
  --bg: #070a12;
  --bg-soft: #0d1322;
  --card: #111827;
  --border: #1f2a3d;
  --text: #e7edf7;
  --muted: #7d8aa3;
  --cyan: #22d3ee;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --violet: #a78bfa;

  /* ระยะขอบจอ: บวก safe-area ไว้ในตัวแปรเดียว จะได้ไม่ต้องไล่ใส่ env() ทุกบล็อก
     (env() คืน 0 ถ้าไม่มี viewport-fit=cover ที่ <meta> — ดู index.html) */
  --pad-l: calc(16px + env(safe-area-inset-left));
  --pad-r: calc(16px + env(safe-area-inset-right));
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans Thai', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  /* 100vh บนซาฟารีมือถือ = ความสูงตอนซ่อนแถบที่อยู่ → เนื้อหาล่างโดนบัง
     คง 100vh ไว้เป็น fallback ให้เบราว์เซอร์เก่าที่ไม่รู้จัก dvh */
  min-height: 100dvh;
  background-image:
    radial-gradient(circle at 15% 10%, rgba(34, 211, 238, .10), transparent 42%),
    radial-gradient(circle at 85% 85%, rgba(167, 139, 250, .10), transparent 42%);
  background-attachment: fixed;
}

/* ───────────── หัวเว็บ ───────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px var(--pad-r) 14px var(--pad-l);
  /* sticky top:0 + viewport-fit=cover = หัวเว็บไปนอนใต้รอยบาก ต้องดันลงมาเอง */
  padding-top: calc(14px + env(safe-area-inset-top));
  background: rgba(7, 10, 18, .88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 26px; filter: drop-shadow(0 0 10px rgba(34, 211, 238, .6)); }
.brand h1 { font-size: 18px; letter-spacing: 4px; font-weight: 800; color: var(--cyan); }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.stat {
  display: flex; flex-direction: column; align-items: center;
  min-width: 54px; padding: 4px 8px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg-soft);
}
.stat b { font-size: 16px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 9px; color: var(--muted); letter-spacing: .5px; }

.pulse {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--muted);
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-soft);
}
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.pulse.is-stale .pulse-dot { background: var(--red); box-shadow: 0 0 8px var(--red); }
.pulse.is-fetching .pulse-dot { animation: blink .6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .25; } }

.stale-banner {
  margin: 10px var(--pad-r) 0 var(--pad-l);
  padding: 10px 14px; border-radius: 10px;
  background: rgba(248, 113, 113, .12);
  border: 1px solid rgba(248, 113, 113, .4);
  color: #fecaca; font-size: 12px; line-height: 1.5;
}

main { padding: 16px var(--pad-r) 24px var(--pad-l); max-width: 1280px; margin: 0 auto; }

/* ───────────── กระดาน ───────────── */
.board { position: relative; }

/* เส้นวิ่งต้องอยู่ "ใต้" การ์ด ไม่งั้นทับตัวหนังสือ และต้องกดทะลุไปโดนการ์ดได้ */
.wires { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; overflow: visible; }

.hub { position: relative; z-index: 2; margin-bottom: 18px; }
.grid {
  position: relative; z-index: 2;
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

/* ───────────── การ์ดห้อง ───────────── */
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 13px;
  overflow: hidden;
  transition: border-color .25s, box-shadow .25s, transform .25s;
}

.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.card-name { font-size: 13px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; }
.card-kind { margin-left: auto; font-size: 9px; color: var(--muted); letter-spacing: .5px; }

.card-meta { font-size: 11px; color: var(--muted); line-height: 1.6; }
.card-meta b { color: #b9c6dc; font-weight: 600; font-variant-numeric: tabular-nums; }

.card-state {
  display: inline-block; margin-top: 8px;
  font-size: 9px; letter-spacing: 1px; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted);
}

/* กำลังทำงาน = เรืองแสง (คำสั่งคุณแบงค์ข้อ 1) */
.card.is-running {
  border-color: rgba(52, 211, 153, .55);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, .18), 0 0 26px rgba(52, 211, 153, .22);
  animation: breathe 2.2s ease-in-out infinite;
}
.card.is-running .dot { background: var(--green); box-shadow: 0 0 10px var(--green); }
.card.is-running .card-state { border-color: rgba(52, 211, 153, .5); color: var(--green); }
@keyframes breathe {
  50% { box-shadow: 0 0 0 1px rgba(52, 211, 153, .32), 0 0 40px rgba(52, 211, 153, .38); }
}

.card.is-recent { border-color: rgba(251, 191, 36, .35); }
.card.is-recent .dot { background: var(--amber); box-shadow: 0 0 8px rgba(251, 191, 36, .8); }
.card.is-recent .card-state { color: var(--amber); }

.card.is-idle { opacity: .72; }

/* ห้องที่มีตั๋วค้าง — ขอบม่วง + แถบจับเวลา */
.card.has-ticket { border-color: rgba(167, 139, 250, .6); }

.ticket-chip {
  display: flex; align-items: center; gap: 6px;
  margin-top: 9px; padding: 6px 8px;
  border-radius: 9px;
  background: rgba(167, 139, 250, .12);
  border: 1px solid rgba(167, 139, 250, .35);
  font-size: 10px; color: #ddd6fe;
}
.ticket-chip .timer { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; letter-spacing: .5px; }
.tk-badge { overflow-wrap: anywhere; }

/* บรรทัดรอง: เปิดตั๋วมานานแค่ไหน + ส่งข่าวมากี่ครั้ง
   แยกจากตัวเลขใหญ่ตั้งใจ — "ทำงานนาน" กับ "เงียบหาย" คนละเรื่องกัน */
.ticket-sub {
  display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap;
  margin-top: 5px; font-size: 9px; color: var(--muted);
}
.ticket-sub b { color: #b9c6dc; font-variant-numeric: tabular-nums; }

/* ───────────── สีตามความเงียบ (silentSec) ─────────────
   เขียว < 5 นาที · เหลือง 5–10 · แดง > 10  (เกณฑ์ ODIN 2026-08-16)
   ตัดสินจาก "เงียบมากี่วิ" ไม่ใช่ ageSec — ห้องที่ส่งข่าวถี่ยังเขียวถึงตั๋วจะเปิดมานาน */
.card.has-ticket.sil-ok { border-color: rgba(52, 211, 153, .6); }
.card.has-ticket.sil-warn { border-color: rgba(251, 191, 36, .65); }
.card.has-ticket.sil-bad {
  border-color: rgba(248, 113, 113, .8);
  box-shadow: 0 0 0 1px rgba(248, 113, 113, .18), 0 0 22px rgba(248, 113, 113, .2);
}

.sil-ok .ticket-chip { background: rgba(52, 211, 153, .12); border-color: rgba(52, 211, 153, .38); color: #bbf7d9; }
.sil-warn .ticket-chip { background: rgba(251, 191, 36, .12); border-color: rgba(251, 191, 36, .42); color: #fde9b0; }
.sil-bad .ticket-chip { background: rgba(248, 113, 113, .14); border-color: rgba(248, 113, 113, .5); color: #fecaca; }

.timer.sil-ok { color: var(--green); }
.timer.sil-warn { color: var(--amber); }
.timer.sil-bad { color: var(--red); }

/* แถวในแผงตั๋ว — ให้ขอบซ้ายเป็นแถบสีเดียวกัน อ่านเร็วกว่าอ่านตัวเลข */
.tickets li.sil-ok { border-left: 3px solid var(--green); }
.tickets li.sil-warn { border-left: 3px solid var(--amber); }
.tickets li.sil-bad { border-left: 3px solid var(--red); }

.last-progress {
  display: block; margin-top: 3px;
  font-size: 10px; color: #9fb0c9; line-height: 1.45;
  overflow-wrap: anywhere;
}

/* การ์ด ODIN — แม่ข่าย กว้างเต็มแถว */
.card.hub-card {
  border-color: rgba(34, 211, 238, .45);
  background: linear-gradient(135deg, #0f1a2e 0%, #111827 100%);
  padding: 16px 18px;
}
.card.hub-card .card-name { font-size: 16px; letter-spacing: 3px; color: var(--cyan); }
.card.hub-card.is-running { animation: breathe-cyan 2.2s ease-in-out infinite; border-color: rgba(34, 211, 238, .7); }
@keyframes breathe-cyan {
  0%, 100% { box-shadow: 0 0 0 1px rgba(34, 211, 238, .2), 0 0 24px rgba(34, 211, 238, .2); }
  50% { box-shadow: 0 0 0 1px rgba(34, 211, 238, .35), 0 0 44px rgba(34, 211, 238, .4); }
}

/* ───────────── เส้นวิ่ง ODIN → ห้อง ───────────── */
.wire {
  fill: none;
  stroke: rgba(167, 139, 250, .28);
  stroke-width: 1.6;
  stroke-linecap: round;
}
.wire-flow {
  fill: none;
  stroke: var(--violet);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 10 190;
  filter: drop-shadow(0 0 5px rgba(167, 139, 250, .9));
  animation: dash 1.6s linear infinite;
}
/* สีเส้นเดินตามความเงียบเหมือนการ์ด — มองแวบเดียวรู้ว่าสายไหนกำลังจะมีปัญหา */
.wire-flow.sil-ok { stroke: var(--green); filter: drop-shadow(0 0 5px rgba(52, 211, 153, .9)); }
.wire.sil-ok { stroke: rgba(52, 211, 153, .28); }
.wire-flow.sil-warn { stroke: var(--amber); filter: drop-shadow(0 0 5px rgba(251, 191, 36, .9)); }
.wire.sil-warn { stroke: rgba(251, 191, 36, .3); }
.wire-flow.sil-bad { stroke: var(--red); filter: drop-shadow(0 0 5px rgba(248, 113, 113, .9)); }
.wire.sil-bad { stroke: rgba(248, 113, 113, .32); }
/* วิ่งจาก ODIN ไปหาห้อง: dashoffset ลดลง = จุดไหลไปตามทิศทางที่วาด path (ODIN → ห้อง) */
@keyframes dash { to { stroke-dashoffset: -200; } }

/* ───────────── แผงตั๋ว ───────────── */
.panel { margin-top: 26px; }
.panel h2 {
  font-size: 12px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.count {
  font-size: 10px; padding: 2px 7px; border-radius: 999px;
  background: rgba(167, 139, 250, .15); border: 1px solid rgba(167, 139, 250, .35); color: #ddd6fe;
}

.tickets, .closed { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.tickets li, .closed li {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: 11px;
  padding: 10px 12px; font-size: 12px; line-height: 1.5;
}
/* สีของแถวมาจากคลาส .sil-* ข้างบน (ความเงียบ) — ไม่ใช้ .escalated/.nudged มาทาสีซ้ำ
   เพราะกฎที่มาทีหลังจะทับ border-left ของ tier แล้วสีเพี้ยนแบบหาสาเหตุยาก */
.tickets li { align-items: flex-start; }
.tickets li.empty, .closed li.empty { color: var(--muted); justify-content: center; align-items: center; }

.who {
  flex: none; min-width: 74px;
  font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--cyan);
}
.what { flex: 1; min-width: 0; color: #c8d3e6; overflow-wrap: anywhere; }
.when { flex: none; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--violet); }
.closed .when { color: var(--muted); font-weight: 400; }
.why { font-size: 10px; color: var(--muted); }

footer {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 16px var(--pad-r) calc(20px + env(safe-area-inset-bottom)) var(--pad-l);
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 10px;
}

/* ───────────── มือถือ (iPhone Air 430×932) ───────────── */
@media (max-width: 520px) {
  .brand h1 { font-size: 15px; letter-spacing: 3px; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card { padding: 10px 11px; border-radius: 12px; }
  .card-name { font-size: 12px; letter-spacing: .8px; }
  .who { min-width: 0; }
  .tickets li, .closed li { flex-wrap: wrap; }
}

/* เครื่องที่ตั้งค่า "ลดการเคลื่อนไหว" — ปิด animation ทั้งหมด แต่ยังเห็นสี/เส้นครบ */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ───────────── iOS: กันซาฟารีซูมเองตอนแตะช่องกรอก ─────────────
   หน้านี้ยังไม่มีช่องกรอก แต่วางกันไว้ก่อน — วันที่มีคนเติมช่องค้นหา บั๊กจะไม่กลับมา
   :root + :not() ให้ความจำเพาะ (0,5,1) ชนะคลาสเดี่ยว ๆ ที่จะมาทีหลัง
   ⛔ ห้ามแก้อาการนี้ด้วย user-scalable=no */
@media (max-width: 767px) {
  :root input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]),
  :root select:not([hidden]):not([aria-hidden=true]),
  :root textarea:not([hidden]):not([aria-hidden=true]) { font-size: 16px; }
}
