/*
 * Bibliotheque de composants : panneaux, boutons, pastilles d'etat, tableaux,
 * messages, listes de definitions et etats vides.
 */

/* Panneaux ---------------------------------------------------------------- */

.panel {
    padding: var(--rh-space-5);
    border: 1px solid var(--rh-line);
    border-radius: var(--rh-radius-lg);
    background: var(--rh-surface);
    box-shadow: var(--rh-shadow-sm);
}

.panel > :last-child {
    margin-bottom: 0;
}

/* Panneau dont le contenu est un tableau pleine largeur : la gouttiere est
   portee par l'en-tete, pas par le panneau, pour que le tableau touche les
   bords. */
.panel-flush {
    padding: 0;
    overflow: hidden;
}

.panel-flush > .section-head {
    margin-bottom: 0;
    padding: var(--rh-space-5) var(--rh-space-5) var(--rh-space-4);
}

.panel-flush > .table-scroll {
    border-top: 1px solid var(--rh-line);
}

.panel-accent {
    border-color: var(--rh-primary-line);
    background:
        linear-gradient(180deg, var(--rh-primary-soft) 0%, transparent 130px),
        var(--rh-surface);
}

/* Carte cliquable du tableau de bord. */

.tile {
    display: flex;
    flex-direction: column;
    gap: var(--rh-space-3);
    padding: var(--rh-space-5);
    border: 1px solid var(--rh-line);
    border-radius: var(--rh-radius-lg);
    background: var(--rh-surface);
    box-shadow: var(--rh-shadow-sm);
    color: var(--rh-ink);
    text-decoration: none;
    transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

a.tile:hover {
    border-color: var(--rh-primary-line);
    box-shadow: var(--rh-shadow-md);
    color: var(--rh-ink);
    transform: translateY(-2px);
}

.tile-icon {
    display: grid;
    width: 40px;
    height: 40px;
    border-radius: var(--rh-radius-md);
    background: var(--rh-primary-soft);
    color: var(--rh-primary);
    place-items: center;
}

.tile h2,
.tile h3 {
    margin-bottom: 0;
    font-size: 1rem;
}

.tile p {
    margin: 0;
    color: var(--rh-muted);
    font-size: 0.86rem;
}

.tile-more {
    margin-top: auto;
    color: var(--rh-primary);
    font-size: 0.82rem;
    font-weight: 650;
}

/* Boutons ---------------------------------------------------------------- */

.button,
button:not(.unstyled) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--rh-space-2);
    min-height: 38px;
    padding: 0 var(--rh-space-4);
    border: 1px solid var(--rh-line-strong);
    border-radius: var(--rh-radius-sm);
    background: var(--rh-surface);
    color: var(--rh-ink);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 620;
    line-height: 1.2;
    text-decoration: none;
    transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
    white-space: nowrap;
}

.button:hover,
button:not(.unstyled):hover {
    border-color: var(--rh-line-strong);
    background: var(--rh-surface-strong);
    color: var(--rh-ink);
    text-decoration: none;
}

.button-primary,
button.button-primary {
    border-color: transparent;
    background: var(--rh-primary);
    color: var(--rh-primary-ink);
    box-shadow: var(--rh-shadow-sm);
}

.button-primary:hover,
button.button-primary:hover {
    border-color: transparent;
    background: var(--rh-primary-hover);
    color: var(--rh-primary-ink);
}

.button-soft,
button.button-soft {
    border-color: var(--rh-primary-line);
    background: var(--rh-primary-soft);
    color: var(--rh-primary);
}

.button-soft:hover,
button.button-soft:hover {
    background: color-mix(in srgb, var(--rh-primary-soft) 70%, var(--rh-primary) 12%);
    color: var(--rh-primary);
}

.button-danger,
button.button-danger {
    border-color: var(--rh-danger-line);
    background: var(--rh-surface);
    color: var(--rh-danger);
}

.button-danger:hover,
button.button-danger:hover {
    background: var(--rh-danger-soft);
    color: var(--rh-danger);
}

.button-ghost,
button.button-ghost {
    border-color: transparent;
    background: transparent;
    color: var(--rh-ink-soft);
}

.button-ghost:hover,
button.button-ghost:hover {
    background: var(--rh-surface-strong);
    color: var(--rh-ink);
}

.button-sm,
button.button-sm {
    min-height: 30px;
    padding: 0 var(--rh-space-3);
    font-size: 0.8rem;
}

.button-icon,
button.button-icon {
    width: 34px;
    min-height: 34px;
    padding: 0;
    border-radius: var(--rh-radius-sm);
}

.button:focus-visible,
button:focus-visible {
    box-shadow: var(--rh-ring);
    outline-offset: 1px;
}

.button[aria-disabled="true"],
button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    box-shadow: none;
}

/* Barre d'actions. Les formulaires en ligne (un bouton POST + jeton CSRF) ne
   doivent pas casser l'alignement : ils restent des boites en ligne. */

.actions {
    display: flex;
    align-items: center;
    gap: var(--rh-space-2);
    flex-wrap: wrap;
}

.actions > form {
    display: inline-flex;
}

/* Relance des contrôles : plage de dates en ligne (du … au …) + bouton. */
.audit-run-form {
    display: inline-flex;
    align-items: center;
    gap: var(--rh-space-2);
    flex-wrap: wrap;
}

.audit-run-date {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: var(--rh-text-muted, inherit);
}

.actions-end {
    justify-content: flex-end;
}

.inline-form {
    display: inline-flex;
    align-items: center;
    gap: var(--rh-space-2);
}

/* Pastilles d'etat ------------------------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--rh-space-1);
    min-height: 22px;
    padding: 0 var(--rh-space-2);
    border: 1px solid var(--rh-line);
    border-radius: var(--rh-radius-pill);
    background: var(--rh-surface-muted);
    color: var(--rh-ink-soft);
    font-size: 0.75rem;
    font-weight: 650;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.badge::before {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentcolor;
    content: "";
    opacity: 0.85;
}

.badge-plain::before {
    display: none;
}

.badge-neutral {
    border-color: var(--rh-line);
    background: var(--rh-surface-muted);
    color: var(--rh-muted);
}

.badge-info {
    border-color: var(--rh-info-line);
    background: var(--rh-info-soft);
    color: var(--rh-info);
}

.badge-accent {
    border-color: var(--rh-accent-line);
    background: var(--rh-accent-soft);
    color: var(--rh-accent);
}

.badge-success {
    border-color: var(--rh-success-line);
    background: var(--rh-success-soft);
    color: var(--rh-success);
}

.badge-warning {
    border-color: var(--rh-warning-line);
    background: var(--rh-warning-soft);
    color: var(--rh-warning);
}

.badge-danger {
    border-color: var(--rh-danger-line);
    background: var(--rh-danger-soft);
    color: var(--rh-danger);
}

.meta-line {
    display: flex;
    align-items: center;
    gap: var(--rh-space-3);
    flex-wrap: wrap;
    color: var(--rh-muted);
    font-size: 0.85rem;
}

.meta-line > * + *::before {
    margin-right: var(--rh-space-3);
    color: var(--rh-line-strong);
    content: "·";
}

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

.mono {
    font-family: var(--rh-font-mono);
    font-size: 0.86em;
}

/* Tableaux --------------------------------------------------------------- */

.table-scroll {
    overflow-x: auto;
    overscroll-behavior-x: contain;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead th {
    padding: var(--rh-space-3) var(--rh-space-4);
    border-bottom: 1px solid var(--rh-line);
    background: var(--rh-surface-muted);
    color: var(--rh-muted);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}

tbody td {
    padding: var(--rh-space-3) var(--rh-space-4);
    border-bottom: 1px solid var(--rh-line);
    color: var(--rh-ink-soft);
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover td {
    background: color-mix(in srgb, var(--rh-surface-strong) 55%, transparent);
}

tbody td:first-child {
    color: var(--rh-ink);
    font-weight: 600;
}

.col-actions {
    width: 1%;
    text-align: right;
    white-space: nowrap;
}

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

.cell-stack {
    display: grid;
    gap: 2px;
}

.cell-stack small {
    color: var(--rh-muted);
}

.cell-empty {
    padding: var(--rh-space-6) var(--rh-space-4) !important;
    color: var(--rh-muted);
    font-weight: 500 !important;
    text-align: center;
}

/* Messages --------------------------------------------------------------- */

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--rh-space-3);
    padding: var(--rh-space-3) var(--rh-space-4);
    border: 1px solid var(--rh-line);
    border-left-width: 3px;
    border-radius: var(--rh-radius-md);
    background: var(--rh-surface-muted);
    color: var(--rh-ink-soft);
    font-size: 0.88rem;
}

.alert + .alert {
    margin-top: var(--rh-space-2);
}

.alert > svg {
    flex: 0 0 auto;
    margin-top: 1px;
}

.alert-success {
    border-color: var(--rh-success-line);
    background: var(--rh-success-soft);
    color: color-mix(in srgb, var(--rh-success) 82%, var(--rh-ink));
}

.alert-error {
    border-color: var(--rh-danger-line);
    background: var(--rh-danger-soft);
    color: color-mix(in srgb, var(--rh-danger) 82%, var(--rh-ink));
}

.alert-warning {
    border-color: var(--rh-warning-line);
    background: var(--rh-warning-soft);
    color: color-mix(in srgb, var(--rh-warning) 82%, var(--rh-ink));
}

.alert-info {
    border-color: var(--rh-info-line);
    background: var(--rh-info-soft);
    color: color-mix(in srgb, var(--rh-info) 82%, var(--rh-ink));
}

.flash-stack:not(:empty) {
    display: grid;
    gap: var(--rh-space-2);
}

/* Listes de definitions -------------------------------------------------- */

.data-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: var(--rh-space-4);
    margin: 0;
}

.data-list > div {
    display: grid;
    gap: 2px;
    padding-left: var(--rh-space-3);
    border-left: 2px solid var(--rh-line);
}

.data-list dt {
    color: var(--rh-muted);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.data-list dd {
    margin: 0;
    color: var(--rh-ink);
    font-weight: 550;
    overflow-wrap: anywhere;
}

/* Liste d'enregistrements (contrats, cycles horaires). */

.record-list {
    display: grid;
    gap: var(--rh-space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.record-list > li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--rh-space-4);
    flex-wrap: wrap;
    padding: var(--rh-space-3) var(--rh-space-4);
    border: 1px solid var(--rh-line);
    border-radius: var(--rh-radius-md);
    background: var(--rh-surface-muted);
}

.record-main {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.record-main strong {
    color: var(--rh-ink);
}

.record-main span {
    color: var(--rh-muted);
    font-size: 0.83rem;
}

/* Etat vide -------------------------------------------------------------- */

.empty-state {
    display: grid;
    padding: var(--rh-space-6) var(--rh-space-5);
    gap: var(--rh-space-2);
    justify-items: center;
    color: var(--rh-muted);
    text-align: center;
}

.empty-state strong {
    color: var(--rh-ink);
    font-size: 0.95rem;
}

.empty-state p {
    max-width: 46ch;
    margin: 0;
    font-size: 0.88rem;
}

/* Details / depliants ---------------------------------------------------- */

details.disclosure {
    padding: var(--rh-space-3) var(--rh-space-4);
    border: 1px solid var(--rh-line);
    border-radius: var(--rh-radius-md);
    background: var(--rh-surface-muted);
}

details.disclosure > summary {
    color: var(--rh-ink-soft);
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 620;
}

details.disclosure[open] > summary {
    margin-bottom: var(--rh-space-3);
}

/* Bascule de theme ------------------------------------------------------- */

.theme-toggle {
    position: relative;
    overflow: hidden;
}

/* Doit suivre `.theme-toggle` : meme specificite, donc l'ordre decide du
   `position` retenu. */
.auth-theme-toggle {
    position: fixed;
    top: var(--rh-space-4);
    right: var(--rh-space-4);
}

.theme-toggle .theme-icon-sun {
    display: none;
}

:root[data-theme="dark"] .theme-toggle .theme-icon-sun {
    display: block;
}

:root[data-theme="dark"] .theme-toggle .theme-icon-moon {
    display: none;
}
