/* govhouse-pass — single stylesheet. No build step, no framework.
   Palette follows docs/wireframes: navy #1F3A5F, LINE green #06C755. */

:root {
  --navy: #1f3a5f;
  --navy-dark: #172c47;
  --line-green: #06c755;
  --line-green-dark: #05a948;
  --ink: #1b2430;
  --muted: #5b6673;
  --border: #dfe4ea;
  --bg: #f6f8fa;
  --white: #fff;
  --radius: 10px;

  --tag-wait-bg: #fdf0d5;
  --tag-wait-fg: #8a5a00;
  --tag-info-bg: #dbeafe;
  --tag-info-fg: #1e4b8f;
  --tag-ok-bg: #d8f3dc;
  --tag-ok-fg: #17663a;
  --tag-bad-bg: #fde2e1;
  --tag-bad-fg: #a12622;
  --tag-mute-bg: #eceff3;
  --tag-mute-fg: #5b6673;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Sarabun", "Noto Sans Thai", -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

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

/* --- Watermark on every page (login's right panel has its own at 55%) --- */
:root { --wm-opacity: 0.35; }
body.has-watermark::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  /* Full WebP on top; a 32px blurred placeholder (embedded) shows underneath until it arrives. */
  background-image: url("img/watermark.webp"), url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABQODxIPDRQSEBIXFRQYHjIhHhwcHj0sLiQySUBMS0dARkVQWnNiUFVtVkVGZIhlbXd7gYKBTmCNl4x9lnN+gXz/2wBDARUXFx4aHjshITt8U0ZTfHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHz/wAARCAASACADASIAAhEBAxEB/8QAGQAAAwADAAAAAAAAAAAAAAAAAAMEAQIF/8QAIBAAAgEEAgMBAAAAAAAAAAAAAAECAwQRIRIiMUFhkf/EABcBAAMBAAAAAAAAAAAAAAAAAAECBAP/xAAZEQADAQEBAAAAAAAAAAAAAAAAAQIUMQT/2gAMAwEAAhEDEQA/AFU6EZLq8mXbv0QWqq0px7dfaydSV7FLSSZpua4TZZfRKoNvBrcUYUtSZYrmPFPg8iLxyqpSUdfRd1Uxl5YRHBaRZbxi/MV+ABGikswseETXAAGRj//Z");
  background-position: center 45%, center 45%;
  background-size: cover, cover;
  background-repeat: no-repeat, no-repeat;
  opacity: var(--wm-opacity);
}
/* Liquid Glass on every page: 12% white surfaces that blur the photo behind,
   light rim, darker + bold text so it stays crisp over the picture. */
body.has-watermark { color: #16202b; }
body.has-watermark .card,
body.has-watermark .tile,
body.has-watermark .flash,
body.has-watermark .stepper,
body.has-watermark .page > p.muted {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: 0 10px 34px rgba(31, 58, 95, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.75);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
  border-radius: 16px;
}
body.has-watermark .page > p.muted { padding: 6px 12px; display: inline-block; }
body.has-watermark .card-table { overflow: hidden; }
body.has-watermark table, body.has-watermark .card-table table { background: transparent; }
body.has-watermark thead th { background: rgba(255, 255, 255, 0.28); color: var(--navy-dark); font-weight: 700; }
body.has-watermark th, body.has-watermark td { border-bottom-color: rgba(255, 255, 255, 0.55); }
body.has-watermark tbody tr:hover { background: rgba(255, 255, 255, 0.22); }
body.has-watermark .flash-ok { background: rgba(216, 243, 220, 0.55); }
body.has-watermark .flash-error { background: rgba(253, 226, 225, 0.6); }
body.has-watermark .flash-warn { background: rgba(253, 240, 213, 0.6); }
body.has-watermark .card-warn { background: rgba(255, 250, 240, 0.35); }

body.has-watermark h1, body.has-watermark h2, body.has-watermark .section-title { color: var(--navy-dark); font-weight: 700; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7); }
body.has-watermark .card, body.has-watermark .tile, body.has-watermark td, body.has-watermark .page > p.muted,
body.has-watermark label, body.has-watermark .dl dt, body.has-watermark .dl dd { font-weight: 600; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); }
body.has-watermark .muted, body.has-watermark label, body.has-watermark .tile .label { color: #2f3a47; }
body.has-watermark .tile .n { text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8); }
/* Navy panel on the login page keeps white text (the dark-text rules above must not win). */
body.has-watermark .split .left h1 { color: var(--white); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); }
body.has-watermark .split .left p { color: #d6dee9; font-weight: 600; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); }
body.has-watermark .stepper .step { background: transparent; }
body.has-watermark .stepper .step.current { background: rgba(31, 58, 95, 0.75); color: var(--white); }
body.has-watermark .stepper .step.done { background: rgba(216, 243, 220, 0.6); }

body.has-watermark input[type="text"], body.has-watermark input[type="tel"], body.has-watermark input[type="search"],
body.has-watermark select, body.has-watermark textarea {
  background: rgba(255, 255, 255, 0.55);
  border-color: rgba(255, 255, 255, 0.8);
  font-weight: 600;
}
body.has-watermark input[readonly] { background: rgba(255, 255, 255, 0.35); }
body.has-watermark .slot { background: rgba(255, 255, 255, 0.35); }
body.has-watermark .slot.has-file { background: rgba(216, 243, 220, 0.5); }

body.has-watermark .btn {
  background: rgba(31, 58, 95, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 8px 24px rgba(31, 58, 95, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
  font-weight: 700; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
body.has-watermark .btn:hover { background: rgba(23, 44, 71, 0.82); }
body.has-watermark .btn-ghost { background: rgba(255, 255, 255, 0.4); color: var(--navy-dark); text-shadow: none; }
body.has-watermark .btn-ghost:hover { background: rgba(255, 255, 255, 0.6); }
body.has-watermark .btn-danger { background: rgba(255, 255, 255, 0.4); color: var(--tag-bad-fg); text-shadow: none; border-color: rgba(161, 38, 34, 0.5); }
body.has-watermark .topbar .btn-ghost { background: rgba(255, 255, 255, 0.92); }
body.has-watermark .tag { font-weight: 700; }
body.has-watermark .code-display { background: rgba(255, 255, 255, 0.45); }

/* --- Top bar ------------------------------------------------------------ */
.topbar {
  position: sticky;   /* the bar stays put on every screen (Chuey, 8 ก.ย. 69) */
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--navy);
  color: var(--white);
}
.topbar .brand { font-weight: 700; font-size: 18px; }
.topbar nav { display: flex; gap: 6px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.topbar nav::-webkit-scrollbar { display: none; }
/* Each tab: one line, Liquid Glass pill. */
.topbar nav a {
  color: #e6ecf4;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 10px;
  white-space: nowrap;
  flex: none;
  font-weight: 600;
  font-size: 15px;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 14px rgba(0, 0, 0, 0.12);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  backdrop-filter: blur(10px) saturate(140%);
}
.topbar nav a:hover { background: rgba(255, 255, 255, 0.2); color: var(--white); }
.topbar nav a.active { background: rgba(255, 255, 255, 0.32); border-color: rgba(255, 255, 255, 0.6); color: var(--white); }
.topbar .brand { white-space: nowrap; }
.topbar .who { white-space: nowrap; flex: none; }
/* Desktop: the menu wrapper is invisible to layout (nav + who sit directly in the bar). */
.topbar-menu { display: contents; }
.nav-toggle { display: none; }
@media (max-width: 1500px) {
  .topbar { gap: 12px; padding: 10px 14px; }
  .topbar .brand { font-size: 15px; }
  .topbar nav { gap: 4px; }
  .topbar nav a { padding: 5px 8px; font-size: 13px; }
  .topbar .who { font-size: 14px; gap: 8px; }
  .topbar .who .who-role { display: none; }
  .topbar .who > span, .topbar .who > .who-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
  .topbar .btn-ghost { padding: 7px 11px; font-size: 13.5px; }
}
.topbar .who { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.topbar .dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--line-green); display: inline-block;
}
.topbar form { margin: 0; }

/* --- Layout ------------------------------------------------------------- */
.page { max-width: 1180px; margin: 0 auto; padding: 28px 24px 48px; }
h1 { font-size: 26px; margin: 0 0 20px; }
h2 { font-size: 20px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 18px;
}

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.tile { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; text-align: center; }
.tile .n { font-size: 32px; font-weight: 700; color: var(--navy); }
.tile .label { color: var(--muted); font-size: 14px; }

/* --- Forms and buttons -------------------------------------------------- */
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="tel"], input[type="search"], input[type="date"], select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--white);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--navy);
  outline-offset: 1px;
  border-color: var(--navy);
}
.field { margin-bottom: 16px; }
.code-input { letter-spacing: 4px; text-transform: uppercase; font-size: 18px; }

.btn {
  display: inline-block;
  padding: 11px 20px;
  border: 1px solid var(--navy);
  border-radius: 8px;
  background: var(--navy);
  color: var(--white);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--navy-dark); }
.btn-ghost { background: var(--white); color: var(--navy); }
.btn-ghost:hover { background: #eef2f7; }
.btn-line {
  background: var(--line-green);
  border-color: var(--line-green);
  width: 100%;
  text-align: center;
  font-size: 18px;
  padding: 14px;
}
.btn-line:hover { background: var(--line-green-dark); }
.btn[disabled], .btn.disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* --- Tables ------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; background: var(--white); }
thead th { background: #f2f5f8; text-align: left; font-size: 15px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: #fafbfc; }

/* --- Status tags -------------------------------------------------------- */
.tag { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 14px; white-space: nowrap; }
.tag-wait { background: var(--tag-wait-bg); color: var(--tag-wait-fg); }
.tag-info { background: var(--tag-info-bg); color: var(--tag-info-fg); }
.tag-ok { background: var(--tag-ok-bg); color: var(--tag-ok-fg); }
.tag-bad { background: var(--tag-bad-bg); color: var(--tag-bad-fg); }
.tag-mute { background: var(--tag-mute-bg); color: var(--tag-mute-fg); }

/* --- Flash messages ----------------------------------------------------- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.flash-error { background: var(--tag-bad-bg); color: var(--tag-bad-fg); }
.flash-ok { background: var(--tag-ok-bg); color: var(--tag-ok-fg); }
.flash-warn { background: var(--tag-wait-bg); color: var(--tag-wait-fg); }

/* --- Split login screen (wireframe s1) ----------------------------------
   Fits the viewport in any orientation: the page itself never scrolls; the
   right panel scrolls internally only when the screen is very short. */
body.login-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
body.login-page .split { flex: 1 1 auto; min-height: 0; }
.split { display: grid; grid-template-columns: 48% 52%; }
.split .left {
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(24px, 5vw, 60px);
  overflow: hidden;
  min-height: 0;
}
.split .left .seal {
  width: clamp(90px, 12vw, 150px); height: clamp(90px, 12vw, 150px); border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; margin-bottom: clamp(16px, 3vh, 36px); flex: none;
}
/* Official seal: the round PNG fills the circle edge to edge (no padding). */
.split .left .seal-img { border-color: rgba(255, 255, 255, 0.9); overflow: hidden; background: var(--navy); }
.split .left .seal-img img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.split .left h1 { font-size: clamp(24px, 3vw, 38px); line-height: 1.3; margin-bottom: clamp(8px, 2vh, 20px); }
.split .left p { color: #c9d4e2; margin: 0; font-size: clamp(14px, 1.2vw, 16px); }
.split .right {
  background: var(--white);
  padding: clamp(16px, 4vw, 48px);
  display: flex; flex-direction: column; justify-content: center;
  gap: clamp(10px, 2vh, 18px);
  overflow-y: auto; min-height: 0;
}
.split .right .card { max-width: 560px; width: 100%; padding: clamp(14px, 2.5vh, 22px) clamp(16px, 2.5vw, 24px); margin-bottom: 0; flex: none; }
.split .right h2 { font-size: clamp(17px, 1.6vw, 20px); }
.split .right .btn-line { padding: clamp(10px, 1.6vh, 14px); font-size: clamp(16px, 1.4vw, 18px); }

/* Short landscape screens (phones sideways, small laptops): tighter left panel. */
@media (max-height: 560px) and (orientation: landscape) {
  .split { grid-template-columns: 38% 62%; }
  .split .left { padding: 16px 24px; }
  .split .left .seal { width: 72px; height: 72px; margin-bottom: 10px; }
  .split .left h1 { font-size: 20px; margin-bottom: 6px; }
  .split .left p { font-size: 12px; }
  .split .right { justify-content: flex-start; padding: 14px 20px; gap: 10px; }
  .split .right .card { padding: 12px 16px; }
  .split .right p { margin: 4px 0; }
}

/* Portrait / narrow screens: navy band on top, panel fills the rest. */
@media (orientation: portrait) and (max-width: 1100px), (max-width: 600px) {
  .split { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .split .left { flex-direction: row; align-items: center; gap: 16px; padding: 16px 20px; justify-content: flex-start; }
  .split .left .seal { width: clamp(64px, 18vw, 96px); height: clamp(64px, 18vw, 96px); margin: 0; }
  /* Two fixed lines on phones: "ระบบขอรับบัตรผ่าน" / "ทำเนียบรัฐบาล" (Chuey) — never re-wrapped */
  .split .left h1 { font-size: clamp(16px, 4.3vw, 24px); margin: 0 0 4px; flex: none; }
  .split .left h1 .t1, .split .left h1 .t2 { white-space: nowrap; }
  .split .left p { flex: 1 1 auto; min-width: 0; }
  .split .left p { font-size: 13px; }
  .split .right { justify-content: flex-start; padding: 16px; }
  .split .right .card { max-width: none; }
}

/* Watermark photo behind the right panel. Intensity is one variable. */
:root { --login-wm-opacity: 0.55; }
.split .right.has-watermark { position: relative; }
.split .right.has-watermark::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: url("img/watermark-login.webp"), url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABQODxIPDRQSEBIXFRQYHjIhHhwcHj0sLiQySUBMS0dARkVQWnNiUFVtVkVGZIhlbXd7gYKBTmCNl4x9lnN+gXz/2wBDARUXFx4aHjshITt8U0ZTfHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHz/wAARCAA4ACADASIAAhEBAxEB/8QAGgAAAQUBAAAAAAAAAAAAAAAAAAECAwUGBP/EACYQAAEEAQMDBAMAAAAAAAAAAAEAAgMRBBIhMQUTFEFCUWEGI7H/xAAYAQACAwAAAAAAAAAAAAAAAAABAgADBP/EABsRAAMBAQADAAAAAAAAAAAAAAABAhEhAxJB/9oADAMBAAIRAxEAPwCM4A0B1fRWd6jiOxsgtPB3C3MjWxtF8FUn5Bi64A9o3Z/Enjvo9Iy1JFYYXTJcwPLRQaOVxyxOieWPBBC0ppvCvDf9QfXbI4G5TciNs+KLHI3TZddaZdx8qSVwb2x7S1YviwuGRGHGxxHGNgN6VL17DZLE2eEWfcrftltNFaTyknhDsd8LQNNWpDc1oH1HTIQQWuFikPhuIXuANvpVuRM7yXFhNWAu850TToJ9Em+oSKR8Y0jVxyErNDpQGuppb8oIxxpsXqSlmO17Qdr4Ty9Ayh8vVX060eV+23eqEJK6wDps4tcwN9Eec57m3vR2QhSVgNP/2Q==");
  background-position: center 30%, center 30%;
  background-size: cover, cover;
  background-repeat: no-repeat, no-repeat;
  opacity: var(--login-wm-opacity);
}
.split .right.has-watermark > * { position: relative; }

/* Liquid Glass: translucent surfaces that blur what is behind them, with a
   light rim so edges stay visible; text stays on a soft frosted background. */
.split .right.has-watermark .card,
.split .right.has-watermark > p {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: 0 10px 34px rgba(31, 58, 95, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.75);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
  border-radius: 16px;
}
.split .right.has-watermark > p { padding: 8px 14px; display: inline-block; }
/* Text on glass: darker and bold so it stays crisp over the photo. */
.split .right.has-watermark .card h2 { color: var(--navy-dark); font-weight: 700; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7); }
.split .right.has-watermark .card p,
.split .right.has-watermark .card .muted,
.split .right.has-watermark > p { color: #16202b; font-weight: 600; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6); }
.split .right.has-watermark .card .small { font-weight: 600; }
.split .right.has-watermark .btn { font-weight: 700; }

.split .right.has-watermark .btn-line,
.split .right.has-watermark .btn-line.disabled {
  background: rgba(6, 199, 85, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 8px 24px rgba(6, 199, 85, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.55);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  backdrop-filter: blur(14px) saturate(160%);
  color: var(--white); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.split .right.has-watermark .btn-line.disabled { opacity: 0.7; }
.split .right.has-watermark .btn-line:hover { background: rgba(5, 169, 72, 0.75); }
.split .right.has-watermark .card .btn:not(.btn-line) {
  background: rgba(31, 58, 95, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 8px 24px rgba(31, 58, 95, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  backdrop-filter: blur(14px) saturate(160%);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.split .right.has-watermark .card .btn:not(.btn-line):hover { background: rgba(23, 44, 71, 0.8); }

/* --- Dev banner --------------------------------------------------------- */
.env-banner {
  background: #ffe8a3;
  color: #6b4e00;
  text-align: center;
  font-size: 14px;
  padding: 6px 12px;
}

footer.page-footer { color: var(--muted); font-size: 14px; padding: 8px 24px 32px; text-align: center; }

@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
}

/* --- Admin screens (M1) ------------------------------------------------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 16px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters input[type="search"], .filters input[type="text"] { width: 280px; }
.filters select { width: auto; min-width: 180px; }
.card-table { padding: 0; overflow-x: auto; }
.card-form { max-width: 640px; }
.card-done { border-left: 4px solid var(--line-green); }
.btn-sm { padding: 6px 12px; font-size: 14px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95em; }
/* Agency ids and card numbers contain hyphens ("สป-กค", "รมว-กค-001"); a narrow column
   would otherwise break them across two lines. Tables scroll sideways on phones instead. */
table code { white-space: nowrap; }
code.wrap { white-space: pre-wrap; word-break: break-all; }
.code-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 34px; letter-spacing: 6px; font-weight: 700; color: var(--navy);
  background: var(--bg); border: 2px dashed var(--navy); border-radius: var(--radius);
  padding: 22px; text-align: center; margin: 16px 0; user-select: all;
}
.pager { display: flex; gap: 10px; align-items: center; margin-top: 12px; }

/* --- Agency request screens (M3, wireframes s2/s3) ---------------------- */
.toolbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.toolbar .filters { margin-bottom: 16px; }
.toolbar .filters input[type="search"] { width: 340px; }

.stepper { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 22px; background: var(--white); }
.stepper .step { padding: 14px; text-align: center; font-weight: 600; color: var(--muted); text-decoration: none; border-right: 1px solid var(--border); }
.stepper .step:last-child { border-right: 0; }
.stepper .step.current { background: var(--navy); color: var(--white); }
.stepper .step.done { background: var(--tag-ok-bg); color: var(--tag-ok-fg); }

.section-title { border-left: 5px solid var(--navy); padding-left: 12px; font-size: 19px; margin-bottom: 16px; }
.section-title.in-table { margin: 18px 24px 8px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 20px; }
input[readonly] { background: #f2f5f8; color: var(--muted); }
input[type="tel"], input[type="file"] { font: inherit; }
input[type="file"] { width: 100%; }
.attached { margin: 0 0 6px; }

.table-wrap { overflow-x: auto; margin-bottom: 12px; }
table.items th, table.items td { padding: 8px 8px; vertical-align: top; }
table.items input[type="text"], table.items select { padding: 8px 10px; min-width: 120px; }
table.items .row-no { width: 32px; text-align: center; padding-top: 16px; color: var(--muted); }
table.items .slots { min-width: 260px; }
.slot { display: block; border: 1px dashed #aab4c0; border-radius: 8px; padding: 6px 10px; margin: 0 0 6px; color: var(--ink); font-size: 14px; cursor: pointer; background: #fafbfc; }
.slot.has-file { border-color: var(--line-green); border-style: solid; background: #f1fbf4; }
.slot input[type="file"] { display: block; font-size: 13px; margin-top: 4px; }
.slot a { font-weight: 700; color: var(--tag-ok-fg); text-decoration: none; }
input.invalid { border-color: var(--tag-bad-fg); outline-color: var(--tag-bad-fg); }
.btn-danger { background: var(--white); color: var(--tag-bad-fg); border-color: var(--tag-bad-fg); }
.btn-danger:hover { background: var(--tag-bad-bg); }
.btn-danger-ghost { color: var(--tag-bad-fg); border-color: var(--border); }

.form-footer { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin: 8px 0 24px; }
#autosave-status.warn { color: var(--tag-bad-fg); }
form.inline { display: inline; margin: 0; }
.cancel-form { margin: -8px 0 24px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.card-warn { border-left: 4px solid var(--tag-wait-fg); background: #fffaf0; }
/* Mandatory-signature notice above each item table (step 2). */
.note-required {
  margin: -4px 0 14px; padding: 10px 14px; border-radius: 10px;
  background: rgba(253, 240, 213, 0.9); border: 1px solid rgba(138, 90, 0, 0.35);
  color: #6b4500; font-weight: 600;
}
.note-required strong { color: #a12622; font-weight: 700; }
.star { color: #a12622; font-weight: 700; }
.problems { margin: 0 0 12px; padding-left: 22px; }
.dl { display: grid; grid-template-columns: 160px 1fr; gap: 6px 16px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

/* --- Print view --------------------------------------------------------- */
.print-sheet { max-width: 960px; margin: 0 auto; }
.print-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.print-title { font-size: 24px; font-weight: 700; color: var(--navy); }
@media print {
  .env-banner, .topbar, .no-print, .flash, body.has-watermark::before { display: none !important; }
  body { background: var(--white); font-size: 13px; }
  .page { padding: 0; max-width: none; }
  .card { break-inside: avoid; border-color: #999; }
  a { color: inherit; text-decoration: none; }
}

@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr; }
  .stepper { grid-template-columns: 1fr; }
  .stepper .step { border-right: 0; border-bottom: 1px solid var(--border); }
  .dl { grid-template-columns: 1fr; }
}

/* --- Reviewer queue (M4, wireframe s4) ---------------------------------- */
.review-layout { display: grid; grid-template-columns: 340px 1fr; gap: 24px; align-items: start; }
.review-queue h1 { font-size: 20px; }
.filters.stack { flex-direction: column; align-items: stretch; }
.filters.stack select { width: 100%; }
.queue-list { display: flex; flex-direction: column; gap: 10px; }
.queue-item { display: block; text-decoration: none; color: inherit; background: rgba(255, 255, 255, 0.55); border: 1px solid rgba(255, 255, 255, 0.7); border-radius: 12px; padding: 12px 14px; }
.queue-item:hover { background: rgba(255, 255, 255, 0.75); }
.queue-item.selected { border: 2px solid var(--navy); background: rgba(219, 234, 254, 0.7); }
.queue-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.review-detail .page-head h1 { font-size: 22px; }
table.review-items td { vertical-align: top; }
.decide-form textarea { min-height: 52px; margin-bottom: 8px; font-size: 14px; }
.decision-now { margin: 0 0 8px; }
.btn-approve { background: var(--line-green); border-color: var(--line-green); }
.btn-approve:hover { background: var(--line-green-dark); }
body.has-watermark .btn-approve { background: rgba(6, 199, 85, 0.75); }
body.has-watermark .btn-approve:hover { background: rgba(5, 169, 72, 0.9); }
@media (max-width: 1100px) { .review-layout { grid-template-columns: 1fr; } .review-layout > * { min-width: 0; } }

/* RFID number entry (card room / queue) */
.rfid-form { margin: 4px 0 0; gap: 6px; }
.rfid-form .rfid-input { width: 190px; padding: 6px 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* --- Gate screen (M5, wireframe s5; phone first) ------------------------- */
.gate { max-width: 560px; margin: 0 auto; }
.gate-search { text-align: center; }
.gate-scan { width: 100%; font-size: 18px; padding: 14px; margin-bottom: 8px; }
.qr-reader { width: 100%; max-width: 360px; margin: 0 auto 12px; border: 2px dashed #9aa7b5; border-radius: 12px; overflow: hidden; }
.gate-form { display: flex; gap: 8px; }
.gate-form .gate-input { font-size: 18px; text-align: center; }
.gate-result { border: 2px solid; border-radius: 14px; padding: 18px; margin-bottom: 16px; }
.gate-ok { border-color: #17663a; background: rgba(216, 243, 220, 0.75); }
.gate-bad { border-color: #a12622; background: rgba(253, 226, 225, 0.8); }
.gate-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.gate-ok h2 { color: #17663a; margin: 0; font-size: 24px; }
.gate-bad h2 { color: #a12622; margin: 0; font-size: 24px; }
.gate-photo { display: block; width: 120px; height: 150px; object-fit: cover; border-radius: 10px; margin: 12px auto; border: 2px solid rgba(255,255,255,0.8); box-shadow: 0 4px 14px rgba(0,0,0,0.15); }
.gate-table { margin-top: 12px; background: rgba(255, 255, 255, 0.6); }
.gate-table th { width: 34%; text-align: left; color: #46525f; font-weight: 600; }
.gate-alert { display: block; text-align: center; margin: 14px 0 6px; }
body.has-watermark .gate-ok, body.has-watermark .gate-bad { -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
@media (max-width: 600px) {
  .page { padding: 14px 12px 40px; }
  .gate-form { flex-direction: column; }
  .gate-table th, .gate-table td { padding: 8px 10px; }
}

/* --- M6: card changes ------------------------------------------------- */
.card-danger { border-left: 4px solid var(--tag-bad-fg); }
body.has-watermark .card-danger { background: rgba(253, 236, 235, 0.35); }
.revoke-form { margin: 0; }
.revoke-form input[type=text] { min-width: 220px; }
.amend-form .grid-3 { margin-bottom: 8px; }
s.muted { color: var(--muted); }
a.block-link { display: block; text-decoration: none; font-weight: 600; }

h1.mt { margin-top: 32px; }
.topbar .who-name { color: inherit; text-decoration: none; white-space: nowrap; border-bottom: 1px dotted rgba(255,255,255,0.5); }
.topbar .who-name:hover { border-bottom-color: #fff; }

/* --- LIFF entry page ------------------------------------------------- */
.liff-wait { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 12px; background: var(--navy); color: var(--white); }
.liff-wait h1 { color: var(--white); font-size: 24px; line-height: 1.3; margin: 0; }
.liff-wait .muted { color: #d6dee9; }
.liff-seal { width: 96px; height: 96px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.9); background: var(--navy); }
.liff-error { color: #ffd4d1; font-weight: 600; max-width: 420px; }
.split .right .btn-liff { display: block; width: 100%; text-align: center; margin-top: 10px; }
body.liff-page::before { display: none; }
body.has-watermark .liff-wait h1 { color: var(--white); text-shadow: 0 1px 3px rgba(0,0,0,0.35); }
body.has-watermark .liff-wait .muted { color: #d6dee9; text-shadow: none; }
#liff-open-app:not([hidden]) { display: flex; flex-direction: column; gap: 10px; align-items: center; }
#liff-open-app .btn-line { width: auto; min-width: 240px; }

/* --- Phones & tablets (portrait or landscape, ≤ 900px): hamburger menu ------
   The tab strip cannot fit, so brand + "เมนู" button form the bar; tabs, the
   account link and "ออกจากระบบ" drop down under it (Chuey, 7 ก.ย. 69). */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; }
  .topbar .brand { flex: 1 1 auto; min-width: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; }
  .nav-toggle {
    display: inline-flex; align-items: center; gap: 8px; flex: none;
    color: var(--white); font: inherit; font-weight: 700; font-size: 15px;
    padding: 7px 12px; border-radius: 10px; cursor: pointer;
    background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
  }
  .nav-toggle-bars { display: block; width: 18px; height: 2px; background: currentColor; position: relative; }
  .nav-toggle-bars::before, .nav-toggle-bars::after { content: ""; position: absolute; left: 0; width: 18px; height: 2px; background: currentColor; }
  .nav-toggle-bars::before { top: -6px; }
  .nav-toggle-bars::after { top: 6px; }
  .topbar.nav-open .nav-toggle { background: rgba(255, 255, 255, 0.32); }
  .topbar-menu { display: none; flex: 1 1 100%; flex-direction: column; gap: 10px; padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, 0.25); }
  .topbar.nav-open .topbar-menu { display: flex; }
  /* A long menu (admin has 9 tabs) must stay reachable on a short landscape screen. */
  .topbar.nav-open .topbar-menu { max-height: calc(100vh - 64px); overflow-y: auto; }
  .topbar nav { flex-direction: column; overflow: visible; gap: 6px; flex: none; }
  .topbar nav a { font-size: 16px; padding: 10px 14px; white-space: normal; }
  .topbar .who { display: flex; width: 100%; white-space: normal; font-size: 15px; gap: 10px; }
  .topbar .who .who-role { display: inline; }
  .topbar .who > .who-name { flex: 1 1 auto; min-width: 0; max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .btn-ghost { flex: none; padding: 8px 12px; font-size: 14px; }
}

/* Landscape phones / small tablets: two columns of tabs so the menu needs less scrolling. */
@media (max-width: 900px) and (min-width: 600px) {
  .topbar nav { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
}

/* --- Phones (≤ 760px, either orientation): everything fits the screen width ---
   Nothing scrolls sideways except a data table inside its own card. */
@media (max-width: 760px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  .page { padding: 14px 12px 40px; }
  h1 { font-size: 22px; line-height: 1.3; margin: 0 0 14px; overflow-wrap: anywhere; }
  h1.mt { margin-top: 24px; }
  h2 { font-size: 18px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 8px; margin-bottom: 8px; }
  .page-head h1 { margin: 0 0 4px; }
  .page-head > .btn, .page-head > a.btn { display: block; text-align: center; }
  .page-head .btn-row { width: 100%; }
  .tiles { gap: 10px; margin-bottom: 14px; }
  .tile { padding: 12px 8px; }
  .tile .n { font-size: 26px; }
  .tile .label { font-size: 13px; line-height: 1.35; }
  .filters { gap: 8px; margin-bottom: 12px; }
  .filters input[type="search"], .filters input[type="text"], .filters select { width: 100%; min-width: 0; }
  .filters .btn { width: 100%; text-align: center; }
  .card { padding: 14px; }
  .card-form { max-width: none; }
  .card-table { padding: 0; }
  /* Data tables keep their columns and scroll inside the card; the page itself never does. */
  table:not(.gate-table) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; font-size: 14px; }
  table:not(.gate-table) > thead, table:not(.gate-table) > tbody { min-width: 100%; }
  th, td { padding: 8px 10px; }
  thead th { font-size: 14px; white-space: nowrap; }
  .btn { padding: 10px 14px; }
  .btn-row .btn { flex: 1 1 auto; text-align: center; }
  .rfid-form .rfid-input, .revoke-form input[type=text] { width: 100%; min-width: 0; }
  .decide-form textarea { font-size: 15px; }
  .review-queue h1 { font-size: 20px; }
  .flash { padding: 10px 12px; font-size: 15px; }
}
.liff-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; margin-top: 8px; }
.liff-actions .btn { width: 100%; text-align: center; }

/* --- Personal-pass form: one card per person (Chuey, 8 ก.ย. 69) ------------- */
.person-card { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 14px; background: rgba(255,255,255,0.5); }
body.has-watermark .person-card { background: rgba(255, 255, 255, 0.28); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.person-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.person-head .row-no { font-weight: 700; color: var(--navy); }
.person-card .field { margin-bottom: 10px; }
.person-card label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.person-card .slot { display: inline-flex; }
.person-card .slots > label:first-child { margin-bottom: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.subgroup { border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px; margin: 0 0 10px; }
.subgroup legend { font-weight: 700; font-size: 14px; padding: 0 6px; }
.declaration .doc-list { margin: 0 0 8px 18px; padding: 0; }
.declaration .consent-text { border-left: 4px solid var(--navy); padding: 8px 12px; margin-top: 8px; background: rgba(31, 58, 95, 0.06); }
.declaration .consent-text p { margin: 4px 0; font-weight: 600; }
@media (max-width: 760px) {
  .grid-2 { grid-template-columns: 1fr; }
  .person-card { padding: 12px; }
}
.person-summary { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.person-summary:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.person-summary h3 { margin: 0 0 8px; font-size: 17px; }
.person-summary .dl { margin: 0; }
.doc-list { list-style: none; margin: 0 0 10px; padding: 0; }
.doc-item { display: flex; align-items: flex-start; gap: 8px; font-weight: 600; margin-bottom: 6px; }
.doc-check, .doc-total { width: 18px; height: 18px; accent-color: var(--line-green); flex: none; margin-top: 2px; }
.doc-check, .doc-total { pointer-events: none; }  /* read-only indicators */
.slot .doc-check { margin-right: 4px; vertical-align: -3px; }
.consent-check { display: flex; align-items: flex-start; gap: 10px; margin-top: 12px; font-weight: 700; }
.consent-check input { width: 20px; height: 20px; accent-color: var(--line-green); flex: none; margin-top: 2px; }
.consent-done { margin-top: 12px; font-weight: 700; color: var(--tag-ok-fg); }

/* Missing-field report on the request form */
#form-problems h2 { font-size: 18px; margin: 0 0 8px; }
#form-problems .problems { margin: 0 0 0 18px; padding: 0; }
#form-problems .problems li { margin-bottom: 4px; }
input.invalid, select.invalid, textarea.invalid { border-color: var(--tag-bad-fg); background: rgba(253, 226, 225, 0.5); }
.person-card input[type="date"] { width: 100%; }
.group-row td { background: rgba(31, 58, 95, 0.08); font-weight: 700; color: var(--navy-dark); }
body.has-watermark .group-row td { background: rgba(31, 58, 95, 0.14); }

/* --- QR sign-in (login page) + the note under it -------------------------- */
/* The note used to stretch to the panel width while the card stops at 560px
   (Chuey, 21 ก.ย. 69: make both the same width). */
.split .right > p.login-note { max-width: 560px; width: 100%; margin: 0; }
.split .right.has-watermark > p.login-note { display: block; }

.btn-qr { width: 100%; }
.qr-panel { margin-top: 12px; text-align: center; }
.qr-panel img {
  width: 220px; height: 220px; display: block; margin: 0 auto 10px;
  background: #fff; padding: 8px; border-radius: 10px;
}
.qr-panel p { margin: 4px 0; }
.qr-pair code {
  font-size: 22px; font-weight: 700; letter-spacing: 3px;
  background: var(--tag-info-bg); color: var(--tag-info-fg);
  padding: 2px 10px; border-radius: 6px;
}
.qr-status-bad { color: var(--tag-bad-fg); font-weight: 700; }
body.has-watermark .qr-panel img { background: rgba(255, 255, 255, 0.92); }

/* Confirmation screen shown inside the LINE app after scanning. */
.qr-confirm { max-width: 460px; margin: 24px auto; }
.qr-confirm h1 { font-size: 22px; margin-bottom: 8px; }
.qr-confirm .qr-code-big { text-align: center; margin: 14px 0; }
.qr-confirm .qr-code-big code {
  font-size: 34px; font-weight: 700; letter-spacing: 8px;
  background: var(--tag-info-bg); color: var(--tag-info-fg);
  padding: 6px 16px; border-radius: 10px;
}
.qr-confirm form { margin-top: 10px; }
.qr-confirm .btn { width: 100%; }
