/* =========================================================
   FaclimMail2Odoo — Stylesheet
   ========================================================= */

/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg:         #f5f5f5;
  --surface:    #ffffff;
  --border:     #e0e0e0;
  --primary:    #1976d2;
  --primary-dk: #1565c0;
  --danger:     #d32f2f;
  --danger-dk:  #b71c1c;
  --success:    #388e3c;
  --success-dk: #2e7d32;
  --warning:    #f57c00;
  --text:       #212121;
  --text-muted: #757575;
  --shadow:     0 1px 4px rgba(0,0,0,.12);
  --radius:     6px;
}

/* ── Reset minimal ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

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

/* ── Header ─────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 52px;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
}

/* Lien retour dans le header (detail.html) */
.btn-back {
  color: #fff;
  font-size: .9rem;
  opacity: .85;
  white-space: nowrap;
  padding: .3rem .6rem;
  border-radius: var(--radius);
  transition: background .15s;
}
.btn-back:hover { background: rgba(255,255,255,.15); text-decoration: none; opacity: 1; }

/* Indicateur polling */
.polling-dot {
  font-size: 1.1rem;
  cursor: default;
  animation: pulse 2s infinite;
  color: #a5d6a7;
}
.polling-dot.inactive { color: #ef9a9a; animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

/* ── Layout principal ───────────────────────────────────── */
main {
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1.25rem 3rem;
  flex: 1;
}

/* ── Card ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

/* ── Filtres ────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.filter-btn {
  padding: .35rem .9rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: .85rem;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.filter-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 500;
}

/* ── Table mails ────────────────────────────────────────── */
#mails-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

#mails-table thead {
  background: #f9f9f9;
}

#mails-table th {
  text-align: left;
  padding: .65rem 1rem;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

#mails-table td {
  padding: .7rem 1rem;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
  font-size: .9rem;
}

#mails-table tbody tr:last-child td { border-bottom: none; }

#mails-table tbody tr:hover { background: #fafafa; }

/* Colonne icône statut */
#mails-table td:first-child { width: 32px; text-align: center; font-size: 1rem; }

/* Colonne mail info */
.mail-info strong { display: block; font-size: .9rem; color: var(--text); }
.mail-info .subject { font-size: .82rem; color: var(--text-muted); }
.mail-info .att-icon { margin-left: .4rem; font-size: .85rem; }

/* Colonne date */
#mails-table td:nth-child(3) { white-space: nowrap; color: var(--text-muted); font-size: .82rem; width: 90px; }

/* Colonne partner */
#mails-table td:nth-child(4) { width: 160px; font-size: .85rem; }

/* Colonne actions */
.actions { white-space: nowrap; width: 140px; }

/* Message état vide / chargement */
.loading, .empty { text-align: center; padding: 2rem; color: var(--text-muted); font-size: .95rem; }

/* ── Badges statut ──────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .03em;
  white-space: nowrap;
}

.badge-new        { background: #e3f2fd; color: #1565c0; }
.badge-processing { background: #fff3e0; color: #e65100; }
.badge-processed  { background: #e8f5e9; color: #2e7d32; }
.badge-trash      { background: #f5f5f5; color: #757575; }

/* Badges confidence */
.badge-exact      { background: #e8f5e9; color: #2e7d32; }
.badge-domain     { background: #fff9c4; color: #f57f17; }
.badge-ambiguous  { background: #fff3e0; color: #e65100; }
.badge-unknown    { background: #ffebee; color: #c62828; }

/* ── Boutons ────────────────────────────────────────────── */
button, .btn-primary, .btn-secondary, .btn-danger, .btn-success {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s, box-shadow .15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dk); }

.btn-secondary {
  background: rgba(255,255,255,.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,.35);
}
.btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,.28); }

/* Variante claire pour usage hors header */
.btn-secondary-light {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary-light:hover:not(:disabled) { background: #f0f0f0; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-dk); }

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover:not(:disabled) { background: var(--success-dk); }

button:disabled, .btn-primary:disabled, .btn-danger:disabled, .btn-success:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* Petits boutons dans le tableau */
.btn-sm {
  padding: .3rem .65rem;
  font-size: .8rem;
}

/* Groupe de boutons (section-actions) */
.btn-group {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: center;
}

/* ── Info-table (section détail) ────────────────────────── */
.info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.info-table th {
  text-align: left;
  width: 100px;
  padding: .4rem .6rem .4rem 0;
  color: var(--text-muted);
  font-weight: 500;
  vertical-align: top;
}
.info-table td {
  padding: .4rem 0;
  word-break: break-word;
}

/* ── Section partner ────────────────────────────────────── */
.partner-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
}

.partner-name { font-weight: 600; font-size: .95rem; }

.candidates-select {
  padding: .35rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .88rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.partner-search-row {
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: .5rem;
}

.partner-input {
  flex: 1;
  min-width: 180px;
  padding: .4rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .88rem;
  color: var(--text);
}
.partner-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(25,118,210,.15); }

.partner-override-note {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: .4rem;
}

/* ── Corps du mail ──────────────────────────────────────── */
.mail-body-content {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: .82rem;
  line-height: 1.6;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  max-height: 320px;
  overflow-y: auto;
  color: var(--text);
}

/* Affichage HTML du mail dans iframe */
.mail-body-frame {
  width: 100%;
  height: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

/* ── Pièces jointes ─────────────────────────────────────── */
#attachments-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

#attachments-list li {
  display: flex;
  align-items: center;
  gap: .65rem;
  font-size: .88rem;
  padding: .4rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafafa;
}

#attachments-list li .att-name { flex: 1; font-weight: 500; word-break: break-all; }
#attachments-list li .att-meta { color: var(--text-muted); font-size: .78rem; white-space: nowrap; }
#attachments-list li a { margin-left: auto; }

/* ── Table items extraits ───────────────────────────────── */
#items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  margin-top: .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

#items-table thead { background: #f5f5f5; }
#items-table th {
  text-align: left;
  padding: .5rem .85rem;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
#items-table td {
  padding: .5rem .85rem;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: top;
}
#items-table tbody tr:last-child td { border-bottom: none; }
#items-table tbody tr:hover { background: #fafafa; }

.dims-list { font-size: .8rem; color: var(--text-muted); }
.source-badge {
  display: inline-block;
  padding: .15rem .45rem;
  border-radius: 10px;
  font-size: .72rem;
  font-weight: 600;
  background: #e3f2fd;
  color: #1565c0;
}

/* ── Section résultat devis ─────────────────────────────── */
#section-result {
  border-left: 4px solid var(--success);
}
#section-result h2 { color: var(--success); border-color: #c8e6c9; }
#odoo-quote-link {
  font-weight: 600;
  color: var(--primary);
  font-size: .95rem;
}

/* ── Loading spinner ────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .65s linear infinite;
  vertical-align: middle;
  margin-right: .3rem;
}
.spinner-dark {
  border-color: rgba(0,0,0,.15);
  border-top-color: var(--text-muted);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal partner ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  width: 100%;
  max-width: 480px;
  padding: 1.5rem;
}

.modal h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.modal-input {
  width: 100%;
  padding: .45rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  margin-bottom: .75rem;
  color: var(--text);
}
.modal-input:focus { outline: none; border-color: var(--primary); }

.modal-results {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .75rem;
}

.modal-result-item {
  padding: .55rem .85rem;
  cursor: pointer;
  font-size: .88rem;
  border-bottom: 1px solid #f0f0f0;
  transition: background .1s;
}
.modal-result-item:last-child { border-bottom: none; }
.modal-result-item:hover { background: #e3f2fd; }
.modal-result-item .res-name { font-weight: 500; }
.modal-result-item .res-email { font-size: .78rem; color: var(--text-muted); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

/* ── Toast notification ─────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-width: 340px;
}

.toast {
  padding: .75rem 1.1rem;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,.2);
  animation: slideIn .2s ease;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--primary); }

@keyframes slideIn {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 720px) {
  header { padding: 0 .85rem; }
  header h1 { font-size: 1rem; }

  main { margin: .75rem auto; padding: 0 .75rem 2rem; }

  #mails-table thead { display: none; }
  #mails-table, #mails-table tbody, #mails-table tr, #mails-table td {
    display: block;
    width: 100%;
  }
  #mails-table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: .5rem;
    padding: .5rem .75rem;
    background: var(--surface);
  }
  #mails-table td { border: none; padding: .2rem 0; }
  #mails-table td:first-child { position: absolute; top: .5rem; right: .75rem; }

  .actions { display: flex; gap: .4rem; margin-top: .4rem; }

  .info-table th { width: 80px; }

  .partner-row { flex-direction: column; align-items: flex-start; }

  .card { padding: 1rem 1rem; }
}

@media (max-width: 420px) {
  .filters { gap: .35rem; }
  .filter-btn { padding: .28rem .65rem; font-size: .78rem; }
  #items-table th:nth-child(4), #items-table td:nth-child(4) { display: none; }
}

/* =========================================================
   Auth — Login page & user bar
   ========================================================= */

/* ── Page login ─────────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  text-align: center;
}

.login-logo { font-size: 3rem; margin-bottom: .5rem; }

.login-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .25rem;
}

.login-subtitle {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.form-group {
  text-align: left;
  margin-bottom: 1.1rem;
}

.form-group label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .35rem;
}

.form-group input {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  color: var(--text);
  background: var(--bg);
  transition: border-color .15s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

.login-error {
  background: #fdecea;
  color: var(--danger);
  border: 1px solid #f5c6cb;
  border-radius: var(--radius);
  padding: .6rem .85rem;
  font-size: .87rem;
  text-align: left;
  margin-bottom: 1rem;
}

.btn-full { width: 100%; justify-content: center; }

/* ── User bar (injectée dans <header> par auth.js) ───────── */
.user-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-left: auto;
}

.user-name {
  font-size: .85rem;
  color: var(--text-muted);
  white-space: nowrap;
}
