/* ==========================================================================
   Composants ajoutés (commentaires, historique, graphiques, exports)
   et mode sombre. Chargé après styles.css et guest-layout.css.
   ========================================================================== */

:root {
    color-scheme: light;
    --chart-bar: #2a5b94;
    --chart-track: #e8eef6;
    --surface: #fff;
    --border: #e2e8f0;
    --muted: #64748b;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Barre d'outils au-dessus des listes (création + exports) */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 18px 0;
}

.toolbar-spacer { flex: 1; }

.button--secondary {
    background: transparent;
    color: #1c64d1;
    box-shadow: inset 0 0 0 1px #1c64d1;
}

.button--secondary:hover {
    background: #edf4ff;
    color: #174ea6;
}

.form-link { justify-self: start; }

/* Badges de statut de ticket : le libellé reste toujours affiché */
.status-ouvert { background: #e0ecfb; color: #174ea6; }
.status-en-cours { background: #fef3c7; color: #92400e; }
.status-resolu { background: #dcfce7; color: #166534; }

/* Compteurs cliquables de « Mes tickets assignés » */
.stat-card--link {
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, box-shadow .15s;
}

.stat-card--link:hover,
.stat-card--link.is-active {
    border-color: #1c64d1;
    box-shadow: 0 0 0 2px rgba(28, 100, 209, .15);
}

/* Les libellés des indicateurs sont rédigés en français : pas de majuscule à chaque mot */
.stat-card span { text-transform: none; }

/* Commentaires et historique sur la fiche ticket */
.ticket-activity {
    margin-top: 28px;
    align-items: start;
}

.ticket-activity > section { margin: 0; }
.ticket-activity h2 { margin-top: 0; }

.comments,
.timeline {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
    display: grid;
    gap: 12px;
}

.comment {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid #94a3b8;
    border-radius: 10px;
    padding: 12px 16px;
}

.comment--support { border-left-color: #1c64d1; }
.comment p { margin: 0; overflow-wrap: anywhere; }
.comment .comment-meta { margin-bottom: 6px; color: var(--muted); font-size: .9rem; }
.comment .comment-meta strong { color: inherit; }
.comment .comment-meta .badge { font-size: .75rem; padding: 2px 8px; }

.comment-form { max-width: none; }

.timeline {
    position: relative;
    padding-left: 18px;
    border-left: 2px solid var(--border);
}

.timeline li { position: relative; }
.timeline li::before {
    content: "";
    position: absolute;
    left: -24px;
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--chart-bar);
    box-shadow: 0 0 0 3px var(--surface);
}

.timeline li.hint::before { display: none; }
.timeline p { margin: 2px 0; overflow-wrap: anywhere; }
.timeline .timeline-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timeline time, .timeline .hint { font-size: .85rem; color: var(--muted); }

/* Graphiques du tableau de bord */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
    gap: 14px;
}

.chart {
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
}

.chart .chart { border: 0; padding: 12px 0 0; border-radius: 0; }
.chart-title { font-weight: 650; margin-bottom: 4px; }
.chart-subtitle { margin: 0 0 10px; color: var(--muted); font-size: .88rem; }
.chart-hero { margin: 6px 0 2px; font-size: 2rem; font-weight: 700; color: #174ea6; }

table.chart-bars {
    min-width: 0;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 6px;
}

.chart-bars th,
.chart-bars td {
    padding: 0;
    border: 0;
    background: none;
    font-size: .92rem;
    text-transform: none;
    letter-spacing: 0;
    vertical-align: middle;
}

.chart-bars th {
    width: 36%;
    padding-right: 12px;
    color: inherit;
    font-weight: 550;
    overflow-wrap: anywhere;
}

.chart-bars td {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-bars tr { cursor: default; }
.chart-bars tr:hover .chart-bar { filter: brightness(1.15); }

.chart-track {
    flex: 1;
    height: 12px;
    background: var(--chart-track);
    border-radius: 0 4px 4px 0;
    overflow: hidden;
}

.chart-bar {
    display: block;
    height: 100%;
    background: var(--chart-bar);
    border-radius: 0 4px 4px 0;
}

.chart-value {
    min-width: 3.5em;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    white-space: nowrap;
}

.chart-value .hint { font-weight: 400; }

/* Lien de réinitialisation affiché uniquement en développement local */
.dev-note {
    max-width: 680px;
    background: #fffbeb;
    color: #78350f;
    border: 1px dashed #d97706;
    border-radius: 8px;
    padding: 12px 16px;
    overflow-wrap: anywhere;
}

/* Bouton clair / sombre */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    background: transparent;
    color: #405168;
    box-shadow: inset 0 0 0 1px var(--border);
}

.theme-toggle:hover { background: #edf4ff; color: #174ea6; }
.theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

@media (max-width: 560px) {
    .toolbar .button { flex: 1 1 auto; }
    .toolbar-spacer { display: none; }
    .chart-bars th { width: 40%; }
}

/* ==========================================================================
   Mode sombre
   ========================================================================== */

[data-theme="dark"] {
    color-scheme: dark;
    --chart-bar: #4f97d6;
    --chart-track: #1f2b3e;
    --surface: #151d2b;
    --border: #26324a;
    --muted: #94a3b8;
    color: #e6ebf2;
    background: #0f1621;
}

[data-theme="dark"] body { background: #0f1621; }

[data-theme="dark"] .topbar,
[data-theme="dark"] .sidebar,
[data-theme="dark"] form.form-card,
[data-theme="dark"] form.filters,
[data-theme="dark"] .table-wrap,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .detail-grid article {
    background: #151d2b;
    border-color: #26324a;
}

[data-theme="dark"] .brand-name { color: #fff; }
[data-theme="dark"] .brand-name span { color: #6fb4ec; }
[data-theme="dark"] .account { color: #9aa8bb; }

[data-theme="dark"] .sidebar a { color: #b5c1d1; }
[data-theme="dark"] .sidebar a:hover,
[data-theme="dark"] .sidebar a:focus { background: #1c2a40; color: #8cc2f2; }

[data-theme="dark"] a { color: #7fb6ee; }
[data-theme="dark"] .button,
[data-theme="dark"] button { color: #fff; }
[data-theme="dark"] .button--secondary { color: #8cc2f2; background: transparent; box-shadow: inset 0 0 0 1px #4f97d6; }
[data-theme="dark"] .button--secondary:hover { background: #1c2a40; }
[data-theme="dark"] .theme-toggle { color: #b5c1d1; background: transparent; }
[data-theme="dark"] .theme-toggle:hover { background: #1c2a40; color: #8cc2f2; }

[data-theme="dark"] label { color: #c3cdda; }
[data-theme="dark"] .detail-grid dt { color: #9aa8bb; }
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: #0f1621;
    border-color: #34445a;
    color: #e6ebf2;
}
[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus { outline-color: #1e3a5f; border-color: #4f97d6; }

[data-theme="dark"] th,
[data-theme="dark"] td { border-bottom-color: #222d40; }
[data-theme="dark"] th { background: #1a2436; color: #9aa8bb; }
[data-theme="dark"] .chart-bars th { background: none; color: inherit; }

[data-theme="dark"] .stat-card span { color: #9aa8bb; }
[data-theme="dark"] .stat-card strong,
[data-theme="dark"] .chart-hero { color: #8cc2f2; }
[data-theme="dark"] .hint { color: #94a3b8; }

[data-theme="dark"] .badge { background: #26324a; color: #d3dce8; }
[data-theme="dark"] .priority-faible { background: #24324a; color: #b9c7da; }
[data-theme="dark"] .priority-normale,
[data-theme="dark"] .status-resolu { background: #14352a; color: #86efac; }
[data-theme="dark"] .priority-haute,
[data-theme="dark"] .status-en-cours { background: #3f2a14; color: #fdba74; }
[data-theme="dark"] .priority-critique { background: #3f1a1d; color: #fca5a5; }
[data-theme="dark"] .status-ouvert { background: #1c2f4d; color: #9cc8f5; }

[data-theme="dark"] [role=alert] { color: #fca5a5; background: #3a1a1f; }
[data-theme="dark"] [role=status] { color: #86efac; background: #13301f; }
[data-theme="dark"] .dev-note { background: #2d2310; color: #fcd34d; border-color: #b45309; }
[data-theme="dark"] .demo-accounts { border-top-color: #26324a; }

[data-theme="dark"] .stat-card--link:hover,
[data-theme="dark"] .stat-card--link.is-active { border-color: #4f97d6; }

/* Écran d'ouverture en sombre, aux couleurs du logo « horizontal-dark » */
[data-theme="dark"] #splash {
    --sp-bg: #0f1a2b;
    --sp-text: #fff;
    --sp-a200: #1f3047;
    --sp-a400: #35516d;
    --sp-a700: #8aa6c2;
}
[data-theme="dark"] #splash .sp-name span { color: #6fb4ec; }
