:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1b2733;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f5c8c;
  --brand-ink: #ffffff;
  --accent: #d97706;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --radius: 12px;
}

* { box-sizing: border-box; }
/* The [hidden] attribute must win over author display rules (.btn/.cta set display). */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

header.topbar {
  background: var(--brand);
  color: var(--brand-ink);
  padding: .6rem 1rem;
  position: sticky; top: 0; z-index: 10;
}
header.topbar .bar {
  max-width: 960px; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
header.topbar a { color: var(--brand-ink); }
.brand { font-weight: 800; font-size: 1.15rem; letter-spacing: .5px; }
.brand small { font-weight: 500; opacity: .8; font-size: .7rem; display: block; }
header.topbar nav { display: flex; gap: .9rem; flex-wrap: wrap; align-items: center; }
header.topbar nav a { opacity: .9; }
header.topbar nav a.active { text-decoration: underline; opacity: 1; font-weight: 700; }
.spacer { flex: 1; }
.who { opacity: .85; font-size: .85rem; }

main { max-width: 960px; margin: 1.2rem auto; padding: 0 1rem 3rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1.1rem;
}
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 0 0 .8rem; }
h3 { font-size: 1rem; margin: 1rem 0 .3rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

label { display: block; font-weight: 600; margin: .8rem 0 .3rem; }
input, select, textarea {
  width: 100%; padding: .7rem .8rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: .8rem; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

.btn {
  display: inline-block; padding: .75rem 1.1rem; font-size: 1rem; font-weight: 700;
  border: none; border-radius: 10px; cursor: pointer;
  background: var(--brand); color: #fff;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.big { width: 100%; padding: 1rem; font-size: 1.1rem; }
.btn.ghost { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.btn.warn { background: var(--accent); }
.btn.grey { background: #64748b; }
.btn.danger { background: var(--danger); }
.btn.sm { padding: .4rem .7rem; font-size: .85rem; }

.flash { padding: .7rem .9rem; border-radius: 10px; margin-bottom: 1rem; }
.flash.err { background: #fee2e2; color: var(--danger); }
.flash.ok { background: #dcfce7; color: var(--ok); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block; padding: .15rem .55rem; border-radius: 999px;
  font-size: .75rem; font-weight: 700;
}
.badge.maintenance { background: #dbeafe; color: #1e40af; }
.badge.depannage { background: #ffedd5; color: #9a3412; }
.badge.autre { background: #e2e8f0; color: #475569; }
.badge.en_fonction { background: #dcfce7; color: var(--ok); }
.badge.en_panne { background: #fee2e2; color: var(--danger); }
.badge.en_arret { background: #e2e8f0; color: #475569; }
.badge.termine { background: #e0e7ff; color: #3730a3; }
.badge.rev { background: #dcfce7; color: var(--ok); }

.thumbs { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }
.thumbs a img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

.ai {
  background: #f0f9ff; border: 1px solid #bae6fd; border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.ai h3 { color: var(--brand); }
.ai ul { margin: .3rem 0 .3rem 1.1rem; }
.ai .q { margin: .25rem 0; }
.synthese { white-space: pre-wrap; }

.login-wrap { max-width: 380px; margin: 8vh auto; }

.canvas-wrap { border: 1px dashed var(--line); border-radius: 10px; padding: .5rem; background: #fff; }
#sketch { width: 100%; height: 260px; touch-action: none; border-radius: 8px; background: #fff; display: block; }
.canvas-tools { display: flex; gap: .5rem; margin-top: .5rem; }

.list-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline-form { display: inline; margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

/* --- Icons --- */
.ico { width: 1.05em; height: 1.05em; vertical-align: -.16em; flex: none; }
h1 .ico, h2 .ico { vertical-align: -.1em; margin-right: .35rem; color: var(--brand); }
.btn .ico { margin-right: .35rem; }
.icon-btn { display: inline-flex; align-items: center; }
.icon-btn .ico { margin: 0; }

/* --- Brand / logo (white artwork sits directly on the blue bar) --- */
.brand { display: flex; align-items: center; }
.brand img { height: 57px; display: block; }

/* --- Nav links with glyphs --- */
header.topbar nav a { display: inline-flex; align-items: center; gap: .3rem; }

/* --- Ask EmisIA button + usage bar --- */
.emisia-nav { display: flex; flex-direction: column; gap: 3px; align-items: stretch; min-width: 132px; }
.btn-emisia {
  display: inline-flex; align-items: center; gap: .35rem; justify-content: center;
  background: var(--accent); color: #fff; font-weight: 800; font-size: .9rem;
  padding: .45rem .8rem; border-radius: 999px; border: 1px solid rgba(255,255,255,.3);
}
.btn-emisia:hover { filter: brightness(1.08); text-decoration: none; }
.btn-emisia.on { box-shadow: 0 0 0 2px rgba(255,255,255,.5); }
.usage { padding: 0 2px; }
.usage-track { height: 6px; border-radius: 999px; background: rgba(255,255,255,.35); overflow: hidden; }
.usage-fill { height: 100%; border-radius: 999px; transition: width .3s; }
.usage-fill.green { background: #34d399; }
.usage-fill.amber { background: #fbbf24; }
.usage-fill.red { background: #f87171; }
.usage-legend { display: flex; align-items: center; gap: .5rem; }
.usage-legend .usage-track { flex: 1; height: 10px; }

/* --- CTA (big + Rapport) --- */
.cta {
  display: flex; align-items: center; gap: .6rem; justify-content: center;
  width: 100%; padding: 1.1rem; font-size: 1.15rem; font-weight: 800;
  background: linear-gradient(135deg, var(--brand), #1477b8); color: #fff;
  border: none; border-radius: var(--radius); cursor: pointer;
}
.cta:hover { filter: brightness(1.06); text-decoration: none; }
.cta .ico { width: 1.3em; height: 1.3em; margin: 0; }

/* --- Filter bar --- */
.filterbar { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: 1.1rem; }
.filterbar .row > * { min-width: 120px; }
.sortlink { display: inline-flex; align-items: center; gap: .2rem; color: var(--brand); }
select[multiple] { min-height: 108px; }

/* --- Sketch tabs --- */
.tabbar { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-bottom: .5rem; }
.tab { padding: .35rem .8rem; border: 1px solid var(--line); border-radius: 8px 8px 0 0; background: #f1f5f9; cursor: pointer; font-weight: 600; }
.tab.active { background: #fff; border-bottom-color: #fff; color: var(--brand); }
.tab-add { border-style: dashed; color: var(--brand); }
.sheet { display: none; }
.sheet.active { display: block; }

/* --- Attachment thumbs / file chips --- */
.file-chip { display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.att-item { position: relative; }
.att-del { position: absolute; top: -8px; right: -8px; background: var(--danger); color: #fff; border: none; border-radius: 999px; width: 22px; height: 22px; cursor: pointer; font-weight: 700; line-height: 1; }
.previews { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.previews img { width: 90px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

/* --- EmisIA loader overlay (hidden by default; shown via .on) --- */
.loader-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: none; align-items: center; justify-content: center; z-index: 100; }
.loader-overlay.on { display: flex; }
.loader-box { background: #fff; padding: 1.6rem 2rem; border-radius: var(--radius); text-align: center; }
.loader-box p { margin: .8rem 0 0; font-weight: 700; color: var(--brand); }
.spinner { width: 42px; height: 42px; margin: 0 auto; border: 4px solid #e2e8f0; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.table-wrap { overflow-x: auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }

/* --- Footer (user identity + logout) --- */
.site-footer { border-top: 1px solid var(--line); background: var(--card); margin-top: 2rem; }
.site-footer .foot { max-width: 960px; margin: 0 auto; padding: .8rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.site-footer .who { color: var(--muted); display: inline-flex; align-items: center; gap: .35rem; }

/* --- Global search (home + results page) --- */
.home-bar { display: flex; gap: .6rem; align-items: stretch; margin: 0 0 1.1rem; flex-wrap: wrap; }
.home-search { display: flex; gap: .6rem; flex: 1; min-width: 260px; }
.home-search input { flex: 1; padding: .95rem 1.1rem; font-size: 1.1rem; border-radius: 999px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.home-search .btn { border-radius: 999px; padding-left: 1.2rem; padding-right: 1.2rem; }
.btn-new { border-radius: 999px; display: inline-flex; align-items: center; white-space: nowrap; }
.btn.green { background: var(--ok); color: #fff; }
.btn.green:hover { filter: brightness(1.08); }
.searchbar { display: flex; gap: .6rem; margin-bottom: 1rem; }
.searchbar input { flex: 1; padding: .8rem 1rem; font-size: 1.05rem; border-radius: 10px; }

/* --- Row actions + per-row export menu --- */
.row-actions { display: flex; gap: .35rem; align-items: center; }
.exp-menu { position: relative; display: inline-block; }
.exp-menu > summary { list-style: none; cursor: pointer; }
.exp-menu > summary::-webkit-details-marker { display: none; }
.exp-pop { position: absolute; right: 0; z-index: 5; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.12); min-width: 90px; padding: .25rem; }
.exp-pop a { display: block; padding: .4rem .6rem; border-radius: 6px; }
.exp-pop a:hover { background: #f1f5f9; text-decoration: none; }

/* --- Footer version --- */
.foot-version { flex: 1; text-align: center; }
.typing-status { vertical-align: middle; }

/* --- Report list: stacked chips under the date --- */
.date-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.date-cell .date-d { font-weight: 600; white-space: nowrap; }
.date-cell .badge { display: inline-flex; align-items: center; }

/* --- Consommation big bar (settings) --- */
.usage-big { margin-top: .4rem; }
.usage-track.big { height: 18px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.usage-figures { display: flex; align-items: baseline; gap: .8rem; margin-top: .5rem; flex-wrap: wrap; }
.usage-pct { font-size: 1.6rem; font-weight: 800; }

/* --- Complément EmisIA card (distinct, accent-framed) --- */
.complement-card { border-left: 4px solid var(--accent); background: #fffaf2; }
.complement-card h3 { color: var(--accent); margin-top: 0; }

/* --- Analyse des images (collapsed card) --- */
.images-card > summary { cursor: pointer; font-weight: 700; color: var(--brand); list-style: none; display: flex; align-items: center; gap: .4rem; }
.images-card > summary::-webkit-details-marker { display: none; }
.images-card > summary::after { content: "▸"; margin-left: auto; color: var(--muted); }
.images-card[open] > summary::after { content: "▾"; }

/* --- Lightbox --- */
.lightbox { position: fixed; inset: 0; background: rgba(10,15,25,.9); display: flex; align-items: center; justify-content: center; z-index: 200; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 92vw; max-height: 90vh; border-radius: 8px; box-shadow: 0 8px 40px rgba(0,0,0,.5); }
.lb-close { position: absolute; top: 14px; right: 20px; width: 44px; height: 44px; border: none; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; font-size: 1.8rem; line-height: 1; cursor: pointer; }
.lb-close:hover { background: rgba(255,255,255,.3); }

/* --- Ask EmisIA chat --- */
.chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-log { display: flex; flex-direction: column; gap: .6rem; padding: 1rem; overflow-y: auto; height: 58vh; min-height: 320px; background: #f8fafc; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.bot { justify-content: flex-start; }
.msg .bubble { max-width: 80%; padding: .6rem .85rem; border-radius: 14px; line-height: 1.45; }
.msg.user .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot .bubble p { margin: 0 0 .5rem; }
.msg.bot .bubble p:last-child { margin-bottom: 0; }
.msg.bot .bubble ul { margin: .3rem 0 .3rem 1.1rem; }
.chat-input { display: flex; gap: .5rem; align-items: flex-end; padding: .7rem; border-top: 1px solid var(--line); background: #fff; }
.chat-input textarea { flex: 1; resize: none; min-height: 44px; max-height: 140px; }
.deep-toggle { font-weight: 400; font-size: .85rem; color: var(--muted); display: inline-flex; align-items: center; gap: .25rem; white-space: nowrap; margin: 0; }
.deep-toggle input { width: auto; }
.bubble.typing { display: inline-flex; gap: 4px; align-items: center; }
.bubble.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .5; animation: blink 1.2s infinite; }
.bubble.typing span:nth-child(2) { animation-delay: .2s; }
.bubble.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .25; } 30% { opacity: .9; } }

/* --- Rendered markdown (EmisIA output) --- */
.synthese p { margin: 0 0 .6rem; }
.synthese p:last-child { margin-bottom: 0; }
.synthese ul { margin: .3rem 0 .6rem 1.1rem; }
.synthese li { margin: .15rem 0; }
.synthese code { background: #eef2f7; padding: .05rem .3rem; border-radius: 4px; font-family: ui-monospace, monospace; font-size: .9em; }
.q code { background: #eef2f7; padding: .05rem .3rem; border-radius: 4px; }

/* --- Report creation wizard --- */
.wizard-progress { height: 6px; background: #e2e8f0; border-radius: 4px; overflow: hidden; margin-bottom: 1rem; }
.wizard-bar { height: 100%; width: 0; background: var(--brand); transition: width .25s ease; }
.wizard-step h2 { margin-top: 0; }
.chip-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.chip { border: 1px solid var(--brand); background: #fff; color: var(--brand); border-radius: 999px; padding: .35rem .9rem; cursor: pointer; font-size: .95rem; }
.chip.on, .chip:hover { background: var(--brand); color: #fff; }
.pick-list { display: flex; flex-direction: column; gap: .5rem; margin: .4rem 0; }
.pick { display: flex; align-items: center; gap: .6rem; border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem; cursor: pointer; }
.pick:hover { border-color: var(--brand); background: #f5f9fc; }
.pick input { width: 1.1rem; height: 1.1rem; flex: none; }
.wizard-nav { display: flex; align-items: center; gap: .6rem; margin-top: 1rem; }
.wizard-err { margin-top: .6rem; }
.review { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 1rem; }
.review-row { display: flex; gap: .8rem; padding: .5rem .8rem; border-bottom: 1px solid var(--line); }
.review-row:last-child { border-bottom: none; }
.review-k { flex: 0 0 40%; color: #64748b; font-size: .9rem; }
.review-v { flex: 1; font-weight: 600; white-space: pre-wrap; }

/* --- Wizard client combobox (type-to-filter dropdown) --- */
.combo { position: relative; }
.combo-list { list-style: none; margin: .2rem 0 0; padding: .25rem; position: absolute; z-index: 20; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(15,23,42,.12); max-height: 260px; overflow-y: auto; }
.combo-item { padding: .6rem .7rem; border-radius: 8px; cursor: pointer; }
.combo-item:hover { background: #f5f9fc; }
.chosen { color: var(--ok); font-weight: 600; margin-top: .5rem; }

/* --- Photo analysis coverage (which photos EmisIA considered) --- */
.thumb { position: relative; display: inline-block; }
.thumb-skipped img { filter: grayscale(1); opacity: .45; }
.thumb-tag { position: absolute; left: 6px; bottom: 6px; background: rgba(15,23,42,.82); color: #fff; font-size: .7rem; font-weight: 700; padding: .1rem .45rem; border-radius: 6px; pointer-events: none; }
