/* ═══════════════════════════════════════════════════
   AdTracker Pro — Admin UI Stylesheet
   ═══════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

/* ─── CSS Variables ─────────────────────────────── */
:root {
    --color-primary:    #22c55e;
    --color-primary-dim: rgba(34,197,94,0.15);
    --color-accent:     #3b82f6;

    --radius-sm:  4px;
    --radius-md:  8px;
    --radius-lg:  12px;
    --radius-xl:  16px;

    --sidebar-w:  240px;
    --topbar-h:   56px;

    --transition: 150ms ease;
    --font-main:  'DM Sans', system-ui, sans-serif;
    --font-mono:  'DM Mono', 'JetBrains Mono', monospace;
}

/* Dark Theme (default) */
[data-theme="dark"] {
    --bg-page:      #0a0a0f;
    --bg-surface:   #111118;
    --bg-elevated:  #18181f;
    --bg-overlay:   #1e1e28;
    --bg-hover:     #23232e;

    --border:       rgba(255,255,255,0.07);
    --border-focus: rgba(34,197,94,0.5);

    --text-primary:   #f1f1f3;
    --text-secondary: #8b8b9a;
    --text-muted:     #55556a;

    --shadow-card: 0 1px 3px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05);
    --shadow-elevated: 0 4px 24px rgba(0,0,0,0.6);
    --shadow-glow: 0 0 20px rgba(34,197,94,0.15);
}

/* Light Theme */
[data-theme="light"] {
    --bg-page:      #f4f4f8;
    --bg-surface:   #ffffff;
    --bg-elevated:  #f9f9fc;
    --bg-overlay:   #f0f0f5;
    --bg-hover:     #ebebf2;

    --border:       rgba(0,0,0,0.08);
    --border-focus: rgba(34,197,94,0.6);

    --text-primary:   #0f0f14;
    --text-secondary: #5a5a6e;
    --text-muted:     #9999b0;

    --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.04);
    --shadow-elevated: 0 4px 24px rgba(0,0,0,0.1);
    --shadow-glow: 0 0 20px rgba(34,197,94,0.1);
}

/* ─── Reset & Base ──────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; height: 100%; }

body {
    font-family: var(--font-main);
    background: var(--bg-page);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ─── Sidebar ───────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width var(--transition), transform var(--transition);
    overflow: hidden;
}

.sidebar.collapsed { width: 60px; }

.sidebar-header {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.3px;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-brand { transition: opacity var(--transition); }
.sidebar.collapsed .sidebar-brand { opacity: 0; pointer-events: none; }

.sidebar-toggle {
    color: var(--text-muted);
    padding: 6px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    transition: color var(--transition), background var(--transition);
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }

/* Nav */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.nav-group { margin-bottom: 4px; }

.nav-group-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 8px 16px 4px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--transition);
}
.sidebar.collapsed .nav-group-label { opacity: 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    border-radius: 0;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 450;
    position: relative;
    transition: color var(--transition), background var(--transition);
    white-space: nowrap;
    margin: 1px 8px;
    border-radius: var(--radius-md);
}

.nav-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: none;
}

.nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-item.active {
    color: var(--color-primary);
    background: var(--color-primary-dim);
    font-weight: 500;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    background: var(--color-primary);
    border-radius: 0 3px 3px 0;
}

.nav-badge {
    margin-left: auto;
    background: var(--bg-overlay);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 20px;
    font-family: var(--font-mono);
    min-width: 20px;
    text-align: center;
    transition: opacity var(--transition);
}
.sidebar.collapsed .nav-badge { opacity: 0; }

/* Sidebar footer */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--color-primary-dim);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}

.user-meta {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    transition: opacity var(--transition);
}
.sidebar.collapsed .user-meta { opacity: 0; pointer-events: none; }

.user-name {
    display: block;
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: capitalize;
}

.logout-btn {
    color: var(--text-muted);
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: color var(--transition);
    flex-shrink: 0;
}
.logout-btn:hover { color: #ef4444; }

/* ─── Main Content ──────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition);
}

body.sidebar-collapsed .main-content { margin-left: 60px; }

/* Topbar */
.topbar {
    height: var(--topbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.topbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar-time {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
}

.mobile-menu-btn {
    display: none;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: var(--radius-sm);
}

/* Theme toggle */
.theme-toggle {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    transition: all var(--transition);
}
.theme-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }

[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }

/* Real-time indicator */
.realtime-indicator, .realtime-dot {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--color-primary);
}

.pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-primary);
    animation: pulse 2s infinite;
}

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

/* ─── Page Content ──────────────────────────────── */
.page-content {
    padding: 24px;
    flex: 1;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.page-subtitle {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 3px;
}

.page-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* ─── Period Selector ───────────────────────────── */
.period-selector {
    display: flex;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 3px;
    gap: 2px;
}

.period-btn {
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.period-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.period-btn.active { color: var(--text-primary); background: var(--bg-surface); box-shadow: var(--shadow-card); }

/* ─── Stats Grid ────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    box-shadow: var(--shadow-card);
    transition: border-color var(--transition), box-shadow var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 60%, rgba(255,255,255,0.02));
    pointer-events: none;
}

.stat-card:hover {
    border-color: rgba(255,255,255,0.12);
    box-shadow: var(--shadow-elevated);
}

.stat-card--wide { grid-column: span 2; }

.stat-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 16px; height: 16px; }

.stat-icon--blue    { background: rgba(59,130,246,0.15); color: #3b82f6; }
.stat-icon--purple  { background: rgba(139,92,246,0.15); color: #8b5cf6; }
.stat-icon--green   { background: rgba(34,197,94,0.15);  color: #22c55e; }
.stat-icon--red     { background: rgba(239,68,68,0.15);  color: #ef4444; }
.stat-icon--emerald { background: rgba(16,185,129,0.15); color: #10b981; }
.stat-icon--teal    { background: rgba(20,184,166,0.15); color: #14b8a6; }
.stat-icon--orange  { background: rgba(249,115,22,0.15); color: #f97316; }

.stat-body { flex: 1; min-width: 0; }
.stat-label { font-size: 11px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; letter-spacing: -0.8px; font-variant-numeric: tabular-nums; line-height: 1; }
.stat-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; font-family: var(--font-mono); }
.stat-trend { font-size: 11px; margin-top: 4px; }

.text-green { color: #22c55e; }
.text-red   { color: #ef4444; }

/* ─── Charts ────────────────────────────────────── */
.chart-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 12px;
}

.chart-title { font-weight: 600; font-size: 14px; }

.chart-legend {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    transition: color var(--transition);
    user-select: none;
    opacity: 0.5;
}

.legend-item.active { opacity: 1; color: var(--text-primary); }
.legend-item:hover { color: var(--text-primary); }

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.chart-body {
    padding: 20px;
    position: relative;
}

/* ─── Tables ────────────────────────────────────── */
.dashboard-tables {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.table-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.table-title { font-weight: 600; font-size: 13px; }
.table-link { font-size: 12px; color: var(--color-primary); }
.table-link:hover { opacity: 0.8; }

.table-body { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

thead th {
    padding: 8px 14px;
    text-align: left;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

thead th:first-child { padding-left: 18px; }

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-elevated); }

tbody td {
    padding: 9px 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

tbody td:first-child { padding-left: 18px; color: var(--text-primary); font-weight: 500; }

.table-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
}

.table-empty {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ─── Buttons ───────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
    white-space: nowrap;
    cursor: pointer;
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--color-primary);
    color: #000;
    font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.1); box-shadow: var(--shadow-glow); }

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger { background: rgba(239,68,68,0.15); color: #ef4444; border-color: rgba(239,68,68,0.2); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }

.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ─── Badges / Status ───────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.badge-green   { background: rgba(34,197,94,0.15);  color: #22c55e; }
.badge-red     { background: rgba(239,68,68,0.15);  color: #ef4444; }
.badge-yellow  { background: rgba(234,179,8,0.15);  color: #eab308; }
.badge-gray    { background: var(--bg-overlay);      color: var(--text-muted); }
.badge-blue    { background: rgba(59,130,246,0.15); color: #3b82f6; }

/* ─── Forms ─────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    padding: 8px 12px;
    font-size: 13.5px;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-dim);
}

.form-control::placeholder { color: var(--text-muted); }

/* ─── Login Page ────────────────────────────────── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin-left: 0;
}

.login-container {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 380px;
    padding: 24px;
    text-align: center;
}

.login-logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.4px;
    margin-bottom: 28px;
}

.login-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 28px;
    box-shadow: var(--shadow-elevated);
    text-align: left;
}

.login-card h1 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 24px; }

.login-error {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.2);
    color: #ef4444;
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 16px;
}

.login-footer {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 20px;
}

.login-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}

.login-bg-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 40px 40px;
    opacity: 0.5;
}

.login-bg-glow {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(34,197,94,0.08) 0%, transparent 70%);
    pointer-events: none;
}

/* ─── Spinner ───────────────────────────────────── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Scrollbar ─────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Responsive ────────────────────────────────── */
@media (max-width: 1024px) {
    .dashboard-tables { grid-template-columns: 1fr; }
    .stat-card--wide { grid-column: span 1; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-w) !important;
    }
    .sidebar.mobile-open { transform: translateX(0); }
    .main-content { margin-left: 0 !important; }
    .mobile-menu-btn { display: flex; }
    .page-content { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .period-selector { flex-wrap: wrap; }
    .topbar { padding: 0 16px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
}
