/* ================================================================
   Web Stats — Design System  (full rewrite, clean & mobile-first)
   ================================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Brand */
    --primary:        #6366f1;
    --primary-dark:   #4f46e5;
    --primary-deeper: #3730a3;
    --primary-light:  rgba(99,102,241,0.10);
    --primary-border: rgba(99,102,241,0.22);
    --purple:         #8b5cf6;

    /* Semantic */
    --success:       #10b981;
    --success-light: rgba(16,185,129,0.12);
    --warning:       #f59e0b;
    --warning-light: rgba(245,158,11,0.12);
    --danger:        #ef4444;
    --danger-light:  rgba(239,68,68,0.12);
    --info:          #06b6d4;
    --info-light:    rgba(6,182,212,0.12);

    /* Surfaces */
    --bg:        #f1f5f9;
    --surface:   #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #f1f5f9;

    /* Text */
    --text:       #0f172a;
    --text-2:     #334155;
    --text-muted: #64748b;
    --text-light: #94a3b8;

    /* Borders */
    --border:       #e2e8f0;
    --border-light: #f1f5f9;

    /* Layout */
    --sidebar-bg:    #0f172a;
    --sidebar-width: 252px;
    --topbar-height: 62px;

    /* Shadows */
    --shadow-xs:   0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm:   0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow:      0 2px 8px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md:   0 4px 12px rgba(0,0,0,0.07), 0 2px 5px rgba(0,0,0,0.04);
    --shadow-lg:   0 10px 30px rgba(0,0,0,0.09), 0 4px 10px rgba(0,0,0,0.05);
    --shadow-card: 0 0 0 1px rgba(0,0,0,0.03), 0 2px 8px rgba(0,0,0,0.05);

    /* Radii */
    --radius-xs:   4px;
    --radius-sm:   6px;
    --radius:      10px;
    --radius-lg:   14px;
    --radius-xl:   20px;
    --radius-full: 9999px;

    /* Motion */
    --t:      0.18s ease;
    --t-slow: 0.3s cubic-bezier(0.4,0,0.2,1);
}

/* ================================================================
   BASE
   ================================================================ */
html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv02","cv03","cv04","cv11";
}

/* ================================================================
   TOPBAR
   ================================================================ */
.topbar {
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
    box-shadow: var(--shadow-xs);
}
.topbar-left  { display: flex; align-items: center; gap: 14px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.logo {
    display: flex; align-items: center; gap: 9px;
    font-size: 1.1rem; font-weight: 800;
    letter-spacing: -0.03em;
    text-decoration: none; color: var(--text);
}
.logo-icon {
    width: 30px; height: 30px;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 0.8rem;
    flex-shrink: 0;
}
.logo-text {
    background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-toggle {
    display: none;
    background: none; border: none;
    font-size: 1rem; cursor: pointer;
    color: var(--text-muted);
    padding: 8px; border-radius: var(--radius-sm);
    transition: background var(--t), color var(--t);
    line-height: 1;
}
.sidebar-toggle:hover { background: var(--bg); color: var(--text); }

.topbar-divider { width: 1px; height: 22px; background: var(--border); margin: 0 2px; }

.btn-topbar {
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none; font-size: 0.95rem;
    transition: all var(--t);
    background: none; border: none; cursor: pointer;
}
.btn-topbar:hover { background: var(--bg); color: var(--text); }

.topbar-user  { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.topbar-user-text { line-height: 1.2; }
.topbar-user-name { font-size: 0.82rem; font-weight: 700; color: var(--text); }
.topbar-user-role { font-size: 0.7rem; color: var(--text-muted); text-transform: capitalize; }

.user-avatar {
    width: 32px; height: 32px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary), var(--purple));
    color: #fff; font-size: 0.75rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; text-decoration: none;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(99,102,241,0.35);
}

/* ================================================================
   LAYOUT
   ================================================================ */
.layout {
    display: flex;
    padding-top: var(--topbar-height);
    min-height: 100vh;
}

/* ================================================================
   SIDEBAR OVERLAY (mobile)
   ================================================================ */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15,23,42,0.5);
    backdrop-filter: blur(3px);
    z-index: 89;
}

/* ================================================================
   SIDEBAR
   ================================================================ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    flex-shrink: 0;
    position: fixed;
    top: var(--topbar-height); left: 0; bottom: 0;
    overflow-y: auto;
    transition: transform var(--t-slow);
    z-index: 90;
    display: flex; flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.sidebar::-webkit-scrollbar       { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 99px; }

.sidebar-nav { display: flex; flex-direction: column; flex: 1; padding: 12px 10px 8px; gap: 1px; }

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px;
    color: rgba(148,163,184,0.85);
    text-decoration: none;
    font-size: 0.875rem; font-weight: 500;
    border-radius: var(--radius);
    transition: background var(--t), color var(--t);
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: rgba(226,232,240,0.95); }
.nav-item.active {
    background: linear-gradient(135deg, rgba(99,102,241,0.22) 0%, rgba(139,92,246,0.16) 100%);
    color: #ffffff; font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(99,102,241,0.3);
}
.nav-item i { width: 17px; text-align: center; font-size: 0.875rem; flex-shrink: 0; opacity: 0.85; }
.nav-item.active i { opacity: 1; }

.nav-section-title {
    padding: 18px 12px 6px;
    font-size: 0.62rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1.8px;
    color: rgba(255,255,255,0.18);
}

.sidebar-footer {
    padding: 10px;
    border-top: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}
.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 10px; border-radius: var(--radius);
    cursor: pointer; transition: background var(--t);
    text-decoration: none;
}
.sidebar-user:hover { background: rgba(255,255,255,0.06); }
.sidebar-user-avatar {
    width: 34px; height: 34px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary), var(--purple));
    display: flex; align-items: center; justify-content: center;
    font-size: 0.78rem; font-weight: 800; color: #fff;
    flex-shrink: 0; letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(99,102,241,0.3);
}
.sidebar-user-name { font-size: 0.8rem; font-weight: 700; color: #e2e8f0; line-height: 1.25; }
.sidebar-user-role { font-size: 0.68rem; color: rgba(148,163,184,0.7); text-transform: capitalize; margin-top: 1px; }

/* ================================================================
   MAIN CONTENT
   ================================================================ */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 28px;
    min-height: calc(100vh - var(--topbar-height));
    max-width: 100%;
    overflow-x: hidden;
}

/* ================================================================
   AUTH LAYOUT
   ================================================================ */
.auth-layout {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 40%, #312e81 75%, #4c1d95 100%);
    position: relative; overflow: hidden;
}
.auth-layout::before {
    content: '';
    position: absolute;
    width: 700px; height: 700px; border-radius: 50%;
    background: radial-gradient(circle, rgba(99,102,241,0.12) 0%, transparent 70%);
    top: -200px; right: -150px; pointer-events: none;
}
.auth-layout::after {
    content: '';
    position: absolute;
    width: 500px; height: 500px; border-radius: 50%;
    background: radial-gradient(circle, rgba(139,92,246,0.1) 0%, transparent 70%);
    bottom: -150px; left: -100px; pointer-events: none;
}

/* ================================================================
   CARDS
   ================================================================ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    margin-bottom: 20px;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
}
.card-header h3 {
    font-size: 0.925rem; font-weight: 700;
    color: var(--text); letter-spacing: -0.01em;
    display: flex; align-items: center; gap: 8px;
}
.card-header h3 i { color: var(--primary); }
.card-body { padding: 20px; }
.card-body.p-0 { padding: 0; }
.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: center;
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ================================================================
   PAGE HEADER
   ================================================================ */
.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-header h1 {
    font-size: 1.45rem; font-weight: 800;
    color: var(--text); letter-spacing: -0.03em; line-height: 1.2;
}
.page-subtitle {
    font-size: 0.84rem; color: var(--text-muted);
    margin-top: 3px; font-weight: 400;
}
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ================================================================
   STAT CARDS
   ================================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex; align-items: center; gap: 16px;
    box-shadow: var(--shadow-card);
    transition: transform var(--t), box-shadow var(--t);
    position: relative; overflow: hidden; cursor: default;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card::after {
    content: '';
    position: absolute; right: -20px; bottom: -20px;
    width: 90px; height: 90px; border-radius: 50%;
    opacity: 0.07; pointer-events: none;
}
.stat-card-1::after { background: #8b5cf6; }
.stat-card-2::after { background: #6366f1; }
.stat-card-3::after { background: #10b981; }
.stat-card-4::after { background: #f59e0b; }

.stat-icon {
    width: 50px; height: 50px; border-radius: 13px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; color: #fff; flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(0,0,0,0.15);
}
.stat-icon-1 { background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%); }
.stat-icon-2 { background: linear-gradient(135deg, #6366f1 0%, #06b6d4 100%); }
.stat-icon-3 { background: linear-gradient(135deg, #10b981 0%, #06b6d4 100%); }
.stat-icon-4 { background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%); }

.stat-content { min-width: 0; flex: 1; }
.stat-value {
    font-size: 1.85rem; font-weight: 800;
    letter-spacing: -0.04em; color: var(--text);
    line-height: 1; margin-bottom: 5px;
}
.stat-label {
    font-size: 0.75rem; font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.6px;
}

/* ================================================================
   WEBSITE CARDS (dashboard)
   ================================================================ */
.sites-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px; padding: 20px;
}

.site-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex; flex-direction: column; gap: 14px;
    transition: border-color var(--t), box-shadow var(--t), transform var(--t);
    background: var(--surface);
}
.site-card:hover {
    border-color: var(--primary-border);
    box-shadow: 0 0 0 1px var(--primary-light), var(--shadow-md);
    transform: translateY(-1px);
}
.site-card-top   { display: flex; align-items: center; gap: 12px; }
.site-card-meta  { min-width: 0; flex: 1; }
.site-card-name  { font-size: 0.9rem; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-card-domain{ font-size: 0.76rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }

.site-avatar {
    width: 42px; height: 42px; border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.05rem; font-weight: 800; color: #fff;
    flex-shrink: 0; text-transform: uppercase;
    box-shadow: 0 3px 10px rgba(0,0,0,0.18); letter-spacing: -0.02em;
}
.av-1 { background: linear-gradient(135deg,#8b5cf6,#6366f1); }
.av-2 { background: linear-gradient(135deg,#06b6d4,#6366f1); }
.av-3 { background: linear-gradient(135deg,#10b981,#06b6d4); }
.av-4 { background: linear-gradient(135deg,#f59e0b,#ef4444); }
.av-5 { background: linear-gradient(135deg,#ec4899,#8b5cf6); }
.av-6 { background: linear-gradient(135deg,#14b8a6,#10b981); }
.av-7 { background: linear-gradient(135deg,#3b82f6,#6366f1); }
.av-8 { background: linear-gradient(135deg,#f97316,#ef4444); }

/* Live badge */
.live-badge {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 0.7rem; font-weight: 700;
    padding: 3px 9px; border-radius: var(--radius-full);
    flex-shrink: 0; white-space: nowrap;
}
.live-badge-on  { background: rgba(16,185,129,0.12); color: #059669; }
.live-badge-off { background: var(--surface-3); color: var(--text-muted); }
.live-badge-on::before, .live-badge-off::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%; flex-shrink: 0;
}
.live-badge-on::before  { background: var(--success); animation: livePulse 2s infinite; }
.live-badge-off::before { background: var(--text-light); }

@keyframes livePulse {
    0%,100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.5; transform: scale(0.85); }
}

/* Site stat bar */
.site-stats-row {
    display: flex;
    background: var(--surface-2);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    overflow: hidden;
}
.site-stat-item {
    flex: 1; padding: 10px 14px;
    display: flex; flex-direction: column; gap: 2px;
    border-right: 1px solid var(--border-light);
}
.site-stat-item:last-child { border-right: none; }
.site-stat-val { font-size: 1.05rem; font-weight: 800; color: var(--text); letter-spacing: -0.03em; line-height: 1; }
.site-stat-lbl { font-size: 0.67rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; }

.site-card-actions { display: flex; gap: 8px; }
.site-card-actions .btn { flex: 1; justify-content: center; font-size: 0.8rem; }

/* ================================================================
   TABLES
   ================================================================ */
.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left; padding: 11px 16px;
    font-size: 0.71rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.7px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    background: var(--surface-2); white-space: nowrap;
}
.table td {
    padding: 11px 16px; font-size: 0.875rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--t); }
.table tbody tr:hover td { background: var(--surface-2); }
.table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ================================================================
   FORMS
   ================================================================ */
.form-group  { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.84rem; color: var(--text-2); }
.form-control {
    width: 100%; padding: 10px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem; font-family: inherit; color: var(--text);
    background: var(--surface);
    transition: border-color var(--t), box-shadow var(--t);
    appearance: none;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.12); }
.form-control::placeholder { color: var(--text-light); }
.form-control.is-invalid { border-color: var(--danger); }
.invalid-feedback { color: var(--danger); font-size: 0.8rem; margin-top: 5px; }
.form-text { font-size: 0.79rem; color: var(--text-muted); margin-top: 5px; display: block; }
.checkbox-label { display: flex; align-items: center; gap: 9px; cursor: pointer; font-weight: 500; font-size: 0.875rem; }
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); border-radius: 3px; }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 100px; }

/* ================================================================
   BUTTONS
   ================================================================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 18px;
    border: none; border-radius: var(--radius);
    font-size: 0.875rem; font-weight: 600; font-family: inherit;
    cursor: pointer; text-decoration: none;
    transition: all var(--t);
    white-space: nowrap; letter-spacing: -0.01em; line-height: 1.2;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99,102,241,0.3);
}
.btn-primary:hover { box-shadow: 0 4px 14px rgba(99,102,241,0.4); filter: brightness(1.06); }

.btn-secondary { background: var(--surface); color: var(--text-2); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--bg); border-color: #cbd5e1; }

.btn-success { background: var(--success); color: #fff; box-shadow: 0 2px 8px rgba(16,185,129,0.3); }
.btn-success:hover { filter: brightness(1.06); }
.btn-danger  { background: var(--danger);  color: #fff; box-shadow: 0 2px 8px rgba(239,68,68,0.2); }
.btn-danger:hover  { filter: brightness(1.06); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-info    { background: var(--info);    color: #fff; }

.btn-sm   { padding: 6px 13px;  font-size: 0.8rem;  border-radius: var(--radius-sm); gap: 5px; }
.btn-xs   { padding: 3px 9px;   font-size: 0.72rem; border-radius: var(--radius-sm); gap: 4px; font-weight: 600; }
.btn-block{ width: 100%; }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; }
.btn-icon:hover { color: var(--text); }

/* ================================================================
   ALERTS
   ================================================================ */
.alert {
    padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px;
    font-size: 0.875rem; display: flex; align-items: center; gap: 10px;
    font-weight: 500;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ================================================================
   AUTH CARD
   ================================================================ */
.auth-card {
    background: #fff; border-radius: var(--radius-xl);
    padding: 40px; width: 100%; max-width: 420px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.35);
    position: relative; z-index: 1;
}
.auth-card-wide { max-width: 520px; }
.auth-card-header { text-align: center; margin-bottom: 32px; }
.auth-card-header .auth-logo {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; margin-bottom: 20px; text-decoration: none;
}
.auth-card-header .auth-logo-icon {
    width: 44px; height: 44px;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1.3rem;
    box-shadow: 0 4px 14px rgba(99,102,241,0.35);
}
.auth-card-header .auth-logo-text {
    font-size: 1.4rem; font-weight: 800; letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.auth-card-header h1  { font-size: 1.4rem; font-weight: 700; color: var(--text); margin-bottom: 6px; letter-spacing: -0.02em; }
.auth-card-header p   { color: var(--text-muted); font-size: 0.88rem; }
.auth-form   { display: flex; flex-direction: column; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 0.875rem; color: var(--text-muted); }
.auth-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }
.auth-footer a:hover { text-decoration: underline; }

/* ================================================================
   TABS (legacy nav-tabs)
   ================================================================ */
.nav-tabs {
    display: flex; gap: 0;
    border-bottom: 2px solid var(--border);
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }
.tab {
    padding: 10px 16px;
    font-size: 0.84rem; font-weight: 600;
    color: var(--text-muted); text-decoration: none;
    border-bottom: 2px solid transparent; margin-bottom: -2px;
    white-space: nowrap; transition: all var(--t);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ================================================================
   PERIOD SELECTOR (legacy, used in sidebar/other pages)
   ================================================================ */
.period-selector {
    display: flex; gap: 3px;
    background: var(--surface-2); border: 1px solid var(--border);
    padding: 3px; border-radius: var(--radius);
}
.period-selector .btn {
    flex: 1; background: transparent; color: var(--text-muted);
    box-shadow: none; padding: 5px 11px; font-size: 0.8rem;
    border-radius: var(--radius-sm); border: none;
}
.period-selector .btn:hover { background: var(--surface); color: var(--text); }
.period-selector .btn.active {
    background: var(--surface); color: var(--primary); font-weight: 700;
    box-shadow: var(--shadow-xs); transform: none;
}

/* ================================================================
   EMPTY STATE
   ================================================================ */
.empty-state {
    text-align: center; padding: 64px 24px;
    display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.empty-state-icon {
    width: 72px; height: 72px; background: var(--primary-light);
    border-radius: var(--radius-xl);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.75rem; color: var(--primary); margin-bottom: 4px;
}
.empty-state > i { font-size: 2.5rem; color: var(--text-light); margin-bottom: 4px; }
.empty-state h3  { font-size: 1.1rem; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.empty-state p   { color: var(--text-muted); font-size: 0.875rem; max-width: 320px; line-height: 1.6; }

/* ================================================================
   PAGINATION
   ================================================================ */
.pagination { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.page-link {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 34px; padding: 0 10px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text-2);
    text-decoration: none; font-size: 0.84rem; font-weight: 500;
    transition: all var(--t);
}
.page-link:hover        { border-color: var(--primary); color: var(--primary); }
.page-link.active       { background: var(--primary); color: #fff; border-color: var(--primary); cursor: default; }
.page-link.page-ellipsis{ border: none; background: none; color: var(--text-muted); min-width: auto; cursor: default; }

/* ================================================================
   BADGES
   ================================================================ */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 9px; border-radius: var(--radius-full);
    font-size: 0.71rem; font-weight: 700; letter-spacing: 0.3px;
    white-space: nowrap;
}
.badge-success { background: var(--success-light); color: #065f46; }
.badge-danger  { background: var(--danger-light);  color: #991b1b; }
.badge-browser { background: var(--primary-light); color: var(--primary); }

/* ================================================================
   UTILITIES
   ================================================================ */
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-center   { text-align: center; }
.text-muted    { color: var(--text-muted); }
.text-success  { color: var(--success); }
.text-danger   { color: var(--danger); }
.action-cell   { white-space: nowrap; }
.action-cell .btn { margin-right: 4px; }
.ip-hash  { font-size: 0.71rem; color: var(--text-muted); background: var(--bg); padding: 2px 7px; border-radius: var(--radius-xs); font-family: 'Fira Code','Cascadia Code','Consolas',monospace; }
.code-block { background: #0f172a; color: #e2e8f0; padding: 18px; border-radius: var(--radius); font-size: 0.84rem; overflow-x: auto; white-space: pre-wrap; word-break: break-all; line-height: 1.75; font-family: 'Fira Code','Cascadia Code',monospace; }
.mt-2 { margin-top: 8px; }  .mt-3 { margin-top: 12px; }  .mt-4 { margin-top: 24px; }
.mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 24px; }
.p-4  { padding: 24px; } .p-0  { padding: 0; }
.flex { display: flex; } .gap-2 { gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
hr { border: none; border-top: 1px solid var(--border); margin: 22px 0; }

/* Feature list */
.feature-list { display: flex; flex-direction: column; gap: 16px; }
.feature-item { display: flex; gap: 12px; align-items: flex-start; }
.feature-item i      { font-size: 1.1rem; margin-top: 3px; }
.feature-item strong { display: block; margin-bottom: 2px; }
.feature-item p      { font-size: 0.84rem; color: var(--text-muted); }

/* ================================================================
   ANALYTICS NAV — sticky combined tabs + period selector
   ================================================================ */
.analytics-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 5px;
    margin-bottom: 22px;
    box-shadow: var(--shadow-card);
    position: sticky;
    top: calc(var(--topbar-height) + 8px);
    z-index: 40;
    /* NO overflow:hidden — it breaks position:sticky scroll detection */
}

.analytics-tabs {
    display: flex;
    gap: 2px;
    flex: 1;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    min-width: 0;
    /* Mask edges to hint scrollability */
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 8px, #000 calc(100% - 8px), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 8px, #000 calc(100% - 8px), transparent 100%);
}
.analytics-tabs::-webkit-scrollbar { display: none; }

.analytics-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--t), color var(--t);
    flex-shrink: 0;
    border: 1.5px solid transparent;
    line-height: 1;
}
.analytics-tab:hover  { background: var(--bg); color: var(--text); }
.analytics-tab.active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary-border);
}
.analytics-tab i { font-size: 0.72rem; opacity: 0.8; }
.analytics-tab.active i { opacity: 1; }

/* Animated dot for Real-Time tab */
.analytics-tab .rt-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
    display: inline-block;
}
.analytics-tab.active .rt-dot { animation: livePulse 1.8s infinite; }

/* Vertical separator between tabs and period picker */
.analytics-nav-sep {
    width: 1px; height: 24px;
    background: var(--border);
    flex-shrink: 0;
    margin: 0 2px;
}

/* Period picker pill group */
.analytics-periods {
    display: flex;
    gap: 1px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px;
    flex-shrink: 0;
}
.period-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px 12px;
    border-radius: var(--radius-xs);
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--text-muted);
    text-decoration: none;
    transition: all var(--t);
    white-space: nowrap;
    letter-spacing: 0.02em;
    min-width: 36px;
}
.period-btn:hover { color: var(--text); background: rgba(255,255,255,0.7); }
.period-btn.active {
    background: var(--surface);   /* white on light-grey bg = clear pop */
    color: var(--primary);
    font-weight: 800;
    box-shadow: 0 1px 4px rgba(0,0,0,0.10), 0 0 0 1px var(--primary-border);
}

/* ================================================================
   ANALYTICS PAGE HEADER
   ================================================================ */
.analytics-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    flex-wrap: wrap;
    gap: 10px;
}
.analytics-page-header h1 {
    font-size: 1.3rem; font-weight: 800;
    color: var(--text); letter-spacing: -0.03em;
}
.analytics-breadcrumb {
    font-size: 0.8rem; color: var(--text-muted);
    display: flex; align-items: center; gap: 5px; margin-top: 2px;
}
.analytics-breadcrumb a { color: var(--text-muted); text-decoration: none; }
.analytics-breadcrumb a:hover { color: var(--primary); }

/* ================================================================
   MAP (jsvectormap)
   ================================================================ */
.map-container {
    height: 400px;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface-2);
}
.jvm-tooltip {
    background: #0f172a !important;
    color: #f1f5f9 !important;
    border-radius: var(--radius-sm) !important;
    padding: 8px 12px !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 0.8rem !important;
    font-weight: 600 !important;
    border: 1px solid #1e293b !important;
    box-shadow: var(--shadow-md) !important;
    pointer-events: none !important;
}
.jvm-zoom-btn {
    background: var(--surface) !important;
    border: 1px solid var(--border) !important;
    color: var(--text) !important;
    border-radius: var(--radius-sm) !important;
    line-height: 1 !important;
}

/* ================================================================
   RESPONSIVE — 1200px (large tablets / small laptops)
   ================================================================ */
@media (max-width: 1200px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ================================================================
   RESPONSIVE — 1024px (tablets)
   ================================================================ */
@media (max-width: 1024px) {
    .grid-3 { grid-template-columns: 1fr 1fr; }
    .sites-grid { grid-template-columns: repeat(2, 1fr); }

    .analytics-tab i { display: none; }
    .analytics-tab   { padding: 8px 11px; font-size: 0.8rem; }

    .hide-tablet { display: none !important; }
}

/* ================================================================
   RESPONSIVE — 768px (mobile)
   ================================================================ */
@media (max-width: 768px) {
    :root { --topbar-height: 56px; }

    /* Sidebar: hidden off-screen, toggleable */
    .sidebar               { transform: translateX(-100%); }
    .sidebar.open          { transform: translateX(0); }
    .sidebar-overlay.open  { display: block; }
    .sidebar-toggle        { display: flex; }

    /* Content */
    .main-content { margin-left: 0; padding: 16px; }

    /* Grids collapse to single column */
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .stats-grid      { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 18px; }
    .sites-grid      { grid-template-columns: 1fr; padding: 14px; gap: 12px; }

    /* Page headers */
    .page-header { flex-direction: column; align-items: flex-start; }
    .header-actions { width: 100%; }
    .period-selector { width: 100%; }

    /* Topbar */
    .topbar-user-text { display: none; }
    .topbar-divider   { display: none; }

    /* Stat cards */
    .stat-card  { padding: 16px 14px; gap: 12px; }
    .stat-icon  { width: 42px; height: 42px; font-size: 1rem; border-radius: 10px; }
    .stat-value { font-size: 1.45rem; }

    /* Auth */
    .auth-card { padding: 28px 20px; }
    .empty-state { padding: 48px 16px; }
    .code-block  { font-size: 0.75rem; padding: 12px; }

    /* Tables */
    .table td, .table th { padding: 9px 12px; }
    .action-cell .btn { margin-right: 0; }

    /* Analytics nav: stack tabs on top, period below */
    .analytics-nav {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        padding: 6px;
        border-radius: var(--radius);
        top: calc(var(--topbar-height) + 4px);
    }
    .analytics-tabs    { order: 1; -webkit-mask-image: none; mask-image: none; }
    .analytics-nav-sep { display: none; }
    .analytics-periods { order: 2; justify-content: center; background: var(--bg); }
    .period-btn { flex: 1; padding: 6px 4px; }

    /* Map */
    .map-container { height: 240px; }
}

/* ================================================================
   RESPONSIVE — 480px (small phones)
   ================================================================ */
@media (max-width: 480px) {
    .main-content { padding: 10px; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card  { padding: 14px 12px; gap: 10px; }
    .stat-icon  { width: 38px; height: 38px; font-size: 0.9rem; border-radius: 9px; }
    .stat-value { font-size: 1.25rem; }
    .stat-label { font-size: 0.68rem; }

    .btn     { padding: 9px 14px; }
    .btn-sm  { padding: 6px 10px; font-size: 0.75rem; }
    .btn-xs  { padding: 3px 7px;  font-size: 0.7rem; }

    .card-header { padding: 13px 14px; }
    .card-body   { padding: 14px; }

    .hide-mobile { display: none !important; }

    .nav-tabs .tab { padding: 8px 10px; font-size: 0.78rem; }
    .table-container { margin: 0 -10px; }
    .table th, .table td { padding: 7px 8px; font-size: 0.79rem; }

    .pagination .page-link { min-width: 30px; height: 30px; font-size: 0.75rem; padding: 0 6px; }
    .pagination { gap: 2px; }

    .analytics-tab  { padding: 7px 9px; font-size: 0.76rem; }
    .period-btn     { padding: 5px 3px; font-size: 0.72rem; min-width: 0; }

    .sites-grid { padding: 10px; gap: 10px; }

    .auth-card { padding: 22px 16px; }
    .auth-card-header { margin-bottom: 22px; }
    .empty-state { padding: 36px 12px; }
}
