/* =========================================================================
   Éditeur de procédures chantier — design pro, mobile-first, responsive.
   ========================================================================= */

:root {
    --navy: #0f1a2e;
    --navy-light: #1a2942;
    --navy-muted: #8fa3bf;
    --bleu-bar: #1e4a8c;
    --bleu-bar-hover: #2559a8;
    --vert-bar: #1a5c42;
    --vert-bar-hover: #227a56;
    --accent: #3dba5c;
    --accent-dark: #2d9a4a;
    --jaune: #f5c518;
    --jaune-hover: #e0b310;
    --blanc: #ffffff;
    --fond: #eef1f5;
    --fond-card: #ffffff;
    --texte: #1c2430;
    --texte-doux: #5c6b7f;
    --bord: #d5dce6;
    --rouge: #d63b3b;
    --ombre: 0 2px 12px rgba(15, 26, 46, .08);
    --ombre-forte: 0 8px 28px rgba(15, 26, 46, .14);
    --radius: 10px;
    --radius-sm: 6px;
    --topbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
    color: var(--texte);
    background: var(--fond);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* ---------- Barre supérieure (style dashboard pro) ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--navy);
    padding: 0 16px;
    height: var(--topbar-h);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1rem;
    text-decoration: none;
    color: var(--blanc);
    min-width: 0;
}

.topbar__brand:hover { text-decoration: none; opacity: .92; }

.topbar__logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent) 0%, #2d8a4e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: .85rem;
    color: #fff;
    font-weight: 800;
}

.topbar__brand-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar__right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.topbar__user {
    color: var(--navy-muted);
    font-size: .875rem;
    display: none;
}

@media (min-width: 600px) {
    .topbar { padding: 0 24px; }
    .topbar__brand { font-size: 1.05rem; }
    .topbar__user { display: inline; }
}

/* ---------- Conteneur ---------- */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px;
}

@media (min-width: 768px) {
    .container { padding: 24px; }
}

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-size: .9375rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    background: var(--blanc);
    color: var(--texte);
    transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
    white-space: nowrap;
    font-family: inherit;
}

.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn:active { transform: scale(.98); }

.btn--primary { background: var(--bleu-bar); color: #fff; border-color: var(--bleu-bar); }
.btn--primary:hover { background: var(--bleu-bar-hover); }
.btn--success { background: var(--accent); color: #fff; border-color: var(--accent-dark); }
.btn--success:hover { background: var(--accent-dark); }
.btn--danger { background: var(--rouge); color: #fff; }
.btn--ghost { background: transparent; border-color: var(--bord); color: var(--texte); }
.btn--topbar {
    background: rgba(255, 255, 255, .08);
    border-color: rgba(255, 255, 255, .15);
    color: var(--blanc);
    padding: 8px 14px;
    font-size: .875rem;
}
.btn--topbar:hover { background: rgba(255, 255, 255, .14); filter: none; }
.btn--fab {
    background: var(--jaune);
    color: var(--navy);
    border: none;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    font-size: 1.6rem;
    line-height: 1;
    padding: 0;
    box-shadow: var(--ombre-forte);
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 40;
}
.btn--fab:hover { background: var(--jaune-hover); filter: none; }
.btn--block { width: 100%; }
.btn--lg { padding: 14px 20px; font-size: 1rem; }
.btn--sm { padding: 7px 12px; font-size: .8125rem; }

@media (min-width: 768px) {
    .btn--fab { position: static; width: auto; height: auto; border-radius: var(--radius-sm); font-size: .9375rem; padding: 10px 18px; box-shadow: var(--ombre); }
}

/* ---------- Champs ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-weight: 600; font-size: .875rem; color: var(--texte-doux); }
.field__input, .field__textarea {
    border: 1px solid var(--bord);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 1rem;
    font-family: inherit;
    width: 100%;
    background: var(--blanc);
    color: var(--texte);
}
.field__input:focus, .field__textarea:focus {
    outline: none;
    border-color: var(--bleu-bar);
    box-shadow: 0 0 0 3px rgba(30, 74, 140, .12);
}

/* ---------- Messages flash ---------- */
.flash {
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-weight: 500;
    font-size: .9375rem;
}
.flash--success { background: #e4f5ea; color: #1a6b3c; border-left: 4px solid var(--accent); }
.flash--error { background: #fce8e8; color: #9c2020; border-left: 4px solid var(--rouge); }
.flash--info { background: #e6eef8; color: var(--bleu-bar); border-left: 4px solid var(--bleu-bar); }

/* ---------- Connexion ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--navy);
}

.login-page__bar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 10px;
}

.login-page__brand {
    color: var(--blanc);
    font-weight: 700;
    font-size: 1.05rem;
}

.login {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: linear-gradient(180deg, var(--navy) 0%, var(--navy-light) 40%, var(--fond) 40%);
}

.login__card {
    background: var(--blanc);
    padding: 32px 28px;
    border-radius: var(--radius);
    box-shadow: var(--ombre-forte);
    width: 100%;
    max-width: 400px;
}

.login__title { margin: 0 0 4px; color: var(--navy); font-size: 1.35rem; }
.login__subtitle { margin: 0 0 24px; color: var(--texte-doux); font-size: .9375rem; }

/* ---------- En-tête de section ---------- */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--texte);
}

.section-title__bar {
    display: inline-block;
    width: 4px;
    height: 1.4em;
    background: var(--accent);
    border-radius: 2px;
    flex-shrink: 0;
}

.page-head__actions { display: none; }

.page-head__actions--mobile-only { display: block; }

@media (min-width: 768px) {
    .section-title { font-size: 1.4rem; }
    .page-head__actions { display: block; }
    .page-head__actions--mobile-only { display: none; }
}

/* ---------- Onglets ---------- */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    background: var(--blanc);
    border-radius: var(--radius-sm);
    padding: 4px;
    box-shadow: var(--ombre);
    border: 1px solid var(--bord);
}

.tab {
    flex: 1;
    text-align: center;
    padding: 10px 12px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--texte-doux);
    font-weight: 600;
    font-size: .875rem;
    transition: background .15s ease, color .15s ease;
}

.tab:hover { text-decoration: none; color: var(--texte); background: var(--fond); }
.tab--active { background: var(--navy); color: var(--blanc); }
.tab--active:hover { color: var(--blanc); background: var(--navy-light); }

/* ---------- Liste procédures (style barres dashboard) ---------- */
.proc-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.proc-row {
    background: var(--bleu-bar);
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--ombre);
    transition: transform .12s ease, box-shadow .12s ease;
}

.proc-row--green { background: var(--vert-bar); }
.proc-row:hover { transform: translateY(-1px); box-shadow: var(--ombre-forte); }

.proc-row__inner {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
    color: var(--blanc);
}

@media (min-width: 600px) {
    .proc-row__inner {
        flex-direction: row;
        align-items: center;
        padding: 16px 20px;
    }
}

.proc-row__main {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.proc-row__icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.proc-row__thumb {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .2) center/cover no-repeat;
    flex-shrink: 0;
}

.proc-row__content { min-width: 0; flex: 1; }

.proc-row__title {
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.proc-row__meta {
    font-size: .8125rem;
    opacity: .85;
    margin-top: 2px;
}

.proc-row__badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.proc-row__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.proc-row__actions .btn {
    background: rgba(255, 255, 255, .95);
    color: var(--navy);
    border: none;
    font-size: .8125rem;
    padding: 8px 14px;
}

.proc-row__actions .btn:hover { background: #fff; filter: none; }
.proc-row--green .proc-row__actions .btn { color: var(--vert-bar); }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.badge--draft { background: rgba(255, 255, 255, .25); color: #fff; }
.badge--done { background: rgba(61, 186, 92, .35); color: #fff; }

.empty {
    text-align: center;
    color: var(--texte-doux);
    padding: 48px 20px;
    background: var(--blanc);
    border-radius: var(--radius);
    border: 2px dashed var(--bord);
    font-size: .9375rem;
}

/* ---------- Éditeur ---------- */
.editor-head {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
    background: var(--blanc);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--ombre);
    border: 1px solid var(--bord);
}

@media (min-width: 768px) {
    .editor-head {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }
}

.editor-head__title {
    flex: 1 1 100%;
    font-size: 1.15rem;
    font-weight: 700;
    padding: 10px 12px;
    border: 1px solid var(--bord);
    border-radius: var(--radius-sm);
}

@media (min-width: 768px) {
    .editor-head__title { flex: 1 1 240px; }
}

.editor-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

@media (min-width: 768px) {
    .editor-actions { width: auto; flex: 1 1 auto; justify-content: flex-end; }
}

.editor-actions .btn { flex: 1 1 auto; }

@media (min-width: 480px) {
    .editor-actions .btn { flex: 0 1 auto; }
}

.save-state { font-size: .8125rem; color: var(--texte-doux); min-height: 1.2em; width: 100%; }
.save-state--ok { color: var(--accent-dark); }
.save-state--saving { color: var(--bleu-bar); }
.save-state--error { color: var(--rouge); }

/* Zone de dépôt */
.dropzone {
    border: 2px dashed var(--bleu-bar);
    border-radius: var(--radius);
    background: var(--blanc);
    padding: 28px 16px;
    text-align: center;
    color: var(--texte-doux);
    margin-bottom: 20px;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease;
}

.dropzone:hover, .dropzone--over {
    background: #e8f0fa;
    border-color: var(--accent);
}

.dropzone__hint { font-size: .875rem; margin-top: 6px; }

/* Blocs */
.blocks { display: flex; flex-direction: column; gap: 0; }

.insert-row { display: flex; justify-content: center; padding: 6px 0; }
.insert-btn {
    border: 1px dashed var(--bord);
    background: var(--blanc);
    color: var(--bleu-bar);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
}
.insert-btn:hover { background: var(--fond); }

.insert-menu {
    display: none;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 8px;
}
.insert-menu--open { display: flex; }

.block {
    background: var(--blanc);
    border-radius: var(--radius);
    box-shadow: var(--ombre);
    padding: 14px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    border: 1px solid var(--bord);
}

@media (min-width: 720px) {
    .block--two { grid-template-columns: 1fr 1fr; }
}

.block__handle {
    cursor: grab;
    color: var(--texte-doux);
    user-select: none;
    font-size: 1.1rem;
    padding: 4px;
}

.block__head {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.block__title-input { flex: 1; padding: 8px 10px; font-weight: 600; }
.block__col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.block__photo {
    position: relative;
    background: var(--fond);
    border-radius: var(--radius-sm);
    overflow: hidden;
    min-height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.block__photo img { width: 100%; height: auto; display: block; cursor: pointer; }
.block__comment { width: 100%; min-height: 120px; resize: vertical; }

.photo-empty {
    width: 100%;
    min-height: 140px;
    border: 2px dashed var(--bord);
    border-radius: var(--radius-sm);
    background: var(--fond);
    color: var(--texte-doux);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 12px;
    font-size: .875rem;
}

.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.block--annotating {
    box-shadow: 0 0 0 3px rgba(30, 74, 140, .35);
}

/* ---------- Annotation inline (dans le bloc) ---------- */
.block--annotating .block__photo {
    min-height: 0;
    background: #1a1a1a;
}

.block--annotating .annot-stage {
    display: block;
    width: 100%;
}

.annot-stage {
    width: 100%;
    background: #1a1a1a;
    border-radius: var(--radius-sm);
    overflow: hidden;
    touch-action: none;
}

.annot-stage .canvas-container {
    margin: 0 auto !important;
    display: block !important;
}

.annot-tools {
    margin-top: 4px;
}

.annot-tools__bar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 10px;
    border: 1px solid var(--bord);
    border-radius: var(--radius-sm);
    align-items: center;
    background: var(--fond);
}

.annot-tools__sep {
    width: 1px;
    height: 28px;
    background: var(--bord);
    margin: 0 2px;
}

.tool {
    border: 1px solid var(--bord);
    background: var(--blanc);
    border-radius: var(--radius-sm);
    padding: 7px 11px;
    cursor: pointer;
    font-weight: 600;
    font-size: .8125rem;
    font-family: inherit;
}

.tool--active { background: var(--bleu-bar); color: #fff; border-color: var(--bleu-bar); }

.swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px var(--bord);
    cursor: pointer;
}

.swatch--active { box-shadow: 0 0 0 3px var(--bleu-bar); }

.sortable-ghost { opacity: .4; }
.sortable-chosen { box-shadow: 0 0 0 3px rgba(30, 74, 140, .25); }

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, .85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    font-weight: 600;
    color: var(--navy);
}

.overlay--open { display: flex; }

/* ---------- Page publique ---------- */
.public-page { background: var(--fond); min-height: 100vh; }

.public-topbar {
    background: var(--navy);
    color: var(--blanc);
    padding: 14px 16px;
    text-align: center;
    font-size: .875rem;
}

.public-head {
    text-align: center;
    margin-bottom: 24px;
    padding-top: 8px;
}

.public-head h1 {
    margin: 0 0 8px;
    font-size: 1.35rem;
    color: var(--navy);
}

.public-block {
    background: var(--blanc);
    border-radius: var(--radius);
    box-shadow: var(--ombre);
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--bord);
}

.public-block h2 {
    margin: 0 0 12px;
    font-size: 1.05rem;
    color: var(--bleu-bar);
}

.public-block__layout {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@media (min-width: 600px) {
    .public-block__layout--side { flex-direction: row; }
    .public-block__layout--side .public-block__photo { flex: 0 0 55%; }
    .public-block__layout--side .public-block__text { flex: 1; }
}

.public-block img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    display: block;
}

.hidden { display: none !important; }
