/* === Base === */
:root {
    --primary: #8b1a1a;
    --primary-light: #b22222;
    --danger: #c0392b;
    --warning: #e67e22;
    --success: #27ae60;
    --bg: #f4f6f8;
    --card: #ffffff;
    --border: #dce1e6;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --radius: 6px;
}

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

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

/* === Nav === */
.navbar {
    background: var(--primary);
    color: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-links a { color: rgba(255,255,255,0.9); text-decoration: none; }
.nav-links a:hover { color: white; }
.nav-links .btn { color: white; background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.3); }
.nav-links .btn:hover { background: rgba(255,255,255,0.25); }
.nav-user { color: rgba(255,255,255,0.7); font-size: 0.85rem; }

/* === Container === */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    font-size: 0.85rem;
    text-decoration: none;
    transition: all 0.15s;
}
.btn:hover { background: #eef1f4; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-light); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.9; }
.btn-warning { background: var(--warning); color: white; border-color: var(--warning); }
.btn-warning:hover { opacity: 0.9; }

/* === Flash Messages === */
.flash-messages { margin-bottom: 1rem; }
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}
.flash-error { background: #fde8e8; color: var(--danger); border: 1px solid #f5c6cb; }
.flash-success { background: #e8f5e9; color: var(--success); border: 1px solid #c3e6cb; }

/* === Auth === */
.auth-container {
    max-width: 400px;
    margin: 4rem auto;
    background: var(--card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.auth-container h2 { margin-bottom: 1.5rem; text-align: center; }
.auth-form .form-group { margin-bottom: 1rem; }
.auth-form .btn { width: 100%; }
.auth-link { text-align: center; margin-top: 1rem; color: var(--text-muted); font-size: 0.85rem; }
.auth-link a { color: var(--primary-light); }

/* === Dashboard === */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.chart-table {
    width: 100%;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    border-collapse: collapse;
}
.chart-table th {
    background: #f0f3f6;
    padding: 0.65rem 0.75rem;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}
.chart-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.chart-table tr:last-child td { border-bottom: none; }
.chart-table tr:hover td { background: #f8f9fa; }

.status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.status-draft { background: #eef1f4; color: var(--text-muted); }
.status-submitted { background: #fef3cd; color: #856404; }
.status-reviewed { background: #d4edda; color: #155724; }

.dashboard-section { margin-bottom: 1.5rem; }

.section-title {
    font-size: 0.95rem;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius) var(--radius) 0 0;
    margin: 0;
    border: 1px solid var(--border);
    border-bottom: none;
}
.section-draft { background: #eef1f4; color: var(--text-muted); }
.section-submitted { background: #fff3cd; color: #856404; }
.section-reviewed { background: #d4edda; color: #155724; }

.dashboard-section .chart-table { border-radius: 0 0 var(--radius) var(--radius); }

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
    background: var(--card);
    border-radius: var(--radius);
}

/* === Chart Form === */
.chart-container {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    overflow: hidden;
}

.chart-header {
    background: var(--primary);
    color: white;
    padding: 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chart-header h2 { font-size: 1.1rem; }
.chart-actions { display: flex; align-items: center; gap: 0.5rem; }
.chart-actions .status-badge { font-size: 0.7rem; }

.save-indicator { font-size: 0.8rem; color: rgba(255,255,255,0.7); }
.save-indicator.saving { color: #f1c40f; }
.save-indicator.saved { color: #2ecc71; }
.save-indicator.error { color: #e74c3c; }

/* --- Tabs --- */
.tab-nav {
    display: flex;
    background: #f0f3f6;
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
}

.tab-btn {
    padding: 0.65rem 1rem;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); background: rgba(0,0,0,0.03); }
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: white;
}

.tab-panel { display: none; padding: 1.25rem; }
.tab-panel.active { display: block; }
.tab-panel.active + .tab-panel.active { border-top: 2px solid var(--border); }
.tab-panel h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}
.tab-panel h4 {
    font-size: 0.9rem;
    margin: 1rem 0 0.5rem;
    color: var(--text-muted);
}

/* --- Forms --- */
.form-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.form-group {
    flex: 1;
    min-width: 140px;
    margin-bottom: 0.5rem;
}
.form-group.flex-2 { flex: 2; }

.form-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.88rem;
    font-family: inherit;
    color: var(--text);
    background: white;
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 2px rgba(178,34,34,0.15);
}

.form-group textarea { resize: vertical; }
.form-group input[readonly],
.form-group textarea[readonly],
.form-group select[disabled] {
    background: #f0f1f3;
    cursor: default;
}

.times-row .form-group { min-width: 110px; }

.info-note {
    background: #fdf2f2;
    border: 1px solid #e8a9a9;
    border-radius: var(--radius);
    padding: 0.6rem 0.8rem;
    font-size: 0.85rem;
    color: var(--primary);
    margin-bottom: 1rem;
}

/* --- Exam Grid --- */
.exam-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}
@media (max-width: 768px) {
    .exam-grid { grid-template-columns: 1fr; }
}

/* --- Vitals / Treatments --- */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}
.section-header h3 { border: none; padding: 0; margin: 0; }

.vital-set, .treatment-entry {
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}

.vital-set-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

/* --- Validation --- */
.validation-score {
    font-size: 1.3rem;
    text-align: center;
    padding: 1rem;
    margin-bottom: 1rem;
    background: #f8f9fa;
    border-radius: var(--radius);
}

.validation-section {
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}
.validation-section h4 { margin-bottom: 0.4rem; font-size: 0.9rem; border: none; padding: 0; }
.validation-section ul { margin-left: 1.5rem; }
.validation-section li { margin-bottom: 0.25rem; font-size: 0.88rem; }

.validation-errors { background: #fde8e8; border: 1px solid #f5c6cb; }
.validation-errors h4 { color: var(--danger); }
.validation-warnings { background: #fff3cd; border: 1px solid #ffeaa7; }
.validation-warnings h4 { color: #856404; }
.validation-suggestions { background: #fdf2f2; border: 1px solid #e8a9a9; }
.validation-suggestions h4 { color: var(--primary); }
.validation-success { background: #d4edda; border: 1px solid #c3e6cb; color: #155724; text-align: center; }

/* --- Review Feedback (student view) --- */
.review-feedback {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: var(--radius);
}
.review-feedback h3 {
    color: #155724;
    border-bottom-color: #c3e6cb;
}
.review-score-display {
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
}
.review-comments {
    white-space: pre-wrap;
    font-size: 0.92rem;
    line-height: 1.6;
}

/* --- Review Panel (instructor form) --- */
.review-panel {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--border);
}

/* --- Admin --- */
.role-select {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
    background: white;
}

.btn-active { background: #d4edda; color: #155724; border-color: #c3e6cb; }
.btn-active:hover { background: #c3e6cb; }
.btn-inactive { background: #fde8e8; color: var(--danger); border-color: #f5c6cb; }
.btn-inactive:hover { background: #f5c6cb; }

.text-muted { color: var(--text-muted); }

/* --- Settings --- */
.settings-group {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.settings-group h3 {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
    color: var(--primary);
}
.settings-group .form-group { max-width: 500px; margin-bottom: 0.75rem; }
.settings-group textarea { font-family: monospace; font-size: 0.85rem; }

.setting-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.setting-locked { opacity: 0.6; }
.lock-badge {
    font-size: 0.7rem;
    background: #fde8e8;
    color: var(--danger);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-weight: 600;
}
.lock-toggle {
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    text-transform: none;
    font-weight: normal;
    color: var(--text-muted);
}
.lock-toggle input { width: auto; margin: 0; }

/* --- Stats Cards --- */
.stats-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.stat-card {
    flex: 1;
    min-width: 120px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}
.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* --- Progress Bars --- */
.progress-list { padding: 0.75rem; }
.progress-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
.progress-row:last-child { border-bottom: none; }
.progress-student { min-width: 180px; font-size: 0.88rem; }
.progress-bar-container {
    flex: 1;
    height: 20px;
    background: #eef1f4;
    border-radius: 10px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    border-radius: 10px;
    transition: width 0.3s;
    min-width: 2px;
}
.progress-low { background: var(--danger); }
.progress-mid { background: var(--warning); }
.progress-complete { background: var(--success); }
.progress-count {
    min-width: 50px;
    text-align: right;
    font-weight: 600;
    font-size: 0.88rem;
}

/* --- Profile --- */
.profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
@media (max-width: 768px) {
    .profile-grid { grid-template-columns: 1fr; }
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 440px;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 1.25rem; }
.modal-body .form-group { margin-bottom: 0.75rem; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    background: #f8f9fa;
}

/* === Responsive === */
@media (max-width: 600px) {
    .form-row { flex-direction: column; }
    .form-group { min-width: 100%; }
    .tab-nav { font-size: 0.8rem; }
    .chart-header { flex-direction: column; gap: 0.5rem; }
}
