* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; background: #f3f4f6; color: #1f2937; }

/* ─── Login ─── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login { padding: 32px; background: white; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.08); width: 100%; max-width: 400px; }
.login h1 { font-size: 24px; margin-bottom: 8px; color: #1a56db; }
.login p { color: #6b7280; margin-bottom: 20px; font-size: 14px; }
.login input { width: 100%; padding: 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 16px; margin-bottom: 12px; }
.login input:focus { outline: none; border-color: #1a56db; }
.login button { width: 100%; padding: 12px; background: #1a56db; color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; }
.login button:disabled { opacity: 0.5; cursor: not-allowed; }
.login .msg { margin-top: 12px; padding: 10px; border-radius: 6px; font-size: 14px; }
.login .msg.error { background: #fef2f2; color: #b91c1c; }
.login .msg.success { background: #ecfdf5; color: #15803d; }

/* ─── Layout back-office ─── */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: white; border-right: 1px solid #e5e7eb; padding: 20px 0; display: flex; flex-direction: column; }
.sidebar .brand { padding: 0 20px 20px; border-bottom: 1px solid #e5e7eb; }
.sidebar .brand h1 { font-size: 18px; color: #1a56db; }
.sidebar .brand p { font-size: 12px; color: #9ca3af; margin-top: 4px; }
.sidebar nav { flex: 1; padding: 16px 0; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: #4b5563; text-decoration: none; font-size: 14px; font-weight: 500; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: #f9fafb; }
.sidebar nav a.active { background: #eff6ff; color: #1a56db; border-left-color: #1a56db; }
.sidebar nav .badge { margin-left: auto; background: #fee2e2; color: #b91c1c; font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.sidebar .footer { padding: 16px 20px; border-top: 1px solid #e5e7eb; font-size: 13px; color: #6b7280; }
.sidebar .footer button { width: 100%; padding: 8px; margin-top: 8px; background: white; border: 1px solid #d1d5db; border-radius: 6px; cursor: pointer; font-size: 13px; }
.sidebar .footer button:hover { background: #f9fafb; }

.main { flex: 1; padding: 24px; overflow-y: auto; }
.main h2 { font-size: 22px; color: #1f2937; margin-bottom: 6px; }
.main > p.subtitle { color: #6b7280; margin-bottom: 24px; font-size: 14px; }

/* ─── Cards / stats ─── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: white; padding: 18px; border-radius: 10px; border: 1px solid #e5e7eb; }
.stat .label { font-size: 12px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.stat .value { font-size: 26px; font-weight: 700; color: #1f2937; }
.stat .sub { font-size: 12px; color: #9ca3af; margin-top: 4px; }
.stat.alert .value { color: #b91c1c; }

.card { background: white; border-radius: 10px; border: 1px solid #e5e7eb; padding: 20px; margin-bottom: 20px; }
.card h3 { font-size: 16px; margin-bottom: 12px; color: #1f2937; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
table th { text-align: left; padding: 10px; border-bottom: 2px solid #e5e7eb; color: #6b7280; font-weight: 600; font-size: 12px; text-transform: uppercase; }
table td { padding: 10px; border-bottom: 1px solid #f3f4f6; }
table tr:hover { background: #fafbfc; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.badge.new { background: #dbeafe; color: #1e40af; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.ok { background: #d1fae5; color: #065f46; }
.badge.err { background: #fee2e2; color: #b91c1c; }
.badge.sent { background: #e0e7ff; color: #3730a3; }

/* ─── Boutons ─── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border: 1px solid transparent; border-radius: 6px; font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none; background: white; color: #1f2937; }
.btn:hover { background: #f3f4f6; }
.btn.primary { background: #1a56db; color: white; border-color: #1a56db; }
.btn.primary:hover { background: #1e40af; }
.btn.success { background: #16a34a; color: white; border-color: #16a34a; }
.btn.success:hover { background: #15803d; }
.btn.danger { background: #dc2626; color: white; border-color: #dc2626; }
.btn.danger:hover { background: #b91c1c; }
.btn.outline { background: white; border-color: #d1d5db; }

/* ─── Forms ─── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-row.full { grid-template-columns: 1fr; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: #374151; margin-bottom: 6px; }
.form-group label .req { color: #dc2626; margin-left: 2px; }
.form-group input, .form-group textarea, .form-group select { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; font-family: inherit; }
.form-group input:focus, .form-group textarea:focus, .form-group select:focus { outline: none; border-color: #1a56db; }
.form-group input.invalid, .form-group textarea.invalid, .form-group select.invalid { border-color: #dc2626; }
.form-group .hint { font-size: 12px; color: #6b7280; margin-top: 4px; }
.form-group .error-msg { font-size: 12px; color: #dc2626; margin-top: 4px; }
.form-group .input-wrap { position: relative; }
.form-group .input-wrap .clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: none; border: none; color: #9ca3af; cursor: pointer; font-size: 18px; }

/* ─── Autocomplete ─── */
.autocomplete { position: relative; }
.autocomplete-list { position: absolute; top: 100%; left: 0; right: 0; background: white; border: 1px solid #d1d5db; border-radius: 6px; margin-top: 2px; max-height: 240px; overflow-y: auto; z-index: 10; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.autocomplete-list .item { padding: 10px 12px; cursor: pointer; font-size: 14px; border-bottom: 1px solid #f3f4f6; }
.autocomplete-list .item:hover, .autocomplete-list .item.active { background: #eff6ff; }
.autocomplete-list .item .sub { font-size: 12px; color: #6b7280; }

/* ─── Calc display ─── */
.calc-box { background: #f9fafb; padding: 16px; border-radius: 8px; margin-top: 16px; border: 1px solid #e5e7eb; }
.calc-box .line { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.calc-box .line.total { border-top: 1px solid #d1d5db; margin-top: 8px; padding-top: 8px; font-weight: 700; font-size: 16px; color: #1a56db; }

/* ─── Messages globaux ─── */
.flash { position: fixed; top: 20px; right: 20px; z-index: 100; padding: 12px 20px; border-radius: 8px; font-size: 14px; font-weight: 500; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.flash.success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.flash.error { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }

/* ─── Mail log ─── */
.mail-filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.mail-filters > div { min-width: 130px; }
.mail-filters label { display: block; font-size: 12px; color: #6b7280; margin-bottom: 4px; font-weight: 500; }
.mail-filters input, .mail-filters select { width: 100%; padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; font-family: inherit; background: white; }
.mail-filters input:focus, .mail-filters select:focus { outline: none; border-color: #1a56db; }
.mail-filters .btn { padding: 7px 14px; font-size: 13px; }

.mail-log-table tbody tr:hover { background: #eff6ff; }

.mail-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px; }
.mail-modal { background: white; border-radius: 12px; max-width: 760px; width: 100%; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,0.3); overflow: hidden; }
.mail-modal .hd { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid #e5e7eb; }
.mail-modal .hd h3 { font-size: 17px; color: #1f2937; flex: 1; padding-right: 16px; word-break: break-word; }
.mail-modal .hd .close { background: none; border: none; font-size: 28px; line-height: 1; color: #9ca3af; cursor: pointer; padding: 0 8px; }
.mail-modal .hd .close:hover { color: #1f2937; }
.mail-modal .meta { padding: 14px 20px; background: #f9fafb; border-bottom: 1px solid #e5e7eb; font-size: 13px; color: #4b5563; display: flex; flex-direction: column; gap: 4px; }
.mail-modal .meta strong { color: #1f2937; font-weight: 600; margin-right: 4px; }
.mail-modal .meta .pj { display: inline-block; background: #e0e7ff; color: #3730a3; padding: 2px 8px; border-radius: 4px; margin-right: 6px; font-size: 12px; }
.mail-modal .meta .err-msg { background: #fee2e2; color: #b91c1c; padding: 8px 12px; border-radius: 6px; margin-top: 4px; }
.mail-modal .body { padding: 20px; overflow-y: auto; flex: 1; }
.mail-modal .body pre { white-space: pre-wrap; word-break: break-word; font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; font-size: 14px; line-height: 1.6; color: #1f2937; margin: 0; }

/* ─── Mobile ─── */
@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; padding: 10px; }
  .sidebar .brand { border-bottom: none; padding: 10px; width: 100%; }
  .sidebar nav { display: flex; overflow-x: auto; padding: 0 10px; width: 100%; flex: none; }
  .sidebar nav a { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; padding: 8px 12px; }
  .sidebar nav a.active { border-left: none; border-bottom-color: #1a56db; }
  .sidebar .footer { width: 100%; }
  .sidebar .footer button { width: auto; margin-top: 0; }
  .main { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  table { font-size: 13px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .btn { width: 100%; justify-content: center; }
  .form-actions .btn { width: 100%; }
  .hide-sm { display: none; }
}
