/* ============================================================
   Archivage Mail — Feuille de styles principale
   Palette : bleu indigo (#1d4ed8) / fond gris clair (#f1f5f9)
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #1d4ed8;
  --primary-dark:  #1e40af;
  --primary-light: #eff6ff;
  --success:       #059669;
  --success-light: #ecfdf5;
  --warning:       #d97706;
  --warning-light: #fffbeb;
  --danger:        #dc2626;
  --danger-light:  #fef2f2;
  --gray-50:       #f8fafc;
  --gray-100:      #f1f5f9;
  --gray-200:      #e2e8f0;
  --gray-300:      #cbd5e1;
  --gray-500:      #64748b;
  --gray-700:      #334155;
  --gray-900:      #0f172a;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.08);
  --shadow:        0 4px 16px rgba(0,0,0,.10);
  --font:          'Inter', system-ui, sans-serif;
  --transition:    .18s ease;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--gray-900);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────── */
.site-header {
  background: var(--primary);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  text-decoration: none;
  color: #fff;
  flex-shrink: 0;
}
.brand-icon { font-size: 1.6rem; line-height: 1; }
.brand-name { font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em; }
.header-nav {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-left: auto;
}
.header-nav .nav-link {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
  padding: .4rem .75rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}
.header-nav .nav-link:hover,
.header-nav .nav-link.active { background: rgba(255,255,255,.15); color: #fff; }
.nav-user {
  font-size: .85rem;
  color: rgba(255,255,255,.7);
  padding: .4rem .5rem;
}
.nav-logout { color: rgba(255,255,255,.7) !important; }

/* ── Flash messages ──────────────────────────────────────── */
.flash-container { max-width: 1200px; margin: 1rem auto 0; padding: 0 1.5rem; }
.flash {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  margin-bottom: .5rem;
}
.flash-success { background: var(--success-light); color: #065f46; border-left: 4px solid var(--success); }
.flash-error   { background: var(--danger-light);  color: #991b1b; border-left: 4px solid var(--danger); }
.flash-info    { background: var(--primary-light); color: #1e40af; border-left: 4px solid var(--primary); }

/* ── Main content ────────────────────────────────────────── */
.main-content {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── Page header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}
.page-title { font-size: 1.4rem; font-weight: 700; color: var(--gray-900); }

/* ── Footer ──────────────────────────────────────────────── */
.site-footer {
  background: var(--gray-200);
  border-top: 1px solid var(--gray-300);
  text-align: center;
  padding: .75rem 1rem;
  font-size: .8rem;
  color: var(--gray-500);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-warning  { background: var(--warning); color: #fff; }
.btn-warning:hover  { background: #b45309; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: #b91c1c; }
.btn-ghost    { background: transparent; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-ghost:hover    { background: var(--gray-100); }
.btn-sm       { padding: .35rem .75rem; font-size: .82rem; }
.btn-block    { width: 100%; justify-content: center; }

/* ── Login page ──────────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 50%, #3b82f6 100%);
  min-height: 100vh;
}
.login-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
}
.login-brand { text-align: center; margin-bottom: 1.75rem; }
.login-icon  { font-size: 3rem; margin-bottom: .5rem; }
.login-title { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); }
.login-subtitle { color: var(--gray-500); font-size: .9rem; margin-top: .25rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; margin-top: .5rem; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label { font-size: .88rem; font-weight: 600; color: var(--gray-700); }
.form-group input,
.form-group select,
.form-group textarea {
  padding: .6rem .85rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .95rem;
  color: var(--gray-900);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
.input-readonly { background: var(--gray-100); color: var(--gray-500); }
.form-hint  { font-size: .8rem; color: var(--gray-500); }
.form-hint-inline { font-weight: 400; color: var(--gray-500); }
.required   { color: var(--danger); }
.form-row   { display: flex; gap: 1rem; }
.flex-3     { flex: 3; }
.flex-1     { flex: 1; }
.form-fieldset { border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); padding: 1rem 1.25rem; }
.form-fieldset legend { font-weight: 600; font-size: .9rem; color: var(--gray-700); padding: 0 .4rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1rem; }
.form-inline  { display: inline; }
.form-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 2rem;
  max-width: 600px;
}
.account-form { display: flex; flex-direction: column; gap: 1.25rem; }

.input-password-wrap { position: relative; display: flex; }
.input-password-wrap input { flex: 1; padding-right: 2.8rem; }
.btn-show-password {
  position: absolute;
  right: .5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--gray-500);
  padding: .2rem;
}

/* ── Account cards grid ──────────────────────────────────── */
.accounts-grid { display: flex; flex-direction: column; gap: 1rem; }

.account-card {
  background: #fff;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  transition: box-shadow var(--transition);
}
.account-card:hover { box-shadow: var(--shadow); }

.account-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .75rem;
}
.account-email { font-size: 1.05rem; font-weight: 700; color: var(--primary); word-break: break-all; }
.account-label { font-size: .85rem; color: var(--gray-500); margin-top: .1rem; }
.account-meta  { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .4rem; }
.meta-item     { font-size: .8rem; color: var(--gray-500); background: var(--gray-100); padding: .15rem .5rem; border-radius: 99px; }

.badge { display: inline-block; padding: .3rem .7rem; border-radius: 99px; font-size: .8rem; font-weight: 700; }
.badge-count   { background: var(--primary-light); color: var(--primary); }
.badge-unknown { background: var(--gray-100); color: var(--gray-500); }

.last-job {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .75rem;
  font-size: .83rem;
  color: var(--gray-500);
}
.job-label   { font-weight: 600; }
.job-date    { }
.job-status  { padding: .15rem .55rem; border-radius: 99px; font-weight: 600; font-size: .78rem; }
.status-done    { background: var(--success-light); color: #065f46; }
.status-running { background: var(--warning-light); color: #92400e; }
.status-error   { background: var(--danger-light);  color: #991b1b; }
.status-pending { background: var(--gray-100);       color: var(--gray-700); }
.job-archived   { color: var(--success); font-weight: 600; }

.account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .25rem;
}

/* ── Progress zone ───────────────────────────────────────── */
.progress-zone { margin: .75rem 0; }
.progress-bar-wrap {
  height: 8px;
  background: var(--gray-200);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: .4rem;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width .3s ease;
}
.progress-msg { font-size: .82rem; color: var(--gray-500); }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--gray-500);
}
.empty-icon { font-size: 3.5rem; margin-bottom: 1rem; }
.empty-state p { font-size: 1.1rem; margin-bottom: 1.25rem; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%;
  max-width: 480px;
  animation: modal-in .2s ease;
}
@keyframes modal-in {
  from { transform: scale(.95); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}
.modal-title  { font-size: 1.1rem; font-weight: 700; }
.modal-close  { background: none; border: none; font-size: 1.5rem; color: var(--gray-500); cursor: pointer; line-height: 1; padding: 0 .25rem; }
.modal-close:hover { color: var(--gray-900); }
.modal-body   { padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-hint   { font-size: .88rem; color: var(--gray-500); line-height: 1.5; }
.modal-hint strong { color: var(--gray-900); }
.modal-hint code   { background: var(--gray-100); padding: .1rem .35rem; border-radius: var(--radius-sm); font-size: .83rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
}

/* ── Log viewer ──────────────────────────────────────────── */
.log-toolbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: .75rem;
  flex-wrap: wrap;
}
.log-filter-label { display: flex; align-items: center; gap: .5rem; font-size: .88rem; font-weight: 600; color: var(--gray-700); }
.log-filter-input {
  padding: .35rem .65rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-family: var(--font);
  width: 240px;
}
.log-filter-input:focus { outline: none; border-color: var(--primary); }
.log-autoscroll { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--gray-600); cursor: pointer; }
.log-box {
  background: #0f172a;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  height: 65vh;
  overflow-y: auto;
  font-family: 'Courier New', Consolas, monospace;
  font-size: .78rem;
  line-height: 1.6;
}
#log-content { white-space: pre-wrap; word-break: break-all; }
.log-line      { display: block; color: #94a3b8; }
.log-line.log-error { color: #f87171; font-weight: 600; }
.log-line.log-warn  { color: #fbbf24; }
.log-line.log-info  { color: #86efac; }
.log-hint { font-size: .78rem; color: var(--gray-500); margin-top: .5rem; }

/* ── Info banner ─────────────────────────────────────────── */
.info-banner {
  display: flex;
  align-items: flex-start;
  gap: .85rem;
  background: var(--primary-light);
  border: 1.5px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: .9rem 1.1rem;
  margin-bottom: 1.5rem;
  font-size: .88rem;
  color: #1e3a8a;
  line-height: 1.55;
}
.info-banner-icon { font-size: 1.2rem; flex-shrink: 0; margin-top: .05rem; }
.info-banner-struct { color: #3b5ab5; font-size: .83rem; }
.info-banner code  { background: #dbeafe; padding: .1rem .35rem; border-radius: 4px; font-size: .82rem; }

/* ── Dossier detail (après sync) ─────────────────────────── */
.count-detail {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: .5rem 0 .25rem;
}
.detail-item {
  font-size: .8rem;
  font-weight: 600;
  padding: .2rem .65rem;
  border-radius: 99px;
}
.detail-inbox { background: #eff6ff; color: #1d4ed8; }
.detail-sent  { background: #f0fdf4; color: #15803d; }

.meta-folders { color: var(--primary) !important; background: var(--primary-light) !important; }

/* ── Modal folder badges ─────────────────────────────────── */
.modal-folders-info {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  margin: -.25rem 0 .25rem;
}
.folder-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .82rem;
  font-weight: 700;
  padding: .3rem .8rem;
  border-radius: 99px;
}
.folder-inbox { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.folder-sent  { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* ── Vue utilisateur (archives) ──────────────────────────── */
.site-header-user { background: #0f766e; }
.header-inner-user {
  flex-wrap: wrap;
  gap: .75rem;
}
.header-search {
  flex: 1;
  min-width: 200px;
  max-width: 420px;
}
.user-search-form {
  display: flex;
  gap: .4rem;
  width: 100%;
}
.user-search-input {
  flex: 1;
  padding: .45rem .75rem;
  border: 1.5px solid rgba(255,255,255,.35);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .88rem;
  background: rgba(255,255,255,.12);
  color: #fff;
}
.user-search-input::placeholder { color: rgba(255,255,255,.65); }
.user-search-input:focus {
  outline: none;
  border-color: #fff;
  background: rgba(255,255,255,.2);
}
.user-search-btn { flex-shrink: 0; }
.search-panel {
  margin-bottom: 1.25rem;
  max-width: 560px;
}
.search-panel-inline { max-width: 480px; }
.search-panel .user-search-input {
  background: #fff;
  color: var(--gray-900);
  border-color: var(--gray-300);
}
.search-panel .user-search-input::placeholder { color: var(--gray-500); }
.message-row-search { align-items: flex-start; }
.message-row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .3rem;
  font-size: .78rem;
  color: var(--gray-500);
}
.search-badge {
  padding: .1rem .45rem;
  border-radius: 99px;
  font-weight: 600;
  font-size: .72rem;
}
.search-badge-inbox { background: #eff6ff; color: #1d4ed8; }
.search-badge-sent { background: #f0fdf4; color: #15803d; }
.search-limit-hint { margin-top: 1rem; text-align: center; }
.nav-user-email { font-size: .85rem; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-subtitle { color: var(--gray-500); font-size: .95rem; margin-top: .25rem; }
.info-banner-user { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }

.archive-sections { display: flex; flex-direction: column; gap: 2rem; }
.archive-section { }
.section-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1rem; color: var(--gray-900); }
.empty-folder { color: var(--gray-500); font-size: .9rem; }

.year-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .75rem;
}
.year-card {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  padding: 1.1rem 1rem;
  background: #fff;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: box-shadow var(--transition), border-color var(--transition);
}
.year-card:hover { box-shadow: var(--shadow); border-color: var(--primary); }
.year-card-sent:hover { border-color: #059669; }
.year-card-year { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.year-card-sent .year-card-year { color: #059669; }
.year-card-count { font-size: .82rem; color: var(--gray-500); }

.breadcrumb { font-size: .85rem; color: var(--gray-500); margin-bottom: .35rem; }
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb-sep { margin: 0 .35rem; color: var(--gray-300); }

.message-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.message-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem 1rem;
  background: #fff;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: inherit;
  transition: box-shadow var(--transition), border-color var(--transition);
}
.message-row:hover { box-shadow: var(--shadow-sm); border-color: var(--primary); }
.message-row-main { flex: 1; min-width: 0; }
.message-row-name {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  color: var(--gray-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-row-date { font-size: .78rem; color: var(--gray-500); }
.message-row-size { font-size: .78rem; color: var(--gray-500); flex-shrink: 0; }

.header-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.message-view {
  background: #fff;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
}
.message-meta {
  padding: 1rem 1.25rem;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  gap: .45rem;
}
.meta-row { display: flex; gap: .75rem; font-size: .88rem; }
.meta-label { font-weight: 600; color: var(--gray-500); min-width: 3.5rem; flex-shrink: 0; }
.meta-filename { font-family: monospace; font-size: .82rem; word-break: break-all; }
.message-subject { word-break: break-word; }

.message-attachments {
  padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--gray-200);
  font-size: .88rem;
}
.message-attachments h4 { font-size: .9rem; margin-bottom: .75rem; }
.attachment-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 1rem; }
.attachment-item {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: .75rem;
  background: var(--gray-50);
}
.attachment-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
}
.attachment-name { font-weight: 600; flex: 1; min-width: 0; word-break: break-all; }
.attachment-actions { display: flex; gap: .35rem; margin-left: auto; }
.attachment-preview {
  margin-top: .75rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--gray-200);
}
.attachment-preview img {
  display: block;
  max-width: 100%;
  max-height: 400px;
  height: auto;
  margin: 0 auto;
}
.attachment-preview-pdf iframe {
  width: 100%;
  height: 420px;
  border: none;
}
.att-size { color: var(--gray-500); font-size: .82rem; }

.message-body {
  padding: 1.25rem;
  max-height: 60vh;
  overflow-y: auto;
}
.message-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: .9rem;
  line-height: 1.6;
  margin: 0;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
  .header-inner { padding: .65rem 1rem; }
  .brand-name   { font-size: 1rem; }
  .header-nav .nav-link { padding: .35rem .5rem; font-size: .82rem; }
  .nav-user-email { display: none; }
  .header-search { order: 3; flex: 1 1 100%; max-width: none; }
  .main-content { padding: 1.25rem 1rem; }
  .form-row     { flex-direction: column; }
  .form-card    { padding: 1.25rem 1rem; }
  .account-card { padding: 1rem; }
  .account-actions { gap: .35rem; }
  .modal-overlay { align-items: flex-end; }
  .modal { border-radius: var(--radius) var(--radius) 0 0; max-height: 90vh; overflow-y: auto; }
}
