/* ==================== RESET & BASE ==================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f0f1a;
    --bg-card: #1a1a2e;
    --bg-sidebar: #12121f;
    --text: #e0e0e0;
    --text-muted: #888;
    --primary: #6c63ff;
    --primary-hover: #5a52d5;
    --success: #2ecc71;
    --danger: #e74c3c;
    --warning: #f39c12;
    --border: #2a2a3e;
    --radius: 8px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }

/* ==================== PROGRESS BAR ==================== */
.global-progress {
    position: fixed; top: 0; left: 0; width: 0%; height: 3px;
    background: linear-gradient(90deg, var(--primary), #a78bfa, var(--primary));
    background-size: 200% 100%;
    z-index: 100000; pointer-events: none;
    transition: width 0.25s ease-out;
    box-shadow: 0 0 8px rgba(108, 99, 255, 0.5);
}
.global-progress.done {
    width: 100% !important; opacity: 0;
    transition: width 0.3s ease-out, opacity 0.4s ease 0.3s;
}
.global-progress.active {
    animation: shimmer 1.5s linear infinite;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==================== LOGIN SCREEN ==================== */
.login-screen {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
}
.login-card {
    background: var(--bg-card); border-radius: 16px; padding: 3rem 2.5rem;
    width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    border: 1px solid var(--border);
}
.login-header { text-align: center; margin-bottom: 2rem; }
.login-header i { font-size: 3rem; color: var(--primary); margin-bottom: 0.5rem; }
.login-header h1 { font-size: 1.8rem; color: #fff; }
.login-header p { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.25rem; }

/* ==================== FORM ELEMENTS ==================== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.35rem; font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 0.7rem 0.9rem;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text);
    font-size: 0.95rem; font-family: inherit;
    transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary);
}

.btn-primary {
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.75rem 1.5rem; background: var(--primary);
    color: #fff; border: none; border-radius: var(--radius);
    font-size: 0.95rem; font-weight: 600; cursor: pointer;
    transition: background 0.2s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-sm {
    padding: 0.35rem 0.7rem; font-size: 0.8rem; border-radius: 6px;
    border: 1px solid var(--border); background: var(--bg-card);
    color: var(--text); cursor: pointer; transition: all 0.2s;
}
.btn-sm:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm.danger { color: var(--danger); }
.btn-sm.danger:hover { border-color: var(--danger); background: rgba(231,76,60,0.1); }

.error-msg { color: var(--danger); font-size: 0.85rem; margin-bottom: 0.75rem; padding: 0.5rem; background: rgba(231,76,60,0.1); border-radius: var(--radius); }

/* ==================== LAYOUT ==================== */
#app { display: flex; min-height: 100vh; }

#sidebar {
    width: 240px; background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 1.5rem; font-size: 1.3rem; font-weight: 700; color: #fff;
}
.sidebar-brand i { color: var(--primary); font-size: 1.5rem; }
.sidebar-brand span { letter-spacing: -0.5px; }

nav { flex: 1; padding: 0.5rem 0.75rem; }
.nav-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.7rem 0.9rem; border-radius: var(--radius);
    color: var(--text-muted); font-size: 0.9rem; font-weight: 500;
    transition: all 0.2s; margin-bottom: 2px;
}
.nav-item:hover { background: rgba(108,99,255,0.1); color: var(--text); }
.nav-item.active { background: rgba(108,99,255,0.2); color: var(--primary); }
.nav-item i { width: 20px; text-align: center; }

.sidebar-footer {
    padding: 1rem 1.25rem; border-top: 1px solid var(--border);
}
.admin-name { display: block; font-size: 0.85rem; color: var(--text); margin-bottom: 0.5rem; }
.logout-btn {
    display: flex; align-items: center; gap: 0.5rem;
    color: var(--text-muted); font-size: 0.85rem; transition: color 0.2s;
}
.logout-btn:hover { color: var(--danger); }

#mainContent {
    flex: 1; margin-left: 240px; padding: 2rem;
    max-width: calc(100vw - 240px);
}

/* ==================== PAGES ==================== */
.page { display: none; }
.page.active { display: block; }

h2 { font-size: 1.5rem; margin-bottom: 1.5rem; color: #fff; display: flex; align-items: center; gap: 0.6rem; }
h2 i { color: var(--primary); }
h3 { font-size: 1.1rem; margin-bottom: 1rem; color: #ccc; }

/* ==================== KPI CARDS ==================== */
.kpi-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem; margin-bottom: 1.5rem;
}
.kpi-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem;
}
.kpi-card .kpi-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-card .kpi-value { font-size: 1.8rem; font-weight: 700; color: #fff; margin-top: 0.25rem; }
.kpi-card .kpi-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ==================== CARDS ==================== */
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.5rem;
}

/* ==================== CHART ==================== */
.chart-container {
    display: flex; align-items: end; gap: 0.5rem; height: 200px; padding-top: 1rem;
}
.chart-bar-wrapper {
    flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%;
}
.chart-bar {
    width: 100%; max-width: 50px; background: var(--primary);
    border-radius: 4px 4px 0 0; transition: height 0.5s ease;
    min-height: 2px;
}
.chart-label { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.35rem; text-align: center; }
.chart-value { font-size: 0.75rem; color: #fff; margin-bottom: 0.25rem; font-weight: 600; }

/* ==================== TOOLBAR ==================== */
.toolbar {
    display: flex; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.toolbar input, .toolbar select {
    padding: 0.55rem 0.75rem; background: var(--bg-card);
    border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); font-size: 0.85rem; font-family: inherit;
}
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--primary); }
.toolbar input { min-width: 250px; }

/* ==================== TABLE ==================== */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th {
    text-align: left; padding: 0.7rem 0.75rem;
    background: var(--bg-sidebar); color: var(--text-muted);
    font-weight: 600; font-size: 0.8rem; text-transform: uppercase;
    letter-spacing: 0.5px; border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
td {
    padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border);
    max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
tr:hover td { background: rgba(108,99,255,0.03); }

.status-badge {
    display: inline-block; padding: 0.15rem 0.5rem; border-radius: 12px;
    font-size: 0.75rem; font-weight: 600;
}
.status-active { background: rgba(46,204,113,0.15); color: var(--success); }
.status-nullified { background: rgba(243,156,18,0.15); color: var(--warning); }
.status-outdated { background: rgba(108,99,255,0.15); color: var(--primary); }
.status-deleted { background: rgba(231,76,60,0.15); color: var(--danger); }

/* ==================== PAGINATION ==================== */
.pagination {
    display: flex; justify-content: center; align-items: center;
    gap: 0.5rem; margin-top: 1rem;
}
.pagination button {
    padding: 0.4rem 0.8rem; background: var(--bg-card);
    border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); cursor: pointer; font-size: 0.85rem;
    transition: all 0.2s;
}
.pagination button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination span { font-size: 0.85rem; color: var(--text-muted); }

/* ==================== TABS ==================== */
.tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; }
.tab-btn {
    padding: 0.5rem 1rem; background: transparent;
    border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text-muted); cursor: pointer; font-size: 0.85rem;
    transition: all 0.2s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ==================== LOG VIEWER ==================== */
.log-viewer {
    background: #0a0a14; border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.8rem; line-height: 1.6; color: #a0a0b0;
    max-height: 70vh; overflow-y: auto; white-space: pre-wrap; word-break: break-all;
}

/* ==================== MODAL ==================== */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
.modal-content {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; width: 90%; max-width: 700px; max-height: 85vh;
    overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; }
.modal-close {
    background: none; border: none; color: var(--text-muted);
    font-size: 1.5rem; cursor: pointer; padding: 0; line-height: 1;
}
.modal-close:hover { color: var(--danger); }
#modalBody { padding: 1.5rem; }

/* ==================== TOAST ==================== */
.toast {
    position: fixed; bottom: 2rem; right: 2rem; z-index: 9999;
    padding: 0.75rem 1.25rem; border-radius: var(--radius);
    font-size: 0.9rem; font-weight: 500; color: #fff;
    transform: translateY(100px); opacity: 0;
    transition: transform 0.3s, opacity 0.3s;
    pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    #sidebar { width: 60px; }
    .sidebar-brand span, .nav-item span:not(.fa, i), .admin-name { display: none; }
    .nav-item { justify-content: center; padding: 0.7rem; }
    .nav-item i { margin: 0; }
    #mainContent { margin-left: 60px; max-width: calc(100vw - 60px); padding: 1rem; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .toolbar { flex-direction: column; }
    .toolbar input { min-width: auto; }
}
