/* ═══ Heady Admin — Premium Dark Theme ═══ */
:root {
    --bg-deep: #050505;
    --bg-surface: #0a0a0a;
    --bg-card: #0f0f0f;
    --bg-hover: #1a1a1a;
    --bg-input: #101010;
    --border: #333;
    --border-active: #FF107A;
    --text-primary: #FFFFFF;
    --text-secondary: #A0A0A0;
    --text-muted: #666666;
    --accent-blue: #00F0FF;
    --accent-purple: #FF107A;
    --accent-green: #00FF66;
    --accent-amber: #FFB800;
    --accent-red: #FF0033;
    --accent-cyan: #00F0FF;
    --gradient-blue: linear-gradient(135deg, #FF107A, #A10050);
    --gradient-purple: linear-gradient(135deg, #A100FF, #FF107A);
    --gradient-green: linear-gradient(135deg, #00FF66, #008A37);
    --gradient-amber: linear-gradient(135deg, #FFB800, #8A6300);
    --glass: rgba(10, 10, 10, 0.9);
    --glass-border: rgba(255, 16, 122, 0.3);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --sidebar-w: 240px;
    --buddy-w: 380px;
    --topbar-h: 64px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ── Auth Modal ── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(12px);
}

.modal-glass {
    background: var(--bg-card);
    border: 1px solid var(--border-active);
    border-radius: 0;
    padding: 40px;
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 0 40px rgba(255, 16, 122, 0.2);
    text-align: center;
    position: relative;
}

.modal-glass::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--gradient-blue);
}

.modal-header {
    margin-bottom: 28px;
}

.logo-glow {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 800;
    color: #fff;
    background: transparent;
    border: 2px solid var(--border-active);
    border-radius: 0;
    box-shadow: inset 0 0 20px rgba(255, 16, 122, 0.4), 0 0 30px rgba(255, 16, 122, 0.4);
    animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {

    0%,
    100% {
        box-shadow: inset 0 0 20px rgba(255, 16, 122, 0.3), 0 0 30px rgba(255, 16, 122, 0.3);
    }

    50% {
        box-shadow: inset 0 0 30px rgba(255, 16, 122, 0.6), 0 0 50px rgba(255, 16, 122, 0.6);
    }
}

.modal-header h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.subtle {
    color: var(--text-secondary);
    font-size: 14px;
}

.btn-auth {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-google {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: none;
}

.btn-google:hover {
    border-color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-email {
    background: transparent;
    color: var(--accent-purple);
    border: 1px solid var(--accent-purple);
    box-shadow: 0 0 15px rgba(255, 16, 122, 0.2);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-email:hover {
    background: rgba(255, 16, 122, 0.1);
    box-shadow: 0 0 25px rgba(255, 16, 122, 0.4);
    transform: translateY(-1px);
}

.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0;
    color: var(--text-muted);
    font-size: 12px;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.email-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.email-form input {
    padding: 12px 16px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

.email-form input:focus {
    border-color: var(--border-active);
    box-shadow: 0 0 10px rgba(255, 16, 122, 0.2);
}

.auth-toggle {
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}

.auth-toggle a {
    color: var(--accent-blue);
    text-decoration: none;
}

/* ── App Layout ── */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 16px 0;
    flex-shrink: 0;
    transition: var(--transition);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px 20px;
}

.logo-mark {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 800;
    color: var(--accent-purple);
    background: transparent;
    border: 1px solid var(--accent-purple);
    border-radius: 0;
    box-shadow: 0 0 15px rgba(255, 16, 122, 0.2);
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.nav-items {
    list-style: none;
    flex: 1;
    padding: 8px 10px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    margin-bottom: 2px;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

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

.nav-item.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--accent-blue);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    margin-top: auto;
    cursor: pointer;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-purple);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
}

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

/* ── Main Content ── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ── Top Bar ── */
.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
}

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

.page-title {
    font-size: 20px;
    font-weight: 700;
}

.live-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-green);
    background: rgba(34, 197, 94, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pulse {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-green);
    animation: pulse 2s ease infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

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

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 14px;
}

.search-box svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

.search-box input {
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    width: 200px;
}

.btn-icon {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    position: relative;
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

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

.notif-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-red);
}

/* ── Pages ── */
.page {
    display: none;
    padding: 28px;
    overflow-y: auto;
    flex: 1;
}

.page.active {
    display: block;
}

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    padding: 20px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    background: var(--bg-card);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.stat-card.gradient-blue::before {
    background: var(--gradient-blue);
}

.stat-card.gradient-purple::before {
    background: var(--gradient-purple);
}

.stat-card.gradient-green::before {
    background: var(--gradient-green);
}

.stat-card.gradient-amber::before {
    background: var(--gradient-amber);
}

.stat-icon {
    font-size: 28px;
}

.stat-body {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -1px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-top: 2px;
}

/* ── Section Headers ── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.btn-refresh {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    transition: var(--transition);
}

.btn-refresh:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

/* ── Services Grid ── */
.services-grid,
.services-full-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.service-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    transition: var(--transition);
    cursor: default;
}

.service-card:hover {
    border-color: var(--border-active);
    box-shadow: var(--shadow-sm);
}

.service-card.loading {
    min-height: 80px;
}

.service-card .svc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.service-card .svc-name {
    font-size: 14px;
    font-weight: 600;
}

.service-card .svc-status {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.svc-status.online {
    background: rgba(34, 197, 94, 0.15);
    color: var(--accent-green);
}

.svc-status.offline {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
}

.service-card .svc-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.shimmer {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 37%, var(--bg-card) 63%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease infinite;
}

@keyframes shimmer {
    0% {
        background-position: 100% 0;
    }

    100% {
        background-position: -100% 0;
    }
}

/* ── Race Log ── */
.race-log {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.race-entry {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 13px;
}

.race-entry.loading {
    height: 52px;
}

.race-winner {
    font-weight: 700;
    color: var(--accent-green);
}

.race-latency {
    color: var(--accent-cyan);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.race-providers {
    color: var(--text-muted);
}

.race-time {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 11px;
}

/* ── Memory Page ── */
.memory-search {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.memory-search input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

.memory-search input:focus {
    border-color: var(--accent-blue);
}

.btn-primary {
    padding: 10px 20px;
    background: var(--gradient-blue);
    border: none;
    border-radius: var(--radius-md);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);
}

.memory-results {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
}

.memory-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}

.memory-item .mem-score {
    font-size: 12px;
    color: var(--accent-cyan);
    font-weight: 700;
}

.memory-item .mem-content {
    font-size: 13px;
    margin-top: 4px;
    color: var(--text-secondary);
}

textarea {
    width: 100%;
    padding: 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    resize: vertical;
    margin-bottom: 12px;
    transition: var(--transition);
}

textarea:focus {
    border-color: var(--accent-blue);
}

.memory-stats {
    font-size: 13px;
    color: var(--text-muted);
}

/* ── Agents Grid ── */
.agents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}

.agent-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    text-align: center;
    transition: var(--transition);
}

.agent-card:hover {
    border-color: var(--accent-purple);
    box-shadow: var(--shadow-sm);
}

.agent-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.agent-name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
}

.agent-desc {
    font-size: 12px;
    color: var(--text-muted);
}

/* ── HeadyBuddy Panel ── */
.buddy-panel {
    width: 0;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease;
    flex-shrink: 0;
}

.buddy-panel.open {
    width: var(--buddy-w);
}

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

.buddy-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.buddy-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-purple);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.buddy-title h3 {
    font-size: 15px;
    font-weight: 700;
}

.buddy-status {
    font-size: 11px;
    color: var(--accent-green);
}

.btn-close-buddy {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

.buddy-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.msg {
    max-width: 90%;
}

.msg-buddy {
    align-self: flex-start;
}

.msg-user {
    align-self: flex-end;
}

.msg-content {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
}

.msg-buddy .msg-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg-user .msg-content {
    background: var(--gradient-blue);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.buddy-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.buddy-input input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
}

.buddy-input input:focus {
    border-color: var(--accent-blue);
}

.btn-voice,
.btn-send {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-voice {
    background: var(--bg-input);
    color: var(--text-secondary);
}

.btn-voice:hover {
    background: var(--bg-hover);
    color: var(--accent-red);
}

.btn-voice.recording {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
    animation: voicePulse 1.5s ease infinite;
}

@keyframes voicePulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }
}

.btn-voice svg,
.btn-send svg {
    width: 18px;
    height: 18px;
}

.btn-send {
    background: var(--gradient-blue);
    color: #fff;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.btn-send:hover {
    transform: scale(1.05);
}

/* ── Gateway Info ── */
.gateway-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.gw-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
}

.gw-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.gw-value {
    font-size: 15px;
    font-weight: 600;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .sidebar {
        width: 64px;
    }

    .sidebar .logo-text,
    .sidebar .nav-item span,
    .sidebar .user-info {
        display: none;
    }

    .sidebar-logo {
        justify-content: center;
    }

    .nav-item {
        justify-content: center;
        padding: 12px;
    }

    .sidebar-user {
        justify-content: center;
    }
}

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

    .search-box {
        display: none;
    }

    .buddy-panel.open {
        width: 100vw;
        position: fixed;
        inset: 0;
        z-index: 100;
    }
}