* { box-sizing: border-box; }

:root {
    --bg: #f3f5fa;
    --panel: #ffffff;
    --border: #e6e8f0;
    --text: #14162b;
    --text-muted: #6b7085;
    --primary: #4f5aff;
    --primary-dark: #3f47db;
    --primary-soft: #eef0ff;
    --success: #17a674;
    --success-soft: #e6f7ef;
    --danger: #e5484d;
    --danger-soft: #fdeceb;
    --sidebar-bg: #12142a;
    --sidebar-bg-2: #191c38;
    --shadow: 0 1px 2px rgba(20, 22, 43, 0.04), 0 4px 16px rgba(20, 22, 43, 0.06);
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
    color: #fff;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px 28px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.brand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), #8a6bff);
    font-size: 16px;
}

.nav-links { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sidebar a {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #aab0d6;
    text-decoration: none;
    padding: 11px 12px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar a .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }
.sidebar a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar a.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 10px rgba(79, 90, 255, 0.35);
}
.sidebar a.logout {
    color: #ff9b9b;
    margin-top: 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 16px;
}
.sidebar a.logout:hover { background: rgba(229, 72, 77, 0.12); color: #ff9b9b; }

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    margin-left: auto;
    box-shadow: 0 0 0 rgba(34, 197, 94, 0.6);
    animation: pulse 1.8s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
    70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* ---------- Content ---------- */
.content { flex: 1; padding: 36px 44px; max-width: 1180px; }

.page-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-title-row h1 { display: flex; align-items: center; gap: 10px; margin-bottom: 0; }

.refresh-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: background 0.15s ease, border-color 0.15s ease;
}
.refresh-btn:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.refresh-btn svg { transition: transform 0.5s ease; }
.refresh-btn.spinning svg { transform: rotate(360deg); }

h1 {
    margin: 0 0 24px;
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.01em;
}
h2 { font-size: 15px; font-weight: 700; letter-spacing: -0.005em; }

/* ---------- Stat cards ---------- */
.stat-cards { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 24px;
    box-shadow: var(--shadow);
    min-width: 170px;
}
.stat-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { display: block; font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }

.stat-card { display: flex; align-items: center; gap: 16px; }
.stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border-radius: 12px;
    flex-shrink: 0;
}
.stat-icon-blue { background: var(--primary-soft); color: var(--primary); }
.stat-icon-green { background: var(--success-soft); color: var(--success); }
.stat-icon-amber { background: #fef3e2; color: #b6720a; }

/* ---------- Panels ---------- */
.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}
.panel h2 { margin-top: 0; margin-bottom: 16px; }
.panel h2 small { font-weight: 500; color: var(--text-muted); font-size: 12px; text-transform: none; letter-spacing: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; }
@media (max-width: 1000px) { .grid-3 { grid-template-columns: 1fr; } }

.stat-label small { text-transform: none; letter-spacing: 0; font-weight: 500; color: #9297ad; }

/* ---------- Filter bar ---------- */
.filter-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.filter-btn {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: #fbfbfe;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.custom-range-inputs { display: inline-flex; align-items: center; gap: 8px; margin-left: 4px; }
.custom-range-inputs input[type="date"] {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    background: #fbfbfe;
}
.custom-range-inputs span { color: var(--text-muted); font-size: 13px; }
.btn-apply {
    padding: 7px 14px;
    border: none;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-apply:hover { background: var(--primary-dark); }

.analytics-summary {
    display: flex;
    gap: 40px;
    margin-bottom: 20px;
}
.analytics-summary > div { display: flex; flex-direction: column; gap: 6px; }
.analytics-period { font-size: 15px !important; font-weight: 700 !important; }

/* ---------- Realtime hero ---------- */
.realtime-hero {
    display: flex;
    align-items: center;
    gap: 40px;
}
.realtime-users { display: flex; align-items: center; gap: 16px; }
.realtime-number {
    font-size: 56px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--success);
    line-height: 1;
}
.realtime-caption { font-size: 13px; color: var(--text-muted); font-weight: 600; line-height: 1.5; }
.realtime-caption small { font-weight: 500; color: #9297ad; }
.realtime-divider { width: 1px; align-self: stretch; background: var(--border); }
.realtime-mini { display: flex; flex-direction: column; gap: 6px; }

/* ---------- Tables ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th, .data-table td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--text-muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table tbody tr:hover { background: #fafbff; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table .actions a { margin-right: 12px; font-size: 13px; color: var(--primary); text-decoration: none; font-weight: 500; }
.data-table .actions a:hover { text-decoration: underline; }
.data-table .actions a.danger { color: var(--danger); }
.data-table a { color: var(--primary); text-decoration: none; font-weight: 600; }
.data-table a:hover { text-decoration: underline; }

@keyframes rowIn {
    from { background: var(--primary-soft); }
    to { background: transparent; }
}
.new-row { animation: rowIn 2s ease; }

/* ---------- Badges ---------- */
.badge { padding: 4px 11px; border-radius: 20px; font-size: 11.5px; font-weight: 700; letter-spacing: 0.01em; }
.badge-active { background: var(--success-soft); color: var(--success); }
.badge-inactive { background: var(--danger-soft); color: var(--danger); }

/* ---------- Forms ---------- */
.inline-form { display: flex; flex-direction: column; gap: 6px; max-width: 480px; }
.inline-form label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-top: 10px; }
.inline-form input {
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fbfbfe;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.inline-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
    background: #fff;
}
.inline-form button, .btn-secondary {
    margin-top: 18px;
    padding: 11px 20px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    width: fit-content;
    text-decoration: none;
    display: inline-block;
    transition: background 0.15s ease, transform 0.05s ease;
}
.inline-form button:hover { background: var(--primary-dark); }
.inline-form button:active { transform: translateY(1px); }
.btn-secondary { background: #eef0f6; color: var(--text); margin-left: 8px; }
.btn-secondary:hover { background: #e3e6ef; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 10px; font-size: 14px; margin-bottom: 18px; font-weight: 500; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }

/* ---------- Login page ---------- */
.login-page {
    display: flex; align-items: center; justify-content: center; min-height: 100vh;
    background: radial-gradient(circle at 20% 20%, #1b1e3d 0%, #0d0f22 60%);
}
.login-box {
    background: #fff;
    padding: 36px 32px;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.35);
    width: 340px;
}
.login-box h1 { font-size: 20px; margin-top: 0; margin-bottom: 4px; }
.login-box label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-top: 14px; }
.login-box input {
    width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 8px; margin-top: 6px;
    font-family: inherit; font-size: 14px; background: #fbfbfe;
}
.login-box input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: #fff; }
.login-box button {
    width: 100%; margin-top: 22px; padding: 12px; border: none; border-radius: 8px;
    background: var(--primary); color: #fff; font-size: 14px; font-weight: 700; cursor: pointer;
}
.login-box button:hover { background: var(--primary-dark); }
.login-box .hint { font-size: 12px; color: #9297ad; margin-top: 18px; line-height: 1.5; }
