/* ===== CSS Reset (small & targeted) ===== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji"; }

/* ===== Theme Vars ===== */
:root {
    --bg: #0f1115;
    --bg-elev: #151925;
    --bg-elev-2: #1b2030;
    --text: #e8ebf1;
    --muted: #aab2c3;
    --primary: #7aa2ff;
    --primary-2: #9bb8ff;
    --ok: #2ecc71;
    --warn: #f39c12;
    --err: #e74c3c;
    --ghost: #4b5675;
    --card-r: 16px;
    --gap: 18px;
    --ring: 0 0 0 2px color-mix(in hsl, var(--primary) 40%, transparent);
    color-scheme: dark;
}
html[data-theme="light"] {
    --bg: #f6f8fc;
    --bg-elev: #ffffff;
    --bg-elev-2: #f1f4fb;
    --text: #0e1525;
    --muted: #4a5568;
    --primary: #3b82f6;
    --primary-2: #60a5fa;
    --ok: #16a34a;
    --warn: #d97706;
    --err: #dc2626;
    --ghost: #8b9bb7;
    color-scheme: light;
}

/* ===== App Shell ===== */
.app-header {
    background: linear-gradient(90deg, var(--bg-elev-2), var(--bg-elev));
    border-bottom: 1px solid color-mix(in hsl, var(--ghost) 25%, transparent);
}
.header-inner {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 0;
}
.container { width: min(1200px, 92vw); margin: 0 auto; }
.brand { display:flex; gap:14px; align-items:center; }
.logo { font-size: 28px; line-height: 1; }
.titles h1 { margin: 0; font-weight: 700; font-size: 20px; color: var(--text); }
.sub { display:flex; gap:8px; margin-top:6px; }

.header-actions { display:flex; gap:10px; }

/* Footer */
.app-footer { border-top: 1px solid color-mix(in hsl, var(--ghost) 25%, transparent); padding: 14px 0; margin-top: 30px; }

/* ===== Global ===== */
body { background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
.muted { color: var(--muted); }
.muted.small { font-size: 12px; }
.small { font-size:12px; }

.app-main { padding: 20px 0 30px; }

/* ===== Pills ===== */
.pill {
    display:inline-flex; align-items:center; gap:6px; padding:6px 10px; border-radius:999px;
    font-size: 12px; background: var(--bg-elev-2); color: var(--text); border:1px solid rgba(127,127,127,0.18);
}
.pill-ok { background: color-mix(in srgb, var(--ok) 20%, transparent); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill-warn { background: color-mix(in srgb, var(--warn) 20%, transparent); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill-error { background: color-mix(in srgb, var(--err) 20%, transparent); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.pill-ghost { background: transparent; border-color: color-mix(in srgb, var(--ghost) 50%, transparent); color: var(--ghost); }

/* Small chip for IDs */
.chip {
    display:inline-block; padding:2px 8px; border-radius:999px;
    background: var(--bg-elev-2); border:1px solid color-mix(in hsl, var(--ghost) 35%, transparent);
    font-size:12px; color: var(--muted);
}

/* ===== Cards & Grid ===== */
.grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: var(--gap);
}
.card {
    grid-column: span 4;
    background: var(--bg-elev);
    border: 1px solid color-mix(in hsl, var(--ghost) 25%, transparent);
    border-radius: var(--card-r);
    overflow: clip;
    box-shadow: 0 10px 30px rgba(0,0,0,0.18);
}
.card-span { grid-column: 1 / -1; } /* leaderboard full width */
@media (max-width: 960px){
    .card { grid-column: 1 / -1; }
}

.card-head { padding: 16px 18px; display:flex; align-items:center; justify-content:space-between; border-bottom: 1px solid color-mix(in hsl, var(--ghost) 25%, transparent); }
.card-head h2 { margin: 0; font-size: 18px; }
.card-body { padding: 18px; }
.hr { margin:14px 0;border:0;border-top:1px solid rgba(255,255,255,.12); }

/* ===== Forms ===== */
.form-row { display:flex; flex-direction:column; gap:8px; margin-bottom:12px; }
.form-grid { display:grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
@media (max-width: 780px){ .form-grid { grid-template-columns: 1fr; } }

label { font-weight: 600; font-size: 13px; color: var(--muted); }
input, select {
    appearance: none; width: 100%;
    padding: 12px 12px; border-radius: 12px;
    background: var(--bg-elev-2); color: var(--text);
    border: 1px solid color-mix(in hsl, var(--ghost) 25%, transparent);
    outline: none; transition: box-shadow .15s ease, border-color .15s ease, background .15s ease;
}
input:focus, select:focus { box-shadow: var(--ring); border-color: var(--primary); }

.btn-row { display:flex; gap:10px; flex-wrap: wrap; }

.btn {
    padding: 10px 14px; border-radius: 12px; border: 1px solid transparent;
    background: var(--bg-elev-2); color: var(--text); cursor: pointer; font-weight: 600;
    transition: transform .05s ease, filter .15s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: white; }
.btn-ghost { background: transparent; border-color: color-mix(in hsl, var(--ghost) 40%, transparent); color: var(--text); }
.btn-sm { padding: 6px 10px; font-size: 12px; }

/* ===== Notices ===== */
.notice {
    display:flex; gap:14px; align-items:flex-start; border-radius: 16px; padding: 14px 16px; margin-bottom: 18px;
    background: color-mix(in srgb, var(--warn) 14%, var(--bg-elev));
    border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
}
.notice .notice-icon { font-size: 20px; }
.notice h3 { margin: 0 0 6px 0; }

/* ===== Table ===== */
.table-scroll { overflow:auto; border-radius: 12px; border:1px solid color-mix(in hsl, var(--ghost) 25%, transparent); }
.table { width: 100%; border-collapse: collapse; background: var(--bg-elev-2); }
.table th, .table td { padding: 12px 12px; border-bottom: 1px solid color-mix(in hsl, var(--ghost) 20%, transparent); white-space: nowrap; }
.table thead th { position: sticky; top: 0; background: var(--bg-elev); text-align:left; font-size: 13px; color: var(--muted); }
.table tbody tr:hover { background: color-mix(in hsl, var(--primary) 8%, transparent); }

.hide-sm { display: table-cell; }
@media (max-width: 720px){ .hide-sm { display: none; } }

/* Avatar + user row */
.user { display:flex; align-items:center; gap:10px; }
.avatar {
    width: 30px; height: 30px; border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff; display:grid; place-items:center; font-weight: 800;
}

/* Meter */
.meter {
    height: 8px; background: color-mix(in hsl, var(--ghost) 30%, transparent);
    border-radius: 999px; overflow: hidden; margin-bottom: 6px;
}
.meter-fill {
    height: 100%; width: 0%; background: linear-gradient(90deg, var(--ok), var(--primary));
    transition: width .5s ease;
}
.good { color: var(--ok); }
.warn { color: var(--warn); }
.bad  { color: var(--err); }

/* Skeleton */
.skeleton-table { display:grid; gap: 8px; }
.skeleton-row { height: 48px; border-radius: 10px; background: linear-gradient(90deg, rgba(255,255,255,0.05), rgba(255,255,255,0.12), rgba(255,255,255,0.05)); background-size: 200% 100%; animation: ske 1.1s infinite; }
@keyframes ske { to { background-position: -200% 0; } }

/* Toasts */
.toasts {
    position: fixed; right: 16px; bottom: 16px; display: grid; gap: 10px; z-index: 9999;
}
.toast {
    padding: 10px 12px; border-radius: 12px; font-weight: 600;
    background: var(--bg-elev); color: var(--text); border: 1px solid color-mix(in hsl, var(--ghost) 30%, transparent);
    box-shadow: 0 6px 20px rgba(0,0,0,0.25); transform: translateY(0); opacity: 1; transition: transform .3s ease, opacity .3s ease;
}
.toast.success { border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.toast.error   { border-color: color-mix(in srgb, var(--err) 50%, transparent); }
.toast.hide { transform: translateY(6px); opacity: 0; }

/* Buttons inside table header (legend) */
.legend { color: var(--muted); font-size: 12px; }
.legend-item { margin-left: 8px; }

/* Status colors */
.ok  { color: var(--ok); }
.err { color: var(--err); }
