:root {
  --izzi: #e2001a;
  --izzi-dark: #b00015;
  --ink: #1a1d24;
  --muted: #6b7280;
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e5e7eb;
  --ok-bg: #e7f6ec;
  --ok-border: #36b37e;
  --err-bg: #fdecea;
  --err-border: #e2001a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

.brand { font-size: 1.4rem; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.brand span { color: var(--izzi); }
a.brand { color: var(--ink); text-decoration: none; cursor: pointer; }
a.brand:hover { opacity: .8; }

/* ---------------- Login ---------------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1rem;
}
.login-card {
  background: var(--card); padding: 2.5rem; border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,0,0,.08); width: 100%; max-width: 360px;
}
.login-card .brand { font-size: 1.8rem; }
.subtitle { color: var(--muted); margin: .25rem 0 1.5rem; }
.login-card label { display: block; font-weight: 600; margin-bottom: .4rem; font-size: .9rem; }
.login-card input {
  width: 100%; padding: .7rem; border: 1px solid var(--border);
  border-radius: 8px; font-size: 1rem; margin-bottom: 1rem;
}

/* ---------------- App ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
}
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
/* Bouton Administration dans la barre du haut : distinct des onglets de contenu. */
#tab-admin.active { color: var(--izzi); border-color: var(--izzi); }
.container { max-width: 1080px; margin: 1.5rem auto; padding: 0 1.5rem; }
.phase-note {
  background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 8px;
  padding: .75rem 1rem; font-size: .9rem; color: #3730a3;
}
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem 1.5rem; margin-bottom: 1.25rem;
}
.card h2 { margin-top: 0; font-size: 1.1rem; }

.search-row { display: flex; align-items: center; gap: .75rem; }
#client-search {
  flex: 1; padding: .65rem; border: 1px solid var(--border);
  border-radius: 8px; font-size: 1rem;
}
.muted { color: var(--muted); font-size: .85rem; }

.results { list-style: none; margin: .75rem 0 0; padding: 0; }
.result-item {
  padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: .4rem; cursor: pointer; display: flex; justify-content: space-between;
  gap: 1rem; align-items: baseline;
}
.result-item:hover { border-color: var(--izzi); background: #fff5f6; }
.result-name { font-weight: 600; }

.selected {
  margin-top: .75rem; padding: .6rem .75rem; background: var(--ok-bg);
  border: 1px solid var(--ok-border); border-radius: 8px;
}
.selected .muted { margin-left: .25rem; }

.result { margin-top: 1rem; padding: .75rem 1rem; border-radius: 8px; }
.alert { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-success { background: var(--ok-bg); border: 1px solid var(--ok-border); }
.alert-error { background: var(--err-bg); border: 1px solid var(--err-border); }
.alert-success a { color: var(--izzi-dark); font-weight: 600; }

.hidden { display: none; }

/* ---------------- Buttons ---------------- */
.btn {
  font-size: .95rem; font-weight: 600; padding: .6rem 1.1rem;
  border-radius: 8px; border: 1px solid transparent; cursor: pointer;
}
.btn-primary { background: var(--izzi); color: #fff; width: 100%; }
.btn-primary:hover:not(:disabled) { background: var(--izzi-dark); }
.btn-primary:disabled { background: #d1d5db; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-ghost:hover { background: var(--bg); }
.btn-small { padding: .3rem .6rem; font-size: .8rem; }

/* ---------------- Génération ---------------- */
#meeting-notes {
  width: 100%; padding: .7rem; border: 1px solid var(--border);
  border-radius: 8px; font-size: .95rem; font-family: inherit;
  margin-bottom: .75rem; resize: vertical;
}
#generate-hint, #generate-status { margin: .5rem 0 0; }
.model-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.model-row label { font-weight: 600; font-size: .9rem; color: var(--muted); }
#model-select {
  padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 8px;
  font-size: .9rem; background: #fff;
}

.card h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.card h4 { margin: .75rem 0 .35rem; }

.besoins-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.besoins-table th, .besoins-table td {
  text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.besoins-table th { color: var(--muted); font-weight: 600; }
tr.statut-couvert td:nth-child(3) { color: var(--ok-border); }
tr.statut-ambigu td:nth-child(3) { color: #b45309; }
tr.statut-non_chiffre td:nth-child(3) { color: var(--izzi-dark); }

.section-block ul { margin: .25rem 0 .75rem; padding-left: 1.2rem; }
.section-block li { margin-bottom: .25rem; }

#res-json {
  background: #1a1d24; color: #e5e7eb; padding: 1rem; border-radius: 8px;
  overflow-x: auto; font-size: .8rem; max-height: 420px; overflow-y: auto;
}
details summary { cursor: pointer; font-weight: 600; margin-top: 1rem; }

/* ---------------- Édition du devis ---------------- */
.section-block { margin-bottom: 1.25rem; }
.line-row {
  border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem;
  margin-bottom: .5rem; background: #fafbfc;
}
.line-main { display: flex; flex-direction: column; gap: .4rem; }
.line-titre {
  width: 100%; padding: .4rem .5rem; border: 1px solid var(--border);
  border-radius: 6px; font-size: .95rem; font-weight: 600;
}
.line-controls { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.line-qte, .line-pu {
  width: 5.5rem; padding: .35rem .45rem; border: 1px solid var(--border);
  border-radius: 6px; font-size: .9rem;
}
.line-controls .mult { color: var(--muted); }
.line-eq { margin-left: .25rem; white-space: nowrap; }
.opt-toggle { font-size: .8rem; color: var(--muted); display: inline-flex; align-items: center; gap: .25rem; }
.line-move {
  padding: .3rem .4rem; border: 1px solid var(--border); border-radius: 6px;
  font-size: .8rem; margin-left: auto;
}
.btn-del {
  border: 1px solid var(--border); background: #fff; color: var(--izzi);
  border-radius: 6px; cursor: pointer; padding: .3rem .5rem; font-weight: 700;
}
.btn-del:hover { background: var(--err-bg); border-color: var(--err-border); }
.line-desc {
  width: 100%; margin-top: .4rem; padding: .5rem .6rem; border: 1px solid var(--border);
  border-radius: 6px; font-size: .9rem; line-height: 1.45; font-family: inherit;
  resize: vertical; min-height: 4.5rem; overflow: hidden;
}
.line-meta { margin-top: .3rem; font-size: .75rem; }
.line-estim {
  margin-top: .35rem; font-size: .8rem; color: #92400e;
  background: #fef3c7; border: 1px solid #fcd34d; border-radius: 6px; padding: .3rem .5rem;
}

.besoin-orphelin { opacity: .7; }
.badge-orphelin {
  background: var(--err-bg); color: var(--izzi-dark); border: 1px solid var(--err-border);
  border-radius: 4px; padding: .1rem .35rem; font-size: .75rem; font-weight: 600;
}

.totaux-box {
  background: #f5f6f8; border: 1px solid var(--border); border-radius: 8px;
  padding: .75rem 1rem; margin: 1rem 0; max-width: 460px;
}
.tot-line { display: flex; justify-content: space-between; padding: .2rem 0; }
.tot-opt { color: #b45309; font-size: .9rem; }
.tot-sep { border-top: 1px solid var(--border); margin: .4rem 0; }
.tot-total { border-top: 2px solid var(--ink); margin-top: .4rem; padding-top: .4rem; font-weight: 600; }

.edit-actions { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }
.edit-actions .btn-primary { width: auto; }

#pennylane-card label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
#pl-subject {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--border);
  border-radius: 8px; font-size: 1rem; margin-bottom: .9rem;
}
#pennylane-card .btn-primary { width: auto; }
#email-tools { margin-top: 1.25rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.email-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .6rem; }
.email-actions .btn { width: auto; }
#email-output {
  width: 100%; padding: .7rem; border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: .92rem; line-height: 1.5; resize: vertical; overflow: hidden;
  margin-bottom: .5rem;
}
.email-output-actions { display: flex; gap: .5rem; }

/* ---------------- Onglets ---------------- */
.tabs { display: flex; gap: .5rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.tab {
  background: transparent; border: none; border-bottom: 3px solid transparent;
  padding: .6rem 1rem; font-size: .95rem; font-weight: 600; color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--izzi); border-bottom-color: var(--izzi); }

.archive-banner {
  background: #eef2ff; border: 1px solid #c7d2fe; color: #3730a3;
  border-radius: 8px; padding: .6rem .9rem; margin-bottom: 1rem; font-size: .9rem;
}

/* ---------------- Archives ---------------- */
.archives-head { display: flex; align-items: center; justify-content: space-between; }
/* Conteneur à défilement : le tableau ne déborde jamais de la carte. */
.table-scroll { width: 100%; overflow-x: auto; }
.archives-table { width: 100%; border-collapse: collapse; font-size: .88rem; margin-top: .5rem; }
.archives-table th, .archives-table td {
  text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border);
  white-space: normal; vertical-align: top;
}
/* Colonnes courtes (date, prix) et actions : pas de retour à la ligne disgracieux. */
#archives-table td:nth-child(1), #archives-table td:nth-child(4),
#archives-table td:nth-child(5), #archives-table td:nth-child(6),
#archives-table td:last-child { white-space: nowrap; }
.archives-table th { color: var(--muted); font-weight: 600; }
.archive-row { cursor: pointer; }
.archive-row:hover { background: #fff5f6; }

.status-badge { padding: .12rem .45rem; border-radius: 4px; font-size: .75rem; font-weight: 600; }
.status-generated { background: #eef2ff; color: #3730a3; }
.status-edited { background: #fef3c7; color: #92400e; }
.status-sent_to_pennylane { background: var(--ok-bg); color: #1d6b46; }
.status-duplicated { background: #ede9fe; color: #5b21b6; }
.status-error { background: var(--err-bg); color: var(--izzi-dark); }

.arch-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: .5rem 0 .75rem; }
.arch-toolbar input[type="text"] { flex: 1 1 200px; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 8px; }
.arch-toolbar select { padding: .45rem .5rem; border: 1px solid var(--border); border-radius: 8px; }
.arch-date { font-size: .82rem; color: var(--muted); display: inline-flex; align-items: center; gap: .3rem; }
.arch-date input { padding: .35rem .4rem; border: 1px solid var(--border); border-radius: 6px; }
.email-pill { display: inline-block; background: #eef2ff; color: #3730a3; border-radius: 4px; padding: .05rem .35rem; font-size: .72rem; font-weight: 600; }

#consult-original h4 { margin: .6rem 0 .3rem; }
#consult-original ul { margin: .2rem 0 .6rem; padding-left: 1.2rem; }
#consult-payload, #consult-response {
  background: #1a1d24; color: #e5e7eb; padding: 1rem; border-radius: 8px;
  overflow: auto; font-size: .78rem; max-height: 360px;
}

/* ---------------- Administration ---------------- */
.subtabs {
  display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.subtab {
  background: transparent; border: none; border-bottom: 2px solid transparent;
  padding: .45rem .8rem; font-size: .88rem; font-weight: 600; color: var(--muted);
  cursor: pointer;
}
.subtab:hover:not(:disabled) { color: var(--ink); }
.subtab.active { color: var(--izzi); border-bottom-color: var(--izzi); }
.subtab:disabled { opacity: .45; cursor: not-allowed; }

.form-grid { display: grid; grid-template-columns: 220px 1fr; gap: .6rem 1rem; align-items: start; margin: .5rem 0 1rem; }
.form-grid label { font-weight: 600; font-size: .9rem; padding-top: .45rem; }
.form-grid input, .form-grid textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--border);
  border-radius: 8px; font-size: .95rem; font-family: inherit;
}
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } .form-grid label { padding-top: 0; } }

.secrets-list { list-style: none; padding: 0; margin: .4rem 0 0; }
.secrets-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: .4rem .2rem; border-bottom: 1px solid var(--border); max-width: 420px;
}
.secret-name { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }
.secret-badge { padding: .12rem .5rem; border-radius: 4px; font-size: .75rem; font-weight: 600; }
.secret-badge.ok { background: var(--ok-bg); color: #1d6b46; }
.secret-badge.ko { background: var(--err-bg); color: var(--izzi-dark); }

.vars-row { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.var-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .76rem;
  padding: .12rem .45rem; border-radius: 4px; font-weight: 600;
}
.var-chip.ok { background: var(--ok-bg); color: #1d6b46; }
.var-chip.ko { background: var(--err-bg); color: var(--izzi-dark); }
#prompt-content {
  width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .82rem; line-height: 1.45; padding: .75rem; border: 1px solid var(--border);
  border-radius: 8px; resize: vertical;
}
#prompt-select { padding: .35rem .5rem; border: 1px solid var(--border); border-radius: 6px; }

.cat-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin: .5rem 0; }
.cat-toolbar input[type="text"] { flex: 1 1 220px; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 8px; }
.cat-toolbar select { padding: .45rem .5rem; border: 1px solid var(--border); border-radius: 8px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .76rem; }
#cat-table td { white-space: normal; vertical-align: top; }
.row-inactive { opacity: .55; }
.row-inactive td:first-child { text-decoration: line-through; }
.cat-form {
  margin-top: 1rem; padding: 1rem; border: 1px solid var(--border);
  border-radius: 8px; background: #fafbfc;
}
.cat-form h3 { margin-top: 0; }
.cat-form input[type="checkbox"] { width: 18px; height: 18px; }

#r-regles, #r-advanced {
  width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .82rem; line-height: 1.45; padding: .6rem; border: 1px solid var(--border);
  border-radius: 8px; resize: vertical;
}
#r-mapping-table input, #r-mapping-table select,
#r-recurrents-table input { width: 100%; padding: .35rem .45rem; border: 1px solid var(--border); border-radius: 6px; }
#admin-panel-regles h3 { margin: 1.1rem 0 .4rem; font-size: 1rem; }

#em-table td { white-space: normal; vertical-align: top; }
#em-table input[type="text"], #em-table textarea {
  width: 100%; padding: .35rem .45rem; border: 1px solid var(--border); border-radius: 6px;
  font-family: inherit; font-size: .85rem;
}
#em-table input[type="checkbox"], #em-table input[type="radio"] { width: 16px; height: 16px; }
