:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --text: #2d3436;
    --text-secondary: #636e72;
    --primary: #0984e3;
    --primary-hover: #0770c2;
    --danger: #d63031;
    --warning: #fdcb6e;
    --success: #00b894;
    --border: #dfe6e9;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

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

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

header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 32px;
    box-shadow: var(--shadow);
}

header h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
}

nav#tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.tab {
    padding: 8px 16px;
    border: none;
    background: none;
    font-size: 14px;
    cursor: pointer;
    border-radius: var(--radius);
    color: var(--text-secondary);
    transition: all 0.2s;
}

.tab:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.tab.active { background: var(--primary); color: white; }
.tab:disabled { opacity: 0.4; cursor: not-allowed; }

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* Upload */
.upload-zone {
    border: 3px dashed var(--border);
    border-radius: 12px;
    padding: 80px 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: var(--surface);
    max-width: 600px;
    margin: 60px auto;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: #f0f7ff;
}

.upload-icon { font-size: 48px; margin-bottom: 16px; }
.upload-zone p { font-size: 18px; color: var(--text); margin-bottom: 8px; }
.upload-sub { font-size: 14px; color: var(--text-secondary) !important; }

.upload-status {
    max-width: 600px;
    margin: 16px auto;
    padding: 12px 16px;
    border-radius: var(--radius);
    display: none;
}

.upload-status.success { display: block; background: #d4edda; color: #155724; }
.upload-status.error { display: block; background: #f8d7da; color: #721c24; }
.upload-status.loading { display: block; background: #cce5ff; color: #004085; }

/* Mapping dialog */
.mapping-dialog {
    max-width: 600px;
    margin: 24px auto;
    background: var(--surface);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.mapping-dialog h3 { margin-bottom: 8px; }
.mapping-dialog p { color: var(--text-secondary); margin-bottom: 16px; font-size: 14px; }

.mapping-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.mapping-row label {
    width: 140px;
    font-weight: 600;
    font-size: 14px;
}

.mapping-row select {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    margin-top: 8px;
    transition: background 0.2s;
}

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

/* Cards */
.cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.card .card-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
}

.card .card-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.card.danger .card-value { color: var(--danger); }
.card.warning .card-value { color: #e17055; }
.card.success .card-value { color: var(--success); }

/* Charts */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.chart-container {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.chart-container.wide {
    grid-column: 1 / -1;
}

.chart-container h3 {
    font-size: 15px;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

/* Backlog table */
.backlog-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.backlog-table th, .backlog-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.backlog-table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.backlog-table th:hover { color: var(--text); }

.backlog-table tr.agent-row { cursor: pointer; }
.backlog-table tr.agent-row:hover { background: #f8f9ff; }

.health-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    color: white;
}

.health-red { background: var(--danger); }
.health-yellow { background: #e17055; }
.health-green { background: var(--success); }

.ticket-details {
    display: none;
    background: var(--bg);
}

.ticket-details td { padding: 8px 16px 8px 40px; font-size: 13px; }
.ticket-details.open { display: table-row; }

/* Rebalancing */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-item {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-item .stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

.stat-item .stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.suggestions-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-top: 20px;
}

.suggestions-table th, .suggestions-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.suggestions-table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-secondary);
}

.risk-low { color: var(--success); font-weight: 600; }
.risk-medium { color: #e17055; font-weight: 600; }

.arrow { color: var(--primary); font-weight: bold; }

.export-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    margin-top: 12px;
    transition: all 0.2s;
}

.export-btn:hover { border-color: var(--primary); color: var(--primary); }

/* Priority badges */
.priority-urgent { color: var(--danger); font-weight: 700; }
.priority-high { color: #e17055; font-weight: 600; }
.priority-normal { color: var(--text-secondary); }
.priority-low { color: var(--success); }

/* Staffing */
.staffing-form {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.staffing-form h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--text);
}

.staffing-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.staffing-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.staffing-form label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.staffing-form input,
.staffing-form select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text);
    background: white;
    transition: border-color 0.2s;
}

.staffing-form input:focus,
.staffing-form select:focus {
    outline: none;
    border-color: var(--primary);
}

.staffing-form-actions {
    display: flex;
    gap: 8px;
}

.btn-cancel {
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 10px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel:hover {
    border-color: var(--text-secondary);
    color: var(--text);
}

.staffing-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.staffing-table th,
.staffing-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.staffing-table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-secondary);
}

.staffing-table tr:hover {
    background: #f8f9ff;
}

.btn-edit,
.btn-delete {
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.2s;
}

.btn-edit {
    background: #dfe6fd;
    color: var(--primary);
}

.btn-delete {
    background: #fde2e2;
    color: var(--danger);
    margin-left: 4px;
}

.btn-edit:hover,
.btn-delete:hover {
    opacity: 0.8;
}

.pole-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    color: white;
}

.pole-immat { background: #0984e3; }
.pole-modif { background: #6c5ce7; }
.pole-disso { background: #00b894; }
.pole-ae { background: #e17055; }
.pole-marque { background: #e84393; }

.statut-actif { color: #00b894; font-weight: 600; }
.statut-absent { color: #e17055; font-weight: 600; }
.statut-parti { color: #b2bec3; font-weight: 600; }

.presence-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    color: white;
}

.presence-p { background: #00b894; }
.presence-tt { background: #0984e3; }
.presence-cp { background: #e17055; }
.presence-x { background: #b2bec3; }

.pole-separator {
    background: var(--bg) !important;
}

.pole-separator td {
    padding: 8px 16px !important;
    font-size: 13px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border) !important;
}

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

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.modal-header h3 { font-size: 16px; }

.modal-close {
    border: none;
    background: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 4px;
}

.modal-close:hover { color: var(--text); }

#horsDelaisBody { padding: 16px 24px; }

#horsDelaisBody table {
    width: 100%;
    border-collapse: collapse;
}

#horsDelaisBody th, #horsDelaisBody td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

#horsDelaisBody th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-secondary);
}

.card.clickable { cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.card.clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.12); }

/* Alert badges */
.alert-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    color: white;
    letter-spacing: 0.5px;
}

.alert-critique { background: #d63031; }
.alert-urgent { background: #e17055; }
.alert-a-risque { background: #fdcb6e; color: #2d3436; }

/* Filter buttons */
.filter-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
}

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

/* Alert modal body */
#alertModalBody { padding: 16px 24px; }

#alertModalBody table {
    width: 100%;
    border-collapse: collapse;
}

#alertModalBody th, #alertModalBody td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

#alertModalBody th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-secondary);
}

/* Upload cards (3-column layout) */
.upload-card {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.upload-card-header {
    background: var(--bg);
    padding: 12px 16px;
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    text-align: center;
}

.upload-zone-card {
    padding: 32px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
}

.upload-zone-card:hover, .upload-zone-card.dragover {
    background: #f0f7ff;
}

.upload-zone-card .upload-icon { font-size: 36px; margin-bottom: 8px; }
.upload-zone-card p { font-size: 14px; color: var(--text); margin-bottom: 4px; }
.upload-zone-card .upload-sub { font-size: 12px; color: var(--text-secondary) !important; }

/* Assignment upload zones */
.upload-zone-small {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: var(--bg);
}

.upload-zone-small:hover, .upload-zone-small.dragover {
    border-color: var(--primary);
    background: #f0f7ff;
}

.upload-zone-small p {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0;
}

.upload-status-small {
    margin-top: 8px;
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    display: none;
}

.upload-status-small.success { display: block; background: #d4edda; color: #155724; }
.upload-status-small.error { display: block; background: #f8d7da; color: #721c24; }
.upload-status-small.loading { display: block; background: #cce5ff; color: #004085; }

/* Skills matrix */
.skills-table th.skill-header {
    font-size: 11px;
    text-align: center;
    padding: 8px 6px;
    writing-mode: vertical-lr;
    transform: rotate(180deg);
    white-space: nowrap;
    min-width: 36px;
}

.skills-table td.skill-cell {
    text-align: center;
    padding: 6px;
}

.skills-table td.skill-cell input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* Rules inputs */
.rule-input {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    color: var(--text);
    background: white;
    transition: border-color 0.2s;
}

.rule-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Refresh button */
.btn-refresh {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 13px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.btn-refresh:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Print */
@media print {
    header { display: none; }
    .btn-refresh, .btn-primary, .btn-cancel, .export-btn, .filter-btn { display: none !important; }
    .tab-content { display: none !important; }
    .tab-content.active { display: block !important; }
    main { max-width: 100%; padding: 0; }
    body { background: white; }
    .card { box-shadow: none; border: 1px solid #ddd; }
    .chart-container { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; }
    .backlog-table { box-shadow: none; }
    .modal-overlay { display: none !important; }
    canvas { max-height: 300px; }
}

/* Responsive */
@media (max-width: 768px) {
    header { flex-direction: column; gap: 12px; }
    .charts-grid { grid-template-columns: 1fr; }
    .cards { grid-template-columns: repeat(2, 1fr); }
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}
