*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:       #0b1117;
    --surface:  #121b24;
    --surface2: #182431;
    --border:   #253545;
    --accent:   #0ea5e9;
    --accent-h: #38bdf8;
    --text:     #e7f0f7;
    --muted:    #8ba0b3;
    --green:    #22c55e;
    --orange:   #f59e0b;
    --red:      #ef4444;
    --violet:   #a78bfa;
    --radius:   12px;
    --p1: #ef4444; --p2: #f59e0b; --p3: #0ea5e9; --p4: #64748b;
}

body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; padding: 1.25rem; line-height: 1.45; }
a { color: var(--accent-h); }
.wrap { max-width: 1280px; margin: 0 auto; }
.wrap-narrow { max-width: 760px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.25rem; }
.card h2 { font-size: 1rem; margin-bottom: .9rem; }
h1 { font-size: 1.35rem; font-weight: 800; margin-bottom: .25rem; }
h3 { font-size: .9rem; margin-bottom: .5rem; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.hint { font-size: .78rem; color: var(--muted); margin-top: .35rem; }
.mb { margin-bottom: 1rem; }

/* ── En-tête ── */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.logo { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--text); }
.logo-text { font-size: 1.25rem; font-weight: 800; letter-spacing: -.4px; }
.logo-text span { color: var(--accent-h); }
.nav { display: flex; gap: .35rem; flex-wrap: wrap; }
.nav a { font-size: .85rem; color: var(--muted); text-decoration: none; padding: .45rem .8rem; border-radius: 8px; border: 1px solid transparent; }
.nav a:hover { color: var(--text); border-color: var(--border); }
.nav a.active { color: var(--accent-h); border-color: var(--accent); background: rgba(14,165,233,.08); }
.back-link { display: inline-flex; gap: .4rem; align-items: center; font-size: .8rem; color: var(--muted); text-decoration: none; margin-bottom: 1rem; }

/* ── Formulaires ── */
label, .label { display: block; font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .35rem; }
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=date], input[type=datetime-local], input[type=time], input[type=search], select, textarea {
    width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text);
    font-size: .95rem; padding: .6rem .8rem; font-family: inherit; outline: none; color-scheme: dark;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: .9rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .9rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 .9rem; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 .9rem; }
.inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline > input, .inline > select { flex: 1; min-width: 120px; width: auto; }
.check { display: inline-flex; align-items: center; gap: .4rem; font-size: .88rem; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text); margin: 0 .9rem .4rem 0; cursor: pointer; }
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }

/* ── Boutons ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem; background: var(--accent); color: #03141f;
    border: none; border-radius: 8px; font-size: .9rem; font-weight: 700; padding: .65rem 1.1rem; cursor: pointer;
    text-decoration: none; font-family: inherit; white-space: nowrap;
}
.btn:hover { background: var(--accent-h); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); }
.btn-danger { background: transparent; color: #fca5a5; border: 1px solid rgba(239,68,68,.45); }
.btn-danger:hover { background: rgba(239,68,68,.12); }
.btn-green { background: var(--green); color: #052e16; }
.btn-orange { background: var(--orange); color: #2a1700; }
.btn-sm { font-size: .8rem; padding: .4rem .75rem; }
.btn-xs { font-size: .72rem; padding: .25rem .5rem; border-radius: 6px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.btn-row form { margin: 0; }
form.inline-form { display: inline; }

.alert { border-radius: 8px; padding: .75rem 1rem; font-size: .875rem; margin-bottom: 1rem; display: flex; gap: .6rem; align-items: flex-start; }
.alert svg { flex-shrink: 0; margin-top: 2px; }
.alert-error   { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.3); color: #86efac; }
.alert-info    { background: rgba(14,165,233,.1); border: 1px solid rgba(14,165,233,.3); color: #7dd3fc; }
.alert-warn    { background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.35); color: #fcd34d; }

/* ── Pastilles ── */
.pill { display: inline-flex; align-items: center; gap: .3rem; font-size: .7rem; font-weight: 700; padding: .2rem .55rem; border-radius: 999px; white-space: nowrap; background: var(--surface2); color: var(--muted); }
.prio-1 { background: rgba(239,68,68,.18); color: #fca5a5; }
.prio-2 { background: rgba(245,158,11,.18); color: #fcd34d; }
.prio-3 { background: rgba(14,165,233,.16); color: #7dd3fc; }
.prio-4 { background: rgba(100,116,139,.2); color: #cbd5e1; }
.st-planifie { background: rgba(100,116,139,.2); color: #cbd5e1; }
.st-arrive { background: rgba(167,139,250,.18); color: #c4b5fd; }
.st-en_cours { background: rgba(14,165,233,.2); color: #7dd3fc; }
.st-en_attente { background: rgba(245,158,11,.2); color: #fcd34d; }
.st-termine { background: rgba(34,197,94,.18); color: #86efac; }
.st-restitue { background: rgba(34,197,94,.08); color: #6b9b7c; }
.st-annule { background: rgba(239,68,68,.1); color: #f87171; text-decoration: line-through; }

/* ── Mise en page accueil ── */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; align-items: start; }
.daynav { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.daynav h2 { margin: 0 .5rem 0 0; font-size: 1.05rem; text-transform: capitalize; }
.list { display: flex; flex-direction: column; gap: .5rem; }
.rdv-item {
    display: block; text-decoration: none; color: var(--text); background: var(--bg); border: 1px solid var(--border);
    border-left: 4px solid var(--p3); border-radius: 8px; padding: .6rem .75rem;
}
a.rdv-item:hover { border-color: var(--accent); }
.rdv-item.p1 { border-left-color: var(--p1); } .rdv-item.p2 { border-left-color: var(--p2); } .rdv-item.p4 { border-left-color: var(--p4); }
.rdv-item .t { font-weight: 700; font-size: .88rem; }
.rdv-item .m { font-size: .76rem; color: var(--muted); margin-top: .1rem; }
.rdv-item .pills { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .35rem; }
.empty { color: var(--muted); font-size: .85rem; text-align: center; padding: 1rem; border: 1px dashed var(--border); border-radius: 8px; }

/* ── Grille du planning ── */
.planning { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; background: var(--bg); }
.pl-axis { flex: 0 0 46px; position: relative; border-right: 1px solid var(--border); }
.pl-col { flex: 1 0 140px; border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.pl-col:last-child { border-right: none; }
.pl-head { height: 42px; padding: .4rem .5rem; font-size: .8rem; font-weight: 700; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--surface); display: flex; align-items: center; gap: .35rem; }
.pl-head .kind { font-size: .9rem; }
.pl-head.off { opacity: .5; }
.pl-body { position: relative; height: var(--pl-height, 620px); }
.pl-axis .pl-body { position: relative; }
.pl-hour { position: absolute; left: 0; right: 0; border-top: 1px dashed rgba(139,160,179,.18); font-size: .66rem; color: var(--muted); padding-left: .3rem; }
.pl-col .pl-hour { font-size: 0; }
.pl-closed { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(135deg, rgba(139,160,179,.06) 0 6px, transparent 6px 12px); }
.pl-now { position: absolute; left: 0; right: 0; border-top: 2px solid var(--red); z-index: 3; }
.pl-now::before { content: ''; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px; border-radius: 99px; background: var(--red); }
.pl-free { position: absolute; left: 0; right: 0; display: block; }
.pl-free:hover { background: rgba(14,165,233,.08); }
.bloc {
    position: absolute; left: 3px; right: 3px; border-radius: 6px; padding: .25rem .4rem; overflow: hidden; z-index: 2;
    font-size: .72rem; line-height: 1.25; text-decoration: none; color: var(--text); background: var(--surface2);
    border: 1px solid var(--border); border-left: 4px solid var(--p3); min-height: 18px;
}
a.bloc:hover { border-color: var(--accent); z-index: 4; }
.bloc.p1 { border-left-color: var(--p1); } .bloc.p2 { border-left-color: var(--p2); } .bloc.p4 { border-left-color: var(--p4); }
.bloc.s-en_cours { background: rgba(14,165,233,.22); }
.bloc.s-en_attente { background: rgba(245,158,11,.2); }
.bloc.s-termine, .bloc.s-restitue { background: rgba(34,197,94,.14); opacity: .75; }
.bloc.s-arrive { background: rgba(167,139,250,.18); }
.bloc.replan { outline: 2px dashed var(--orange); }
.bloc.forced::after { content: '⚠'; position: absolute; top: 2px; right: 4px; color: var(--orange); }
.bloc .bt { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bloc .bm { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bloc.indispo { background: repeating-linear-gradient(135deg, rgba(239,68,68,.16) 0 8px, rgba(239,68,68,.06) 8px 16px); border-left-color: var(--red); color: #fca5a5; }

/* ── Créneaux proposés ── */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .5rem; margin-bottom: 1rem; }
.slot {
    display: flex; gap: .55rem; align-items: flex-start; background: var(--bg); border: 2px solid var(--border); border-radius: 10px;
    padding: .6rem .7rem; cursor: pointer; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text); margin: 0; font-size: .85rem;
}
.slot:has(input:checked) { border-color: var(--accent); background: rgba(14,165,233,.08); }
.slot input { margin-top: .2rem; accent-color: var(--accent); }
.slot .when { font-weight: 800; text-transform: capitalize; }
.slot.prior { border-color: rgba(245,158,11,.5); }
.conflits { list-style: none; margin: .5rem 0; }
.conflits li { padding: .3rem 0; font-size: .85rem; border-bottom: 1px solid rgba(239,68,68,.15); }

/* ── Fiche RDV ── */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: .35rem .75rem; font-size: .9rem; }
.kv dt { color: var(--muted); font-size: .8rem; }
.desc { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .75rem; font-size: .92rem; }
.note { border-left: 3px solid var(--border); padding: .45rem .7rem; margin-bottom: .5rem; background: var(--bg); border-radius: 0 8px 8px 0; }
.note.recommandation { border-left-color: var(--orange); background: rgba(245,158,11,.07); }
.note.suivi { border-left-color: var(--border); opacity: .8; font-size: .85rem; }
.note .meta { font-size: .72rem; color: var(--muted); margin-bottom: .15rem; }
.note .txt { white-space: pre-wrap; }
.reco-box { background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.35); border-radius: 10px; padding: .9rem 1rem; margin-bottom: 1rem; }
.reco-box li { margin-left: 1.1rem; margin-bottom: .25rem; }
.files { display: flex; flex-wrap: wrap; gap: .5rem; }
.file { display: flex; align-items: center; gap: .5rem; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem; font-size: .82rem; text-decoration: none; color: var(--text); max-width: 100%; }
.file img { width: 44px; height: 44px; object-fit: cover; border-radius: 5px; }
.file .ico { font-size: 1.4rem; }
.zones { display: flex; flex-wrap: wrap; gap: .35rem; }
.car { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; max-width: 520px; margin-bottom: .75rem; }
.car .check { margin: 0; padding: .55rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.car .check:has(input:checked) { border-color: var(--red); background: rgba(239,68,68,.1); }

/* ── Dictée ── */
.dictate { position: relative; }
.mic { position: absolute; right: .5rem; bottom: .5rem; width: 46px; height: 46px; border-radius: 999px; border: none; cursor: pointer; background: var(--surface2); color: var(--text); font-size: 1.3rem; display: none; }
.mic.on { background: var(--red); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.6); } 50% { box-shadow: 0 0 0 10px rgba(239,68,68,0); } }
.dictate textarea { padding-right: 3.5rem; min-height: 110px; font-size: 1rem; }

/* ── Tablette ── */
.tab-body { font-size: 1.02rem; }
.tab-body .btn { font-size: 1rem; padding: .85rem 1.2rem; }
.tab-job { display: block; text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-left: 6px solid var(--p3); border-radius: 12px; padding: 1rem 1.1rem; margin-bottom: .7rem; }
.tab-job.p1 { border-left-color: var(--p1); } .tab-job.p2 { border-left-color: var(--p2); } .tab-job.p4 { border-left-color: var(--p4); }
.tab-job .t { font-size: 1.1rem; font-weight: 800; }
.tab-job .m { color: var(--muted); font-size: .9rem; margin-top: .15rem; }
.tab-job .pills { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .5rem; }
.tab-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.tab-actions .btn { width: 100%; padding: 1.1rem; font-size: 1.05rem; }

/* ── Écran d'atelier ── */
body.ecran { padding: .8rem 1rem; overflow: hidden; }
.ecran-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.ecran-head h1 { font-size: 1.6rem; }
.clock { font-size: 2.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.ecran-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1rem; height: calc(100vh - 90px); }
.ecran .planning { height: 100%; }
.ecran .pl-col { min-width: 160px; }
.ecran .pl-head { font-size: 1rem; height: 48px; }
.ecran .pl-body { height: calc(100vh - 90px - 50px); }
.ecran .bloc { font-size: .92rem; padding: .3rem .5rem; }
.ecran .bloc .bt { font-size: 1rem; }
.ecran-side { overflow: hidden; display: flex; flex-direction: column; gap: .6rem; }
.ecran-side h2 { font-size: 1.05rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ecran-side .rdv-item .t { font-size: 1.05rem; }
.ecran-side .rdv-item .m { font-size: .9rem; }
.stale { position: fixed; bottom: .5rem; right: .8rem; font-size: .8rem; color: var(--orange); display: none; }
.stale.show { display: block; }

footer { margin-top: 1.5rem; font-size: .78rem; color: var(--muted); text-align: center; }

@media (max-width: 1000px) { .layout, .ecran-grid { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
    body { padding: .7rem; }
    .card { padding: 1.1rem; }
    .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
    .kv { grid-template-columns: 1fr; }
    .car { grid-template-columns: repeat(2, 1fr); }
}

/* ── Impression de la fiche de restitution ── */
@media print {
    :root { --bg: #fff; --surface: #fff; --surface2: #f3f4f6; --border: #d1d5db; --text: #111; --muted: #555; }
    body { padding: 0; background: #fff; color: #111; }
    .no-print { display: none !important; }
    .card { border: none; padding: 0; }
    .reco-box { border-color: #f59e0b; }
}
