:root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #f8f9fb;
    --text: #111318;
    --text-2: #374151;
    --muted: #6b7280;
    --line: #e6e8ee;
    --line-strong: #d3d7df;
    --accent: #e11d48;
    --accent-600: #be123c;
    --accent-soft: #fff1f3;
    --accent-ring: rgba(225, 29, 72, .14);
    --ok: #15803d;
    --ok-soft: #ecfdf3;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --side: #0f1115;
    --side-text: #9aa1ae;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body.admin, body.auth {
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
.icon { flex-shrink: 0; display: block; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--side);
    color: var(--side-text);
    display: flex;
    flex-direction: column;
    padding: 22px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; font-weight: 700; padding: 2px 8px 28px; font-size: 16px; line-height: 1.2; }
.brand small { display: block; font-weight: 500; font-size: 12px; color: var(--side-text); margin-top: 2px; }
.brand-mark {
    width: 40px; height: 40px; border-radius: 11px;
    background: linear-gradient(135deg, #fb7185, var(--accent));
    display: grid; place-items: center; color: #fff;
    box-shadow: 0 6px 16px rgba(225, 29, 72, .35);
}
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 10px;
    text-decoration: none; font-weight: 500;
    transition: background .15s, color .15s;
}
.side-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side-link.active { background: rgba(225, 29, 72, .16); color: #fff; }
.side-link.active .icon { color: #fb7185; }
.side-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 4px; border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 12px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.scrim { display: none; }
.content { padding: 36px 44px 72px; max-width: 1360px; width: 100%; margin: 0 auto; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -.025em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- Cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.card-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.stack > * + * { margin-top: 20px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { padding: 18px 20px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 6px; display: flex; align-items: center; gap: 10px; min-height: 40px; }
.stat-value .avatar { width: 36px; height: 36px; font-size: 13px; }
.stat-leader { font-size: 16px; font-weight: 700; line-height: 1.2; }
.stat-leader small { display: block; color: var(--muted); font-weight: 500; font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font: inherit; font-weight: 600; font-size: 14px;
    padding: 10px 16px; border-radius: 10px; border: 1px solid transparent;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--accent-ring); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(225, 29, 72, .3); }
.btn-primary:hover { background: var(--accent-600); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--line-strong); background: var(--surface-2); }
.btn-danger { background: var(--surface); border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-lg { padding: 14px 20px; font-size: 16px; width: 100%; border-radius: 12px; }
.icon-btn {
    width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center;
    border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.input {
    font: inherit; width: 100%; padding: 10px 12px;
    border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.input:hover { border-color: var(--line-strong); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
textarea.input { min-height: 92px; resize: vertical; }
select.input { cursor: pointer; }
.hint { font-size: 13px; color: var(--muted); }
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; margin-bottom: 20px; font-size: 14px; }
.alert-error { background: var(--danger-soft); color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: var(--ok-soft); color: var(--ok); border: 1px solid #bbf7d0; }
.alert ul { margin: 0; padding-left: 4px; list-style: none; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; top: 20px; right: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
    display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px;
    background: var(--text); color: #fff; font-weight: 500; max-width: 440px; cursor: pointer;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .2);
    animation: toast-in .25s ease-out;
    transition: opacity .3s, transform .3s;
}
.toast-success .icon { color: #4ade80; }
.toast-error { background: var(--danger); }
.toast.hide { opacity: 0; transform: translateY(-8px); pointer-events: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- Avatars & badges ---------- */
.avatar {
    width: 40px; height: 40px; border-radius: 50%; object-fit: cover;
    display: inline-grid; place-items: center; flex-shrink: 0;
    background: linear-gradient(135deg, #f1f2f6, #e3e6ec); color: #4b5563; font-weight: 700; font-size: 14px;
}
.avatar--lg { width: 80px; height: 80px; font-size: 24px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.badge-plus { background: var(--ok-soft); color: var(--ok); }
.badge-minus { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: #eef0f4; color: var(--muted); font-weight: 600; }
.badge-gold { background: #fef3c7; color: #92400e; }

/* ---------- Award points ---------- */
.award { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
.award-side { position: sticky; top: 24px; }
.picker-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 1; min-width: 200px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 38px; }
.count-pill { font-size: 13px; font-weight: 600; background: #eef0f4; color: var(--text-2); padding: 5px 12px; border-radius: 999px; transition: background .15s, color .15s; }
.count-pill.on { background: var(--accent); color: #fff; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; padding: 20px 22px 22px; }
.person {
    position: relative; display: flex; align-items: center; gap: 12px;
    padding: 12px 36px 12px 12px; border: 1.5px solid var(--line); border-radius: 12px;
    cursor: pointer; user-select: none; background: #fff;
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.person:hover { border-color: var(--line-strong); }
.person input { position: absolute; opacity: 0; pointer-events: none; }
.person-name { font-weight: 600; font-size: 14px; line-height: 1.25; }
.person-meta { font-size: 12px; color: var(--muted); }
.person .check {
    position: absolute; top: 50%; right: 12px; transform: translateY(-50%);
    width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid #d1d5db;
    display: grid; place-items: center; color: #fff; background: #fff; transition: all .15s;
}
.person .check .icon { opacity: 0; transition: opacity .15s; }
.person:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px rgba(225, 29, 72, .07); }
.person:has(input:checked) .check { background: var(--accent); border-color: var(--accent); }
.person:has(input:checked) .check .icon { opacity: 1; }
.person:has(input:focus-visible) { box-shadow: 0 0 0 4px var(--accent-ring); }
.person[hidden] { display: none; }
.person-edit { position: absolute; top: 4px; right: 34px; opacity: 0; color: var(--muted); padding: 4px; border-radius: 6px; transition: opacity .15s; }
.person:hover .person-edit { opacity: 1; }
.person-edit:hover { color: var(--accent); background: #fff; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.tile {
    font: inherit; font-size: 22px; font-weight: 800; padding: 14px 0 12px; border-radius: 12px;
    border: 1.5px solid var(--line); background: #fff; color: var(--text); cursor: pointer;
    transition: all .15s; line-height: 1.1;
}
.tile small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-top: 2px; }
.tile:hover { border-color: var(--accent); color: var(--accent); }
.tile.active { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(225, 29, 72, .25); }
.tile.active small { color: rgba(255, 255, 255, .85); }
.stepper { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.stepper button { width: 46px; border: 0; background: var(--surface-2); font-size: 20px; cursor: pointer; color: var(--text-2); font-family: inherit; }
.stepper button:hover { background: #eef0f4; color: var(--text); }
.stepper input { border: 0; text-align: center; font-weight: 800; font-size: 20px; width: 100%; padding: 10px; font-family: inherit; color: var(--text); -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: none; }
.stepper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { font: inherit; font-size: 13px; font-weight: 600; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; color: var(--text-2); }
.chip:hover, .chip.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.summary { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 6px 0 16px; font-size: 14px; color: var(--text-2); }
.summary strong { font-size: 18px; color: var(--text); }
.summary .negative { color: var(--danger); }
.empty { padding: 48px 22px; text-align: center; color: var(--muted); }
.empty .icon { margin: 0 auto 10px; color: #c0c5cf; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; text-align: left; padding: 12px 22px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 14px 22px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: var(--surface-2); }
.who { display: flex; align-items: center; gap: 10px; font-weight: 600; white-space: nowrap; }
.who .avatar { width: 32px; height: 32px; font-size: 12px; }
.who small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.date-cell { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.note-cell { color: var(--text-2); min-width: 220px; }
.actions-cell { text-align: right; width: 1%; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.toolbar select.input { width: auto; min-width: 260px; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 22px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }

/* ---------- Ambassadors ---------- */
.grid-people { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.amb-card {
    position: relative; padding: 24px 18px 20px; display: flex; flex-direction: column; align-items: center;
    text-align: center; gap: 10px; text-decoration: none; transition: transform .15s, box-shadow .15s, border-color .15s;
}
.amb-card:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(16, 24, 40, .1); border-color: var(--line-strong); }
.amb-card .avatar { width: 84px; height: 84px; font-size: 26px; }
.amb-name { font-weight: 700; font-size: 16px; line-height: 1.25; }
.amb-place { position: absolute; top: 12px; left: 12px; }
.amb-edit { position: absolute; top: 12px; right: 12px; color: var(--muted); opacity: 0; transition: opacity .15s; }
.amb-card:hover .amb-edit { opacity: 1; }
.amb-add { border: 1.5px dashed var(--line-strong); background: transparent; box-shadow: none; color: var(--muted); justify-content: center; min-height: 200px; }
.amb-add:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.archived-row { display: flex; align-items: center; gap: 12px; padding: 12px 22px; border-top: 1px solid var(--line); }
.archived-row:first-child { border-top: 0; }
.archived-row .who { flex: 1; color: var(--muted); }
.archived-row .avatar { filter: grayscale(1); opacity: .7; }

/* ---------- Ambassador form ---------- */
.form-grid { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 32px; }
.photo-drop {
    display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 22px 16px;
    border: 1.5px dashed var(--line-strong); border-radius: 14px; text-align: center; cursor: pointer;
    transition: border-color .15s, background .15s;
}
.photo-drop:hover, .photo-drop.drag { border-color: var(--accent); background: var(--accent-soft); }
.photo-drop input { display: none; }
.photo-preview { width: 128px; height: 128px; border-radius: 50%; object-fit: cover; background: #eef0f4; display: grid; place-items: center; color: #9aa1ae; overflow: hidden; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-drop strong { font-size: 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.danger-zone { margin-top: 20px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.danger-zone h3 { margin: 0; font-size: 15px; }
.danger-zone p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.check-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; gap: 20px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.settings-grid .span-2 { grid-column: 1 / -1; }

.setting-block { margin-bottom: 22px; }
.setting-block > .label { display: block; margin-bottom: 4px; }
.setting-block > .hint { margin: 0 0 10px; }
.segmented { display: inline-flex; background: #eef0f4; border-radius: 12px; padding: 4px; gap: 2px; flex-wrap: wrap; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: 8px 18px; border-radius: 9px; font-weight: 600; font-size: 14px; color: #4b5563; transition: all .15s; }
.segmented label:hover span { color: var(--text); }
.segmented input:checked + span { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.segmented input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-ring); }
.checks { display: flex; gap: 8px; flex-wrap: wrap; }
.check-pill { position: relative; cursor: pointer; }
.check-pill input { position: absolute; opacity: 0; }
.check-pill span { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line); font-weight: 600; font-size: 14px; color: var(--text-2); transition: all .15s; }
.check-pill span .icon { display: none; }
.check-pill input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.check-pill input:checked + span .icon { display: block; }
.check-pill input:disabled + span { cursor: not-allowed; opacity: .8; }
.check-pill input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-ring); }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 0; border-top: 1px solid var(--line); cursor: pointer; }
.switch-row strong { display: block; font-size: 14px; }
.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: #d1d5db; border-radius: 999px; transition: background .2s; }
.switch i::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { box-shadow: 0 0 0 4px var(--accent-ring); }
.card-foot { padding: 16px 22px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); display: flex; justify-content: flex-end; }

/* ---------- Auth ---------- */
body.auth {
    min-height: 100vh; display: grid; place-items: center; padding: 16px;
    background: radial-gradient(1200px 600px at 10% -10%, #ffe4ea 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #e0e7ff 0%, transparent 55%), var(--bg);
}
.auth-card { width: min(400px, 100%); padding: 36px 32px; text-align: center; }
.auth-card .brand-mark { margin: 0 auto 18px; width: 52px; height: 52px; border-radius: 14px; }
.auth-card h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.auth-card p { margin: 6px 0 24px; color: var(--muted); }
.pin-input { font-size: 26px; letter-spacing: .5em; text-align: center; font-weight: 700; padding: 14px; text-indent: .5em; }
.auth-card .btn-lg { margin-top: 14px; }
.auth-card .alert { text-align: left; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
    .award { grid-template-columns: 1fr; }
    .award-side { position: static; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 880px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 264px; z-index: 40; transform: translateX(-100%); transition: transform .22s ease; }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(15, 17, 21, .45); z-index: 30; }
    .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; font-weight: 700; }
    .menu-btn { border: 0; background: none; padding: 6px; margin-left: -6px; cursor: pointer; color: var(--text); }
    .content { padding: 20px 16px 56px; }
    .page-head h1 { font-size: 22px; }
    .settings-grid, .form-grid { grid-template-columns: 1fr; }
    .table th, .table td { padding: 12px 14px; }
    .toolbar select.input { min-width: 0; width: 100%; }
    .toasts { left: 16px; right: 16px; }
    .person-edit, .amb-edit { opacity: 1; }
}
@media (max-width: 520px) {
    .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat { padding: 14px; }
    .stat-value { font-size: 20px; }
    .people { grid-template-columns: 1fr; }
}
