/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f4f6fb;
    color: #1f2937;
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; color: #111827; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }

/* ===== SIDEBAR ===== */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 240px; background: #0f172a; color: #cbd5e1;
    display: flex; flex-direction: column;
    z-index: 10;
}
.brand {
    padding: 22px 20px;
    display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid #1e293b;
}
.brand-mark {
    width: 40px; height: 40px; border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: white; font-weight: 800; font-size: 15px;
    display: grid; place-items: center;
    flex-shrink: 0;
}
.brand-mark.lg { width: 56px; height: 56px; font-size: 20px; border-radius: 14px; }
.brand-text { display: flex; flex-direction: column; }
.brand-text strong { color: white; font-size: 14px; }
.brand-text span { font-size: 11px; color: #94a3b8; }

.nav { padding: 16px 12px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; border-radius: 8px;
    color: #cbd5e1; font-size: 13.5px; font-weight: 500;
    transition: all 0.15s;
}
.nav-link:hover { background: #1e293b; color: white; text-decoration: none; }
.nav-link.active { background: #2563eb; color: white; }
.nav-link .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
    padding: 14px 16px; border-top: 1px solid #1e293b;
    display: flex; align-items: center; gap: 10px;
}
.user-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: #334155; color: white;
    display: grid; place-items: center;
    font-weight: 700; font-size: 13px;
    flex-shrink: 0;
}
.user-info strong { display: block; color: white; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-info span { display: block; color: #94a3b8; font-size: 11px; text-transform: capitalize; }
.logout-btn {
    background: transparent; border: 1px solid #334155;
    color: #cbd5e1; padding: 6px 10px; border-radius: 6px;
    font-size: 12px; cursor: pointer;
}
.logout-btn:hover { background: #334155; color: white; text-decoration: none; }

/* ===== MAIN ===== */
.main { margin-left: 240px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    background: white; padding: 18px 32px;
    border-bottom: 1px solid #e5e7eb;
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; z-index: 5;
}
.page-title { font-size: 20px; margin: 0; font-weight: 700; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.content { padding: 24px 32px; flex: 1; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px;
    font-size: 13.5px; font-weight: 600;
    border: 1px solid transparent; cursor: pointer;
    transition: all 0.15s; text-decoration: none;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; color: white; }
.btn-outline { background: white; color: #374151; border-color: #d1d5db; }
.btn-outline:hover { background: #f9fafb; color: #111827; }
.btn-danger { background: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; color: white; }
.btn-success { background: #059669; color: white; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ===== CARDS ===== */
.card {
    background: white; border-radius: 12px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    overflow: hidden;
    margin-bottom: 20px;
}
.card-header {
    padding: 16px 20px; border-bottom: 1px solid #f3f4f6;
    display: flex; justify-content: space-between; align-items: center;
}
.card-header h2 { margin: 0; }
.card-body { padding: 20px; }
.link { font-size: 13px; font-weight: 600; color: #2563eb; }
.link-mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-weight: 600; }

/* ===== STATS GRID ===== */
.stats-grid {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 16px; margin-bottom: 24px;
}
.stat-card {
    background: white; padding: 20px;
    border-radius: 12px; border: 1px solid #e5e7eb;
    display: flex; flex-direction: column; gap: 4px;
}
.stat-label { font-size: 12px; color: #6b7280; font-weight: 500; text-transform: uppercase; letter-spacing: 0.3px; }
.stat-value { font-size: 22px; font-weight: 700; color: #111827; line-height: 1.2; }
.stat-meta { font-size: 12px; color: #9ca3af; }
.stat-card.highlight { background: linear-gradient(135deg, #eff6ff, #f5f3ff); border-color: #bfdbfe; }
.stat-card.highlight .stat-value { color: #1d4ed8; }
.stat-card.danger { background: #fef2f2; border-color: #fecaca; }
.stat-card.danger .stat-value { color: #b91c1c; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ===== TABLES ===== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table thead th {
    text-align: left; padding: 12px 20px;
    background: #f9fafb; color: #6b7280;
    font-weight: 600; font-size: 12px;
    text-transform: uppercase; letter-spacing: 0.3px;
    border-bottom: 1px solid #e5e7eb;
}
.table tbody td { padding: 14px 20px; border-bottom: 1px solid #f3f4f6; }
.table tbody tr:hover { background: #f9fafb; }
.table tbody tr:last-child td { border-bottom: none; }
.table .right { text-align: right; }
.table .green { color: #059669; font-weight: 600; }
.table .empty { text-align: center; color: #9ca3af; padding: 30px 20px; }

/* ===== ALERTS ===== */
.alert {
    padding: 12px 16px; border-radius: 8px;
    margin-bottom: 16px; font-size: 13.5px;
    border: 1px solid transparent;
}
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert-danger, .alert-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

/* ===== BADGES ===== */
.badge {
    display: inline-block; padding: 3px 10px;
    border-radius: 999px; font-size: 11.5px;
    font-weight: 600; letter-spacing: 0.2px;
}
.bg-secondary { background: #e5e7eb; color: #4b5563; }
.bg-info { background: #dbeafe; color: #1e40af; }
.bg-warning { background: #fef3c7; color: #92400e; }
.bg-success { background: #d1fae5; color: #065f46; }
.bg-danger { background: #fee2e2; color: #991b1b; }
.bg-dark { background: #1f2937; color: white; }

/* ===== LOGIN ===== */
.login-wrap {
    min-height: 100vh;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
    padding: 20px;
}
.login-card {
    background: white; padding: 40px 36px;
    border-radius: 16px; width: 100%; max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand .brand-mark { margin: 0 auto 14px; }
.login-brand h1 { font-size: 22px; margin: 0 0 4px; }
.login-brand p { color: #6b7280; font-size: 13px; margin: 0; }
.login-form label { display: block; margin-bottom: 16px; }
.login-form label span { display: block; font-size: 12.5px; color: #374151; font-weight: 600; margin-bottom: 6px; }
.login-form input[type="text"],
.login-form input[type="password"],
.login-form input[type="email"] {
    width: 100%; padding: 10px 12px;
    border: 1px solid #d1d5db; border-radius: 8px;
    font-size: 14px; transition: border 0.15s;
}
.login-form input:focus {
    outline: none; border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.login-form .check { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }
.login-form .check span { margin: 0; font-weight: 400; }
.login-form .check input { width: auto; }
.login-footer { color: #94a3b8; font-size: 12px; margin-top: 20px; }

/* ===== FORMS ===== */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-row.three { grid-template-columns: 1fr 1fr 1fr; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12.5px; color: #374151; font-weight: 600; margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 9px 12px;
    border: 1px solid #d1d5db; border-radius: 8px;
    font-size: 13.5px; font-family: inherit;
    transition: border 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-group textarea { resize: vertical; min-height: 70px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .main { margin-left: 0; }
    .stats-grid { grid-template-columns: 1fr; }
    .topbar { padding: 14px 16px; }
    .content { padding: 16px; }
    .form-row, .form-row.three { grid-template-columns: 1fr; }
}

/* ===== HELPERS ===== */
.red { color: #dc2626; font-weight: 600; }
.blue { color: #2563eb; font-weight: 600; }
.muted { color: #9ca3af; }
.text-sm { font-size: 12.5px; }
.mt-2 { margin-top: 12px; }
.mt-4 { margin-top: 24px; }

/* ===== NAV SECTIONS ===== */
.nav-section {
    padding: 16px 14px 6px;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #64748b;
    font-weight: 700;
}
.sidebar { overflow-y: auto; }
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

/* ========================================================== */
/* ===== EXCEL-STYLE TABLE ===== */
/* ========================================================== */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    font-family: "Segoe UI", Calibri, Arial, sans-serif;
    border: 1px solid #d1d5db;
    background: white;
}
.table thead th {
    background: #f3f4f6;
    color: #111827;
    font-weight: 700;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-bottom: 2px solid #9ca3af;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 1;
}
.table tbody td {
    padding: 7px 12px;
    border: 1px solid #e5e7eb;
    color: #1f2937;
    vertical-align: middle;
}
.table tbody tr:nth-child(even) {
    background: #f9fafb;
}
.table tbody tr:hover {
    background: #fef9c3;
    transition: background 0.1s;
}
.table tbody tr.selected {
    background: #dbeafe;
}
.table .right { text-align: right; }
.table .center { text-align: center; }
.table .green { color: #047857; font-weight: 600; }
.table .red { color: #b91c1c; font-weight: 600; }
.table .empty {
    text-align: center;
    color: #9ca3af;
    padding: 40px 20px;
    font-style: italic;
    background: #fafafa;
}
.table tbody tr:last-child td { border-bottom: 1px solid #d1d5db; }
.table-wrap {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    background: white;
}

/* Excel column borders (thicker on left edge) */
.table thead th:first-child,
.table tbody td:first-child {
    border-left: 2px solid #9ca3af;
}
.table thead th:last-child,
.table tbody td:last-child {
    border-right: 2px solid #9ca3af;
}

/* ========================================================== */
/* ===== CLICKABLE STAT CARDS ===== */
/* ========================================================== */
.stat-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
}
.stat-card-link:hover {
    text-decoration: none;
    color: inherit;
}
.stat-card {
    position: relative;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
    cursor: pointer;
}
.stat-card-link:hover .stat-card,
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.15);
    border-color: #93c5fd;
}
.stat-card::after {
    content: "→";
    position: absolute;
    top: 12px;
    right: 14px;
    font-size: 16px;
    color: #9ca3af;
    opacity: 0;
    transition: opacity 0.15s, transform 0.15s;
}
.stat-card:hover::after {
    opacity: 1;
    transform: translateX(3px);
    color: #2563eb;
}

/* ========================================================== */
/* ===== SORTABLE TABLE HEADERS ===== */
/* ========================================================== */
.table thead th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 22px;
}
.table thead th.sortable::after {
    content: "⇅";
    position: absolute;
    right: 8px;
    color: #9ca3af;
    font-size: 11px;
}
.table thead th.sortable.asc::after { content: "▲"; color: #2563eb; }
.table thead th.sortable.desc::after { content: "▼"; color: #2563eb; }

/* ========================================================== */
/* ===== PRINT-FRIENDLY ===== */
/* ========================================================== */
@media print {
    .sidebar, .topbar, .btn, .stat-card::after { display: none !important; }
    .main { margin-left: 0 !important; }
    .table { font-size: 10px; }
    .table thead th { background: #f0f0f0; -webkit-print-color-adjust: exact; }
}
