/* Apparence reprise de l'application de bureau (app/ui/theme.py). */
:root {
  --teal: #159ca6;
  --teal-dark: #0e6f77;
  --teal-hover: #0e8a93;
  --header-bg: #12333a;
  --bg: #f4f7f9;
  --text: #1f2d33;
  --muted: #5b6b73;
  --border: #d5dee2;
  --group-border: #cfe3e6;
  --input-bg: #eaf5fc;
  --input-border: #9fc9e2;
  --computed-bg: #fdece3;
  --computed-border: #e8c7ae;
  --computed-text: #6b4a37;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, Arial, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100vh; }
#window { flex: 1; display: flex; min-height: 0; }

/* ------------------------------------------------------------ barre de menus */
#menubar { background: white; border-bottom: 1px solid var(--border); padding: 0 4px; display: flex; }
.menu { position: relative; }
#menu-file { background: none; border: 0; border-radius: 0; padding: 4px 10px; }
#menu-file:hover { background: #e5f1f3; }
.menu-pop { position: absolute; top: 100%; left: 0; z-index: 40; background: white; border: 1px solid #b9c4c8;
            box-shadow: 0 4px 14px rgba(0,0,0,.15); min-width: 280px; padding: 3px 0; }
.menu-pop button { display: flex; justify-content: space-between; gap: 24px; width: 100%; text-align: left; background: none;
                   border: 0; border-radius: 0; padding: 6px 18px; }
.menu-pop button:hover { background: #e5f1f3; }
.shortcut { color: var(--muted); }
#statusbar { background: white; border-top: 1px solid var(--border); min-height: 22px; padding: 2px 10px; font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------ barre latérale */
#sidebar { width: 230px; flex: none; background: var(--header-bg); display: flex; flex-direction: column; }
#sidebar .logo { background: white; padding: 14px; text-align: center; }
#sidebar .logo img { width: 160px; display: block; margin: 0 auto; }
#side-list { padding: 8px 0; overflow-y: auto; flex: 1; }
.side-item { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 0;
             border-left: 4px solid transparent; color: #d7ecee; padding: 9px 16px; cursor: pointer; }
.side-item:hover:not(:disabled) { background: #1b4a53; }
.side-item.current { background: #1f5b66; color: white; font-weight: 700; border-left-color: #5fd3dc; }
.side-item.module { font-weight: 700; }
.side-item:disabled { color: #6f8f95; cursor: default; background: none; }

/* ------------------------------------------------------------ zone principale */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#top-bar { background: white; border-bottom: 1px solid var(--border); padding: 0 14px; display: flex; gap: 2px; flex-wrap: wrap; }
.top-tab { background: transparent; border: 0; border-bottom: 3px solid transparent; border-radius: 0; padding: 12px 18px;
           font-weight: 600; color: var(--muted); cursor: pointer; }
.top-tab:hover:not(:disabled) { background: #eef6f7; }
.top-tab.current { color: var(--teal-dark); border-bottom-color: var(--teal); }
.top-tab:disabled { color: #b9c4c8; cursor: default; background: transparent; }
#page { flex: 1; overflow: auto; padding: 12px 22px 24px 20px; }
.page-title { font-size: 22px; font-weight: 700; color: var(--teal-dark); margin: 0 0 2px; }
.page-sub { color: var(--muted); margin: 0 0 8px; white-space: pre-line; }
.page-body > .page-sub { margin-bottom: 10px; }
#footer { display: flex; align-items: center; gap: 16px; background: white; border-top: 1px solid var(--border); padding: 10px 20px; }
#legend { flex: 1; text-align: center; color: var(--muted); font-size: 12px; white-space: pre; }
#step { color: var(--text); }

/* ------------------------------------------------------------ boutons */
button { background: white; border: 1px solid #9fb3bb; border-radius: 6px; padding: 6px 16px; cursor: pointer; }
button:hover:not(:disabled) { background: #eef6f7; }
button:disabled { color: #a0aeb4; background: #f1f3f4; cursor: default; }
button.primary { background: var(--teal); color: white; border-color: var(--teal-dark); font-weight: 700; }
button.primary:hover:not(:disabled) { background: var(--teal-hover); }
button.primary:disabled { background: #a9d3d6; border-color: #a9d3d6; }
button.danger { color: #b00020; border-color: #b00020; }
.upload-btn { background: white; border: 1px solid var(--teal-dark); color: var(--teal-dark); font-weight: 700; padding: 4px 8px; min-width: 110px; }
.upload-btn:hover:not(:disabled) { background: var(--teal-dark); color: white; }
.upload-btn:active { background: var(--header-bg); border-color: var(--header-bg); color: white; }

/* ------------------------------------------------------------ cadres (QGroupBox) */
fieldset.group { background: white; border: 1px solid var(--group-border); border-radius: 8px; padding: 8px 10px 8px; margin: 6px 0;
                 min-width: 0; }
fieldset.group > legend { color: var(--teal-dark); font-weight: 700; font-size: 15px; padding: 0 6px; margin-left: 6px; }
fieldset.group.fixed { display: inline-block; vertical-align: top; }
fieldset.group.fill { height: 100%; display: flex; flex-direction: column; }
fieldset.group.fill textarea { flex: 1; min-height: 320px; }

/* ------------------------------------------------------------ champs */
input[type=text], input[type=number], input[type=password], input[type=search], textarea, select {
  background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 5px; padding: 3px 6px; }
input:focus, textarea:focus, select:focus { outline: none; border: 2px solid var(--teal); padding: 2px 5px; }
input.spin { width: 84px; text-align: center; }
input.spin.pct { width: 90px; }
input.computed, input[readonly], input:disabled, textarea:disabled, select:disabled {
  background: var(--computed-bg); border: 1px solid var(--computed-border); color: var(--computed-text); font-weight: 700; }
input.computed:focus { border: 1px solid var(--computed-border); padding: 3px 6px; }
input.spin.error { background: #fdecea; border-color: #e53935; }
textarea { width: 100%; resize: vertical; }
textarea.comment { min-height: 160px; }
textarea.mail-text { min-height: 220px; margin-top: 8px; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; margin: 0; accent-color: var(--teal); cursor: pointer; }
label.check { display: inline-flex; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; margin-right: 14px; }
fieldset.group > label.check, .vcol > label.check { display: flex; }
label.check.disabled { color: #a0aeb4; cursor: default; }
.qualif { display: flex; gap: 30px; }
.qualif label.check { gap: 14px; }
.qualif input[type=checkbox] { width: 18px; height: 18px; }
.radio-row { display: flex; flex-wrap: wrap; gap: 4px 8px; }
.indent { padding-left: 26px; }
.flag { width: 28px; height: 28px; object-fit: contain; }

/* ------------------------------------------------------------ mise en page */
.hrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hrow.top { align-items: flex-start; }
.hrow.fill { align-items: stretch; }
.hrow.nowrap { flex-wrap: nowrap; }
.hrow.stretch { align-items: stretch; flex-wrap: nowrap; }
.hrow.gap40 { gap: 40px; }
.hrow.gap16 { gap: 16px; }
.hrow.gap76 { gap: 76px; }
.hrow > fieldset.group { margin: 6px 0; }
.vcol { display: flex; flex-direction: column; gap: 4px; }
.grow { flex: 1; min-width: 0; }
.hspace { display: inline-block; flex: none; }
.center { text-align: center; }
.bold { font-weight: 700; }
.pre { white-space: pre-line; }
.nowrap { white-space: nowrap; }
.cols { display: flex; gap: 18px; align-items: stretch; }
.cols > .col-3 { flex: 3; min-width: 0; }
.cols > .col-2 { flex: 2; min-width: 0; }
.cols > .col-1 { flex: 1; min-width: 0; }
.red-note { color: #c0392b; font-style: italic; margin: 2px 0 6px; }

.form { display: grid; grid-template-columns: max-content max-content; gap: 4px 10px; align-items: center; }
.form > label { white-space: pre-line; }
.form.right > label { text-align: right; }
.form.right { grid-template-columns: max-content minmax(0, 1fr); }
.form.right input[type=text] { width: 100%; min-width: 220px; }
.form-span { grid-column: 1 / -1; }
.form-field { display: flex; align-items: center; }
.narrow-check { display: inline-flex; justify-content: center; width: 60px; }

.banner { border-radius: 6px; padding: 8px 10px; margin: 6px 0; white-space: pre-line; }
.banner.info { background: #e3f2fd; border: 1px solid #90caf9; }
.banner.warn { background: #fff4e0; border: 1px solid #ffb74d; }
.banner.error { background: #fdecea; border: 1px solid #ef9a9a; }
.banner.ok { background: #e8f5e9; border: 1px solid #a5d6a7; }

/* ------------------------------------------------------------ cartes produit */
.card-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.card { background: white; border: 1px solid var(--border); border-radius: 8px; padding: 6px; display: flex; flex-direction: column;
        gap: 3px; flex: none; }
.card.clickable { cursor: pointer; }
.card.selected { border: 2px solid var(--teal); background: #e9f6f7; padding: 5px; }
.card.disabled { background: #eef0f1; cursor: default; }
/* Titre compact : 2 lignes réservées au minimum (titres courts sans grand vide sous le texte), qui
   s'agrandit si le libellé est plus long. */
.card-title { font-weight: 600; font-size: 12.2px; text-align: center; white-space: pre-line; min-height: 2.2em; line-height: 1.1em;
              display: flex; align-items: flex-start; justify-content: center; }
.card-pic { display: flex; align-items: center; justify-content: center; }
.card-pic img { object-fit: contain; }
.card-pic .missing { color: var(--muted); font-size: 12px; }
.card-img-row { display: flex; align-items: center; justify-content: center; gap: 4px; }
.card-choice { justify-content: center; margin: 0; }
.card-qty { display: flex; justify-content: center; }
.card-extra { align-items: flex-start; font-size: 13px; }
.card-extra label.check { margin: 0; }
.san-side { align-self: center; margin-left: 6px; }
.san-side label.check { margin-right: 8px; }
.rep-grid { display: grid; grid-template-columns: max-content max-content; column-gap: 8px; row-gap: 0; align-items: center; }
.disabled-block > legend, .disabled-block .card-title, .disabled-block label.check { color: #a0aeb4; }
.disabled-block img { opacity: .5; }
.qg-img { text-align: center; margin-bottom: 4px; }
.qg-img img { object-fit: contain; }

/* ------------------------------------------------------------ onglets (QTabWidget) */
.tab-widget { margin-top: 6px; }
.tabs-bar { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid #b9c4c8; }
.tab { background: #e9eef0; border: 1px solid #b9c4c8; border-bottom: 0; border-radius: 6px 6px 0 0; padding: 5px 14px; margin-bottom: -1px; }
.tab.current { background: white; font-weight: 600; color: var(--teal-dark); border-bottom: 1px solid white; }
.tab-panes { border: 1px solid #b9c4c8; border-top: 0; background: var(--bg); padding: 10px 12px; }
.tab-widget.inner .tab-panes { background: var(--bg); }

/* ------------------------------------------------------------ pages particulières */
.direct-cards { display: flex; flex-wrap: wrap; gap: 16px; }
.direct-card { min-width: 190px; min-height: 90px; background: var(--teal-dark); border: 2px solid var(--header-bg); border-radius: 12px;
               color: white; font-weight: 700; font-size: 15px; padding: 12px; white-space: pre-line; }
.direct-card:hover:not(:disabled) { background: #0a565c; }
.direct-card:active { background: var(--header-bg); }
.questions-label { font-weight: 700; font-size: 15px; margin: 6px 0; }
.result-row { margin-top: 6px; }
.result-row .banner { margin: 0; }
.result-row .others { margin-top: 4px; }
.result-row a { color: var(--teal-dark); }
fieldset.group .banner.grow { margin: 0; }
.reco-reason { margin-top: 6px; font-style: italic; }
fieldset.group > .others { margin-top: 4px; }
fieldset.group > .others a { color: var(--teal-dark); }

.reset-unite { width: 158px; height: 150px; padding: 0; background: #0e6f77; border: 2px solid #12333a; border-radius: 8px; flex: none; }
.reset-unite:hover:not(:disabled) { background: #0a565c; }
.reset-unite:active { background: #12333a; }
.reset-unite img { width: 130px; height: 122px; object-fit: contain; }
.reset-unite.reset-small { width: 34px; height: 32px; border-radius: 5px; }
.reset-unite.reset-small img { width: 28px; height: 26px; }
.qualif { align-items: center; }
.ugrid { display: grid; grid-template-columns: max-content max-content; column-gap: 76px; row-gap: 6px; align-items: start; }
.ugrid .span2 { grid-column: 1 / -1; }
.rack label.check { display: flex; margin: 0; }
.mob-section { display: flex; flex-direction: column; gap: 4px; }
.mob-section > .banner { font-weight: 700; }

.arch-view { overflow: auto; min-height: 520px; max-height: 70vh; background: white; border: 1px solid var(--group-border); }
.arch-scene { position: relative; display: inline-block; }
.arch-bg { display: block; user-select: none; }
.arch-links { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
.arch-links line { stroke: #c0392b; stroke-width: 2; stroke-dasharray: 8 4; }
.chip { position: absolute; z-index: 10; cursor: grab; user-select: none; touch-action: none; }
.chip:active { cursor: grabbing; }
.chip.source .chip-img { outline: 2px solid #c0392b; }
.chip-img { width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; }
.chip-img img { max-width: 56px; max-height: 56px; }
.chip-label { position: absolute; top: 58px; left: -12px; white-space: nowrap; font-size: 10.5px; font-weight: 700; color: #1c2b4a; }

/* ------------------------------------------------------------ tableaux */
.table-wrap { overflow: auto; border: 1px solid var(--group-border); border-radius: 6px; background: white; }
.table-wrap.projects { max-height: 378px; }
.table-wrap.tall { min-height: 420px; max-height: 65vh; }
.table-wrap.devis { min-height: 360px; max-height: 60vh; }
.spare { padding: 0 20px; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid.fit { width: auto; }
table.grid th { background: var(--teal-dark); color: white; padding: 6px; font-weight: 600; text-align: left; border-bottom: 5px solid white;
                position: sticky; top: 0; z-index: 1; }
table.grid td { padding: 4px 6px; border-top: 1px solid #e0e8ea; border-right: 1px solid #e0e8ea; vertical-align: middle; }
table.grid tbody tr:nth-child(even) td { background: #f3f9fa; }
table.grid .num { text-align: center; white-space: nowrap; }
table.grid tr.chapter td { background: var(--teal-dark) !important; color: white; font-weight: 700; font-size: 15px; }
table.grid tr.subtotal td { background: #eaf5f6 !important; font-weight: 700; }
table.grid tr.check td { background: #fff4d6 !important; }
table.grid tr.missing td { background: #fdecea !important; }
table.grid th.sortable { cursor: pointer; user-select: none; }
table.projects th { background: var(--header-bg); }
.tiles { display: flex; gap: 14px; margin: 6px 0; }
.tile { flex: 1; background: white; border: 1px solid var(--border); border-radius: 8px; padding: 14px; text-align: center; font-size: 15px; min-height: 70px; }
.tile strong { display: block; font-weight: 400; }
.devis-head { display: flex; justify-content: flex-end; }
.devis-head img { width: 140px; }
.button-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.legend-small { color: var(--muted); font-size: 12px; margin: 6px 0; }

/* ------------------------------------------------------------ fenêtres */
.backdrop { position: fixed; inset: 0; background: rgba(18, 51, 58, .35); display: flex; align-items: center; justify-content: center;
            z-index: 50; padding: 16px; }
.modal { background: white; border-radius: 8px; max-width: 620px; width: 100%; padding: 16px 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal h2 { margin: 0 0 10px; font-size: 16px; }
.modal .body { white-space: pre-line; max-height: 60vh; overflow: auto; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal input[type=text] { width: 100%; }
.license-screen { max-width: 560px; margin: 60px auto; }

/* ------------------------------------------------------------ connexion */
#menubar { align-items: center; }
#user-name { padding: 0 10px; color: var(--muted); font-size: 13px; }
#pending-bell { margin-left: auto; }
#pending-bell[hidden] + #user-name { margin-left: auto; }
.bell { background: #fff4e0; border: 1px solid #ffb74d; color: #8a4b00; font-weight: 700; padding: 2px 12px; border-radius: 12px; font-size: 13px; }
.bell:hover:not(:disabled) { background: #ffe8c2; }
.logout-btn { padding: 2px 12px; font-size: 13px; margin: 3px 6px 3px 0; }
.login-alt { margin: 4px 0 0; text-align: center; font-size: 13px; color: var(--muted); }
.login-link { color: var(--teal-dark); font-weight: 600; background: none; border: 0; padding: 0; text-decoration: underline; }
.login-link:hover:not(:disabled) { background: none; color: var(--teal-hover); }
.login-notice { background: #e8f5e9; border: 1px solid #a5d6a7; border-radius: 6px; padding: 8px 10px; font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-field textarea { padding: 8px 10px; font-weight: 400; font-size: 14px; }
.users-h3 { margin: 14px 0 4px; font-size: 15px; color: var(--teal-dark); }
.users-modal { max-height: 92vh; overflow: auto; }
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px;
                background: linear-gradient(160deg, var(--header-bg) 0%, #1f5b66 55%, var(--teal-dark) 100%); }
.login-card { width: 100%; max-width: 400px; background: white; border-radius: 12px; padding: 32px 32px 28px;
              box-shadow: 0 18px 50px rgba(0, 0, 0, .3); display: flex; flex-direction: column; gap: 14px; }
.login-logo { width: 190px; align-self: center; margin-bottom: 4px; }
.login-card h1 { margin: 0; text-align: center; font-size: 20px; color: var(--teal-dark); }
.login-sub { margin: 0 0 4px; text-align: center; color: var(--muted); font-size: 13px; }
.login-field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.login-field input { padding: 8px 10px; font-weight: 400; font-size: 14px; }
.login-field input:focus { padding: 7px 9px; }
.login-error { color: #b00020; font-size: 13px; min-height: 1em; }
.login-error:empty { display: none; }
.login-btn { padding: 9px 16px; font-size: 15px; margin-top: 4px; }

/* ------------------------------------------------------------ personnes autorisées */
.users-modal { max-width: 980px; }
.users-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 14px; align-items: end; margin: 10px 0 6px; }
.users-form .login-field input { padding: 6px 8px; width: 100%; }
.users-form .hrow input { flex: 1; min-width: 0; }
.users-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.users-table { max-height: 45vh; margin-top: 4px; }
.users-table td button { padding: 3px 10px; }
@media (max-width: 800px) { .users-form { grid-template-columns: 1fr; } }
