:root {
  --bg: #f5f5f4;
  --panel: #ffffff;
  --panel-2: #fafaf9;
  --border: #e7e5e4;
  --text: #1c1917;
  --muted: #78716c;
  --accent: #f2b705;
  --accent-ink: #1c1917;
  --accent-soft: #fdf3d3;
  --accent-text: #8a6400;
  --side: #1c1917;
  --side-text: #d6d3d1;
  --side-active: #292524;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0a09;
    --panel: #1c1917;
    --panel-2: #171412;
    --border: #2e2a27;
    --text: #f5f5f4;
    --muted: #a8a29e;
    --accent-soft: #332806;
    --accent-text: #f5c842;
    --side: #0c0a09;
    --side-active: #1c1917;
    --ok-soft: #12301d;
    --warn-soft: #3a2a0a;
    --bad-soft: #3b1212;
    --info-soft: #0f2246;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Inter, system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-text);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; justify-content: center; padding: 0 6px 18px; }
.brand img { width: 100%; max-width: 190px; height: auto; display: block; }
h1 { font-family: Oswald, Inter, sans-serif; text-transform: uppercase; letter-spacing: .02em; font-weight: 700; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  text-decoration: none; color: var(--side-text); font-weight: 500;
}
.nav a:hover { background: var(--side-active); color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav .badge { margin-left: auto; background: var(--accent); color: var(--accent-ink); font-weight: 700; border-radius: 99px; font-size: 11px; padding: 1px 7px; }
.side-foot { margin-top: auto; }
.side-foot button { width: 100%; background: transparent; border: 1px solid #44403c; color: var(--side-text); }

.main { padding: 28px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }

.stat { padding: 18px; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }

/* controls */
button, .btn {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 8px 14px; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap;
}
button:hover { background: var(--panel-2); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(.95); }
button.danger { color: var(--bad); }
button.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--panel-2); }
button.sm { padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 70px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; }
label.field span { color: var(--muted); }
.form { display: grid; gap: 14px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }
.search { max-width: 320px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
.empty { padding: 36px; text-align: center; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.pill.accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { border: none; background: none; border-radius: 0; padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.progress { height: 6px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }

/* weekly timetable */
.week { display: grid; grid-template-columns: 56px repeat(7, minmax(110px, 1fr)); border-top: 1px solid var(--border); }
.week .wh { padding: 10px 8px; font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--border); border-left: 1px solid var(--border); text-align: center; background: var(--panel-2); position: sticky; top: 0; z-index: 2; }
.week .wh.today { color: var(--accent-text); }
.week .wh small { display: block; color: var(--muted); font-weight: 500; }
.week .hours { position: relative; }
.week .hour { height: 52px; font-size: 11px; color: var(--muted); text-align: right; padding: 2px 6px 0 0; }
.week .col { position: relative; border-left: 1px solid var(--border); }
.week .col .slot { height: 52px; border-bottom: 1px dashed var(--border); cursor: pointer; }
.week .col .slot:hover { background: var(--panel-2); }
.week .ev {
  position: absolute; left: 3px; right: 3px; border-radius: 7px; padding: 4px 7px; font-size: 12px; overflow: hidden;
  background: var(--evbg, var(--accent-soft)); border-left: 3px solid var(--evc, var(--accent)); cursor: pointer; line-height: 1.3; z-index: 1;
}
.week .ev:hover { filter: brightness(.97); z-index: 3; box-shadow: var(--shadow); }
.week .ev b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.week .ev.cancelled { opacity: .45; text-decoration: line-through; }
.week .ev.completed { opacity: .7; }
.week .now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--bad); z-index: 4; pointer-events: none; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(12,10,9,.45); display: grid; place-items: center; z-index: 50; padding: 20px; animation: fade .12s; }
.modal { background: var(--panel); border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(760px, 100%); }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.modal-head .x { margin-left: auto; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--panel-2); position: sticky; bottom: 0; }
@keyframes fade { from { opacity: 0; } }

#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--side); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 360px; animation: fade .15s; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(ellipse at top, #2a2310 0%, #0c0a09 60%); }
.login .card { width: min(400px, 100%); padding: 28px; background: #1c1917; border-color: #2e2a27; color: #f5f5f4; }
.login .brand { padding: 0 0 22px; }
.login .brand img { max-width: 280px; }
.login label.field span { color: #a8a29e; }
.login input { background: #0c0a09; border-color: #2e2a27; color: #f5f5f4; }

/* check-in */
.checkin-result { padding: 24px; border-radius: var(--radius); text-align: center; }
.checkin-result.ok { background: var(--ok-soft); }
.checkin-result.err { background: var(--bad-soft); }
.checkin-result .big { font-size: 22px; font-weight: 700; margin: 6px 0; }
#qr-reader { border-radius: 10px; overflow: hidden; }
#qr-reader video { border-radius: 10px; }

.kiosk { position: fixed; inset: 0; background: #0c0a09; color: #fff; display: grid; place-items: center; z-index: 60; text-align: center; }
.kiosk .qr-box { background: #fff; padding: 22px; border-radius: 20px; display: inline-block; }
.kiosk .qr-box img, .kiosk .qr-box svg { display: block; width: min(48vh, 80vw); height: auto; }
.kiosk .klogo { width: min(420px, 70vw); height: auto; margin-bottom: 12px; }
.kiosk .count { margin-top: 18px; color: #a8a29e; }

.qr-card { display: inline-block; background: #fff; padding: 12px; border-radius: 12px; border: 1px solid var(--border); }
.qr-card img { display: block; width: 180px; height: 180px; image-rendering: pixelated; }

.member-search-results { border: 1px solid var(--border); border-radius: 10px; margin-top: 8px; max-height: 300px; overflow: auto; }
.member-search-results .list-item { cursor: pointer; padding: 10px 12px; }
.member-search-results .list-item:hover { background: var(--panel-2); }

.mobile-top { display: none; }
.detail-grid { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
@media (max-width: 1100px) { .detail-grid { grid-template-columns: 1fr; } }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .mobile-top img { height: 30px; }
  .mobile-top { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--side); color: #fff; position: sticky; top: 0; z-index: 30; }
  .mobile-top button { background: transparent; border-color: #44403c; color: #fff; }
  .main { padding: 18px 16px 50px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .form .two, .form .three { grid-template-columns: 1fr; }
}
