/* Shared UI components for the whole "stages" module (prof + BDE)
   Goal: consistent pagination, tables and drawers across views. */

/* Masquer l'indicateur de calendrier natif pour tous les champs date avec date picker personnalisé */
input[type="date"].date-picker-input::-webkit-calendar-picker-indicator,
input[type="date"].drawer-date-input::-webkit-calendar-picker-indicator,
input.date-picker-input::-webkit-calendar-picker-indicator,
input.drawer-date-input::-webkit-calendar-picker-indicator {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
    visibility: hidden !important;
}

input[type="date"].date-picker-input::-moz-calendar-picker-indicator,
input[type="date"].drawer-date-input::-moz-calendar-picker-indicator,
input.date-picker-input::-moz-calendar-picker-indicator,
input.drawer-date-input::-moz-calendar-picker-indicator {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
    visibility: hidden !important;
}

:root {
    --stages-surface: rgba(2, 6, 23, 0.35);
    --stages-surface-strong: rgba(15, 23, 42, 0.55);
    --stages-border: rgba(148, 163, 184, 0.18);
    --stages-border-strong: rgba(148, 163, 184, 0.30);
    --stages-text: #e5e7eb;
    --stages-muted: #9ca3af;
    --stages-accent: #60a5fa;
    --stages-accent-2: #93c5fd;
    --stages-danger: #ef4444;
    --stages-warning: #f59e0b;
    --stages-success: #22c55e;
}

/* ---------- Badges (BDE dashboard override) ---------- */
/* dashboard_bde.php inclut dashboard_prof.css, qui force parfois un min-width trop grand sur .badge.
   On corrige uniquement dans le contexte BDE pour éviter d'impacter les vues prof. */
.stages-bde .badge {
    min-width: 0 !important;
    padding: 2px 6px !important;
    font-size: 10px !important;
    line-height: 1.1 !important;
    min-height: 18px !important;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.stages-bde .badge i {
    font-size: 11px !important;
    line-height: 1;
}

.stages-bde table .badge {
    min-width: 0 !important;
}

/* dashboard_bde.php utilise aussi des "stages-badge" (design system).
   On les compacte spécifiquement côté BDE. */
.stages-bde .stages-badge {
    padding: 3px 8px !important;
    font-size: 10px !important;
    border-radius: 8px !important;
    letter-spacing: 0.2px !important;
}

.stages-bde .stages-badge i {
    font-size: 11px !important;
}

/* ---------- Flash messages (global) ---------- */
.flash {
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 12px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(15, 23, 42, 0.5);
    color: var(--stages-text);
}

.flash.success {
    background: rgba(34, 197, 94, 0.16);
    border-color: rgba(34, 197, 94, 0.35);
    color: #bbf7d0;
}

.flash.warning {
    background: rgba(245, 158, 11, 0.16);
    border-color: rgba(245, 158, 11, 0.35);
    color: #fde68a;
}

.flash.error {
    background: rgba(239, 68, 68, 0.14);
    border-color: rgba(239, 68, 68, 0.35);
    color: #fecaca;
}

.flash .flash-subtitle {
    margin: 4px 0 0 0;
    font-size: 13px;
    opacity: 0.9;
    color: inherit;
}

/* ---------- Tabs (shared) ---------- */
.tabs-nav {
    display: flex;
    gap: 6px;
    margin-bottom: 18px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
    flex-wrap: wrap;
}

.tab-link {
    padding: 10px 14px;
    text-decoration: none;
    color: #cbd5e1;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px 10px 0 0;
    border: 1px solid transparent;
    border-bottom: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 23, 42, 0.25);
}

.tab-link:hover {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.22);
}

.tab-link.active {
    color: var(--stages-accent);
    background: rgba(59, 130, 246, 0.14);
    border-color: rgba(59, 130, 246, 0.25);
}

.tab-link i {
    font-size: 14px;
}

/* ---------- Pagination (global) ---------- */
.pagination {
    margin-top: 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid var(--stages-border);
    background: var(--stages-surface);
}

.pagination-link {
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: var(--stages-text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
    background: var(--stages-surface-strong);
    white-space: nowrap;
}

.pagination-link:hover {
    background: rgba(59, 130, 246, 0.12) !important;
    border-color: rgba(59, 130, 246, 0.35) !important;
}

.pagination-info {
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.14);
    background: rgba(15, 23, 42, 0.35);
    color: #cbd5e1;
    font-size: 12px;
    white-space: nowrap;
}

.pagination-per-page {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 0;
    justify-content: flex-end;
}

.pagination-per-page label {
    font-size: 12px;
    color: #cbd5e1;
    font-weight: 600;
    margin: 0;
}

.pagination-per-page select {
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: var(--stages-surface-strong);
    color: var(--stages-text);
    font-size: 13px;
    transition: all 0.2s ease;
}

.pagination-per-page select:hover {
    border-color: rgba(148, 163, 184, 0.4);
}

.pagination-per-page select:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.55);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

@media (max-width: 700px) {
    .pagination {
        justify-content: center;
    }

    .pagination-per-page {
        width: 100%;
        justify-content: center;
    }
}

/* ---------- Table headers (title + actions) ---------- */
.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.table-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 750;
    color: var(--stages-text);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.table-header .table-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.table-header .table-header-subtitle {
    width: 100%;
    margin: 6px 0 0 0;
    color: var(--stages-muted);
    font-size: 13px;
    line-height: 1.45;
}

/* In a card-table (flush tables), the header should be padded and separated */
.card.card-table .table-header {
    margin: 0;
    padding: 16px 16px 14px;
    border-bottom: 1px solid var(--stages-border);
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(37, 99, 235, 0.04));
}

/* Common "actions cell" helper used in some list tables */
.actions-cell {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Utility: compact "Actions" column that hugs content */
:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) :is(th.stages-col-actions, td.stages-col-actions) {
    width: var(--stages-actions-col-width, 88px);
    white-space: nowrap;
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) :is(th.stages-col-actions) {
    text-align: right;
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) :is(td.stages-col-actions) {
    padding-left: 10px;
    padding-right: 10px;
}

td.actions-cell.stages-col-actions {
    justify-content: flex-end;
}

/* Utility: compact "Statut" column (badges) */
:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) :is(th.stages-col-status, td.stages-col-status) {
    width: var(--stages-status-col-width, 140px);
    white-space: nowrap;
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) th.stages-col-status {
    text-align: center;
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) td.stages-col-status {
    text-align: center;
}

/* Utility: compact content-driven columns (e.g., Type, Classe) */
:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) :is(th.stages-col-compact, td.stages-col-compact) {
    width: 1%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Common fixed-width columns (used with table-layout: fixed) */
:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) :is(th.stages-col-chevron, td.stages-col-chevron) {
    width: 44px;
    white-space: nowrap;
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) :is(th.stages-col-type, td.stages-col-type) {
    width: var(--stages-type-col-width, 140px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) :is(th.stages-col-class, td.stages-col-class) {
    width: var(--stages-class-col-width, 120px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Tables (module-wide look) ---------- */
:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) {
    width: 100% !important;
    min-width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    table-layout: auto;
    display: table;
    border-collapse: separate !important;
    border-spacing: 0;
    background: rgba(15, 23, 42, 0.35);
    border: 1px solid var(--stages-border);
    border-radius: 12px;
    overflow: hidden;
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) thead th {
    background: rgba(2, 6, 23, 0.55);
    color: #cbd5e1;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    text-align: left;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) tbody td {
    padding: 12px 14px;
    color: var(--stages-text);
    border-bottom: 1px solid rgba(148, 163, 184, 0.10);
    vertical-align: top;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) a,
:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) code,
:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) pre {
    overflow-wrap: anywhere;
    word-break: break-word;
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) tbody tr:last-child td {
    border-bottom: none;
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) tbody tr:nth-child(even) {
    background: rgba(15, 23, 42, 0.20);
}

:is(.stages-table, .companies-table, .requests-table, .catchups-table, .classes-table, .pending-forms-table, .suivi-forms-table) tbody tr:hover {
    background: rgba(59, 130, 246, 0.10);
}

/* Opt-out utility if a specific table needs natural sizing */
.table-layout-auto {
    table-layout: auto !important;
}

/* Keep common "empty value" style consistent */
.empty-value {
    color: var(--stages-muted);
    font-size: 11px;
}

/* Utility: table container */
.table-container {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.stages-section {
    margin-top: 2rem;
}

.stages-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.section-title-meta {
    font-size: 14px;
    font-weight: 400;
    color: #94a3b8;
    margin-left: 0.5rem;
}

.stages-nowrap {
    white-space: nowrap;
}

.btn-xs {
    font-size: 11px;
    padding: 4px 8px;
}

.stages-actions-inline {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.text-center {
    text-align: center;
}

.card.card-table {
    padding: 0;
    overflow: hidden;
}

.card.card-table .table-wrapper {
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.card.card-table .table-wrapper table {
    min-width: 100%;
}

.card.card-table .card-table-body {
    padding: 16px;
}

.card.card-table .card-table-body .stages-empty {
    margin: 0;
}

.card.card-table :is(table.stages-table, table.companies-table, table.requests-table, table.catchups-table, table.classes-table, table.pending-forms-table, table.suivi-forms-table) {
    border: none;
    border-radius: 0;
    background: transparent;
}

.stages-empty {
    padding: 24px;
    text-align: center;
    color: var(--stages-muted);
    font-size: 13px;
}

/* Utility: clickable rows with CSS variables */
.stages-click-row {
    cursor: pointer;
    transition: background-color 0.2s ease;
    background: var(--stages-row-bg, rgba(15, 23, 42, 0.20));
    border-left: 5px solid var(--stages-row-border, transparent);
}

.stages-click-row:hover {
    background: var(--stages-row-hover, rgba(59, 130, 246, 0.10));
}

/* Badges driven by CSS variables (replace heavy inline styles) */
.stages-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    background: var(--stages-badge-bg, rgba(148, 163, 184, 0.12));
    color: var(--stages-badge-color, #cbd5e1);
    border: 1px solid var(--stages-badge-border, rgba(148, 163, 184, 0.25));
    box-shadow: 0 2px 6px var(--stages-badge-shadow, rgba(0, 0, 0, 0.15));
}

.stages-badge i {
    font-size: 13px;
}

/* ---------- Cards (legacy BDE/admin pages use .card) ---------- */
.card {
    background: rgba(15, 23, 42, 0.55);
    border-radius: 14px;
    border: 1px solid var(--stages-border);
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.45);
    margin-bottom: 20px;
}

.card:hover {
    border-color: rgba(148, 163, 184, 0.25);
}

.card h2,
.card h3,
.card h4 {
    color: var(--stages-text);
}

.card p {
    color: var(--stages-muted);
}

/* ---------- Drawers (unify overlay + panel) ---------- */
/* Generic drawer pattern already used by annexes */
.stages-drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: none;
    background: rgba(15, 23, 42, 0.80);
    backdrop-filter: blur(4px);
}

.stages-drawer-overlay.active {
    display: block;
}

.stages-drawer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 900px;
    background: linear-gradient(180deg, #1f2937 0%, #020617 100%);
    border-left: 1px solid var(--stages-border-strong);
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.7);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.stages-drawer-overlay.active .stages-drawer {
    transform: translateX(0);
}

.stages-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.30);
    background: rgba(15, 23, 42, 0.90);
}

.stages-drawer-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--stages-text);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.stages-drawer-title i {
    color: var(--stages-accent);
}

.stages-drawer-subtitle {
    margin: 4px 0 0 0;
    font-size: 12px;
    color: var(--stages-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stages-drawer-close,
.stages-drawer-header .btn.btn-secondary.btn-sm {
    background: none;
    border: none;
    color: var(--stages-muted);
    cursor: pointer;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
}

.stages-drawer-close:hover,
.stages-drawer-header .btn.btn-secondary.btn-sm:hover {
    background: rgba(148, 163, 184, 0.15);
    color: var(--stages-text);
}

.stages-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.stages-drawer-actions {
    padding: 14px 20px;
    border-top: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(2, 6, 23, 0.35);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Map existing drawer implementations to the generic look (no markup change required) */
/* Company drawer (prof) */
.company-drawer.active {
    pointer-events: auto;
}

.company-drawer-overlay {
    background: transparent !important;
}

/* overlay is the container background now */
.company-drawer {
    background: rgba(15, 23, 42, 0.80);
    backdrop-filter: blur(4px);
}

.company-drawer-content {
    background: linear-gradient(180deg, #1f2937 0%, #020617 100%);
    max-width: 900px;
}

/* Class drawers (BDE admin) */
.class-drawer {
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(15, 23, 42, 0.80);
    backdrop-filter: blur(4px);
    pointer-events: none;
    display: none;
}

.class-drawer.active {
    display: block;
    pointer-events: auto;
}

/* S'assurer que le contenu du tiroir peut recevoir les clics */
.class-drawer.active .class-drawer-content {
    pointer-events: auto !important;
}

.class-drawer.active .class-drawer-content * {
    pointer-events: auto !important;
}

.class-drawer .class-drawer-overlay {
    position: absolute;
    inset: 0;
    background: transparent !important;
    opacity: 1 !important;
    z-index: 1;
    pointer-events: auto;
}

/* S'assurer que le contenu du tiroir est au-dessus de l'overlay et intercepte les clics */
.class-drawer .class-drawer-content * {
    pointer-events: auto;
}

.class-drawer .class-drawer-content {
    pointer-events: auto !important;
}

.class-drawer .class-drawer-content {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 900px;
    height: 100%;
    background: linear-gradient(180deg, #1f2937 0%, #020617 100%) !important;
    border-left: 1px solid var(--stages-border-strong);
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 10;
    pointer-events: auto;
}

.class-drawer.active .class-drawer-content {
    transform: translateX(0);
}

.class-drawer .class-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.30);
    background: rgba(15, 23, 42, 0.90) !important;
    flex-shrink: 0;
}

.class-drawer .class-drawer-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--stages-text);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.class-drawer .class-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.class-drawer .class-drawer-body {
    position: relative;
    z-index: 1;
}

.class-drawer .class-drawer-body form {
    position: relative;
    z-index: 2;
    pointer-events: auto;
}

.class-drawer .class-drawer-body button[type="submit"],
.class-drawer .class-drawer-body .btn {
    position: relative;
    z-index: 10;
    pointer-events: auto !important;
    cursor: pointer !important;
}

.class-drawer .class-drawer-body input,
.class-drawer .class-drawer-body select,
.class-drawer .class-drawer-body textarea {
    position: relative;
    z-index: 5;
    pointer-events: auto !important;
    cursor: pointer !important;
}

.class-drawer .class-drawer-close {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.class-drawer .class-drawer-close:hover {
    background: rgba(148, 163, 184, 0.15);
}

/* Catchup drawer (prof) */
#catchup-detail-drawer.catchup-drawer {
    background: rgba(15, 23, 42, 0.80);
    backdrop-filter: blur(4px);
}

#catchup-detail-drawer.active .catchup-drawer-content {
    background: linear-gradient(180deg, #1f2937 0%, #020617 100%);
    max-width: 900px;
}

/* Request detail drawer (prof) */
#request-detail-drawer.request-detail-drawer {
    background: rgba(15, 23, 42, 0.80);
    backdrop-filter: blur(4px);
    z-index: 1100;
}

#request-detail-drawer.active .request-detail-drawer-content {
    background: linear-gradient(180deg, #1f2937 0%, #020617 100%);
}

/* Company form drawer (BDE) */
.company-form-drawer-overlay {
    background: rgba(15, 23, 42, 0.80) !important;
    backdrop-filter: blur(4px);
}

.company-form-drawer {
    background: transparent;
}

.company-form-drawer-content {
    background: linear-gradient(180deg, #1f2937 0%, #020617 100%);
    max-width: 900px;
}