/* ============================================================
   SIGRA – Feuille de style principale
   Mobile-first, responsive, zéro framework
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
    --green-dark:    #1B5E20;
    --green:         #2E7D32;
    --green-mid:     #388E3C;
    --green-light:   #C8E6C9;
    --green-pale:    #F1F8E9;

    --blue-dark:     #0D47A1;
    --blue:          #1565C0;
    --blue-light:    #BBDEFB;
    --blue-pale:     #E3F2FD;

    --amber:         #F57F17;
    --amber-light:   #FFF8E1;
    --amber-pale:    #FFFDE7;

    --red:           #B71C1C;
    --red-light:     #FFCDD2;
    --red-pale:      #FFEBEE;

    --gray-900:      #1a1a1a;
    --gray-700:      #374151;
    --gray-500:      #6B7280;
    --gray-300:      #D1D5DB;
    --gray-100:      #F3F4F6;
    --gray-50:       #F9FAFB;
    --white:         #ffffff;

    --sidebar-w:     240px;
    --header-h:      56px;
    --radius:        8px;
    --radius-lg:     12px;
    --shadow-sm:     0 1px 3px rgba(0,0,0,.10);
    --shadow:        0 2px 8px rgba(0,0,0,.12);

    --font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono:     'Menlo', 'Consolas', monospace;
}

/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    font-size: .9375rem;
    line-height: 1.6;
    color: var(--gray-700);
    background: var(--gray-100);
}

a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* ── Layout principal ───────────────────────────────────────── */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--header-h) 1fr;
    min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────── */
.app-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.25rem;
    background: var(--green-dark);
    color: var(--white);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--white);
    flex-shrink: 0;
    width: calc(var(--sidebar-w) - 1.25rem);
}
.header-logo .logo-icon { font-size: 1.4rem; }

.header-project-name {
    flex: 1;
    font-size: .95rem;
    opacity: .85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-left: auto;
}

.header-user {
    font-size: .85rem;
    opacity: .85;
}

.btn-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--white);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: .25rem;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.app-sidebar {
    background: var(--white);
    border-right: 1px solid var(--gray-300);
    overflow-y: auto;
    position: sticky;
    top: var(--header-h);
    height: calc(100vh - var(--header-h));
}

.sidebar-section {
    padding: .75rem 0;
    border-bottom: 1px solid var(--gray-100);
}

.sidebar-label {
    padding: .25rem 1rem;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--gray-500);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem 1rem;
    color: var(--gray-700);
    font-size: .875rem;
    transition: background .15s;
    cursor: pointer;
}
.sidebar-link:hover { background: var(--gray-50); text-decoration: none; }
.sidebar-link.active {
    background: var(--green-pale);
    color: var(--green-dark);
    font-weight: 500;
    border-left: 3px solid var(--green);
}

.panel-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: .7rem;
    font-weight: 700;
    flex-shrink: 0;
    background: var(--gray-100);
    color: var(--gray-500);
}
.panel-badge.validated { background: var(--green-light); color: var(--green-dark); }
.panel-badge.in_progress { background: var(--blue-light); color: var(--blue-dark); }
.panel-badge.locked { background: var(--gray-300); color: var(--gray-500); }
.panel-badge.danger { background: var(--red-light); color: var(--red); }

/* ── Contenu principal ───────────────────────────────────────── */
.app-main {
    padding: 1.5rem;
    overflow-x: hidden;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200, #E5E7EB);
    margin-bottom: 1.25rem;
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    gap: .75rem;
}
.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    flex: 1;
}
.card-body { padding: 1.25rem; }

/* ── Grille tableau de bord ──────────────────────────────────── */
.tb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200, #E5E7EB);
    display: flex;
    flex-direction: column;
    gap: .3rem;
    cursor: pointer;
    transition: box-shadow .15s;
}
.stat-card:hover { box-shadow: var(--shadow); }
.stat-label { font-size: .78rem; color: var(--gray-500); font-weight: 500; text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--gray-900); line-height: 1; }
.stat-sub { font-size: .8rem; color: var(--gray-500); }
.stat-card.danger .stat-value { color: var(--red); }
.stat-card.warning .stat-value { color: var(--amber); }
.stat-card.success .stat-value { color: var(--green); }

/* ── Barre d'avancement ──────────────────────────────────────── */
.progress-bar-wrap {
    height: 8px;
    background: var(--gray-100);
    border-radius: 99px;
    overflow: hidden;
    margin-top: .4rem;
}
.progress-bar-fill {
    height: 100%;
    border-radius: 99px;
    background: var(--green);
    transition: width .4s ease;
}

/* ── Alertes ─────────────────────────────────────────────────── */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    margin-bottom: .75rem;
    display: flex;
    align-items: flex-start;
    gap: .6rem;
}
.alert-info    { background: var(--blue-pale);  border-left: 4px solid var(--blue);  color: var(--blue-dark); }
.alert-warning { background: var(--amber-pale); border-left: 4px solid var(--amber); color: #7c4f00; }
.alert-danger  { background: var(--red-pale);   border-left: 4px solid var(--red);   color: var(--red); }
.alert-success { background: var(--green-pale); border-left: 4px solid var(--green); color: var(--green-dark); }

/* ── Formulaires ─────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }

label {
    display: block;
    font-size: .875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: .3rem;
}
label .required { color: var(--red); margin-left: .2rem; }

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], input[type=url],
select, textarea {
    width: 100%;
    padding: .55rem .75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: .9rem;
    font-family: var(--font);
    color: var(--gray-900);
    background: var(--white);
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(46,125,50,.15);
}
textarea { min-height: 90px; resize: vertical; }
select { cursor: pointer; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: .75rem;
}

.form-hint {
    font-size: .78rem;
    color: var(--gray-500);
    margin-top: .25rem;
}

/* Évaluation Likert (1-5) */
.likert-group {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}
.likert-group input[type=radio] { display: none; }
.likert-group label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-300);
    cursor: pointer;
    font-weight: 600;
    font-size: .9rem;
    transition: all .15s;
    margin: 0;
    color: var(--gray-500);
}
.likert-group input:checked + label {
    background: var(--green);
    border-color: var(--green);
    color: var(--white);
}
.likert-group label:hover { border-color: var(--green); color: var(--green); }

/* Checkbox / multi-select */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}
.checkbox-pill {
    display: flex;
    align-items: center;
    gap: .35rem;
    padding: .35rem .75rem;
    border: 1px solid var(--gray-300);
    border-radius: 99px;
    font-size: .85rem;
    cursor: pointer;
    transition: all .15s;
    user-select: none;
}
.checkbox-pill input { display: none; }
.checkbox-pill.checked {
    background: var(--green-pale);
    border-color: var(--green);
    color: var(--green-dark);
    font-weight: 500;
}

/* ── Boutons ─────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, box-shadow .15s;
    line-height: 1.4;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--green); color: var(--white); border-color: var(--green-mid); }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: var(--white); color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); }
.btn-danger    { background: var(--red); color: var(--white); }
.btn-danger:hover { background: #8B0000; }
.btn-warning   { background: var(--amber); color: var(--white); }
.btn-sm        { padding: .3rem .7rem; font-size: .8rem; }
.btn-full      { width: 100%; justify-content: center; }
.btn-icon      { padding: .4rem .5rem; }

/* ── Tableaux ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
th {
    background: var(--gray-50);
    padding: .6rem .85rem;
    text-align: left;
    font-weight: 600;
    color: var(--gray-700);
    border-bottom: 2px solid var(--gray-300);
    white-space: nowrap;
}
td {
    padding: .6rem .85rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }

/* Tableau phénologique (semaines) */
.phenology-table th { min-width: 52px; }
.pheno-cell {
    min-width: 52px;
    height: 32px;
    border-radius: 4px;
    text-align: center;
    vertical-align: middle;
    font-size: .72rem;
    font-weight: 600;
    color: var(--white);
}
.pheno-cell.active { opacity: 1; }
.pheno-cell.empty  { background: var(--gray-100); }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: .15rem .55rem;
    border-radius: 99px;
    font-size: .72rem;
    font-weight: 600;
    line-height: 1.5;
}
.badge-success { background: var(--green-light); color: var(--green-dark); }
.badge-warning { background: var(--amber-light); color: #7c4f00; }
.badge-danger  { background: var(--red-light);   color: var(--red); }
.badge-info    { background: var(--blue-light);  color: var(--blue-dark); }
.badge-gray    { background: var(--gray-100);    color: var(--gray-500); }

/* ── Onglets ─────────────────────────────────────────────────── */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--gray-200, #E5E7EB);
    margin-bottom: 1.25rem;
    overflow-x: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
    padding: .6rem 1.1rem;
    font-size: .875rem;
    font-weight: 500;
    color: var(--gray-500);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    white-space: nowrap;
    transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--gray-700); }
.tab-btn.active {
    color: var(--green-dark);
    border-bottom-color: var(--green);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Panel de navigation (panneaux du projet) ────────────────── */
.panel-nav {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}
.panel-nav-btn {
    display: flex;
    align-items: center;
    gap: .35rem;
    padding: .45rem .9rem;
    border-radius: 99px;
    font-size: .8rem;
    font-weight: 500;
    border: 1px solid var(--gray-300);
    background: var(--white);
    color: var(--gray-700);
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
}
.panel-nav-btn:hover { border-color: var(--green); color: var(--green-dark); }
.panel-nav-btn.active { background: var(--green); border-color: var(--green); color: var(--white); }
.panel-nav-btn.locked { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* ── Page d'authentification ─────────────────────────────────── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--green-dark);
    padding: 1rem;
}
.auth-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 24px rgba(0,0,0,.2);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
}
.auth-header { text-align: center; margin-bottom: 1.5rem; }
.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--green-dark);
    margin-bottom: .35rem;
}
.auth-logo .logo-icon { font-size: 2rem; }
.auth-subtitle { color: var(--gray-500); font-size: .9rem; }
.auth-lang {
    text-align: center;
    margin-top: 1.25rem;
    font-size: .85rem;
    color: var(--gray-500);
}
.auth-lang a { color: var(--gray-500); }
.auth-lang a.active { color: var(--green-dark); font-weight: 600; }

/* ── Tableau de bord – liste projets ─────────────────────────── */
.project-list { display: flex; flex-direction: column; gap: .75rem; }
.project-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: .9rem 1.25rem;
    border: 1px solid var(--gray-200, #E5E7EB);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: box-shadow .15s;
    text-decoration: none;
    color: inherit;
}
.project-row:hover { box-shadow: var(--shadow); text-decoration: none; }
.project-code { font-size: .75rem; font-weight: 700; color: var(--gray-500); flex-shrink: 0; }
.project-name { flex: 1; font-weight: 500; color: var(--gray-900); }
.project-progress { flex-shrink: 0; width: 120px; }

/* ── Indicateurs de panneau (TB projet) ──────────────────────── */
.panels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: .75rem;
}
.panel-card {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200, #E5E7EB);
    padding: .85rem;
    text-align: center;
    cursor: pointer;
    transition: box-shadow .15s;
    text-decoration: none;
    color: inherit;
}
.panel-card:hover { box-shadow: var(--shadow); text-decoration: none; }
.panel-card-num { font-size: .72rem; color: var(--gray-500); font-weight: 600; }
.panel-card-title { font-size: .8rem; font-weight: 500; margin-top: .2rem; color: var(--gray-700); line-height: 1.3; }
.panel-card.status-validated { border-color: var(--green); background: var(--green-pale); }
.panel-card.status-in_progress { border-color: var(--blue); background: var(--blue-pale); }
.panel-card.status-danger { border-color: var(--red); background: var(--red-pale); }
.panel-card.status-locked { opacity: .45; pointer-events: none; }

/* ── Upload / lien ───────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    color: var(--gray-500);
    font-size: .875rem;
    transition: border-color .15s;
    cursor: pointer;
}
.upload-zone:hover { border-color: var(--green); }
.upload-zone input { display: none; }

/* ── Modale légère ───────────────────────────────────────────── */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-100);
}
.modal-title { font-size: 1rem; font-weight: 600; flex: 1; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--gray-500);
    line-height: 1;
    padding: .2rem;
}
.modal-body { padding: 1.25rem; }
.modal-footer {
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--gray-100);
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
}

/* ── Toast notification ──────────────────────────────────────── */
#toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    padding: .75rem 1.25rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    box-shadow: var(--shadow);
    z-index: 999;
    transform: translateY(80px);
    opacity: 0;
    transition: transform .25s ease, opacity .25s ease;
    pointer-events: none;
    max-width: 320px;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { background: var(--green); color: var(--white); }
#toast.error   { background: var(--red);   color: var(--white); }
#toast.warning { background: var(--amber); color: var(--white); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: var(--header-h) 1fr;
    }

    .btn-menu-toggle { display: block; }

    .app-sidebar {
        position: fixed;
        top: var(--header-h);
        left: -100%;
        width: var(--sidebar-w);
        height: calc(100vh - var(--header-h));
        z-index: 150;
        transition: left .25s ease;
        box-shadow: var(--shadow);
    }
    .app-sidebar.open { left: 0; }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        top: var(--header-h);
        background: rgba(0,0,0,.4);
        z-index: 140;
    }
    .sidebar-overlay.open { display: block; }

    .app-main { padding: 1rem .75rem; }

    .tb-grid { grid-template-columns: repeat(2, 1fr); }
    .panels-grid { grid-template-columns: repeat(3, 1fr); }

    .form-row { grid-template-columns: 1fr; }

    .header-logo { width: auto; }
    .header-project-name { display: none; }

    table { font-size: .8rem; }
    th, td { padding: .5rem .6rem; }
}

@media (max-width: 480px) {
    .tb-grid { grid-template-columns: 1fr; }
    .panels-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Utilitaires ─────────────────────────────────────────────── */
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-small   { font-size: .8rem; }
.text-muted   { color: var(--gray-500); }
.text-success { color: var(--green); }
.text-danger  { color: var(--red); }
.text-warning { color: var(--amber); }
.fw-600       { font-weight: 600; }
.mt-1  { margin-top: .5rem; }
.mt-2  { margin-top: 1rem; }
.mt-3  { margin-top: 1.5rem; }
.mb-1  { margin-bottom: .5rem; }
.mb-2  { margin-bottom: 1rem; }
.mb-3  { margin-bottom: 1.5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
