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

:root {
    --bg-dark: #070A10;
    --bg-panel: rgba(14, 18, 28, 0.8);
    --bg-glass: rgba(22, 28, 42, 0.7);
    --glass-border: rgba(255, 255, 255, 0.07);
    --glass-border-hover: rgba(99, 102, 241, 0.35);
    --text-primary: #E8ECF4;
    --text-secondary: #8892A4;
    --accent-primary: #6366F1;
    --accent-primary-glow: rgba(99, 102, 241, 0.25);
    --accent-green: #10B981;
    --accent-green-glow: rgba(16, 185, 129, 0.2);
    --accent-red: #EF4444;
    --accent-orange: #F59E0B;
    --accent-blue: #3B82F6;
    --accent-purple: #8B5CF6;
    --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 0.2s ease;
    --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    --radius: 14px;
    --radius-sm: 8px;
    --blur: blur(20px);
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    background-image:
        radial-gradient(ellipse 60% 50% at 10% 50%, rgba(99, 102, 241, 0.07) 0%, transparent 70%),
        radial-gradient(ellipse 60% 50% at 90% 20%, rgba(139, 92, 246, 0.07) 0%, transparent 70%),
        radial-gradient(ellipse 40% 40% at 50% 100%, rgba(16, 185, 129, 0.04) 0%, transparent 70%);
}

.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* ── Glassmorphism utility ── */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

/* ── SIDEBAR ── */
.sidebar {
    width: 248px;
    min-width: 248px;
    height: calc(100vh - 28px);
    margin: 14px 0 14px 14px;
    display: flex;
    flex-direction: column;
    z-index: 10;
    flex-shrink: 0;
}

.brand {
    padding: 22px 20px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--glass-border);
}
.brand-icon {
    width: 34px; height: 34px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-purple));
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    color: white;
    box-shadow: 0 4px 14px var(--accent-primary-glow);
}
.brand-icon svg { width: 18px; height: 18px; }
.brand h2 { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.3px; }

.nav-menu {
    flex: 1;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

.nav-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    padding: 12px 10px 6px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 10px;
    font-weight: 500;
    font-size: 0.92rem;
    transition: var(--transition);
    cursor: pointer;
    border: 1px solid transparent;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.nav-item.active {
    background: var(--accent-primary-glow);
    color: #a5b4fc;
    border-color: rgba(99,102,241,0.25);
}

.sidebar-footer {
    padding: 12px 16px 16px;
    border-top: 1px solid var(--glass-border);
}
.status-indicator {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.8rem; color: var(--text-secondary);
}
.pulse-dot {
    width: 7px; height: 7px;
    background: var(--accent-green);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent-green);
    animation: pulse 2.5s infinite;
    flex-shrink: 0;
}
@keyframes pulse {
    0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(16,185,129,0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 5px rgba(16,185,129,0); }
    100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}

/* ── MAIN CONTENT ── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
    padding: 14px 14px 14px 12px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 4px;
    gap: 16px;
}
.page-title h1 { font-size: 1.55rem; font-weight: 700; line-height: 1.1; }
.page-title p { color: var(--text-secondary); font-size: 0.88rem; margin-top: 3px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.last-updated {
    font-size: 0.8rem; color: var(--text-secondary);
    background: var(--bg-glass);
    padding: 5px 12px; border-radius: 20px;
    border: 1px solid var(--glass-border);
    white-space: nowrap;
}

/* Refresh indicator */
.refresh-ring {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.78rem; color: var(--text-secondary);
}
.refresh-ring.fetching .ring-icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ring-icon { width: 14px; height: 14px; }

.scroll-container {
    flex: 1;
    overflow-y: auto;
    padding: 4px 2px 4px 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) transparent;
    min-height: 0;
}
.scroll-container::-webkit-scrollbar { width: 5px; }
.scroll-container::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 3px; }

/* ── BUTTONS ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 7px; padding: 8px 18px; border-radius: 9px;
    font-size: 0.9rem; font-weight: 600; cursor: pointer; border: none;
    transition: var(--transition); font-family: var(--font-main);
    white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary {
    background: var(--accent-primary); color: white;
    box-shadow: 0 4px 14px var(--accent-primary-glow);
}
.btn-primary:hover { background: #4F46E5; transform: translateY(-1px); box-shadow: 0 6px 20px rgba(99,102,241,0.35); }
.btn-secondary { background: rgba(255,255,255,0.08); color: var(--text-primary); border: 1px solid var(--glass-border); }
.btn-secondary:hover { background: rgba(255,255,255,0.13); }
.btn-danger { background: rgba(239,68,68,0.1); color: var(--accent-red); border: 1px solid rgba(239,68,68,0.2); }
.btn-danger:hover { background: var(--accent-red); color: white; }
.btn-icon svg { width: 16px; height: 16px; }
.btn-back { margin-bottom: 14px; padding: 6px 14px; }

/* ── GLOBAL STAT CARDS (top row) ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 26px;
}
.stat-card {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition-smooth);
}
.stat-card:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.12); }
.stat-icon-wrapper {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon-wrapper svg { width: 24px; height: 24px; }
.bg-blue { background: rgba(59,130,246,0.12); border: 1px solid rgba(59,130,246,0.25); }
.text-blue { color: var(--accent-blue); }
.bg-green { background: rgba(16,185,129,0.12); border: 1px solid rgba(16,185,129,0.25); }
.text-green { color: var(--accent-green); }
.bg-red { background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.25); }
.text-red { color: var(--accent-red); }
.bg-orange { background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.25); }
.text-orange { color: var(--accent-orange); }
.bg-purple { background: rgba(139,92,246,0.12); border: 1px solid rgba(139,92,246,0.25); }
.text-purple { color: var(--accent-purple); }
.stat-info h3 { font-size: 0.82rem; color: var(--text-secondary); font-weight: 500; margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 1.9rem; font-weight: 700; color: var(--text-primary); line-height: 1; }

/* ── SECTION TITLES ── */
.section-title { margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.section-title h2 { font-size: 1.05rem; font-weight: 600; }

/* ── SERVER GRID ── */
.servers-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

@media (max-width: 1100px) {
    .servers-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .servers-grid {
        grid-template-columns: 1fr;
    }
}
.server-card {
    padding: 18px; cursor: pointer;
    transition: var(--transition-smooth);
    position: relative;
}
.server-card:hover {
    transform: translateY(-3px);
    border-color: var(--glass-border-hover);
    box-shadow: 0 12px 36px rgba(0,0,0,0.3);
}
.card-header {
    display: flex; justify-content: space-between;
    align-items: flex-start; margin-bottom: 14px;
}
.server-identity h3 { font-size: 1rem; font-weight: 600; margin-bottom: 2px; }
.server-ip { font-size: 0.75rem; color: var(--text-secondary); font-family: monospace; }
.status-badge {
    padding: 3px 9px; border-radius: 20px;
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
    white-space: nowrap;
}
.status-online  { background: rgba(16,185,129,0.12); color: var(--accent-green);  border: 1px solid rgba(16,185,129,0.25); }
.status-offline { background: rgba(239,68,68,0.12);  color: var(--accent-red);    border: 1px solid rgba(239,68,68,0.25); }
.status-pending { background: rgba(245,158,11,0.12); color: var(--accent-orange); border: 1px solid rgba(245,158,11,0.25); }

/* Mini metric bars on cards */
.metrics-brief {
    display: flex; gap: 0;
    margin-top: 14px; padding-top: 14px;
    border-top: 1px solid var(--glass-border);
}
.metric-mini { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.metric-mini:not(:last-child) { border-right: 1px solid var(--glass-border); margin-right: 12px; padding-right: 12px; }
.metric-label { font-size: 0.7rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.3px; }
.metric-val { font-size: 0.95rem; font-weight: 600; }

/* ── SERVER DETAIL ── */
.server-detail-header {
    padding: 20px 24px; margin-bottom: 20px;
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 12px;
}
/* AI Insights Styles */
.insight-card {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.badge-red {
    background: rgba(239, 68, 68, 0.15);
    color: #EF4444;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-orange {
    background: rgba(245, 158, 11, 0.15);
    color: #F59E0B;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
}

.ai-insight-content {
    line-height: 1.5;
    font-size: 0.9rem;
}

.ai-insight-content ul {
    padding-left: 20px;
    margin: 4px 0;
}

.ai-insight-content li {
    margin-bottom: 2px;
}
/* AI Page Layout */
.ai-layout-grid {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 24px;
    align-items: start;
}

@media (max-width: 1200px) {
    .ai-layout-grid { grid-template-columns: 1fr; }
    .ai-chat-col { height: 600px; }
}

/* Chat Bubbles */
.chat-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

.chat-bubble.assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: #E2E8F0;
    border-bottom-left-radius: 2px;
}

.chat-bubble.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #6366F1 0%, #4F46E5 100%);
    color: #fff;
    border-bottom-right-radius: 2px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.chat-bubble.typing {
    opacity: 0.7;
    font-style: italic;
    font-size: 0.82rem;
}

.chat-bubble pre {
    background: rgba(0,0,0,0.3);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 0.85rem;
}

.chat-bubble code {
    font-family: monospace;
}

/* Custom Scrollbar for Chat */
#chat-messages::-webkit-scrollbar {
    width: 5px;
}
#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
#chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
}
#chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}
.server-title-area { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.ip-address { font-size: 0.82rem; color: var(--text-secondary); font-family: monospace; }
.server-actions { display: flex; gap: 8px; }

/* ── 4-COLUMN METRICS GRID ── */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
@media (max-width: 900px) { .metrics-grid { grid-template-columns: 1fr; } }
.chart-container { 
    padding: 0; 
    position: relative; 
    display: flex; 
    flex-direction: column;
    overflow: hidden;
}
.chart-container h3 { 
    padding: 18px 18px 10px 18px;
    font-size: 0.88rem; 
    color: var(--text-secondary); 
    font-weight: 500; 
    text-transform: uppercase; 
    letter-spacing: 0.5px; 
    flex-shrink: 0;
    margin: 0;
}
.chart-wrapper {
    position: relative;
    flex: 1;
    width: 100%;
    min-height: 0;
    padding: 0 12px 12px 12px; /* Slight padding for the chart area itself */
}
.chart-wrapper canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* ── SERVICE PANELS ── */
.services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}
.service-card { padding: 18px; }
.service-header {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 14px; padding-bottom: 10px;
    border-bottom: 1px solid var(--glass-border);
}
.service-icon svg { width: 22px; height: 22px; }
.service-header h3 { font-size: 0.95rem; font-weight: 600; }
.service-stats { display: flex; flex-direction: column; gap: 10px; }
.stat-row {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.86rem; color: var(--text-secondary);
}
.stat-row b { color: var(--text-primary); font-weight: 600; }

/* ── GLOBAL WEBSITES TABLE ── */
.websites-panel { padding: 4px; }
.search-bar {
    width: 100%; padding: 10px 16px; margin-bottom: 14px;
    border-radius: 9px; border: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.25); color: white;
    font-family: var(--font-main); font-size: 0.9rem;
    transition: var(--transition);
}
.search-bar:focus { outline: none; border-color: var(--accent-primary); background: rgba(0,0,0,0.35); }
.table-wrapper { overflow-x: auto; border-radius: var(--radius-sm); }
table.data-table {
    width: 100%; text-align: left; border-collapse: collapse;
    font-size: 0.88rem;
}
table.data-table th {
    padding: 10px 14px; font-size: 0.75rem; text-transform: uppercase;
    letter-spacing: 0.5px; color: var(--text-secondary); font-weight: 600;
    border-bottom: 1px solid var(--glass-border);
    white-space: nowrap;
}
table.data-table td { padding: 10px 14px; border-bottom: 1px solid rgba(255,255,255,0.03); }
table.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.up-badge { color: var(--accent-green); font-weight: 600; }
.down-badge { color: var(--accent-red); font-weight: 600; }

/* ── ANALYTICS ── */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}
@media (max-width: 900px) { .analytics-grid { grid-template-columns: 1fr; } }

/* ── MODALS ── */
.modal-backdrop {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.55); backdrop-filter: blur(10px);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; opacity: 0; pointer-events: none; transition: var(--transition);
}
.modal-backdrop.show { opacity: 1; pointer-events: all; }
.modal-backdrop.show .modal { transform: scale(1); opacity: 1; }
.modal {
    width: 100%; max-width: 440px;
    transform: scale(0.96); opacity: 0; transition: var(--transition-smooth);
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 22px; border-bottom: 1px solid var(--glass-border);
}
.modal-header h2 { font-size: 1.1rem; font-weight: 600; }
.btn-close { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; transition: var(--transition); }
.btn-close:hover { color: var(--text-primary); }
.btn-close svg { width: 20px; height: 20px; }
.modal-body { padding: 22px; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 7px; font-weight: 500; }
.form-group input {
    width: 100%; padding: 10px 14px;
    background: rgba(0,0,0,0.2); border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm); color: white; font-family: var(--font-main); transition: var(--transition);
}
.form-group input:focus { outline: none; border-color: var(--accent-primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ── VIEW TRANSITIONS ── */
.view { display: none; animation: fadeInUp 0.25s ease; }
.view.active { display: block; }
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── UTILITIES ── */
.hidden { display: none !important; }
.text-muted { color: var(--text-secondary); }
.text-red { color: var(--accent-red); }
.text-green { color: var(--accent-green); }
.text-orange { color: var(--accent-orange); }

.loading-pulse {
    text-align: center; padding: 50px;
    color: var(--text-secondary); font-size: 0.95rem;
    animation: pulseOpac 1.5s infinite;
}
@keyframes pulseOpac { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

.alert { padding: 14px; border-radius: 8px; font-size: 0.85rem; line-height: 1.5; }
.alert-info { background: rgba(59,130,246,0.08); border: 1px solid rgba(59,130,246,0.2); color: #bfdbfe; }
.alert-info code { background: rgba(0,0,0,0.3); padding: 2px 6px; border-radius: 4px; color: #93c5fd; }

/* Progress bar inside cards */
.mini-bar-wrap { width: 100%; height: 4px; background: rgba(255,255,255,0.08); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.mini-bar { height: 100%; border-radius: 2px; transition: width 0.4s ease; }
.mini-bar-cpu { background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple)); }
.mini-bar-ram { background: linear-gradient(90deg, var(--accent-green), #34D399); }

/* UI Switches */
.switch-ui {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 22px;
}
.switch-ui input { 
    opacity: 0;
    width: 0;
    height: 0;
}
.slider-ui {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255,255,255,0.1);
    transition: .4s;
    border-radius: 34px;
}
.slider-ui:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider-ui {
    background-color: #6366f1;
}
input:checked + .slider-ui:before {
    transform: translateX(22px);
}

.sort-icon {
    display: inline-block;
    margin-left: 5px;
    font-size: 0.8rem;
    color: var(--accent-primary);
    vertical-align: middle;
}
