/* ===== Design tokens ===== */
:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #f0f2f7;
    --text: #111827;
    --muted: #6b7280;
    --border: #e4e7ee;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --on-primary: #ffffff;
    --green: #16a34a;
    --green-soft: #dcfce7;
    --amber: #d97706;
    --amber-soft: #fef3c7;
    --red: #dc2626;
    --red-soft: #fee2e2;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .05);
    --focus: 0 0 0 3px rgba(79, 70, 229, .25);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1016;
        --surface: #161922;
        --surface-2: #1e222e;
        --text: #e6e8ee;
        --muted: #9aa1b2;
        --border: #2a2f3d;
        --primary: #818cf8;
        --primary-hover: #a5b4fc;
        --primary-soft: #23264a;
        --on-primary: #0e1016;
        --green: #4ade80;
        --green-soft: rgba(74, 222, 128, .14);
        --amber: #fbbf24;
        --amber-soft: rgba(251, 191, 36, .14);
        --red: #f87171;
        --red-soft: rgba(248, 113, 113, .14);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3);
        --focus: 0 0 0 3px rgba(129, 140, 248, .35);
        color-scheme: dark;
    }
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 700; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

.container { width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 16px; }
main.container { padding-top: 28px; padding-bottom: 48px; }
main.narrow { max-width: 560px; }

.icon { width: 18px; height: 18px; flex-shrink: 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.stack > * + * { margin-top: 16px; }

/* ===== Top bar ===== */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { color: var(--text); }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: var(--on-primary); }
.nav { display: flex; align-items: center; gap: 8px; }
.nav-link { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav-link:hover, .nav-link.active { color: var(--text); background: var(--surface-2); }

.public-brand { display: flex; justify-content: center; margin-bottom: 20px; }

/* ===== Page heading ===== */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head p { margin: 4px 0 0; }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--muted); margin-bottom: 12px; }

/* ===== Cards ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-head { padding: 20px 24px 0; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; font: inherit; font-weight: 600; font-size: .95rem; line-height: 1.2;
    border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap;
    transition: background-color .15s, border-color .15s, color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); color: var(--on-primary); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--surface); color: var(--red); border-color: var(--border); }
.btn-danger:hover { background: var(--red-soft); color: var(--red); border-color: transparent; }
.btn-whatsapp { background: #25d366; color: #fff; }
.btn-whatsapp:hover { background: #1ebe5b; color: #fff; }
.btn-block { width: 100%; padding: 14px 18px; font-size: 1rem; }
.btn-sm { padding: 7px 12px; font-size: .85rem; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }

/* ===== Forms ===== */
.field + .field { margin-top: 18px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 18px; }
.field-row .field + .field { margin-top: 0; }
.label { display: block; font-weight: 600; font-size: .95rem; margin-bottom: 6px; }
.input {
    width: 100%; padding: 12px 14px; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--muted); opacity: .7; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.input.is-invalid { border-color: var(--red); }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; top: 50%; inset-inline-start: 12px; transform: translateY(-50%); color: var(--muted); }
.input-icon .input { padding-inline-start: 38px; }
.hint { margin-top: 6px; font-size: .85rem; color: var(--muted); }
.error { margin-top: 6px; font-size: .85rem; color: var(--red); }
.form-actions { display: flex; gap: 12px; margin-top: 28px; }
.form-actions .btn-primary { flex: 1; }

/* ===== Status colors ===== */
.status-attending { --c: var(--green); --c-soft: var(--green-soft); }
.status-maybe { --c: var(--amber); --c-soft: var(--amber-soft); }
.status-not_attending { --c: var(--red); --c-soft: var(--red-soft); }

/* ===== Attendance choices ===== */
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0 24px; }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-body {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 18px 8px; text-align: center; font-weight: 600;
    border: 2px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
    transition: border-color .15s, background-color .15s, transform .1s;
}
.choice-emoji { font-size: 1.8rem; line-height: 1; }
.choice:hover .choice-body { border-color: var(--c); }
.choice input:checked + .choice-body { border-color: var(--c); background: var(--c-soft); color: var(--c); transform: scale(1.02); }
.choice input:focus-visible + .choice-body { box-shadow: var(--focus); }

/* ===== Course hero ===== */
.eyebrow { display: inline-block; font-size: .8rem; font-weight: 600; color: var(--primary); background: var(--primary-soft); padding: 4px 10px; border-radius: 999px; margin-bottom: 12px; }
.meta { display: flex; flex-wrap: wrap; gap: 10px 20px; margin-top: 14px; color: var(--muted); }
.meta span { display: inline-flex; align-items: center; gap: 6px; }

/* ===== Badges ===== */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-upcoming { background: var(--primary-soft); color: var(--primary); }
.badge-today { background: var(--green-soft); color: var(--green); }
.badge-past { background: var(--surface-2); color: var(--muted); }

/* ===== Attendance bar ===== */
.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.bar-sm { height: 6px; }
.bar-seg { background: var(--c); transition: width .4s ease; }
.results { display: grid; gap: 4px; margin-top: 16px; }
.result-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.result-row:last-child { border-bottom: 0; }
.result-label { display: inline-flex; align-items: center; gap: 10px; font-weight: 500; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.result-count { font-weight: 700; font-size: 1.1rem; }
.result-pct { color: var(--muted); font-size: .85rem; font-weight: 400; margin-inline-start: 6px; }
.counts-inline { display: flex; gap: 12px; margin-top: 8px; font-size: .85rem; font-weight: 600; }
.counts-inline span { display: inline-flex; align-items: center; gap: 5px; }

/* ===== Stats ===== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.stat-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--c-soft, var(--primary-soft)); color: var(--c, var(--primary)); }
.stat-icon .icon { width: 22px; height: 22px; }
.stat-value { display: block; font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: .85rem; color: var(--muted); }

/* ===== Table ===== */
.table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.table th { padding: 12px 24px; font-size: .8rem; font-weight: 600; color: var(--muted); text-align: start; background: var(--surface-2); }
.table td { padding: 16px 24px; border-top: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background-color .15s; }
.table tbody tr:hover { background: var(--surface-2); }
.table .col-responses { min-width: 180px; }
.course-title { display: block; font-weight: 600; color: var(--text); }
.course-title:hover { color: var(--primary); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions form { margin: 0; }
.search { flex: 1 1 200px; max-width: 280px; }
.search .input { padding-top: 9px; padding-bottom: 9px; }

@media (max-width: 760px) {
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { padding: 16px 20px; border-top: 1px solid var(--border); }
    .table td { padding: 4px 0; border: 0; }
    .table td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; color: var(--muted); }
    .table td:first-child::before { display: none; }
    .row-actions { justify-content: flex-start; margin-top: 10px; }
}

/* ===== Share box ===== */
.share { display: flex; gap: 8px; flex-wrap: wrap; }
.share .input { flex: 1 1 240px; direction: ltr; text-align: left; background: var(--surface-2); }

/* ===== Names ===== */
.columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.column-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 12px; margin-bottom: 8px; border-bottom: 2px solid var(--c); }
.column-head h2 { display: inline-flex; align-items: center; gap: 8px; font-size: 1rem; }
.column-count { font-weight: 700; color: var(--c); background: var(--c-soft); padding: 2px 10px; border-radius: 999px; font-size: .85rem; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--c-soft); color: var(--c); font-weight: 700; font-size: .9rem; flex-shrink: 0; }

/* ===== Alerts, empty states ===== */
.alert { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: var(--radius-sm); margin-bottom: 20px; }
.alert-success { background: var(--green-soft); color: var(--green); }
.alert-info { background: var(--surface-2); color: var(--muted); }
.alert .icon { margin-top: 3px; }
.alert strong { display: block; color: var(--text); }

.success-card { text-align: center; }
.success-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%; background: var(--c-soft); color: var(--c); }
.success-icon .icon { width: 30px; height: 30px; stroke-width: 3; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; margin-top: 10px; border-radius: 999px; background: var(--c-soft); color: var(--c); font-weight: 700; }

.empty { text-align: center; padding: 48px 24px; }
.empty-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 18px; background: var(--primary-soft); color: var(--primary); }
.empty-icon .icon { width: 30px; height: 30px; }
.empty p { margin: 6px 0 20px; }
.empty-small { color: var(--muted); font-size: .9rem; padding: 8px 0; }

details.change summary { cursor: pointer; list-style: none; text-align: center; color: var(--primary); font-weight: 600; margin-top: 16px; }
details.change summary::-webkit-details-marker { display: none; }
details.change[open] summary { display: none; }

/* ===== Toast ===== */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px);
    display: inline-flex; align-items: center; gap: 8px;
    padding: 12px 18px; border-radius: 999px; background: var(--text); color: var(--bg);
    font-weight: 600; font-size: .9rem; box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
    opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== Responsive ===== */
@media (max-width: 860px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .columns { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
    h1 { font-size: 1.35rem; }
    .card { padding: 20px; }
    .stats { gap: 10px; }
    .stat { padding: 14px; gap: 10px; }
    .stat-icon { width: 38px; height: 38px; }
    .stat-value { font-size: 1.35rem; }
    .field-row { grid-template-columns: 1fr; }
    .choice-body { padding: 14px 4px; font-size: .9rem; }
    .nav-link { display: none; }
    .search { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
main.wide { max-width: 1040px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
