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

:root {
    /* Updated color scheme from comprehensive_results */
    --primary-color: #1e3c72;
    --secondary-color: #2a5298;
    --success-color: #48bb78;
    --danger-color: #f56565;
    --warning-color: #ed8936;
    --info-color: #4299e1;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --border-color: #e2e8f0;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
}

body {
    font-family: 'Inter', 
                 'Noto Sans', 
                 'Noto Sans Arabic',      /* Arabic support */
                 'Noto Sans Devanagari',  /* Hindi support */
                 'Noto Sans TC',          /* Better Chinese support */
                 -apple-system, 
                 BlinkMacSystemFont, 
                 'Segoe UI', 
                 Roboto, 
                 'Arial Unicode MS',      /* Fallback for various scripts */
                 sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: #f5f7fa;
}

h1 { 
    font-size: 2.5rem; 
    font-weight: 700; 
    margin-bottom: 10px; 
}

h2 { 
    font-size: 1.875rem; 
    font-weight: 600; 
    margin-bottom: 20px; 
}

h3 { 
    font-size: 1.5rem; 
    font-weight: 600; 
    margin-bottom: 15px; 
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Modern header style matching comprehensive_results */
header, .header, .academic-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 2rem;
    text-align: center;
    margin-bottom: 2rem;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

header h1, .header h1, .academic-header h1 { 
    color: white; 
    margin-bottom: 1rem;
}

.subtitle { 
    font-size: 1.2rem; 
    opacity: 0.9; 
}

/* Card system */
.card, .form-section, .info-card {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.metric-card {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
    box-shadow: var(--shadow);
}

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

.metric-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

/* Form elements */
.form-group {
    margin-bottom: 1.5rem;
}

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

input[type="text"],
input[type="email"],
input[type="password"],
select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 60, 114, 0.1);
}

/* Button system */
button, .button, .btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    margin: 5px;
    transition: all 0.3s ease;
    text-align: center;
}

/* Primary buttons */
.button, .btn-primary, button:not([class]) {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
}

.button:hover, .btn-primary:hover, button:not([class]):hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(30, 60, 114, 0.4);
}

/* Colored buttons */
.btn-success { background: var(--success-color); color: white; }
.btn-danger { background: var(--danger-color); color: white; }
.btn-warning { background: var(--warning-color); color: white; }
.btn-info { background: var(--info-color); color: white; }
.btn-secondary { background: #6c757d; color: white; }

.btn-success:hover, .btn-danger:hover, .btn-warning:hover, 
.btn-info:hover, .btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Small buttons */
.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Download buttons */
.download-btn {
    background: var(--info-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    margin: 10px 5px 0 0;
    transition: all 0.2s;
}

.download-btn:hover {
    background: #3182ce;
}

/* Alert system */
.alert, .instructions {
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    font-weight: 500;
    border-left: 4px solid;
}

.alert-success, .instructions {
    background-color: #e3f2fd;
    color: #1976d2;
    border-left-color: #2196f3;
}

.alert-error {
    background-color: #fed7d7;
    color: #742a2a;
    border-left-color: var(--danger-color);
}

.alert-info {
    background-color: #bee3f8;
    color: #2a4e7c;
    border-left-color: var(--info-color);
}

/* Section headers */
.section-header {
    background: var(--bg-secondary);
    padding: 1rem 2rem;
    margin: 2rem 0 1rem 0;
    border-left: 4px solid var(--primary-color);
    font-size: 1.2rem;
    font-weight: 600;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

th, td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

tr:hover {
    background: var(--bg-secondary);
}

.kept, .status-kept { 
    background-color: rgba(72, 187, 120, 0.1); 
}

.laid-off, .status-layoff { 
    background-color: rgba(245, 101, 101, 0.1); 
}

/* Grid systems */
.metrics-summary, .stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.charts-grid {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    margin-bottom: 2rem;
}

/* Chart containers */
.chart-container {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    min-height: 400px;
}

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

.chart-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    text-align: center;
    color: var(--primary-color);
}

/* Rankings and drag-drop */
.draggable-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
    min-height: 400px;
}

.employee-item {
    background: white;
    margin: 0.5rem 0;
    padding: 1rem;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    cursor: move;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 1rem;
    user-select: none;
    touch-action: none;
}

.employee-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.rank-indicator {
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1rem;
    flex-shrink: 0;
}

.employee-info {
    flex: 1;
    color: var(--text-primary);
    font-size: 1rem;
}

.employee-name {
    font-weight: 600;
    display: inline;
}

.employee-desc {
    font-weight: normal;
    display: inline;
    margin-left: 0.5rem;
}

.employee-desc:before {
    content: "- ";
    color: var(--text-secondary);
}

/* Priority indicators */
.priority-indicator {
    text-align: center;
    margin: 1rem 0;
    font-size: 1rem;
    font-weight: 600;
}

.priority-high {
    color: var(--success-color);
}

.priority-low {
    color: var(--danger-color);
}

/* Flash messages */
.flash-messages {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    max-width: 400px;
}

.flash-message {
    background: white;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    border-left: 4px solid;
    animation: slideIn 0.3s ease;
    cursor: pointer;
}

.flash-message.success { border-left-color: var(--success-color); }
.flash-message.error { border-left-color: var(--danger-color); }
.flash-message.info { border-left-color: var(--info-color); }

/* Responsive design */
@media (max-width: 768px) {
    .container { padding: 15px; }
    .card, .form-section { padding: 1.5rem; }
    h1 { font-size: 2rem; }
    .chart-header { flex-direction: column; gap: 1rem; }
}

/* Loading states */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(30, 60, 114, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

/* Confirmation modal */
.confirm-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 9999;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    justify-content: center;
    align-items: center;
}
.confirm-overlay.visible {
    display: -webkit-flex;
    display: flex;
}
.confirm-box {
    background: #fff;
    border-radius: 12px;
    padding: 2rem 2.5rem;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    text-align: center;
    animation: confirmPop 0.2s ease;
}
@keyframes confirmPop {
    from { transform: scale(0.92); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}
.confirm-box h3 {
    margin: 0 0 0.5rem;
    font-size: 1.25rem;
    color: var(--text-primary, #2d3748);
}
.confirm-box p {
    margin: 0 0 1.5rem;
    color: #666;
    font-size: 0.95rem;
    line-height: 1.5;
}
.confirm-box .confirm-actions {
    display: -webkit-flex;
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}
.confirm-box .confirm-actions button {
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s;
}
.confirm-box .btn-confirm-yes {
    background: linear-gradient(135deg, #1e3c72, #2a5298);
    color: #fff;
}
.confirm-box .btn-confirm-yes:hover {
    background: linear-gradient(135deg, #16305e, #1e3c72);
}
.confirm-box .btn-confirm-cancel {
    background: #e2e8f0;
    color: #4a5568;
}
.confirm-box .btn-confirm-cancel:hover {
    background: #cbd5e0;
}

/* Flash message progress bar */
.flash-message {
    position: relative;
    overflow: hidden;
}
.flash-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(0,0,0,0.15);
    animation: flashCountdown linear forwards;
}
@keyframes flashCountdown {
    from { width: 100%; }
    to   { width: 0%; }
}

/* Chart loading placeholder */
.chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: #999;
    gap: 0.75rem;
}
.chart-loading .loading {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

/* Additional ranking page styles */
.ranking-instructions {
    text-align: center;
    margin: 1rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.submit-btn {
    background: linear-gradient(135deg, var(--success-color) 0%, #20c997 100%);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: block;
    margin: 2rem auto 0;
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(40, 167, 69, 0.3);
}

.submit-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.advocate-section {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 8px;
    margin: 1rem 0;
    border-left: 4px solid var(--success-color);
}

/* Drag and drop visual states */
.sortable-ghost {
    opacity: 0.4;
    background: #f0f0f0 !important;
    border: 2px dashed var(--border-color) !important;
}

.sortable-chosen {
    background: #e3f2fd !important;
    border-color: var(--primary-color) !important;
    transform: scale(1.02);
}

.sortable-drag {
    background: white !important;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15) !important;
    transform: rotate(2deg);
    z-index: 1000;
}

/* Mobile-specific improvements for ranking interface */
@media (max-width: 768px) {
    .employee-item {
        margin: 0.25rem 0; /* Reduced from 0.5rem */
        padding: 0.75rem; /* Reduced from 1rem */
        font-size: 0.9rem; /* Slightly smaller text */
    }
    
    .rank-indicator {
        width: 30px; /* Reduced from 35px */
        height: 30px; /* Reduced from 35px */
        font-size: 0.9rem; /* Reduced from 1rem */
    }
    
    .employee-info {
        font-size: 0.9rem; /* Reduced from 1rem */
        line-height: 1.3; /* Tighter line spacing */
    }
    
    .employee-name {
        font-size: 0.95rem;
        font-weight: 600;
    }
    
    .employee-desc {
        font-size: 0.85rem;
        color: #666;
        margin-left: 0.3rem; /* Reduced from 0.5rem */
    }
    
    .draggable-list {
        min-height: auto; /* Remove fixed height on mobile */
        margin: 0.5rem 0; /* Reduced margins */
    }
    
    .priority-indicator {
        font-size: 0.9rem; /* Smaller text */
        margin: 0.5rem 0; /* Reduced margins */
    }
    
    .container {
        padding: 15px; /* Reduced padding */
    }
    
    .card, .form-section {
        padding: 1rem; /* Reduced from 2rem */
        margin-bottom: 1rem; /* Reduced margins */
    }
    
    .ranking-instructions {
        font-size: 1rem; /* Reduced from 1.1rem */
    }
}

/* Even smaller phones */
@media (max-width: 480px) {
    .employee-item {
        padding: 0.6rem;
        font-size: 0.85rem;
    }
    
    .rank-indicator {
        width: 28px;
        height: 28px;
        font-size: 0.85rem;
    }
    
    .employee-name {
        font-size: 0.9rem;
    }
    
    .employee-desc {
        font-size: 0.8rem;
    }
    
    .card, .form-section {
        padding: 0.75rem;
    }
}

/* Budget-based color classes */
.rank-indicator.budget-kept {
    background: #48bb78 !important; /* Green for kept */
}

.rank-indicator.budget-laid-off {
    background: #f56565 !important; /* Red for laid off */
}

/* Footer styles */
footer {
    margin-top: 3rem;
    padding: 2rem 0;
    border-top: 1px solid #e2e8f0;
    background: #f8f9fa;
}

footer a:hover {
    color: var(--primary-color) !important;
    text-decoration: underline !important;
}

/* Legal page styles */
.section {
    background: #f8f9fa;
    padding: 1.5rem;
    margin-bottom: 2rem;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.contact-info {
    background: #e3f2fd;
    padding: 1rem;
    border-radius: 4px;
    margin: 1rem 0;
}

.highlight {
    background: #fff3cd;
    padding: 0.5rem;
    border-radius: 4px;
    border-left: 3px solid #ffc107;
    margin: 1rem 0;
}

/* ===================== RTL Language Support ===================== */
[lang="ar"] {
    direction: rtl;
    text-align: right;
}

[lang="ar"] .container {
    direction: rtl;
}

[lang="ar"] .form-group label {
    text-align: right;
}

[lang="ar"] .employee-item {
    direction: rtl;
}

[lang="ar"] .employee-desc:before {
    content: " -";  /* Move dash to the right side */
}

[lang="ar"] .flash-messages {
    left: 20px;  /* Move flash messages to left side */
    right: auto;
}

/* RTL-specific button alignments */
[lang="ar"] .chart-header {
    direction: rtl;
}

[lang="ar"] table {
    direction: rtl;
}

[lang="ar"] th, [lang="ar"] td {
    text-align: right;
}

/* ===================== Heatmap (Table 2) ===================== */
.heatmap-container table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.heatmap-container th,
.heatmap-container td { border: 1px solid #ddd; padding: 8px 12px; text-align: center; font-size: 0.95rem; }

/* Headers & left columns */
.heatmap-container .category-header { background-color: #87a9ca; color: #495057; font-weight: 600; }
.heatmap-container .dimension-header { background-color: #e9ecef; color: #495057; font-weight: 600; }
.heatmap-container .employees-cell { color: #495057; font-weight: 500; }

/* Horizontal dividers */
.heatmap-container tr.attribute-divider td { border-bottom: 2px solid #e9ecef !important; }
.heatmap-container tr.dimension-group-end td,
.heatmap-container tr.dimension-group-end th { border-bottom: 3px solid #1e3c72 !important; }
/* Thick white divider at the end of each category */
.heatmap-container tr.category-separator td,
.heatmap-container tr.category-separator th { border-bottom: 10px solid #fff !important; }

/* Draw the thick blue line at the bottom of row-spanned header cells too */
.dimension-header.end-of-dimension,
.category-header.end-of-dimension {
  border-bottom: 3px solid #1e3c72 !important;
}

/* Make the thick blue line appear under row-spanned header cells too */
.heatmap-container .dimension-header.end-of-dimension,
.heatmap-container .category-header.end-of-dimension {
  border-bottom: 3px solid #1e3c72 !important;
}

/* Also apply the thick blue rule to category break rows */
.heatmap-container tr.category-separator td,
.heatmap-container tr.category-separator th {
  border-bottom: 3px solid #1e3c72 !important;
}

/* Thick left border only on the actual leftmost table edge */
.heatmap-container table {
  border-left: 3px solid #1e3c72 !important;
}

/* Thick right border on the last column (header + body) */
.heatmap-container thead th:last-child,
.heatmap-container tbody td:last-child {
  border-right: 3px solid #1e3c72 !important;
}

/* Color bins for numeric cells */
.heatmap-container .very-negative     { background-color: #8b0000; color: #fff; } /* < -2.0 (much worse) */
.heatmap-container .strong-negative   { background-color: #dc3545; color: #fff; } /* -2.0 to -1.2 */
.heatmap-container .moderate-negative { background-color: #fd7f7f; color: #000; } /* -1.2 to -0.7 */
.heatmap-container .weak-negative     { background-color: #ffcccb; color: #000; } /* -0.7 to -0.2 */
.heatmap-container .neutral           { background-color: #ffffff; color: #000; } /* -0.2 to +0.2 */
.heatmap-container .weak-positive     { background-color: #d4edda; color: #000; } /* +0.2 to +0.7 */
.heatmap-container .moderate-positive { background-color: #90ee90; color: #000; } /* +0.7 to +1.2 */
.heatmap-container .strong-positive   { background-color: #28a745; color: #fff; } /* +1.2 to +2.0 */
.heatmap-container .very-positive     { background-color: #155724; color: #fff; } /* > +2.0 (much better) */

/* Focus ring for keyboard access */
.heatmap-container tbody td:focus { outline: 2px solid #1e3c72; outline-offset: -2px; }

/* Section container aesthetics */
.heatmap-container { background: #fff; padding: 2rem; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.08); }

/* Blue divider across the whole row at category breaks (matches dimension breaks) */
.heatmap-container tr.category-separator td,
.heatmap-container tr.category-separator th {
  border-bottom: 3px solid #1e3c72 !important;
}

/* Blue divider specifically for category header cells at category breaks */
.heatmap-container .category-header.category-break {
  border-bottom: 3px solid #1e3c72 !important;
}

/* Legend rows: keep color sample and text on the same line */
.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;  /* keep on one line */
}

.legend-row .legend-text { display: inline-block; }

/* ===== Tab Navigation ===== */
.results-tabs {
    display: flex;
    align-items: center;
    gap: 0;
    margin: 1.5rem auto 0 auto;
    border-bottom: 2px solid #e2e8f0;
    max-width: 1200px;
    padding: 0 0.5rem;
}

.results-tab {
    padding: 0.75rem 1.5rem;
    border: none;
    background: transparent;
    font-size: 1rem;
    font-weight: 600;
    color: #718096;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s, background-color 0.2s;
    font-family: inherit;
    border-radius: 8px 8px 0 0;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.results-tab:hover {
    color: #1e3c72;
    background-color: rgba(30, 60, 114, 0.05);
}

.results-tab.active {
    color: #1e3c72;
    border-bottom-color: #1e3c72;
    background-color: rgba(30, 60, 114, 0.08);
    font-weight: 700;
}

.presentation-mode-btn {
    margin-left: auto;
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 0.5rem;
    font-family: inherit;
    white-space: nowrap;
    text-decoration: none !important;
    /* inline-flex + align-items keeps <a> and <button> visually identical;
       baseline-based alignment differs between the two element types and
       causes a 1–2px vertical offset even with matching padding/line-height. */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.5;
    box-sizing: border-box;
    vertical-align: middle;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.presentation-mode-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(30, 60, 114, 0.3);
    color: white;
    text-decoration: none !important;
}

.presentation-mode-btn:visited,
.presentation-mode-btn:active,
.presentation-mode-btn:focus {
    color: white;
    text-decoration: none !important;
}

.download-tab-btn {
    padding: 0.5rem 1rem;
    background: #48bb78;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 0.5rem;
    margin-left: 0.5rem;
    font-family: inherit;
    white-space: nowrap;
    /* Match .presentation-mode-btn — inline-flex avoids the <a> vs <button>
       baseline-rendering discrepancy that causes a tiny vertical mis-alignment. */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.5;
    box-sizing: border-box;
    vertical-align: middle;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.download-tab-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(72, 187, 120, 0.3);
}

/* ===== Page-Based Presentation Mode ===== */

/* Fixed header bar — top of screen on dark background */
.pres-page-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 2rem;
    z-index: 100;
    background: #000;
}

.pres-counter {
    font-size: 1rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
}

.pres-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.pres-close-btn:hover {
    opacity: 1;
}

/* Navigation arrows — on black side strips */
.pres-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 2rem;
    cursor: pointer;
    padding: 1rem 0.75rem;
    border-radius: 8px;
    transition: color 0.2s;
    z-index: 100;
    -webkit-appearance: none;
    appearance: none;
}

.pres-nav:hover {
    color: white;
}

.pres-nav-prev { left: 0.25rem; }
.pres-nav-next { right: 0.25rem; }

.pres-nav:disabled {
    opacity: 0.2;
    cursor: default;
}

.pres-nav:disabled:hover {
    color: rgba(255, 255, 255, 0.7);
    opacity: 0.2;
}

.pres-hint {
    position: fixed;
    bottom: 0.25rem;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.75rem;
    z-index: 100;
}

/* Slide base styles — these are reinforced by .pres-page .pres-slide below
   with !important for cross-browser consistency (overrides in-template styles) */
.pres-slide {
    background: white;
    border-radius: 8px;
    padding: 1.5rem 2rem;
    margin: 2.5rem 3rem 1.5rem;
    width: calc(100vw - 6rem);
    max-width: calc(100vw - 6rem);
    height: calc(100vh - 4rem);
    min-height: calc(100vh - 4rem);
    max-height: calc(100vh - 4rem);
    overflow: visible;
    box-sizing: border-box;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
}

/* Hide elements not needed in presentation mode */
.pres-hidden {
    display: none !important;
}

.pres-page .download-btn,
.pres-page .download-all-btn,
.pres-page .download-tab-btn,
.pres-page .chart-header button {
    display: none !important;
}

/* In presentation mode, disable grid layout so slides are individually controlled */
.pres-page .charts-grid {
    display: block;
}

/* In presentation mode, tab panels don't need container styling */
.pres-page .tab-panel {
    padding: 0;
    margin: 0;
    background: transparent;
}

/* ---- Cross-browser overrides for chart/table containers in presentation ---- */
/* These must override both the external .chart-container rules AND the
   in-template <style> rules, which set max-width:1200px and min-height:400px.
   NOTE: Do NOT use !important on display — JS toggles display:none/flex
   to show/hide slides. Only use !important on sizing props. */
.pres-page .pres-slide {
    max-width: calc(100vw - 6rem) !important;
    width: calc(100vw - 6rem) !important;
    height: calc(100vh - 4rem) !important;
    min-height: calc(100vh - 4rem) !important;
    max-height: calc(100vh - 4rem) !important;
    overflow: visible;
    margin: 2.5rem 3rem 1.5rem !important;
    padding: 1.5rem 2rem;
    box-sizing: border-box;
    flex-direction: column;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    border: none !important;
}

.pres-page .pres-slide canvas {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
}

/* Slide title and subtitle styling */
.pres-slide-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e3c72;
    margin-bottom: 0.25rem;
    text-align: left !important;
}

.pres-slide-title + .pres-slide-subtitle {
    margin-top: 0;
}

.pres-slide-subtitle {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e3c72;
    margin-bottom: 0.75rem;
    text-align: left !important;
}

/* RTL support for tabs and presentation */
[dir="rtl"] .results-tabs {
    direction: rtl;
}

[dir="rtl"] .presentation-mode-btn {
    margin-left: 0.5rem;
    margin-right: auto;
}

[dir="rtl"] .download-tab-btn {
    margin-left: 0;
    margin-right: 0.5rem;
}

[dir="rtl"] .pres-nav-prev {
    left: auto;
    right: 1.5rem;
}

[dir="rtl"] .pres-nav-next {
    right: auto;
    left: 1.5rem;
}

/* Responsive: tabs and presentation */
@media (max-width: 768px) {
    .results-tabs {
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    .results-tab {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
    .presentation-mode-btn,
    .download-tab-btn {
        font-size: 0.75rem;
        padding: 0.4rem 0.75rem;
    }
    .pres-nav {
        padding: 0.5rem 0.75rem;
        font-size: 1.5rem;
    }
    .pres-nav-prev { left: 0.15rem; }
    .pres-nav-next { right: 0.15rem; }
    .pres-slide {
        margin: 2.5rem 2rem 1.5rem;
        width: calc(100vw - 4rem);
        max-width: calc(100vw - 4rem);
        padding: 1rem 1.25rem;
    }
}

/* ==========================================================================
   Admin / Educator shared navbar  (A1/A2)
   ========================================================================== */
.admin-nav {
    background: #1e3c72;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    height: 58px;
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
}
.admin-nav--admin { background: #7b1d1d; }

.admin-nav__brand {
    color: #fff;
    font-weight: 700;
    font-size: .95rem;
    text-decoration: none;
    margin-right: 2rem;
    white-space: nowrap;
    letter-spacing: .2px;
}
.admin-nav__links {
    display: flex;
    gap: 1.25rem;
    flex: 1;
}
.admin-nav__links a {
    color: rgba(255,255,255,.8);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 500;
    transition: color .15s;
}
.admin-nav__links a:hover,
.admin-nav__links a.active { color: #fff; }

.admin-nav__user {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-left: auto;
}
.admin-nav__user-email {
    color: rgba(255,255,255,.7);
    font-size: .82rem;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.admin-nav__user a {
    color: rgba(255,255,255,.82);
    text-decoration: none;
    font-size: .82rem;
    padding: .28rem .4rem;
    transition: color .15s;
}
.admin-nav__user a:hover { color: #fff; }

/* Page header row inside admin pages (title + primary action) */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    gap: 1rem;
}
.page-header h1 { margin: 0; font-size: 1.5rem; color: var(--text-primary); }

/* ==========================================================================
   Bulk-select + action bar  (C8)
   ========================================================================== */
.bulk-cb-all,
.bulk-cb { cursor: pointer; width: 15px; height: 15px; }

.bulk-bar {
    display: flex;
    align-items: center;
    gap: .75rem;
    background: #f0f4ff;
    border: 1px solid #bcd0f7;
    border-radius: 6px;
    padding: .55rem 1rem;
    margin-top: .6rem;
    font-size: .88rem;
}
.bulk-bar--danger { background: #fff0f0; border-color: #f5c6c6; }

.bulk-bar__count { color: #555; font-weight: 600; white-space: nowrap; }
.bulk-bar__actions { display: flex; gap: .5rem; margin-left: .25rem; }
.bulk-bar__clear {
    margin-left: auto;
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: .82rem;
    padding: .2rem .4rem;
}
.bulk-bar__clear:hover { color: #333; }

/* State badges */
.state-badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 700; text-transform: uppercase; vertical-align: middle; margin-left: .35rem; }
.state-badge--test { background: #efefef; color: #4f4f4f; border: 1px solid #d7d7d7; }
.row--test td { background: #fafafa; }

/* Test-class fieldset */
.test-class-fieldset { border: 1.5px solid #f1d9a3; background: #fffaf1; border-radius: 8px; padding: 1rem; margin-top: 1rem; }
.test-class-fieldset legend { font-weight: 700; font-size: .9rem; padding: 0 .4rem; color: #9a6700; }
.factor-hint { font-size: .82rem; color: var(--text-secondary); margin-top: .45rem; margin-bottom: 0; }
.checkbox-inline { display: flex; align-items: flex-start; gap: .5rem; font-size: .9rem; cursor: pointer; }
.checkbox-inline input[type="checkbox"] { margin-top: .2rem; width: 1.05rem; height: 1.05rem; accent-color: #9a6700; flex-shrink: 0; }
.checkbox-inline span { flex: 1; }

/* ==========================================================================
   DataTables custom styling
   ========================================================================== */
.dataTables_wrapper { margin-top: 1rem; }
.dataTables_filter { margin-bottom: 1rem; }
.dataTables_filter input { padding: 0.5rem; border: 1px solid #ccc; border-radius: 4px; margin-left: 0.5rem; }
.dataTables_length { white-space: nowrap; }
.dataTables_length select { padding: 0.25rem; border: 1px solid #ccc; border-radius: 4px; margin: 0 0.25rem; }
.dataTables_info { color: #666; font-size: 0.9rem; }
.dataTables_paginate .paginate_button { padding: 0.25rem 0.5rem; margin: 0 0.125rem; border: 1px solid #ddd; border-radius: 4px; background: white; color: #333; text-decoration: none; }
.dataTables_paginate .paginate_button:hover { background: #f8f9fa; border-color: #adb5bd; }
.dataTables_paginate .paginate_button.current { background: #1e3c72; color: white; border-color: #1e3c72; }
table.dataTable thead th.no-sort { cursor: default; }

/* Override DataTables default sort indicators — uniform ↕ inline next to text */
table.dataTable > thead th.sorting,
table.dataTable > thead th.sorting_asc,
table.dataTable > thead th.sorting_desc {
    background-image: none !important;
    padding-right: 8px !important;
    white-space: nowrap;
}
/* Hide the DataTables ::before arrow */
table.dataTable > thead th.sorting::before,
table.dataTable > thead th.sorting_asc::before,
table.dataTable > thead th.sorting_desc::before,
table.dataTable > thead th.sorting_disabled::before { content: '' !important; display: none !important; }
/* Sort indicators inline after header text */
table.dataTable > thead th.sorting::after {
    content: ' \21C5' !important;
    position: relative !important;
    display: inline !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    opacity: .35 !important;
    color: inherit !important;
    font-size: 0.85em !important;
    line-height: inherit !important;
}
table.dataTable > thead th.sorting_asc::after {
    content: ' \2191' !important;
    position: relative !important;
    display: inline !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    opacity: 1 !important;
    color: var(--primary-color) !important;
    font-size: 0.85em !important;
    line-height: inherit !important;
}
table.dataTable > thead th.sorting_desc::after {
    content: ' \2193' !important;
    position: relative !important;
    display: inline !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    opacity: 1 !important;
    color: var(--primary-color) !important;
    font-size: 0.85em !important;
    line-height: inherit !important;
}
table.dataTable > thead th.sorting_disabled::after { content: '' !important; display: none !important; }
table.dataTable > thead th.no-sort::before,
table.dataTable > thead th.no-sort::after { content: '' !important; display: none !important; }

/* Create/edit class form grid */
.cc-grid { display: grid; gap: .6rem 1rem; align-items: end; }
.cc-grid--3col { grid-template-columns: 165px 1fr 155px; }
.cc-grid--1col { grid-template-columns: 1fr; }
.cc-field label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-secondary); margin-bottom: .3rem; }
.cc-optional { font-weight: 400; font-size: .78rem; color: #999; }
.cc-required { color: #c0392b; }
.cc-code-wrap { display: flex; gap: .35rem; }
.cc-code-wrap input { flex: 1; font-family: monospace; letter-spacing: .08em; }
.btn-regen { height: 2.35rem; padding: 0 .65rem; border: 1.5px solid var(--border-color); border-radius: 6px; background: #f5f5f5; cursor: pointer; font-size: 1.1rem; line-height: 1; transition: background .15s; flex-shrink: 0; }
.btn-regen:hover { background: #e0e0e0; }
.btn-outline { background: transparent; border: 1.5px solid var(--border-color); color: var(--text-primary); }
.btn-outline:hover { background: #f0f0f0; }
/* ============================================================
   Backoffice Users page — unified table controls / bulk / password
   ============================================================ */
.table-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: .9rem;
    flex-wrap: wrap;
}
.table-search {
    width: 100%;
    max-width: 360px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
}
.table-search__hint {
    font-size: .8rem;
    color: #718096;
}
.table-page-size-label {
    display: flex; align-items: center; gap: .4rem;
    font-size: .85rem; color: #718096; white-space: nowrap;
}
.table-page-size {
    padding: .2rem .4rem; font-size: .85rem;
    border: 1px solid var(--border-color); border-radius: 4px; background: #fff;
}
.table-pagination {
    display: flex; align-items: center; gap: .75rem;
    margin: .6rem 0 .25rem; font-size: .85rem;
}
.pagination-info { color: #718096; }

th.sortable-col {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.4rem !important;
}
th.sortable-col:hover { color: var(--primary-color); background: #f0f0f0; }
th.sortable-col::after {
    content: "\21F5";
    position: absolute;
    right: .55rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: .8rem;
    opacity: .35;
}
th.sortable-col.is-sorted-asc::after  { content: "\2191"; opacity: 1; color: var(--primary-color); }
th.sortable-col.is-sorted-desc::after { content: "\2193"; opacity: 1; color: var(--primary-color); }

.table-empty-msg {
    margin-top: 1rem;
    padding: 1rem;
    color: #718096;
    background: #f6f6f6;
    border-radius: 8px;
    text-align: center;
    font-size: .9rem;
}

/* Bulk select */
.col-check {
    width: 2.5rem;
    padding-left: .75rem !important;
    padding-right: .5rem !important;
}
.col-check input[type="checkbox"] { cursor: pointer; accent-color: var(--primary-color); }

.bulk-bar {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem 1.1rem;
    background: var(--primary-color);
    color: #fff;
    border-radius: 10px;
    box-shadow: 0 4px 18px rgba(0,0,0,.22);
    z-index: 200;
    white-space: nowrap;
    flex-wrap: wrap;
}
.bulk-bar[hidden] { display: none; }
.bulk-bar__count { font-size: .875rem; font-weight: 600; }
.bulk-bar__actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.bulk-bar .btn-sm { font-size: .8rem; }
.bulk-bar .btn-secondary { border: 1px solid rgba(255,255,255,.4); color: #fff; background: transparent; }
.bulk-bar .btn-secondary:hover { background: rgba(255,255,255,.12); }
.bulk-bar .btn-danger { background: #c0392b; color: #fff; }
.bulk-bar .btn-danger:hover { background: #a93226; }
.bulk-bar .btn-warning { background: rgba(255,255,255,.15); color: #ffd; border: 1px solid rgba(255,255,255,.3); }
.bulk-bar .btn-warning:hover { background: rgba(255,255,255,.25); }
.bulk-deselect { background: none; border: none; color: rgba(255,255,255,.6); font-size: .8rem; cursor: pointer; padding: 0 .25rem; }
.bulk-deselect:hover { color: #fff; }

/* Role badges */
.role-badge { display: inline-block; padding: .15rem .5rem; border-radius: 4px; font-size: .75rem; font-weight: 700; text-transform: uppercase; }
.role-badge--admin    { background: #fee2e2; color: #991b1b; }
.role-badge--educator { background: #dbeafe; color: #1e40af; }

/* Password show/hide + generate control */
.pw-input-wrap { display: flex; gap: .4rem; align-items: stretch; }
.pw-input-wrap input { flex: 1 1 auto; min-width: 0; }
.pw-toggle, .pw-generate {
    flex: 0 0 auto; cursor: pointer; white-space: nowrap;
    border: 1px solid var(--border-color); background: #f4f5f7;
    border-radius: 6px; padding: 0 .7rem; font-size: .8rem; font-weight: 600;
    color: #555;
}
.pw-toggle:hover, .pw-generate:hover { background: #e9ebef; }
.pw-toggle.is-on { background: #e3e7ee; color: var(--primary-color); }
