:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #eef2ff;
    --text: #172033;
    --muted: #667085;
    --border: #e4e7ec;
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --dark: #334155;
    --shadow: 0 16px 35px rgba(15, 23, 42, .08);
    --radius: 18px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
.mobile-only { display: none; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 270px;
    background: linear-gradient(180deg, #0f172a, #1e293b);
    color: white;
    padding: 24px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; }
.brand.centered { justify-content: center; color: var(--text); }
.brand-mark {
    width: 44px; height: 44px; display: grid; place-items: center;
    border-radius: 14px; background: var(--primary); color: white; font-weight: 800;
}
.brand small, .user-menu span, .muted, .small { color: var(--muted); }
.sidebar .brand small { color: #cbd5e1; display: block; }
.nav { display: grid; gap: 8px; }
.nav a {
    color: #dbeafe; padding: 12px 14px; border-radius: 12px;
    display: block; transition: .2s;
}
.nav a:hover, .nav a.active { background: rgba(255,255,255,.12); color: white; text-decoration: none; }

.main { flex: 1; padding: 26px; min-width: 0; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 18px; margin-bottom: 22px;
}
.topbar h1 { margin: 0 0 4px; font-size: clamp(24px, 3vw, 34px); }
.topbar p { margin: 0; color: var(--muted); }
.user-menu { display: flex; gap: 14px; align-items: center; white-space: nowrap; }

.panel, .stat-card, .login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.panel { padding: 22px; margin-bottom: 22px; }
.panel h2 { margin: 0 0 14px; }
.panel-title {
    display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 16px;
}
.panel-title h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 22px; }
.cards-grid { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 16px; margin-bottom: 22px; }
.small-cards { grid-template-columns: repeat(4, minmax(120px, 1fr)); margin-bottom: 16px; }
.stat-card { padding: 18px; }
.stat-card span { display: block; color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; font-size: 28px; margin-top: 8px; }
.stat-card.success { border-color: rgba(5,150,105,.35); }
.stat-card.danger { border-color: rgba(220,38,38,.35); }
.stat-card.warning { border-color: rgba(217,119,6,.35); }
.stat-card.dark { border-color: rgba(51,65,85,.35); }

.btn, button.btn {
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); background: white; color: var(--text);
    min-height: 40px; padding: 9px 14px; border-radius: 12px; cursor: pointer;
    font-weight: 700;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); text-decoration: none; }
.icon-button { border: 0; background: white; border-radius: 10px; padding: 9px 12px; box-shadow: var(--shadow); }
.link-danger {
    border: 0; background: transparent; color: var(--danger); cursor: pointer; padding: 0;
}
.alert { padding: 14px 16px; border-radius: 14px; margin-bottom: 18px; border: 1px solid; }
.alert.success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert.danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

.form-stack, .form-grid { display: grid; gap: 15px; }
.form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
.form-panel label, .form-stack label, .filter-row label {
    display: grid; gap: 7px; color: var(--dark); font-weight: 700; font-size: 14px;
}
input, select, textarea {
    width: 100%; padding: 11px 12px; border-radius: 12px;
    border: 1px solid var(--border); background: white; color: var(--text);
}
textarea { resize: vertical; }
.check-label { display: flex !important; flex-direction: row; align-items: center; gap: 10px !important; }
.check-label input { width: auto; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 12px; align-items: center; }
.filter-row {
    display: grid; grid-template-columns: repeat(6, minmax(150px, 1fr)); gap: 14px; align-items: end;
}
.table-search { max-width: 360px; margin-bottom: 12px; }

.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; background: white; }
.table th, .table td {
    padding: 12px 11px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top;
}
.table th {
    font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; background: #f8fafc;
}
.table.compact th, .table.compact td { padding: 9px; }
.actions { display: flex; gap: 10px; align-items: center; }

.badge {
    display: inline-flex; align-items: center; padding: 5px 9px; border-radius: 999px;
    background: #e2e8f0; color: #334155; font-size: 12px; font-weight: 800;
}
.badge.success { background: #d1fae5; color: #065f46; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.neutral { background: #e5e7eb; color: #374151; }
.badge.dark { background: #334155; color: white; }

.bar-chart { height: 280px; display: flex; gap: 14px; align-items: end; padding-top: 12px; }
.bar-item { flex: 1; display: grid; gap: 6px; justify-items: center; height: 100%; }
.bar-track { height: 210px; width: 100%; max-width: 34px; display: flex; align-items: end; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.bar-fill { width: 100%; background: linear-gradient(180deg, #60a5fa, #2563eb); border-radius: 999px; }
.simple-list { display: grid; gap: 9px; }
.list-row, .rank-card {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; padding: 12px; background: #f8fafc; border-radius: 14px;
}
.rank-card b {
    width: 36px; height: 36px; display: grid; place-items: center;
    background: var(--surface-2); color: var(--primary); border-radius: 12px;
}
.rank-card div { flex: 1; }
.rank-card span { display: block; color: var(--muted); font-size: 13px; }
.rank-card em { font-style: normal; font-weight: 900; }

.time-pill, .raw-chip {
    display: inline-block; margin: 2px; padding: 4px 8px; border-radius: 999px;
    background: #e5e7eb; font-size: 12px;
}
.time-pill.used { background: #d1fae5; color: #065f46; font-weight: 800; }
.raw-detail-row td { background: #f8fafc; }
.quick-links { display: grid; gap: 10px; }
.quick-links a {
    padding: 14px; border: 1px solid var(--border); border-radius: 14px; background: #f8fafc;
}

.login-body {
    min-height: 100vh; display: grid; place-items: center;
    background: radial-gradient(circle at top, #dbeafe, transparent 35%), var(--bg);
    padding: 20px;
}
.login-card { width: min(440px, 100%); padding: 28px; }

/* Public display */
.display-body {
    background: #08111f;
    color: white;
    min-height: 100vh;
    overflow: hidden;
}
.display-grid {
    display: grid;
    grid-template-columns: minmax(0,1fr) 410px;
    gap: 22px;
    padding: 22px 22px 64px;
    height: 100vh;
}
.display-main, .locked-top5 {
    background: linear-gradient(180deg, rgba(30,41,59,.92), rgba(15,23,42,.92));
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 26px;
    box-shadow: 0 30px 80px rgba(0,0,0,.32);
}
.display-main { position: relative; padding: 28px; overflow: hidden; }
.display-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; }
.display-header h1 { margin: 0; font-size: clamp(34px, 4vw, 58px); }
.display-header p, .locked-top5 p, .display-note { color: #cbd5e1; }
.display-clock { font-size: clamp(28px, 4vw, 54px); font-weight: 900; color: #93c5fd; }
.display-slide {
    opacity: 0; transform: translateY(16px); pointer-events: none;
    position: absolute; left: 28px; right: 28px; top: 135px; bottom: 28px;
    transition: .55s ease;
}
.display-slide.active { opacity: 1; transform: translateY(0); pointer-events: auto; }
.display-slide h2 { margin: 0 0 22px; font-size: clamp(30px, 3vw, 48px); }
.display-cards { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 18px; }
.display-cards div {
    background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12);
    padding: 22px; border-radius: 24px;
}
.display-cards span { color: #cbd5e1; display: block; font-size: 18px; }
.display-cards strong { display: block; font-size: clamp(44px, 6vw, 90px); margin-top: 10px; }
.display-table { display: grid; gap: 13px; }
.display-row {
    display: grid; grid-template-columns: 64px minmax(0,1fr) 130px minmax(200px,.8fr);
    align-items: center; gap: 14px;
    padding: 16px 18px; border-radius: 18px;
    background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1);
}
.display-row b {
    width: 46px; height: 46px; display: grid; place-items: center;
    background: #2563eb; border-radius: 16px; font-size: 20px;
}
.display-row span { font-size: 24px; font-weight: 900; }
.display-row small { display: block; color: #cbd5e1; font-size: 15px; font-weight: 600; margin-top: 3px; }
.display-row strong { font-size: 28px; color: #bfdbfe; text-align: right; }
.display-row em { color: #cbd5e1; font-style: normal; font-size: 17px; text-align: right; }
.display-row.late b { background: #dc2626; }
.two-col { grid-template-columns: repeat(2, minmax(0,1fr)); }
.two-col .display-row { grid-template-columns: 64px 1fr 120px; }
.display-bars { height: 440px; display: flex; align-items: end; gap: 18px; }
.display-bars div { flex: 1; display: grid; justify-items: center; gap: 8px; height: 100%; }
.display-bars span {
    width: 100%; max-width: 54px; background: linear-gradient(180deg, #93c5fd, #2563eb);
    border-radius: 999px; align-self: end;
}
.display-bars small { color: #cbd5e1; }
.display-bars b { font-size: 22px; }

.locked-top5 { padding: 24px; overflow: hidden; }
.locked-top5 h2 { margin: 0; font-size: 30px; }
.locked-card {
    display: grid; grid-template-columns: 56px minmax(0,1fr) 76px; gap: 12px; align-items: center;
    padding: 15px; margin-top: 14px; border-radius: 20px; background: rgba(255,255,255,.08);
}
.locked-card b {
    width: 44px; height: 44px; display: grid; place-items: center;
    background: #f59e0b; border-radius: 16px; color: #111827;
}
.locked-card strong { display: block; font-size: 19px; }
.locked-card span, .locked-card small { display: block; color: #cbd5e1; }
.locked-card em { font-style: normal; font-weight: 900; font-size: 21px; color: #bfdbfe; }
.running-text {
    position: fixed; left: 0; right: 0; bottom: 0; height: 44px;
    background: #2563eb; display: flex; align-items: center; overflow: hidden;
    font-size: 22px; font-weight: 800;
}
.running-text span {
    white-space: nowrap; padding-left: 100%;
    animation: marquee 28s linear infinite;
}
@keyframes marquee { from { transform: translateX(0); } to { transform: translateX(-100%); } }
.display-offline { height: 100vh; display: grid; place-items: center; text-align: center; }

@media (max-width: 1100px) {
    .cards-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .grid-2 { grid-template-columns: 1fr; }
    .filter-row { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .display-grid { grid-template-columns: 1fr; overflow: auto; height: auto; }
    .locked-top5 { order: -1; }
    .display-body { overflow: auto; }
}
@media (max-width: 780px) {
    .mobile-only { display: inline-flex; }
    .sidebar { position: fixed; z-index: 20; transform: translateX(-100%); transition: .2s; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .main { padding: 18px; }
    .topbar { align-items: flex-start; }
    .user-menu { flex-direction: column; align-items: flex-end; gap: 4px; }
    .cards-grid, .small-cards, .filter-row, .form-grid { grid-template-columns: 1fr; }
    .panel-title { flex-direction: column; align-items: flex-start; }
    .display-grid { padding: 12px 12px 64px; }
    .display-main { min-height: 760px; }
    .display-row { grid-template-columns: 52px 1fr; }
    .display-row strong, .display-row em { text-align: left; }
    .display-cards { grid-template-columns: 1fr 1fr; }
}
