/* =========================================================
   ระบบตรวจสอบมิจฉาชีพ — Design tokens (v3 "Threat Console")
   Palette: near-black + cyan signal glow (จากแสง glow ในโลโก้จริง)
   Type: Chakra Petch (display, เหลี่ยม/เทคนิค) / Sarabun (body) / JetBrains Mono (data)
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@500;600;700&family=Sarabun:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --void: #05080C;
  --panel: #0D131C;
  --panel-raised: #131C29;
  --line: #212B38;
  --line-bright: #2E3D4E;

  --ink: #E8EDF3;
  --ink-soft: #8291A6;
  --ink-dim: #566276;

  --signal: #4FD8E8;
  --signal-dim: rgba(79,216,232,0.14);
  --signal-line: rgba(79,216,232,0.3);

  --flag: #FF6161;
  --flag-dim: rgba(255,97,97,0.13);
  --clear: #3EDC97;
  --clear-dim: rgba(62,220,151,0.13);
  --gold: #E8B84F;
  --gold-dim: rgba(232,184,79,0.13);

  --font-display: 'Chakra Petch', sans-serif;
  --font-body: 'Sarabun', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius: 4px;
  --radius-lg: 8px;
  --shadow-lift: 0 16px 44px rgba(0,0,0,0.5);
}

/* กติกาความปลอดภัยระดับ global: attribute hidden ต้องชนะเสมอ ไม่ว่า component
   ใดจะตั้ง display ไว้ก็ตาม (ป้องกันบั๊กคลาส "โมดัลค้างเปิด" ไม่ให้เกิดซ้ำอีก) */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

body {
  margin: 0;
  background-color: var(--void);
  background-image:
    radial-gradient(ellipse 55% 45% at 50% -5%, rgba(79,216,232,0.10), transparent 60%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.028) 0px, rgba(255,255,255,0.028) 1px, transparent 1px, transparent 44px),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.028) 0px, rgba(255,255,255,0.028) 1px, transparent 1px, transparent 44px);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--ink);
  margin: 0 0 0.5em;
  line-height: 1.22;
  font-weight: 600;
  letter-spacing: 0.01em;
}

a { color: var(--signal); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

.mono { font-family: var(--font-mono); letter-spacing: 0.02em; }
.wrap { max-width: 900px; margin: 0 auto; padding: 0 24px; }

/* ---------- 3D reveal / tilt utilities ---------- */
.reveal-3d {
  opacity: 0;
  transform: perspective(1000px) translateY(28px) rotateX(-8deg);
  transform-origin: top center;
  transition: opacity 0.7s ease, transform 0.7s cubic-bezier(.2,.7,.2,1);
}
.reveal-3d.is-visible { opacity: 1; transform: perspective(1000px) translateY(0) rotateX(0deg); }
[data-tilt] { will-change: transform; }
.tilt-card { transition: box-shadow 0.2s ease, transform 0.15s ease-out, border-color 0.2s ease; }
.tilt-card:hover { box-shadow: var(--shadow-lift); border-color: var(--line-bright); }

/* ---------- Fatal error banner (แสดงเมื่อเชื่อมต่อ Firebase ไม่สำเร็จ) ---------- */
.fatal-error {
  background: var(--flag-dim);
  border: 1px solid var(--flag);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 16px 0;
  color: var(--ink);
}
.fatal-error strong { color: var(--flag); font-family: var(--font-display); display: block; margin-bottom: 6px; font-size: 15px; }
.fatal-error p { margin: 4px 0 0; font-size: 13.5px; color: var(--ink-soft); }
.fatal-error .fatal-error-detail { font-family: var(--font-mono); color: var(--ink); font-size: 12.5px; background: rgba(0,0,0,0.3); padding: 8px 10px; border-radius: 3px; margin-top: 8px; word-break: break-word; }

/* ---------- Header ---------- */
.site-header {
  background: rgba(5,8,12,0.85);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid var(--line);
}
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; padding-bottom: 12px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-logo { height: 38px; width: auto; display: block; filter: drop-shadow(0 0 12px rgba(79,216,232,0.4)); }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 15px; color: var(--ink); letter-spacing: 0.02em; }
.brand-name small { display: block; font-family: var(--font-mono); font-weight: 400; font-size: 10.5px; color: var(--signal); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; }
nav.site-nav { display: flex; gap: 22px; font-size: 14px; }
nav.site-nav a { text-decoration: none; color: var(--ink-soft); border-bottom: 1px solid transparent; padding-bottom: 3px; }
nav.site-nav a:hover { color: var(--ink); border-bottom-color: var(--signal); }

/* ---------- Hero ---------- */
.hero { position: relative; padding: 56px 0 60px; overflow: hidden; }
.scan-line {
  position: absolute; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--signal), transparent);
  box-shadow: 0 0 12px 1px var(--signal);
  opacity: 0.6;
  animation: scanSweep 7s linear infinite;
}
@keyframes scanSweep {
  0% { top: 0%; opacity: 0; }
  8% { opacity: 0.6; }
  92% { opacity: 0.6; }
  100% { top: 100%; opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .scan-line { display: none; } }

.eyebrow { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.16em; font-size: 12px; color: var(--signal); margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.eyebrow::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 8px 2px var(--signal); flex-shrink: 0; }
.hero h1 { font-size: clamp(28px, 4.4vw, 42px); max-width: 16ch; }
.hero p.lede { color: var(--ink-soft); max-width: 58ch; font-size: 16px; margin-top: 14px; }

.search-panel {
  margin-top: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  padding: 22px;
}
.search-row { display: flex; gap: 10px; flex-wrap: wrap; }
.search-row input[type="text"] {
  flex: 1 1 260px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius);
  font-family: var(--font-mono); font-size: 15.5px; background: var(--void); color: var(--ink);
}
.search-row input[type="text"]::placeholder { color: var(--ink-dim); font-family: var(--font-body); }
.search-row input[type="text"]:focus { border-color: var(--signal); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 22px; border-radius: var(--radius);
  border: 1px solid var(--signal); background: var(--signal); color: #04191D;
  font-family: var(--font-display); font-weight: 600; font-size: 14.5px; letter-spacing: 0.02em;
  cursor: pointer; text-decoration: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.btn:hover { background: #6DE3F0; box-shadow: 0 0 0 4px var(--signal-dim); }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); font-family: var(--font-body); font-weight: 600; }
.btn-ghost:hover { background: var(--panel-raised); box-shadow: none; border-color: var(--line-bright); }
.btn-danger { border-color: var(--flag); color: var(--flag); background: transparent; font-family: var(--font-body); font-weight: 600; }
.btn-danger:hover { background: var(--flag-dim); box-shadow: none; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-pdf { border-color: var(--line-bright); color: var(--ink); background: var(--panel-raised); font-family: var(--font-body); font-weight: 600; }
.btn-pdf:hover { background: var(--line-bright); box-shadow: none; }
.btn-pdf svg { flex-shrink: 0; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.search-hint { margin-top: 10px; font-size: 13px; color: var(--ink-dim); }

/* ---------- Hex badge — signature element ---------- */
.stamp-row { display: flex; align-items: center; gap: 22px; margin: 34px 0 6px; }
.hex-badge {
  --c: var(--clear); --cglow: rgba(62,220,151,0.5);
  position: relative; flex-shrink: 0; width: 108px; height: 124px;
  animation: hexIn 0.55s cubic-bezier(.2,.8,.2,1) forwards;
}
.hex-badge::before {
  content: ''; position: absolute; inset: 0;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: var(--c); box-shadow: 0 0 30px 2px var(--cglow);
}
.hex-badge::after {
  content: ''; position: absolute; inset: 2.5px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: var(--panel);
}
.hex-badge .hex-label {
  position: relative; z-index: 1; width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--c); font-family: var(--font-mono); font-weight: 600; font-size: 11px;
  letter-spacing: 0.03em; line-height: 1.35; text-align: center;
}
@keyframes hexIn { 0% { transform: scale(0.4) rotate(-10deg); opacity: 0; } 100% { transform: scale(1) rotate(0deg); opacity: 1; } }
.hex-badge.is-flag { --c: var(--flag); --cglow: rgba(255,97,97,0.55); }
.stamp-text h3 { margin-bottom: 4px; font-size: 19px; color: var(--ink); }
.stamp-text p { margin: 0; color: var(--ink-soft); font-size: 14px; max-width: 52ch; }

#results { margin-top: 18px; }

/* ---------- Result cards ---------- */
.result-card {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--flag);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 12px;
  color: var(--ink);
}
.result-card .rc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.result-card h4 { margin: 0; font-size: 17px; font-family: var(--font-display); }
.status-pill { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.04em; padding: 4px 9px; border-radius: 20px; white-space: nowrap; border: 1px solid currentColor; }
.status-preliminary { color: var(--gold); }
.status-confirmed { color: var(--flag); }
.status-in_legal_process { color: var(--ink-soft); }

.rc-meta { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 14px; }
.rc-meta div span.label { display: block; font-size: 11px; color: var(--ink-dim); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.04em; }
.rc-meta div span.val { font-family: var(--font-mono); font-size: 14.5px; color: var(--ink); }
.rc-desc { margin-top: 12px; font-size: 14.5px; color: var(--ink); }
.rc-foot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

.empty-note { font-size: 13.5px; color: var(--ink-soft); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-top: 10px; }

/* ---------- Social channel chips ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chan-chip { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px 4px 4px; font-size: 12.5px; color: var(--ink); background: var(--panel-raised); }
.chan-badge { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.chan-text b { font-weight: 600; }

/* ---------- Timeline ---------- */
.section { padding: 56px 0; border-bottom: 1px solid var(--line); }
.section h2 { font-size: 25px; }
.section .lede { color: var(--ink-soft); max-width: 60ch; margin-top: 8px; margin-bottom: 32px; }

.timeline { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.stage { border-top: 2px solid var(--signal); padding-top: 16px; }
.stage .stage-label { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--signal); }
.stage h3 { font-size: 18px; margin-top: 6px; font-family: var(--font-display); }
.stage ul { padding-left: 18px; margin: 12px 0 0; font-size: 14.5px; color: var(--ink-soft); }
.stage li { margin-bottom: 8px; }
.stage li::marker { color: var(--signal); }

/* ---------- Official channels ---------- */
.channels { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.channel-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 20px; }
.channel-card .ch-eyebrow { font-family: var(--font-mono); font-size: 11px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.channel-card h3 { font-size: 18px; margin: 6px 0 8px; font-family: var(--font-display); }
.channel-card .ch-num { font-family: var(--font-mono); font-size: 22px; color: var(--signal); font-weight: 600; }
.channel-card p { font-size: 14px; color: var(--ink-soft); margin: 8px 0 0; }

/* ---------- Footer ---------- */
.site-footer { padding: 32px 0 48px; }
.site-footer .disclaimer { font-size: 13px; color: var(--ink-soft); max-width: 68ch; border-left: 2px solid var(--line); padding-left: 14px; }
.site-footer .foot-links { margin-top: 18px; font-size: 13px; display: flex; gap: 16px; }
.site-footer a { color: var(--ink-soft); }
.site-footer a:hover { color: var(--signal); }
.site-footer .foot-logo { height: 26px; width: auto; opacity: 0.75; margin-bottom: 14px; }

/* ---------- Admin ---------- */
.admin-shell { min-height: 100vh; }
.login-card {
  max-width: 380px; margin: 90px auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 32px; box-shadow: var(--shadow-lift);
}
.login-card .brand-logo-lg { height: 50px; width: auto; display: block; margin: 0 auto 18px; filter: drop-shadow(0 0 14px rgba(79,216,232,0.4)); }
.login-card h1 { font-size: 21px; text-align: center; }
.login-card > p { text-align: center; color: var(--ink-soft); }
.field { margin-top: 16px; }
.field label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; font-family: var(--font-mono); letter-spacing: 0.02em; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  font-family: var(--font-body); font-size: 15px; background: var(--void); color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--signal); }
.field textarea { resize: vertical; min-height: 80px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.form-msg { font-size: 13.5px; margin-top: 12px; }
.form-msg.err { color: var(--flag); }
.form-msg.ok { color: var(--clear); }

.admin-bar { background: rgba(5,8,12,0.9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.admin-bar .wrap { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; max-width: 1080px; }
.admin-bar-actions { display: flex; align-items: center; gap: 14px; }
.admin-main { max-width: 1080px; margin: 0 auto; padding: 28px 24px 80px; }
.admin-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.admin-toolbar input[type="text"] { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); font-family: var(--font-body); min-width: 240px; background: var(--panel); color: var(--ink); }

.report-table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.report-table th, .report-table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--ink); }
.report-table th { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-dim); background: var(--panel-raised); }
.report-table tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pub-pill { font-size: 11px; font-family: var(--font-mono); padding: 3px 8px; border-radius: 20px; white-space: nowrap; border: 1px solid currentColor; }
.pub-pill.on { color: var(--clear); }
.pub-pill.off { color: var(--ink-dim); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.65); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); max-width: 620px; width: 100%; padding: 28px; box-shadow: var(--shadow-lift); }
.modal h2 { font-size: 20px; }
.modal-close { float: right; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ink-soft); }
.modal-close:hover { color: var(--flag); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-soft); }

@media print {
  .site-header, .admin-bar, .search-panel, .admin-toolbar, footer, nav { display: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .site-header .wrap { flex-wrap: wrap; row-gap: 8px; padding-bottom: 10px; }
  nav.site-nav { width: 100%; justify-content: space-between; gap: 8px; font-size: 12.5px; }
  .brand-name { font-size: 13.5px; }
  .brand-logo { height: 32px; }
  .admin-bar .wrap { flex-wrap: wrap; row-gap: 10px; padding: 12px 16px; }
  .admin-bar-actions { width: 100%; justify-content: space-between; gap: 8px; }
  .admin-bar #current-email { display: none; }
  .timeline { grid-template-columns: 1fr; gap: 28px; }
  .channels { grid-template-columns: 1fr; }
  .stamp-row { flex-direction: column; align-items: flex-start; }
  .field-row { flex-direction: column; }
  .admin-main { padding: 20px 16px 60px; }
  .report-table { display: block; overflow-x: auto; white-space: nowrap; }
  [data-tilt] { transform: none !important; }
}
@media (max-width: 480px) {
  .wrap { padding: 0 16px; }
  .hero { padding: 40px 0 44px; }
  .search-row { flex-direction: column; }
  .search-row input, .search-row button { width: 100%; }
  .rc-foot { flex-direction: column; align-items: stretch; }
}
