:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #475569;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    
    --bg-body: #f1f5f9;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.12);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    padding: 20px 14px;
    min-height: 100vh;
}

.app-container {
    max-width: 1140px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Header Banner */
.app-header {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    color: white;
    padding: 24px 28px;
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
    flex-wrap: wrap;
    gap: 16px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-icon {
    width: 50px;
    height: 50px;
    background: rgba(37, 99, 235, 0.25);
    border: 1px solid rgba(59, 130, 246, 0.4);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #60a5fa;
    flex-shrink: 0;
}

.header-brand h1 {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.header-brand p {
    font-size: 13px;
    color: #94a3b8;
    margin-top: 2px;
}

#db-status-badge {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

/* Stats Cards Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}

.stat-card {
    background: var(--card-bg);
    padding: 18px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.stat-card.blue .stat-icon { background: #eff6ff; color: #2563eb; }
.stat-card.emerald .stat-icon { background: #ecfdf5; color: #10b981; }
.stat-card.purple .stat-icon { background: #f5f3ff; color: #8b5cf6; }
.stat-card.amber .stat-icon { background: #fffbeb; color: #f59e0b; }

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.stat-info h3 {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-primary);
    margin-top: 1px;
}

/* Action Bar */
.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.left-actions, .right-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all 0.2s ease;
    min-height: 42px;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary { background: #334155; color: white; }
.btn-secondary:hover { background: #1e293b; }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: var(--success-hover); }

.btn-outline {
    background: white;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn-outline:hover {
    background: #f8fafc;
    color: var(--text-primary);
}

.btn-danger-outline {
    background: white;
    color: var(--danger);
    border: 1px solid #fca5a5;
}
.btn-danger-outline:hover { background: #fef2f2; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Main Table Card */
.main-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 14px;
}

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

.card-title h2 {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
}

.badge-count {
    background: #e2e8f0;
    color: var(--text-secondary);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
}

.search-box {
    position: relative;
    width: 260px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    padding: 9px 12px 9px 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    outline: none;
    font-size: 14px;
    transition: border-color 0.2s;
}

.search-box input:focus { border-color: var(--primary); }

/* Table Styling */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    white-space: nowrap;
}

.custom-table th {
    background: #f8fafc;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
}

.custom-table td {
    padding: 13px 14px;
    font-size: 14px;
    color: var(--text-primary);
    border-bottom: 1px solid #f1f5f9;
}

.custom-table tbody tr:hover { background: #f8fafc; }

.btn-del {
    background: transparent;
    color: #ef4444;
    border: none;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background 0.2s;
    font-size: 14px;
}

.btn-del:hover { background: #fef2f2; }

/* Empty State */
.empty-state { text-align: center; padding: 40px 16px; }
.empty-icon { font-size: 44px; color: var(--text-muted); margin-bottom: 10px; }
.empty-state h3 { font-size: 16px; color: var(--text-primary); margin-bottom: 4px; }
.empty-state p { font-size: 13px; color: var(--text-secondary); }

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 999; opacity: 0; visibility: hidden;
    padding: 16px;
    transition: all 0.25s ease;
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal-box {
    background: white; width: 100%; max-width: 480px;
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    overflow: hidden; transform: scale(0.95); transition: transform 0.25s ease;
}

.modal-overlay.active .modal-box { transform: scale(1); }

.modal-header {
    padding: 16px 20px; background: #f8fafc;
    border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center;
}

.modal-header h3 { font-size: 16px; font-weight: 700; }
.close-btn { background: transparent; border: none; font-size: 22px; color: var(--text-muted); cursor: pointer; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.req { color: var(--danger); }
.input-icon-wrapper { position: relative; }
.input-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 14px; }
.input-icon-wrapper input {
    width: 100%; padding: 10px 12px 10px 36px;
    border-radius: var(--radius-sm); border: 1px solid var(--border-color);
    outline: none; font-size: 14px; transition: border-color 0.2s;
}
.input-icon-wrapper input:focus { border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.modal-footer {
    padding: 14px 20px; background: #f8fafc;
    border-top: 1px solid var(--border-color);
    display: flex; justify-content: flex-end; gap: 10px;
}

/* Upload Drop Zone */
.drop-zone {
    border: 2px dashed #cbd5e1; border-radius: var(--radius-md);
    padding: 24px 16px; text-align: center; cursor: pointer;
    background: #f8fafc; transition: all 0.2s;
}

.drop-zone:hover { border-color: var(--primary); background: #eff6ff; }
.drop-icon { font-size: 32px; color: var(--primary); margin-bottom: 6px; }
.drop-text { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.file-name-display { display: block; margin-top: 6px; font-size: 12px; color: var(--text-muted); font-weight: 500; }

.info-alert {
    background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af;
    padding: 12px; border-radius: var(--radius-sm); font-size: 13px;
    display: flex; gap: 10px; align-items: flex-start;
}

/* Toast Notifications */
#toast-container {
    position: fixed; bottom: 20px; right: 20px;
    display: flex; flex-direction: column; gap: 8px; z-index: 9999;
}

.toast {
    background: #1e293b; color: white; padding: 12px 18px;
    border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
    font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 10px;
    animation: slideIn 0.3s ease;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===================================================
   RESPONSIVE DESIGN (MOBILE & TABLET OPTIMIZATION)
   =================================================== */

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

@media (max-width: 640px) {
    body {
        padding: 12px 10px;
    }

    .app-header {
        padding: 18px 16px;
        flex-direction: column;
        align-items: flex-start;
    }

    .header-brand h1 {
        font-size: 18px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 14px 12px;
        gap: 10px;
    }

    .stat-icon {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    .stat-info h3 {
        font-size: 16px;
    }

    .action-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .left-actions, .right-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .btn {
        width: 100%;
        font-size: 13px;
        padding: 10px 10px;
    }

    .card-header {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        width: 100%;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}
