/* ==========================================================================
   TimeRrr — feuille de style unique (CSS natif, imbrication « & » : pas de build)
   Aucun style inline dans les pages (CSP stricte) : seules les couleurs de projet sont
   générées, dans un <style nonce> (project_colors_style() → .project-{id} { --project; --project-text }).

   1. Variables            6. Mise en page        11. Boîte à idées / Journal
   2. Base                 7. Dashboard, timers   12. Connexion, erreurs
   3. Icônes               8. Projets, jauges     13. Suivi client, impression
   4. Formulaires, boutons 9. Rapports
   5. Composants          10. Options
   ========================================================================== */


/* 1. Variables
   ========================================================================== */

:root {
    /* Surfaces et texte */
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-alt: #fafbfc;
    --bubble: #eef0f4;
    --border: #e3e5ea;
    --text: #1f2330;
    --muted: #6b7180;            /* 4,9:1 sur blanc */
    --faint: #b5bac5;

    /* Marque : violet du logo assombri (blanc sur violet 7,1:1 ; le #9d6efd clair du logo ne fait que 3,5:1) */
    --primary: #6d28d9;
    --primary-hover: #5b21b6;
    --primary-soft: #f3eefe;     /* fonds pâles : onglet actif, badges, sélection */
    --primary-border: #d9c8fb;
    --danger: #dc2626;
    --danger-text: #b91c1c;
    --success: #16a34a;
    --success-text: #15803d;
    --warning: #f59e0b;
    --warning-text: #92400e;
    --danger-soft: #fef2f2;        /* fond d'alerte */
    --danger-border: #fecaca;
    --warning-soft: #fffbeb;
    --warning-border: #fde68a;
    --neutral-soft: #f3f4f6;       /* badge « Archivé » */

    /* Icônes (palette Material) */
    --md-red: #e53935;
    --md-orange: #fb8c00;
    --md-amber: #ffa000;
    --md-green: #43a047;
    --md-blue: #1e88e5;
    --md-purple: #8e24aa;
    --md-grey: #607d8b;

    /* Formes */
    --radius: 8px;
    --radius-lg: 12px;
    --pill: 999px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .25);
    --mono: ui-monospace, Consolas, monospace;

    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    color: var(--text);
}


/* 2. Base
   ========================================================================== */

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }

a { color: var(--primary); }
[hidden] { display: none !important; }

.muted { color: var(--muted); font-weight: normal; }
.spacer { flex: 1; }
.empty { color: var(--muted); padding: 1rem 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.section-gap { margin-top: 2rem; }
.section-note { margin: -.5rem 0 1rem; }

/* Cartes blanches : un seul style pour tous les blocs */
.panel, .table-wrap, .conversation {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}


/* 3. Icônes (SVG inline via icon() — couleur = currentColor)
   ========================================================================== */

/* Même rendu que Font Awesome : hauteur 1em (suit la taille du texte), largeur propre au dessin
   (viewBox : 448, 512, 576 ou 640 de large), décalage vertical -0.125em. */
.icon {
    display: inline-block; flex: none; width: auto; height: 1em; vertical-align: -.125em;
    fill: currentColor; overflow: visible;
}

/* Actions */
.icon-pen, .icon-comment, .icon-check-double, .icon-file-csv, .icon-link, .icon-copy { color: var(--md-blue); }
.icon-trash, .icon-triangle-exclamation, .icon-bug, .icon-stop { color: var(--md-red); }
.icon-plus, .icon-play, .icon-circle-check, .icon-check { color: var(--md-green); }
.icon-lock, .icon-hourglass-half, .icon-lightbulb { color: var(--md-amber); }
.icon-clock, .icon-stopwatch, .icon-rotate { color: var(--md-orange); }
.icon-circle-question { color: var(--md-purple); }
.icon-xmark, .icon-gear, .icon-chevron-left, .icon-chevron-right, .icon-arrow-left,
.icon-box-archive, .icon-box-open, .icon-link-slash, .msg-read .icon-check { color: var(--md-grey); }

/* Dans un bouton à fond coloré, l'icône garde la couleur du texte (blanc) */
.btn-primary .icon, .btn-danger:hover .icon, .send-btn .icon { color: inherit; }


/* 4. Formulaires et boutons
   ========================================================================== */

label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; font-size: .9rem; }

input, select, textarea {
    font: inherit; padding: .5rem .6rem; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--surface); color: var(--text);
}
textarea { resize: vertical; }

input:focus, select:focus, textarea:focus,
.btn:focus-visible, .link:focus-visible, .icon-btn:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 1px;
}

label.checkbox {
    flex-direction: row; align-items: center; gap: .45rem; cursor: pointer;
    & input { width: 1.05rem; height: 1.05rem; margin: 0; }
}

.error { color: var(--danger); font-weight: normal; &:empty { display: none; } }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 768px) { .form-row { grid-template-columns: 1fr; } }

/* Popup projet : nom + pastille de couleur ronde sur une ligne */
.form-row-color { display: grid; grid-template-columns: 1fr auto; gap: .75rem; align-items: start; }

/* Groupe de cases à cocher (utilisateurs attribués) */
.checkbox-group {
    display: flex; flex-direction: column; gap: .45rem; margin: 0; padding: .75rem .9rem;
    border: 1px solid var(--border); border-radius: var(--radius); max-height: 260px; overflow-y: auto;
    & legend { padding: 0 .3rem; font-weight: 500; font-size: .9rem; }
    & label.checkbox { font-weight: 500; flex-wrap: wrap; }
    & label.checkbox .muted { font-size: .8rem; }
    & p { margin: 0; }
}

/* Choix exclusif présenté en cartes (type de projet) */
.choice-group {
    display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: 0; padding: 0; border: 0;
    & legend { margin-bottom: .3rem; padding: 0; font-weight: 500; font-size: .9rem; }
    & > small { grid-column: 1 / -1; }
    @media (max-width: 480px) { grid-template-columns: 1fr; }
}
.choice {
    flex-direction: row; align-items: flex-start; gap: .5rem; padding: .6rem .7rem; cursor: pointer;
    border: 1px solid var(--border); border-radius: var(--radius); font-weight: normal;
    & input { margin: .2rem 0 0; }
    & span { display: flex; flex-direction: column; gap: .15rem; }
    & small { font-size: .8rem; }
    &:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
}

/* Formulaire simple : champs empilés (Options) */
.stack-form { display: flex; flex-direction: column; gap: .9rem; }

input[type="color"].color-dot {
    appearance: none; width: 2.6rem; height: 2.6rem; padding: 0;
    border: 2px solid var(--border); border-radius: 50%; background: none; cursor: pointer;
    &::-webkit-color-swatch-wrapper { padding: 0; }
    &::-webkit-color-swatch { border: 0; border-radius: 50%; }
    &::-moz-color-swatch { border: 0; border-radius: 50%; }
    &:hover { border-color: var(--muted); }
}

/* Boutons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    padding: .5rem .9rem; border: 1px solid transparent; border-radius: var(--radius);
    font: inherit; font-weight: 500; text-decoration: none; white-space: nowrap; cursor: pointer;
    &:disabled { opacity: .5; cursor: not-allowed; }
    &.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-border); }
}
.btn-primary {
    background: var(--primary); color: #fff;
    &:hover:not(:disabled) { background: var(--primary-hover); }
}
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); &:hover { background: var(--bg); } }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); &:hover { background: var(--danger); color: #fff; } }
.btn-block { width: 100%; margin-top: 1rem; }
.btn-sm { padding: .3rem .7rem; font-size: .85rem; }

.icon-btn {
    border: 0; background: transparent; padding: .25rem .35rem; border-radius: 6px;
    font-size: .95rem; line-height: 1; cursor: pointer;
    &:hover { background: var(--bg); }
}

/* Bouton d'apparence « lien » */
.link {
    border: 0; background: none; padding: 0; font: inherit; font-weight: 600; color: inherit;
    text-align: left; cursor: pointer;
    &:hover { color: var(--primary); text-decoration: underline; }
}

.button-row { display: flex; gap: .5rem; flex-wrap: wrap; }


/* 5. Composants
   ========================================================================== */

/* Pastille de projet (couleur via .project-{id}) */
.pill {
    display: inline-block; max-width: 14rem; padding: .1rem .55rem; border-radius: var(--pill);
    background: var(--project, var(--muted)); color: var(--project-text, #fff);
    font-size: .78rem; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.swatch { display: inline-block; flex: none; width: .8rem; height: .8rem; border-radius: 50%; background: var(--project, var(--border)); }

.badge {
    display: inline-block; margin-left: .5rem; padding: .05rem .5rem; border-radius: var(--pill);
    background: var(--primary-soft); color: var(--primary); font-size: .75rem; font-weight: 600;
}
.billing-badge {
    padding: .05rem .5rem; border-radius: var(--pill); background: var(--neutral-soft); color: var(--muted);
    font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.badge-neutral { background: var(--neutral-soft); color: var(--muted); }
.badge-warning { background: var(--warning-soft); color: var(--warning-text); }

.count-badge {
    display: inline-grid; place-items: center; min-width: 1.25rem; height: 1.25rem; padding: 0 .35rem; margin-left: .35rem;
    border-radius: var(--pill); background: var(--danger); color: #fff;
    font-size: .72rem; font-weight: 700; line-height: 1; vertical-align: 1px;
}

.notice {
    margin-bottom: 1rem; padding: .75rem 1rem; border-radius: var(--radius);
    background: var(--primary-soft); border: 1px solid var(--primary-border);
}
.notice-neutral { background: var(--neutral-soft); border-color: var(--border); }
.alert {
    margin: 0; padding: .6rem .8rem; border-radius: var(--radius);
    background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger-border);
}
.warning-note { margin: .6rem 0; color: var(--warning-text); font-size: .85rem; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
.table {
    width: 100%; border-collapse: collapse;
    & th, & td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
    & th { background: var(--surface-alt); color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; }
    & tbody tr:last-child td { border-bottom: 0; }
    & .col-actions { text-align: right; width: 1%; }
    & .col-center { text-align: center; }
    & .col-num { text-align: right; font-variant-numeric: tabular-nums; }
    & .col-wrap { white-space: normal; overflow-wrap: anywhere; }
    & tfoot td { border-top: 1px solid var(--border); border-bottom: 0; font-weight: 700; }
    & tr.is-current td { background: var(--primary-soft); }
}
/* Tableau dans un panneau : le cadre est porté par le panneau */
.table-flat { border: 0; border-radius: 0; box-shadow: none; & .table th:first-child, & .table td:first-child { padding-left: 0; } }
.table-clickable {
    & tbody tr { cursor: pointer; &:hover { background: var(--surface-alt); } }
    & a { color: inherit; text-decoration: none; }
    & tr.is-unread td { font-weight: 600; }
}

/* Popups (<dialog> natif) */
.dialog {
    width: min(560px, calc(100vw - 2rem)); padding: 0; border: 0; border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    &::backdrop { background: rgba(17, 20, 30, .45); }
    & form { display: flex; flex-direction: column; gap: .9rem; padding: 1.25rem; }
}
.dialog-sm { width: min(400px, calc(100vw - 2rem)); }
.dialog-header { display: flex; justify-content: space-between; align-items: center; }
.dialog-footer { display: flex; align-items: center; gap: .5rem; margin-top: .25rem; }

/* Notifications */
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 100; display: flex; flex-direction: column; gap: .5rem; }
.toast {
    max-width: 340px; padding: .7rem 1rem; border-radius: var(--radius);
    background: var(--success); color: #fff; box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
    animation: toast-in .2s ease-out; transition: opacity .4s, transform .4s;
    &.toast-error { background: var(--danger); }
    &.is-leaving { opacity: 0; transform: translateY(8px); }
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }


/* 6. Mise en page
   ========================================================================== */

.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 1.5rem; padding: .75rem 1.5rem;
    background: var(--surface); border-bottom: 1px solid var(--border);

    @media (max-width: 768px) { flex-wrap: wrap; gap: .5rem 1rem; padding: .6rem 1rem; }
}
.brand {
    display: inline-flex; align-items: center; gap: .5rem;
    color: var(--text); font-size: 1.2rem; font-weight: 800; text-decoration: none;
}
.brand-logo { display: block; width: 32px; height: 32px; }

.nav {
    display: flex; gap: .25rem;
    & a {
        padding: .4rem .75rem; border-radius: var(--radius);
        color: var(--muted); font-weight: 500; text-decoration: none;
        &:hover { background: var(--bg); color: var(--text); }
        &.active { background: var(--primary-soft); color: var(--primary); }
    }
    @media (max-width: 768px) { order: 3; width: 100%; overflow-x: auto; }
}
.topbar-actions { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.topbar-welcome {
    margin-right: .5rem; font-size: .95rem; font-weight: 700; white-space: nowrap;
    @media (max-width: 480px) { display: none; }
}
.logout { margin: 0; }

.page {
    max-width: 1400px; margin: 0 auto; padding: 1.5rem;
    &.page-narrow { max-width: 992px; }   /* Options, Boîte à idées, fiche projet */
    @media (max-width: 768px) { padding: 1rem; }
}
.page-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.back-link { font-size: 1rem; font-weight: 500; text-decoration: none; }

.panel {
    padding: 1.25rem;
    & h2 { margin-bottom: 1rem; }
    & > p { margin: 0 0 1rem; }
    & > p:last-child { margin-bottom: 0; }
}
.panel-header {
    display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: 1rem;
    & h2 { margin: 0; }
}
.section-after { margin: .75rem 0 0; }

.filters {
    display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem;
    & input[type="search"] { flex: 1 1 200px; }
}


/* 7. Dashboard et timers
   ========================================================================== */


/* 8. Projets et jauges
   ========================================================================== */

/* Liste : cartes à liseré de la couleur du projet */
.project-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .75rem;
    list-style: none; margin: 0; padding: 0;
}
.project-card {
    display: flex; flex-direction: column; gap: .5rem; min-width: 0; padding: .9rem 1rem;
    background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--project, var(--border));
    border-radius: var(--radius); box-shadow: var(--shadow);
    &.is-archived { opacity: .7; }
}
.project-card-head { display: flex; align-items: center; gap: .4rem; min-width: 0; & .badge { margin-left: 0; } }
.project-card-title {
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--text); font-weight: 700; text-decoration: none;
    &:hover { color: var(--primary); text-decoration: underline; }
}
.project-card-meta {
    display: flex; flex-wrap: wrap; gap: .25rem 1rem; color: var(--muted); font-size: .85rem;
    &:empty { display: none; }
}
.is-overdue { color: var(--danger-text); font-weight: 600; & .icon { color: inherit; } }
.share-flag { color: var(--md-blue); font-size: .85rem; font-weight: 500; white-space: nowrap; }

/* Fiche projet */
.project-head { display: flex; flex-direction: column; gap: 1rem; }
.project-head-title {
    display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
    & .swatch { width: 1.1rem; height: 1.1rem; }
    & h1 { overflow-wrap: anywhere; }
}
.project-facts {
    display: flex; flex-wrap: wrap; gap: .5rem 2rem; margin: 0;
    & dt { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; }
    & dd { margin: 0; }
}
.project-description { margin: 0; white-space: normal; overflow-wrap: anywhere; }
.project-admin { padding-top: 1rem; border-top: 1px solid var(--border); }

/* Jauge : <progress> natif (CSP : pas de largeur en style=""), couleur selon le niveau */
.gauge {
    --gauge: var(--success);
    display: flex; flex-direction: column; gap: .35rem;
    &.gauge-warn { --gauge: var(--warning); }
    &.gauge-over { --gauge: var(--danger); & .gauge-remaining { color: var(--danger-text); font-weight: 600; } }
    & progress {
        appearance: none; display: block; width: 100%; height: .6rem; border: 0; border-radius: var(--pill);
        background: var(--bubble); overflow: hidden; color: var(--gauge);
        &::-webkit-progress-bar { background: var(--bubble); border-radius: var(--pill); }
        &::-webkit-progress-value { background: var(--gauge); border-radius: var(--pill); }
        &::-moz-progress-bar { background: var(--gauge); border-radius: var(--pill); }
    }
}
.gauge-figures {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem 1rem; font-size: .85rem;
    font-variant-numeric: tabular-nums;
}
.gauge-percent { font-weight: 700; }
.gauge-period { color: var(--muted); font-size: .8rem; font-weight: 600; }
.gauge-pending { margin: 0; color: var(--muted); font-size: .9rem; }
/* Pourcentage et bilan d'une période, aux couleurs de la jauge */
.level-ok { color: var(--success-text); }
.level-warn { color: var(--warning-text); }
.level-over { color: var(--danger-text); font-weight: 600; }
.gauge-remaining { margin-left: auto; color: var(--muted); }
.gauge-detailed {
    & progress { height: .9rem; }
    & .gauge-figures { font-size: 1rem; }
}


/* 9. Rapports
   ========================================================================== */


/* 10. Options
   ========================================================================== */


/* 11. Boîte à idées / Journal
   ========================================================================== */


/* 12. Connexion et pages d'erreur
   ========================================================================== */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card {
    display: flex; flex-direction: column; gap: 1rem; width: min(380px, 100%); padding: 2rem;
    border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow);
    & h1 { font-size: 1.6rem; text-align: center; }
    & > p { margin: -.75rem 0 0; text-align: center; }
    & .alert { margin: 0; }
}
.login-logo { display: block; width: 80px; height: 80px; margin: 0 auto -.25rem; }

.error-card {
    align-items: center; text-align: center;
    & > p { margin: 0; }
    & .btn { align-self: center; }
}
.error-code { margin: 0; color: var(--primary); font-size: 2.5rem; font-weight: 800; line-height: 1; }


/* 13. Suivi client et impression
   ========================================================================== */
