@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;600;800&display=swap');

:root {
    --primary: #6366f1;
    --primary-light: #a5b4fc;
    --primary-dark: #4338ca;
    --secondary: #64748b;
    --bg-app: #f1f5f9;
    --bg-sidebar: #0f172a;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(255, 255, 255, 0.5);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius: 12px;
    --sidebar-width: 280px;
}

[data-theme="dark"] {
    --bg-app: #0f172a; /* Lighter Midnight Blue for better surface separation */
    --bg-sidebar: #0b1120;
    --bg-card: #1e293b; /* More visible cards */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.05);
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1000;
    padding: 2.5rem 1.5rem;
    box-shadow: 4px 0 24px rgba(0,0,0,0.2);
}

.brand {
    display: flex;
    justify-content: center;
    margin-bottom: 3.5rem;
}

.logo-wrapper {
    background: rgba(255, 255, 255, 0.03);
    padding: 0.75rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.logo-img {
    max-height: 44px;
    max-width: 100%;
}

.nav-menu {
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    color: #94a3b8;
    text-decoration: none;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.nav-link:hover {
    background: rgba(255,255,255,0.05);
    color: white;
}

.nav-link.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.nav-link .icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.05);
    padding-top: 1.5rem;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: #f87171;
    text-decoration: none;
    font-weight: 600;
    border-radius: var(--radius);
    transition: all 0.2s ease;
}

.logout-btn:hover {
    background: rgba(239, 68, 68, 0.1);
}

.logout-icon {
    width: 24px;
    height: 24px;
}

.logout-icon svg {
    fill: currentColor;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2.5rem 3.5rem;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3.5rem;
}

.page-title h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 2rem;
    font-weight: 800;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

#theme-toggle {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.user-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-card);
    padding: 0.4rem 0.4rem 0.4rem 1.25rem;
    border-radius: 100px;
    border: 1px solid var(--border);
}

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

.user-name { font-weight: 600; font-size: 0.85rem; }
.user-role { font-size: 0.7rem; color: var(--text-muted); }

.avatar {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.8rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 3.5rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease;
}

.stat-card.certificates { border-left: 4px solid var(--primary); }
.stat-card.agents { border-left: 4px solid var(--success); }
.stat-card.expiring { border-left: 4px solid var(--warning); }

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon.certificates { background: rgba(99, 102, 241, 0.1); color: var(--primary); }
.stat-icon.agents { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.stat-icon.expiring { background: rgba(245, 158, 11, 0.1); color: var(--warning); }

.stat-icon svg { width: 24px; height: 24px; }

.stat-number {
    font-size: 2.25rem;
    font-weight: 800;
    font-family: 'Outfit', sans-serif;
}

/* Buttons - IMPORTANT FIX */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    white-space: nowrap;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-primary svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    flex-shrink: 0;
}

/* Agent Table Actions */
.table-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.btn-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

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

.btn-icon.delete:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

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

/* Page Actions */
.page-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.info p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Cards & Tables */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h3 { font-family: 'Outfit', sans-serif; font-size: 1.25rem; font-weight: 700; }
.card-header p { font-size: 0.85rem; color: var(--text-muted); }

.table-container { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left;
    padding: 1rem 1.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: rgba(0,0,0,0.02);
}

[data-theme="dark"] .data-table th { background: rgba(255,255,255,0.02); }

/* Maintenance Section Styles */
.maintenance-card {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.03) 0%, rgba(16, 185, 129, 0.03) 100%);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    margin: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
    position: relative;
    overflow: hidden;
}

.maintenance-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.05) 0%, transparent 70%);
    opacity: 0.5;
    pointer-events: none;
}

.maintenance-info {
    flex: 1;
    position: relative;
    z-index: 1;
}

.maintenance-info h4 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.maintenance-info p {
    font-size: 0.85rem;
    color: var(--text-muted);
    max-width: 500px;
}

.btn-sync {
    background: var(--bg-card);
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 0.9rem 1.8rem;
    border-radius: 14px;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.1);
    white-space: nowrap;
    position: relative;
    z-index: 1;
}

.btn-sync:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.25);
}

.btn-sync:active {
    transform: translateY(0);
}

.btn-sync.loading svg {
    animation: spin 1s linear infinite;
}

.btn-sync svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.data-table td { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }

.cell-primary { font-weight: 600; color: var(--text-main); }
.cell-secondary { font-size: 0.75rem; color: var(--text-muted); }

/* Empty State Modern Component */
.empty-state-hero {
    padding: 5rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    color: var(--text-muted);
}

.empty-state-hero .icon-hero {
    width: 64px;
    height: 64px;
    margin-bottom: 1.5rem;
    opacity: 0.2;
}

.empty-state-hero h4 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.15rem;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.empty-state-hero p { font-size: 0.9rem; max-width: 300px; }

/* Badges */
.badge { padding: 0.35rem 0.85rem; border-radius: 100px; font-size: 0.75rem; font-weight: 700; }
.badge.online { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.badge.offline { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.badge.badge-pending { background: rgba(99, 102, 241, 0.1); color: var(--primary); }

/* Form Controls (Settings) */
.settings-grid { display: grid; gap: 2rem; padding: 2rem; }
.settings-section h4 { margin-bottom: 1.5rem; font-family: 'Outfit', sans-serif; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }

.form-group { margin-bottom: 1.5rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--text-muted); }

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
}

.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1); }

/* Helpers */
.btn-text { color: var(--primary); text-decoration: none; font-weight: 600; font-size: 0.85rem; }
.btn-text:hover { text-decoration: underline; }

/* Modals - Ultra Glass Premium */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 500px;
    border-radius: 24px;
    border: 1px solid var(--border);
    box-shadow: 0 32px 64px -12px rgba(0,0,0,0.4);
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal.active .modal-content {
    transform: translateY(0);
}

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

.modal-header h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.05);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

[data-theme="dark"] .modal-close { background: rgba(255,255,255,0.05); color: white; }

.modal-close:hover {
    background: var(--danger);
    color: white;
}

.modal-body {
    padding: 2rem;
}

.modal-footer {
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    background: rgba(0,0,0,0.01);
}

/* API Key Display Area */
.api-key-display {
    background: rgba(99, 102, 241, 0.05);
    border: 2px dashed var(--primary);
    padding: 1.5rem;
    border-radius: 12px;
    margin-top: 1rem;
    text-align: center;
}

.api-key-code {
    display: block;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    word-break: break-all;
    margin: 1rem 0;
    user-select: all;
}

/* Icon & Status Refinement */
.icon-tiny {
    width: 14px !important;
    height: 14px !important;
    flex-shrink: 0;
}

.icon-small {
    width: 18px !important;
    height: 18px !important;
    flex-shrink: 0;
}

/* Status Pulse Animation */
.badge-pending { 
    background: rgba(99, 102, 241, 0.1); 
    color: var(--primary); 
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.badge-pending::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    animation: statusPulse 1.5s infinite;
}

@keyframes statusPulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.5); opacity: 0.4; }
    100% { transform: scale(1); opacity: 1; }
}

/* Modern Spinner */
.loader-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

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

/* Enhanced Progress Modal */
.progress-container {
    text-align: center;
    padding: 1rem 0;
}

.processing-icon {
    width: 100px;
    height: 100px;
    margin: 0 auto 2rem;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-bg {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--primary);
    opacity: 0.1;
    border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
    animation: morphing 8s infinite;
}

.icon-inner {
    position: relative;
    z-index: 1;
    color: var(--primary);
    filter: drop-shadow(0 0 15px rgba(99, 102, 241, 0.4));
    animation: pulse-icon 2s infinite ease-in-out;
}

.processing-status {
    margin-bottom: 2rem;
}

.status-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    font-family: 'Outfit', sans-serif;
}

.status-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Terminal Styling */
.log-viewer-container {
    background: #0d1117;
    border-radius: 12px;
    padding: 1.25rem;
    font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 0.8rem;
    color: #e6edf3;
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border);
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.3);
    white-space: pre-wrap;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

.log-viewer-container::-webkit-scrollbar { width: 6px; }
.log-viewer-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
.log-viewer-container::-webkit-scrollbar-thumb:hover { background: var(--primary); }

.log-entry { margin-bottom: 4px; border-left: 2px solid transparent; padding-left: 8px; }
.log-entry:hover { background: rgba(255,255,255,0.03); border-left-color: var(--primary); }

/* Animations */
@keyframes morphing {
    0% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
    25% { border-radius: 58% 42% 75% 25% / 76% 46% 54% 24%; }
    50% { border-radius: 50% 50% 33% 67% / 55% 27% 73% 45%; }
    75% { border-radius: 33% 67% 58% 42% / 63% 68% 32% 37%; }
    100% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
}

@keyframes pulse-icon {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}

/* Success State */
.success-check {
    color: var(--success);
    margin-bottom: 1rem;
    animation: scale-in 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes scale-in {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@media (max-width: 1200px) {
    .sidebar { width: 90px; padding: 2.5rem 1rem; }
    .nav-link span, .user-info, .brand h1, .sidebar-footer span { display: none; }
    .main-content { margin-left: 90px; }
}

/* Toggle Switch Styles */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
    background-color: var(--primary);
    border-color: var(--primary-light);
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--primary);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

.checkbox-group:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    cursor: pointer;
}
