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

/* ── Brand tokens ── */
:root {
  --dang-red:        #FF3131;
  --dang-red-dark:   #B32222;
  --dang-red-deep:   #801919;
  --dang-coral:      #FF6F6F;
  --dang-coral-soft: #FFD5D5;
  --ink:             #1A1410;
  --ink-soft:        #3E3632;
  --muted:           #8A7F78;
  --line:            #E6E2DC;
  --line-strong:     #2A2320;
  --paper:           #FFFFFF;
  --paper-warm:      #FBF7F2;
  --concrete:        #F4EFE9;
  --concrete-2:      #EAE3DB;
  --success:         #1F7A4C;
  --warn:            #B86B0B;
  --danger:          var(--dang-red);
  --r-sm:  8px;
  --r-md:  12px;
  --r-lg:  20px;
  --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(26,20,16,.06), 0 1px 1px rgba(26,20,16,.04);
  --shadow-md: 0 6px 18px rgba(26,20,16,.08), 0 2px 4px rgba(26,20,16,.05);
  --shadow-lg: 0 20px 40px rgba(128,25,25,.15), 0 4px 8px rgba(26,20,16,.06);
  --shadow-red: 0 10px 24px rgba(255,49,49,.28);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: 'Sarabun', 'Jost', sans-serif;
  background: var(--paper-warm);
  color: var(--ink);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ── Utility ── */
.mono { font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: .04em; }
.hand { font-family: 'Caveat', cursive; font-weight: 500; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.fw-700 { font-weight: 700; }
.fw-600 { font-weight: 600; }

/* ── Layout ── */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.page-centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--paper-warm);
  padding: 24px;
}
.container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-title {
  font-weight: 700;
  font-size: 15px;
}
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--ink-soft);
  background: none;
  border: none;
  padding: 4px 0;
}
.back-btn:hover { color: var(--ink); }

/* ── Logo ── */
.logo-wrap { display: inline-flex; align-items: flex-start; gap: 2px; }
.logo-dang {
  font-family: 'Jost', sans-serif;
  font-weight: 700;
  font-size: 38px;
  letter-spacing: -.04em;
  color: var(--dang-red);
  line-height: 1;
  position: relative;
  display: inline-block;
}
.logo-dang::before {
  content: '';
  position: absolute;
  left: 10px; top: -16px;
  width: 13px; height: 18px;
  border: 3px solid var(--dang-red);
  border-bottom: none; border-right: none;
  border-top-left-radius: 4px;
  transform: rotate(25deg);
}
.logo-sub {
  font-size: 9px; font-weight: 500;
  letter-spacing: .18em; color: var(--ink);
  text-transform: uppercase;
  text-align: center; margin-top: 2px;
  font-family: 'Jost', sans-serif;
}
.logo-sm {
  font-family: 'Jost', sans-serif;
  font-weight: 700; font-size: 20px;
  letter-spacing: -.04em; color: var(--dang-red);
  position: relative; display: inline-block;
}
.logo-sm::before {
  content: '';
  position: absolute;
  left: 6px; top: -9px;
  width: 8px; height: 10px;
  border: 2px solid var(--dang-red);
  border-bottom: none; border-right: none;
  border-top-left-radius: 3px;
  transform: rotate(25deg);
}

/* ── Chevron pattern ── */
.chevron-bg {
  background-image:
    linear-gradient(135deg, var(--dang-red-deep) 25%, transparent 25%),
    linear-gradient(225deg, var(--dang-red-deep) 25%, transparent 25%),
    linear-gradient(315deg, var(--dang-red-deep) 25%, transparent 25%),
    linear-gradient(45deg,  var(--dang-red-deep) 25%, transparent 25%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .02em;
  border: none;
  cursor: pointer;
  transition: transform .06s, background .15s, box-shadow .15s;
  width: 100%;
}
.btn:active { transform: translateY(1px); }

.btn-red {
  background: var(--dang-red);
  color: white;
  box-shadow: var(--shadow-red);
}
.btn-red:hover { background: var(--dang-red-dark); }

.btn-dark {
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow-md);
}
.btn-dark:hover { background: var(--ink-soft); }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--line);
  box-shadow: none;
  padding: 12px 18px;
}
.btn-ghost:hover { background: var(--concrete); border-color: var(--ink-soft); }

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: var(--r-sm);
}

/* ── Form inputs ── */
.field { display: flex; flex-direction: column; gap: 6px; }
.label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.input {
  height: 52px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  padding: 0 16px;
  font-size: 15px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
.input::placeholder { color: var(--muted); }
.input:focus { border-color: var(--dang-red); box-shadow: 0 0 0 3px rgba(255,49,49,.15); }
textarea.input { height: auto; padding: 12px 16px; resize: vertical; }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238A7F78' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

.check-label {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 14px; color: var(--ink-soft); cursor: pointer; user-select: none;
}
.check-box {
  width: 20px; height: 20px;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--paper); flex-shrink: 0;
  transition: background .15s, border-color .15s;
}
input[type="checkbox"]:checked + .check-box,
.check-box.checked {
  background: var(--dang-red);
  border-color: var(--dang-red);
}

/* ── Cards / surfaces ── */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card-soft {
  background: var(--concrete);
  border-radius: var(--r-lg);
  padding: 18px;
}
.card-red {
  background: linear-gradient(160deg, var(--dang-red) 0%, var(--dang-red-dark) 100%);
  color: white;
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-lg);
}
.card-red .text-muted { color: rgba(255,255,255,.75); }

/* ── Module rows ── */
.mod-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color .15s, transform .06s;
  text-decoration: none; color: inherit;
}
.mod-row:hover { border-color: var(--ink-soft); }
.mod-row:active { transform: translateY(1px); }
.mod-icon {
  width: 44px; height: 44px;
  border-radius: var(--r-md);
  background: var(--dang-coral-soft);
  color: var(--dang-red-deep);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; flex-shrink: 0;
}
.mod-icon.dark { background: var(--ink); color: white; }
.mod-icon.admin-icon { background: var(--concrete-2); color: var(--ink-soft); }
.mod-body { flex: 1; min-width: 0; }
.mod-title { font-size: 15px; font-weight: 600; }
.mod-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mod-chev { color: var(--muted); font-size: 22px; }

/* ── Pills / badges ── */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  background: var(--concrete); color: var(--ink-soft);
}
.pill-red   { background: var(--dang-coral-soft); color: var(--dang-red-deep); }
.pill-dark  { background: var(--ink); color: white; }
.pill-green { background: #DCF2E6; color: var(--success); }
.pill-warn  { background: #FBE8CE; color: var(--warn); }
.pill-late  { background: #FBE8CE; color: var(--warn); }

/* ── Avatar ── */
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--ink); color: white;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px; flex-shrink: 0;
}
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }

/* ── Type scale ── */
.h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.h2 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; }
.h3 { font-size: 17px; font-weight: 600; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.sub { color: var(--ink-soft); font-size: 14px; }

/* ── Stat cards ── */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px;
  text-align: center;
}
.stat-card .stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat-card .stat-label { font-size: 11px; color: var(--muted); }

/* ── Live status dot ── */
.dot-live {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: var(--dang-red);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,49,49,.5); }
  50%       { box-shadow: 0 0 0 6px rgba(255,49,49,0); }
}

/* ── Bottom nav ── */
.bottom-nav {
  display: flex; justify-content: space-around;
  border-top: 1px solid var(--line);
  padding: 8px 10px 12px;
  background: var(--paper);
  position: sticky; bottom: 0; z-index: 100;
}
.bn-item {
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  padding: 6px 10px;
  font-size: 10px; color: var(--muted); font-weight: 500;
  text-decoration: none; border-radius: var(--r-sm);
  transition: color .15s;
}
.bn-item.active { color: var(--dang-red); }
.bn-dot {
  width: 24px; height: 24px; border-radius: 7px;
  background: var(--concrete); display: flex;
  align-items: center; justify-content: center; font-size: 14px;
}
.bn-item.active .bn-dot { background: var(--dang-red); color: white; }

/* ── Divider ── */
.divider { height: 1px; background: var(--line); width: 100%; }

/* ── Scroll area ── */
.scroll-area { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }

/* ── Section label ── */
.section-label {
  font-size: 12px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
}

/* ── QR display ── */
.qr-wrap {
  background: white; border-radius: var(--r-lg);
  padding: 20px; display: flex; align-items: center;
  justify-content: center; box-shadow: var(--shadow-md);
}
.qr-wrap img { width: 220px; height: 220px; display: block; }

/* ── Countdown ── */
.countdown-ring {
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 4px;
  background: var(--concrete); border-radius: var(--r-lg);
  padding: 16px; text-align: center;
}
.countdown-num { font-size: 32px; font-weight: 700; letter-spacing: -.02em; }
.countdown-num.urgent { color: var(--dang-red); }

/* ── Scanner ── */
.scanner-bg {
  background: #111;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
#qr-reader { width: 100%; }
#qr-reader video { border-radius: 0; }

/* ── Clock record row ── */
.record-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.record-time { font-family: 'JetBrains Mono', monospace; font-size: 13px; width: 50px; color: var(--ink-soft); }

/* ── Success / Error centered ── */
.result-icon {
  width: 80px; height: 80px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
}
.result-icon.ok { background: #DCF2E6; color: var(--success); }
.result-icon.err { background: var(--dang-coral-soft); color: var(--dang-red); }

/* ── Info row in cards ── */
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.info-row:last-child { border-bottom: none; }
.info-key { font-size: 12px; color: var(--muted); }
.info-val { font-size: 14px; font-weight: 600; }

/* ── Table ── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.tbl th { font-weight: 600; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); background: var(--concrete); }
.tbl tr:hover td { background: var(--paper-warm); }

/* ── Messages (Django) ── */
.messages { list-style: none; }
.messages li {
  padding: 12px 16px; border-radius: var(--r-md);
  margin-bottom: 10px; font-size: 14px;
}
.messages .success { background: #DCF2E6; color: var(--success); }
.messages .error   { background: var(--dang-coral-soft); color: var(--dang-red-deep); }
.messages .warning { background: #FBE8CE; color: var(--warn); }
.messages .info    { background: var(--concrete); color: var(--ink-soft); }

/* ── Responsive ── */
@media (min-width: 640px) {
  .container { max-width: 560px; }
  .stat-grid { gap: 14px; }
}
@media (min-width: 1024px) {
  .container { max-width: 760px; }
}
