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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
    --info: #0891b2;
    --bg: #f1f5f9;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #2563eb;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* ===== Login Page ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.login-container { width: 100%; max-width: 400px; padding: 1rem; }

.login-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 1.8rem;
    color: var(--primary);
}

.login-header p {
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* ===== Form ===== */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group { flex: 1; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--bg); }

.btn-secondary { background: #64748b; color: #fff; }
.btn-secondary:hover { background: #475569; }

.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }

.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

/* ===== Sidebar badge ===== */
.nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    margin-left: 4px;
    vertical-align: middle;
}

/* ===== Pending certificates section ===== */
.pending-section {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}
.pending-title {
    font-size: 1rem;
    font-weight: 600;
    color: #92400e;
    margin: 0 0 0.75rem 0;
}
.btn-full { width: 100%; }

/* ===== Activate certificate modal ===== */
.activate-hint {
    font-size: 0.85rem;
    color: #64748b;
    margin-bottom: 1rem;
}
.cert-info-box {
    background: #f8fafc;
    padding: 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}
.access-option {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}
.access-option-body {
    margin-top: 0.5rem;
    padding-left: 1.5rem;
}
.access-option-body select {
    width: 100%;
}
.radio-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    cursor: pointer;
}
.access-hint {
    font-size: 0.78rem;
    color: #64748b;
    margin: 0.25rem 0 0;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}
.modal-actions-between {
    justify-content: space-between;
}

/* ===== User access modal ===== */
.via-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}
.via-group {
    background: #dbeafe;
    color: #1d4ed8;
}
.via-individual {
    background: #fef3c7;
    color: #92400e;
}

/* ===== Certificate permissions modal ===== */
.perm-section {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.perm-section-header {
    margin-bottom: 0.75rem;
}
.perm-section-title {
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.perm-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
    gap: 0.5rem;
}
.perm-row:last-of-type {
    border-bottom: none;
}
.perm-row-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}
.perm-meta {
    font-size: 0.78rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.perm-empty {
    font-size: 0.85rem;
    color: #94a3b8;
    margin: 0 0 0.5rem;
}
.perm-add-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}
.perm-add-row select {
    flex: 1;
}

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    color: #fff;
    font-size: 1.25rem;
}

.sidebar-nav {
    list-style: none;
    padding: 0.75rem 0;
    flex: 1;
}

.sidebar-nav li a {
    display: block;
    padding: 0.75rem 1.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-nav li a:hover {
    background: rgba(255,255,255,0.05);
    color: #fff;
}

.sidebar-nav li a.active {
    background: rgba(37, 99, 235, 0.15);
    color: #fff;
    border-left-color: var(--sidebar-active);
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    font-size: 0.85rem;
    color: #94a3b8;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.page-header h2 { font-size: 1.5rem; }

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

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-left: 4px solid var(--primary);
}

.stat-card.warning { border-left-color: var(--warning); }

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* ===== Table ===== */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.table thead {
    background: #f8fafc;
}

.table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-light);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }

/* ===== Badge ===== */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #e0f2fe; color: #0369a1; }

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden { display: none; }

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

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

.modal-header h3 { font-size: 1.1rem; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
}

#modalBody { padding: 1.5rem; }

/* ===== Filters ===== */
.filters {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.filters select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
}

/* ===== Weekday Checks ===== */
.weekday-checks {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.weekday-checks label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.85rem;
    cursor: pointer;
}

/* ===== Utilities ===== */
.hidden { display: none !important; }
.loading { text-align: center; padding: 2rem; color: var(--text-light); }
.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; padding: 0.5rem; background: #fee2e2; border-radius: var(--radius); }

code {
    background: #f1f5f9;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .app-layout { flex-direction: column; }
    .sidebar { width: 100%; }
    .sidebar-nav { display: flex; overflow-x: auto; padding: 0; }
    .sidebar-nav li a { padding: 0.75rem 1rem; white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
    .sidebar-nav li a.active { border-left: none; border-bottom-color: var(--sidebar-active); }
    .sidebar-footer { justify-content: center; gap: 1rem; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }
}
