*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #0A84FF;
  --blue-dark: #0060DF;
  --sidebar-bg: #1C1C1E;
  --sidebar-text: rgba(255,255,255,0.85);
  --sidebar-sub: rgba(255,255,255,0.45);
  --sidebar-hover: rgba(255,255,255,0.07);
  --sidebar-active: rgba(10,132,255,0.25);
  --list-bg: #F5F5F7;
  --list-border: #E0E0E5;
  --list-hover: #EAEAEF;
  --list-active: #DCE8FF;
  --detail-bg: #FFFFFF;
  --text-primary: #1D1D1F;
  --text-secondary: #6E6E73;
  --text-tertiary: #AEAEB2;
  --unread-dot: #0A84FF;
  --badge-bg: #0A84FF;
  --badge-text: #fff;
  --danger: #FF453A;
  --success: #30D158;
  --shadow: 0 4px 24px rgba(0,0,0,0.10);
  --radius: 10px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: var(--sidebar-bg);
  color: var(--text-primary);
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   AUTH
═══════════════════════════════════════════ */
.auth-bg {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1C1C1E 0%, #2C2C2E 100%); padding: 24px;
}
.auth-card {
  background: #fff; border-radius: 20px; padding: 40px 44px;
  width: 100%; max-width: 420px; box-shadow: 0 24px 64px rgba(0,0,0,0.35);
}
.auth-card--wide { max-width: 580px; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 20px; }
.auth-title { text-align: center; font-size: 28px; font-weight: 700; margin-bottom: 6px; }
.auth-sub { text-align: center; font-size: 14px; color: var(--text-secondary); margin-bottom: 28px; }
.auth-error {
  background: #FFF2F1; border: 1px solid #FFCCC9; color: #C0392B;
  padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 20px;
}
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.field-group input {
  height: 42px; border: 1.5px solid #D2D2D7; border-radius: 10px;
  padding: 0 12px; font-size: 15px; font-family: inherit; color: var(--text-primary);
  transition: border-color .15s, box-shadow .15s; background: #F5F5F7;
}
.field-group input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(10,132,255,.15); background: #fff; }
.field-hint { font-size: 11px; color: var(--text-secondary); }
.req { color: var(--blue); }
.btn-primary {
  height: 46px; background: var(--blue); color: #fff; border: none; border-radius: 12px;
  font-size: 16px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:active { transform: scale(.98); }
.auth-switch { text-align: center; font-size: 13px; color: var(--text-secondary); margin-top: 20px; }
.auth-switch a { color: var(--blue); text-decoration: none; font-weight: 500; }
.auth-switch a:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════
   LAYOUT
═══════════════════════════════════════════ */
.mail-app {
  display: grid;
  grid-template-columns: 240px 320px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════ */
.sidebar {
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.06);
  overflow: hidden;
}
.sidebar-header {
  padding: 20px 16px 12px;
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0;
  cursor: pointer; position: relative; overflow: hidden;
  transition: opacity .15s;
}
.user-avatar:hover { opacity: .85; }
.user-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-edit-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .15s; border-radius: 50%;
}
.user-avatar:hover .avatar-edit-overlay { opacity: 1; }
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; color: var(--sidebar-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 11px; color: var(--sidebar-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-search { padding: 0 12px 12px; }
.search-wrap {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.08); border-radius: 8px; padding: 7px 10px;
}
.search-wrap svg { color: rgba(255,255,255,.35); flex-shrink: 0; }
.search-wrap input { background: none; border: none; outline: none; color: var(--sidebar-text); font-size: 13px; font-family: inherit; width: 100%; }
.search-wrap input::placeholder { color: rgba(255,255,255,.3); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 0 8px; }
.nav-section-label {
  font-size: 10px; font-weight: 600; color: var(--sidebar-sub);
  text-transform: uppercase; letter-spacing: .6px; padding: 8px 8px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  text-decoration: none; color: var(--sidebar-text);
  transition: background .1s; font-size: 14px;
}
.nav-item:hover { background: var(--sidebar-hover); }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-icon { display: flex; align-items: center; color: var(--sidebar-sub); width: 20px; }
.nav-item.active .nav-icon { color: var(--blue); }
.nav-label { flex: 1; }
.nav-badge {
  background: var(--badge-bg); color: var(--badge-text);
  font-size: 11px; font-weight: 700; min-width: 18px; height: 18px;
  border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.nav-badge--gray { background: rgba(255,255,255,.2); }
.sidebar-footer { padding: 12px 16px 20px; border-top: 1px solid rgba(255,255,255,.06); }
.logout-btn {
  display: flex; align-items: center; gap: 8px;
  color: var(--sidebar-sub); background: none; border: none;
  cursor: pointer; font-size: 13px; font-family: inherit;
  padding: 6px 4px; width: 100%; border-radius: 6px; transition: color .1s;
}
.logout-btn:hover { color: var(--danger); }

/* ═══════════════════════════════════════════
   EMAIL LIST PANE
═══════════════════════════════════════════ */
.email-list-pane {
  background: var(--list-bg);
  display: flex; flex-direction: column;
  border-right: 1px solid var(--list-border);
  overflow: hidden;
}
.pane-header {
  padding: 16px 16px 12px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--list-border);
}
.pane-title { font-size: 22px; font-weight: 700; }
.email-list { flex: 1; overflow-y: auto; }

.email-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid var(--list-border);
  transition: background .1s;
}
.email-item:hover { background: var(--list-hover); }
.email-item.selected { background: var(--list-active); }
.email-item.unread .email-item-subject { font-weight: 600; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--unread-dot); flex-shrink: 0; margin-top: 6px; }
.unread-dot.hidden { visibility: hidden; }
.item-avatar { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; color: #fff; flex-shrink: 0; overflow: hidden; }
.email-item-content { flex: 1; min-width: 0; }
.email-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.email-item-from { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.email-item-date { font-size: 11px; color: var(--text-tertiary); flex-shrink: 0; }
.email-item-subject { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 1px 0; }
.email-item-preview { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-item-star { color: #FF9F0A; font-size: 14px; flex-shrink: 0; opacity: 0; transition: opacity .1s; line-height: 1; }
.email-item:hover .email-item-star,
.email-item-star.visible { opacity: 1; }

/* ═══════════════════════════════════════════
   EMAIL DETAIL PANE
═══════════════════════════════════════════ */
.email-detail-pane { background: var(--detail-bg); display: flex; flex-direction: column; overflow: hidden; }
.detail-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--text-tertiary); }
.detail-empty p { font-size: 16px; }
.detail-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.detail-toolbar {
  display: flex; align-items: center; gap: 4px;
  padding: 10px 20px; border-bottom: 1px solid var(--list-border);
  background: #FAFAFA; flex-shrink: 0;
}
.detail-header { padding: 24px 28px 18px; border-bottom: 1px solid var(--list-border); flex-shrink: 0; }
.detail-subject { font-size: 20px; font-weight: 700; margin-bottom: 16px; line-height: 1.3; }
.detail-meta { display: flex; align-items: center; gap: 12px; }
.sender-avatar { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700; color: #fff; flex-shrink: 0; overflow: hidden; }
.detail-from-block { flex: 1; }
.detail-from-name { font-size: 15px; font-weight: 600; }
.detail-from-email { font-size: 13px; color: var(--text-secondary); }
.detail-date { font-size: 12px; color: var(--text-tertiary); }
.detail-recipients { font-size: 12px; color: var(--text-secondary); margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; }

/* Attachments in detail */
.detail-attachments {
  padding: 10px 28px;
  border-bottom: 1px solid var(--list-border);
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: #FAFAFA; flex-shrink: 0;
}
.att-header { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px; width: 100%; margin-bottom: 2px; }
.att-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--list-border); border-radius: 8px;
  padding: 5px 10px; font-size: 12px; color: var(--text-primary);
  text-decoration: none; transition: background .1s;
}
.att-chip:hover { background: var(--list-hover); }
.att-chip.pending { background: #EEF5FF; border-color: #B8D4FF; color: var(--blue); }
.att-size { color: var(--text-tertiary); font-size: 11px; }

.detail-body { flex: 1; overflow-y: auto; padding: 28px; font-size: 15px; line-height: 1.7; }
.detail-body p { margin-bottom: 12px; }
.detail-body img { max-width: 100%; border-radius: 8px; }

/* ═══════════════════════════════════════════
   COMPOSE MODAL
═══════════════════════════════════════════ */
.compose-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.3);
  display: flex; align-items: flex-end; justify-content: flex-end;
  z-index: 1000; padding: 0 24px 24px;
  pointer-events: none; /* allow clicking behind */
}
.compose-overlay > .compose-modal { pointer-events: all; }

.compose-modal {
  background: #fff; border-radius: 16px; width: 580px;
  box-shadow: 0 24px 64px rgba(0,0,0,.28);
  display: flex; flex-direction: column;
  max-height: calc(100vh - 80px);
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.compose-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--list-border);
  flex-shrink: 0;
}
.compose-title { font-size: 14px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compose-header-actions { display: flex; gap: 2px; flex-shrink: 0; }

.compose-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }

/* Tag-based recipient fields */
.compose-field {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 14px; border-bottom: 1px solid var(--list-border);
  position: relative; min-height: 38px;
}
.compose-field label { font-size: 13px; color: var(--text-secondary); width: 36px; flex-shrink: 0; padding-top: 5px; }
.compose-field input {
  border: none; outline: none; font-size: 14px;
  font-family: inherit; color: var(--text-primary);
  min-width: 120px; flex: 1; padding: 4px 0;
}
.compose-field--tags .compose-field { align-items: flex-start; }

.tags-input-wrap {
  flex: 1; display: flex; flex-wrap: wrap; gap: 4px;
  align-items: center; min-height: 28px;
}
.tag-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: #EEF5FF; border: 1px solid #B8D4FF; border-radius: 20px;
  padding: 2px 8px 2px 10px; font-size: 12px; color: var(--blue);
}
.tag-chip button { background: none; border: none; cursor: pointer; color: var(--blue); font-size: 14px; line-height: 1; padding: 0; }

.cc-toggle-btn {
  background: none; border: 1px solid var(--list-border); border-radius: 6px;
  font-size: 11px; font-weight: 600; color: var(--text-secondary); padding: 2px 7px;
  cursor: pointer; align-self: flex-start; margin-top: 5px; flex-shrink: 0;
  transition: background .1s;
}
.cc-toggle-btn:hover { background: var(--list-hover); }

.autocomplete-list {
  position: absolute; top: 100%; left: 50px; right: 14px;
  background: #fff; border-radius: 10px; box-shadow: var(--shadow);
  border: 1px solid var(--list-border); z-index: 20; max-height: 180px; overflow-y: auto;
}
.autocomplete-item { padding: 8px 14px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 10px; }
.autocomplete-item:hover { background: var(--list-hover); }

/* Toolbar */
.compose-toolbar {
  display: flex; align-items: center; gap: 2px; padding: 5px 10px;
  border-bottom: 1px solid var(--list-border); background: #FAFAFA; flex-shrink: 0;
  flex-wrap: wrap;
}
.toolbar-btn {
  width: 28px; height: 28px; border: none; background: none; cursor: pointer;
  border-radius: 6px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--text-secondary); font-family: inherit;
  transition: background .1s;
}
.toolbar-btn:hover { background: var(--list-border); color: var(--text-primary); }
.toolbar-btn.active { background: var(--list-border); color: var(--blue); }
.toolbar-sep { width: 1px; height: 18px; background: var(--list-border); margin: 0 2px; flex-shrink: 0; }
.toolbar-select {
  border: 1px solid var(--list-border); border-radius: 6px; background: #fff;
  font-size: 12px; padding: 3px 5px; color: var(--text-secondary); cursor: pointer;
}

/* Editor */
.compose-editor {
  flex: 1; min-height: 160px; padding: 14px 16px; outline: none;
  font-size: 14px; line-height: 1.65; font-family: inherit; color: var(--text-primary);
  overflow-y: auto;
}
.compose-editor:empty::before { content: attr(data-placeholder); color: var(--text-tertiary); pointer-events: none; display: block; }
.compose-editor img { max-width: 100%; border-radius: 6px; }

/* Attachments zone in compose */
.attachments-zone {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  padding: 8px 14px; border-top: 1px solid var(--list-border);
  background: #FAFAFA; flex-shrink: 0;
}
.attachments-list { display: flex; flex-wrap: wrap; gap: 6px; }
.attach-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-secondary); cursor: pointer;
  padding: 4px 10px; border: 1px dashed var(--list-border); border-radius: 8px;
  transition: background .1s; user-select: none;
}
.attach-btn:hover { background: var(--list-hover); color: var(--text-primary); }

/* Compose footer */
.compose-footer {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; border-top: 1px solid var(--list-border); flex-shrink: 0;
}
.btn-send {
  display: flex; align-items: center; gap: 7px;
  background: var(--blue); color: #fff; border: none; border-radius: 10px;
  padding: 8px 20px; font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: background .15s;
}
.btn-send:hover { background: var(--blue-dark); }
.btn-send:disabled { opacity: .6; cursor: not-allowed; }
.compose-status { font-size: 12px; color: var(--text-tertiary); flex: 1; text-align: right; }

/* ── Minimized tab ─────────────────────────── */
.compose-tab {
  position: fixed; bottom: 0; right: 24px; z-index: 1001;
  background: #2C2C2E; color: rgba(255,255,255,.9);
  border-radius: 12px 12px 0 0;
  padding: 10px 16px; display: flex; align-items: center; gap: 8px;
  cursor: pointer; box-shadow: 0 -4px 20px rgba(0,0,0,.2);
  font-size: 13px; font-weight: 500;
  transition: background .1s;
  max-width: 260px;
}
.compose-tab:hover { background: #3A3A3C; }
.compose-tab span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ═══════════════════════════════════════════
   PROFILE MODAL
═══════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000; padding: 24px;
}
.modal-card {
  background: #fff; border-radius: 20px; width: 100%; max-width: 460px;
  box-shadow: 0 24px 64px rgba(0,0,0,.3); animation: slideUp .2s ease;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px 14px; border-bottom: 1px solid var(--list-border);
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.profile-body { padding: 24px; display: flex; gap: 24px; }
.profile-avatar-section { display: flex; flex-direction: column; align-items: center; gap: 12px; flex-shrink: 0; }
.profile-avatar-preview {
  width: 90px; height: 90px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 700; color: #fff; overflow: hidden;
}
.profile-avatar-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.btn-upload-avatar {
  display: flex; align-items: center; gap: 6px;
  background: var(--blue); color: #fff; border-radius: 8px;
  padding: 7px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; user-select: none; transition: background .1s;
}
.btn-upload-avatar:hover { background: var(--blue-dark); }
.btn-remove-avatar {
  font-size: 12px; color: var(--danger); background: none; border: none;
  cursor: pointer; font-family: inherit;
}
.btn-remove-avatar:hover { text-decoration: underline; }
.profile-info { flex: 1; display: flex; flex-direction: column; gap: 12px; }
.profile-row { display: flex; flex-direction: column; gap: 2px; }
.profile-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--text-tertiary); }
.profile-row span:last-child { font-size: 14px; color: var(--text-primary); }
.modal-footer { padding: 12px 24px; border-top: 1px solid var(--list-border); min-height: 40px; }
.profile-status { font-size: 13px; color: var(--success); }

/* ═══════════════════════════════════════════
   SHARED
═══════════════════════════════════════════ */
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px;
  border: none; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); transition: background .1s, color .1s; flex-shrink: 0;
}
.icon-btn:hover { background: var(--list-hover); color: var(--text-primary); }
.icon-btn--danger:hover { color: var(--danger); background: #FFF2F1; }
.icon-btn.active { color: #FF9F0A; }
.icon-btn.active:hover { color: #e08900; }

.loading-state { display: flex; justify-content: center; align-items: center; padding: 60px; }
.spinner { width: 28px; height: 28px; border: 2.5px solid var(--list-border); border-top-color: var(--blue); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 60px 20px; color: var(--text-tertiary); font-size: 14px; }

/* ═══════════════════════════════════════════
   THREAD (fil de réponses)
═══════════════════════════════════════════ */
.detail-thread { flex-shrink: 0; border-top: 2px solid var(--list-border); background: #FAFAFA; }
.thread-header {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 28px; font-size: 12px; font-weight: 600;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px;
}
.thread-message {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 28px; border-top: 1px solid var(--list-border);
  cursor: pointer; transition: background .1s;
}
.thread-message:hover { background: var(--list-hover); }
.thread-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; overflow: hidden;
}
.thread-content { flex: 1; min-width: 0; }
.thread-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.thread-from { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.thread-date { font-size: 11px; color: var(--text-tertiary); flex-shrink: 0; }
.thread-preview { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

/* ═══════════════════════════════════════════
   COMPOSE RESIZE HANDLE
═══════════════════════════════════════════ */
.compose-resize-handle {
  position: absolute; top: 0; left: 0;
  width: 20px; height: 20px;
  cursor: nw-resize;
  z-index: 10;
}
.compose-resize-handle::before {
  content: '';
  position: absolute; top: 6px; left: 6px;
  width: 8px; height: 8px;
  border-top: 2px solid var(--text-tertiary);
  border-left: 2px solid var(--text-tertiary);
  border-radius: 1px;
}
.compose-modal { position: relative; }

/* ═══════════════════════════════════════════
   Scrollbars
═══════════════════════════════════════════ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); border-radius: 3px; }
