:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --accent: #4f7cff;
    --accent-hover: #3d6bf0;
    --danger: #e5484d;
    --ok: #30a46c;
    --warn: #f5a524;
    --radius: 10px;
    color-scheme: dark;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f6f7f9;
        --surface: #ffffff;
        --surface-2: #f0f2f5;
        --border: #dfe3e8;
        --text: #1a1d23;
        --muted: #667085;
        color-scheme: light;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
    line-height: 1.55;
}

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

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 18px; margin: 0; }
.brand span { color: var(--muted); font-size: 13px; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 24px; }

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }

.tab {
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
}
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

button, .btn {
    font: inherit;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    padding: 8px 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
button:hover, .btn:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: not-allowed; }

.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-hover); }
.danger { color: var(--danger); }
.small { padding: 5px 10px; font-size: 13px; }

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

.card-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.card h3 { margin: 0 0 4px; font-size: 17px; }
.card .desc { color: var(--muted); margin: 6px 0 0; font-size: 14px; white-space: pre-wrap; }

.meta { color: var(--muted); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.meta code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; color: var(--text); }

.badge {
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    white-space: nowrap;
}
.badge.live { background: rgba(48,164,108,.15); color: var(--ok); border-color: rgba(48,164,108,.4); }
.badge.scheduled { background: rgba(245,165,36,.15); color: var(--warn); border-color: rgba(245,165,36,.4); }
.badge.ended, .badge.expired { background: var(--surface-2); color: var(--muted); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* forms */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .field { flex: 1 1 200px; }

input, textarea, select {
    width: 100%;
    font: inherit;
    padding: 9px 11px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; min-height: 72px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    padding: 22px;
    width: min(560px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0,0,0,.55); }
#attendance { width: min(760px, calc(100vw - 32px)); }
#attendance-body { overflow-x: auto; }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.msg { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }
.msg.error { background: rgba(229,72,77,.14); color: var(--danger); border: 1px solid rgba(229,72,77,.35); }
.msg.ok { background: rgba(48,164,108,.14); color: var(--ok); border: 1px solid rgba(48,164,108,.35); }
.msg:empty { display: none; }

/* centred pages: login + join */
.center {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 30px;
    width: min(430px, 100%);
}
.panel h1 { margin: 0 0 6px; font-size: 20px; }
.panel .sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.panel button[type=submit] { width: 100%; }

.toast {
    position: fixed;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 14px;
    opacity: 0;
    transition: opacity .2s;
    pointer-events: none;
}
.toast.show { opacity: 1; }
