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

:root {
  --bg: #0f0f13;
  --surface: #17171f;
  --surface2: #1e1e28;
  --surface3: #25252f;
  --border: #2a2a36;
  --accent: #6366f1;
  --accent-hover: #4f52d3;
  --text: #e8e8f0;
  --text-muted: #8888a8;
  --text-dim: #55556a;
  --danger: #ef4444;
  --success: #22c55e;
  --inbox-width: 320px;
  --sidebar-width: 220px;
}

html, body { height: 100%; font-family: 'Inter', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ── LOGIN ── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: radial-gradient(ellipse at 50% 0%, #1a1a2e 0%, var(--bg) 70%); }

.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 40px 36px; box-shadow: 0 32px 80px rgba(0,0,0,.5); }

.logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.logo svg { width: 36px; height: 36px; flex-shrink: 0; }
.logo span { font-size: 20px; font-weight: 700; letter-spacing: -.3px; color: var(--text); }

.login-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-card .subtitle { color: var(--text-muted); margin-bottom: 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.field input { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; color: var(--text); font-size: 14px; outline: none; transition: border-color .15s; }
.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--text-dim); }

.options { margin-bottom: 20px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text-muted); font-size: 13px; user-select: none; }
.checkbox-label input { accent-color: var(--accent); width: 14px; height: 14px; }

.btn-primary { width: 100%; background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 11px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background .15s, transform .1s; margin-top: 4px; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(.98); }

.error-msg { margin-top: 12px; color: var(--danger); font-size: 13px; text-align: center; }
.hidden { display: none !important; }

/* Saved accounts grid */
.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; margin-bottom: 16px; }

.account-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 16px 10px 14px; text-align: center; cursor: pointer; transition: background .15s, border-color .15s, transform .1s; user-select: none; }
.account-card:hover { background: var(--surface3); border-color: var(--accent); }
.account-card:active { transform: scale(.97); }
.ac-avatar { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; color: #fff; margin: 0 auto 8px; }
.ac-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-email { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.add-account-btn { width: 100%; background: none; border: 1px dashed var(--border); border-radius: 8px; padding: 10px; color: var(--text-muted); font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 7px; transition: border-color .15s, color .15s; margin-top: 4px; }
.add-account-btn:hover { border-color: var(--accent); color: var(--text); }
.add-account-btn svg { width: 14px; height: 14px; }

.back-link { background: none; border: none; color: var(--accent); font-size: 13px; cursor: pointer; padding: 0; margin-top: 16px; display: block; transition: opacity .15s; }
.back-link:hover { opacity: .75; }

/* Quick login */
.quick-avatar { width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; color: #fff; margin: 8px auto 10px; }
.quick-name { font-size: 18px; font-weight: 700; text-align: center; }
.quick-email { font-size: 13px; color: var(--text-muted); text-align: center; margin-top: 2px; }

.danger-link { background: none; border: none; color: var(--danger); font-size: 12px; cursor: pointer; padding: 0; margin-top: 20px; display: block; text-align: center; opacity: .6; transition: opacity .15s; }
.danger-link:hover { opacity: 1; }

/* Create account */
.form-switch { margin-top: 16px; text-align: center; font-size: 13px; color: var(--text-muted); }
.link-btn { background: none; border: none; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; transition: opacity .15s; }
.link-btn:hover { opacity: .75; }

.email-row { display: flex; gap: 8px; }
.email-row input { flex: 1; min-width: 0; }
.email-row select { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; color: var(--text); font-size: 14px; outline: none; cursor: pointer; transition: border-color .15s; }
.email-row select:focus { border-color: var(--accent); }

/* Admin access link (login page) */
.admin-access-link { position: fixed; bottom: 18px; right: 20px; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); text-decoration: none; opacity: .7; transition: opacity .15s, color .15s; }
.admin-access-link svg { width: 14px; height: 14px; }
.admin-access-link:hover { opacity: 1; color: var(--accent); }

/* ── ADMIN PANEL ── */
.admin-tag { font-size: 10px; font-weight: 800; letter-spacing: 1px; background: var(--accent); color: #fff; padding: 2px 6px; border-radius: 5px; vertical-align: middle; }
.admin-shell { display: flex; flex-direction: column; height: 100vh; }
.admin-topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.admin-topbar .logo, #adminLogin .logo { gap: 8px; align-items: center; }
.admin-topbar .logo svg { width: 20px; height: 20px; flex-shrink: 0; }
#adminLogin .logo svg { width: 26px; height: 26px; flex-shrink: 0; }
#adminLogin .logo { margin-bottom: 22px; }
.admin-topbar .logo-name { font-size: 16px; font-weight: 700; line-height: 1; }
#adminLogin .logo-name { font-size: 17px; font-weight: 700; line-height: 1; }
.logo .admin-tag { font-size: 10px; line-height: 1; vertical-align: baseline; }
.admin-owner { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-muted); }
.owner-badge { font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px; background: var(--surface3); color: var(--accent); }

.admin-tabs { display: flex; gap: 2px; padding: 0 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.admin-tab { background: none; border: none; color: var(--text-muted); font-size: 13px; font-weight: 600; padding: 13px 16px; cursor: pointer; border-bottom: 2px solid transparent; transition: color .15s, border-color .15s; }
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--text); border-bottom-color: var(--accent); }

.admin-content { flex: 1; overflow: auto; padding: 24px 28px; }
.admin-section-title { font-size: 16px; font-weight: 700; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.stat-num { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 4px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.data-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); padding: 11px 14px; border-bottom: 1px solid var(--border); background: var(--surface2); }
.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface2); }
.data-table .mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12px; }
.data-table .dim { color: var(--text-dim); }
.empty-row { text-align: center; color: var(--text-dim); padding: 28px !important; }

.tag-pill { display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 20px; background: var(--surface3); color: var(--text-muted); }
.ac-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.founder-badge { font-size: 11px; font-weight: 700; color: var(--success); margin-left: 4px; }

.admin-form-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 22px; max-width: 440px; margin-bottom: 24px; }
.admin-form-card h3 { font-size: 14px; margin-bottom: 4px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }
.btn-danger-sm { background: none; border: 1px solid var(--border); color: var(--danger); font-size: 12px; padding: 4px 11px; border-radius: 6px; cursor: pointer; transition: border-color .15s; }
.btn-danger-sm:hover { border-color: var(--danger); }
.btn-ghost-sm { background: none; border: 1px solid var(--border); color: var(--text-muted); font-size: 12px; padding: 4px 11px; border-radius: 6px; cursor: pointer; transition: border-color .15s, color .15s; }
.btn-ghost-sm:hover { border-color: var(--accent); color: var(--text); }
.row-actions { display: flex; gap: 8px; }
.form-row-btns { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.admin-form-card.editing { border-color: var(--accent); }

/* ── APP SHELL ── */
#app { display: none; height: 100vh; overflow: hidden; }
#app.visible { display: flex; }

/* Sidebar */
.sidebar { width: var(--sidebar-width); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }

.sidebar-header { padding: 18px 16px 14px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); }
.sidebar-header .logo-icon { width: 26px; height: 26px; }
.sidebar-header .brand { font-size: 15px; font-weight: 700; }

/* Account switcher */
.account-switcher { border-bottom: 1px solid var(--border); position: relative; }
.current-account { display: flex; align-items: center; gap: 9px; padding: 10px 12px; cursor: pointer; transition: background .12s; user-select: none; }
.current-account:hover { background: var(--surface2); }
.ac-dot { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; }
.ac-switcher-info { flex: 1; overflow: hidden; }
.ac-switcher-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-switcher-email { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-chevron { width: 14px; height: 14px; color: var(--text-dim); flex-shrink: 0; transition: transform .2s; }
.current-account.open .ac-chevron { transform: rotate(180deg); }

.ac-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-top: none; border-radius: 0 0 10px 10px; box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 50; overflow: hidden; }
.ac-list { max-height: 200px; overflow-y: auto; }
.ac-row { display: flex; align-items: center; gap: 9px; padding: 9px 12px; cursor: pointer; transition: background .1s; }
.ac-row:hover { background: var(--surface2); }
.ac-row.active-account { background: var(--surface3); }
.ac-row-dot { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; }
.ac-row-info { flex: 1; overflow: hidden; }
.ac-row-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-row-email { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-row-check { color: var(--accent); }
.ac-row-check svg { width: 14px; height: 14px; }
.ac-dropdown-footer { border-top: 1px solid var(--border); padding: 6px; }
.ac-add-btn { width: 100%; background: none; border: none; color: var(--text-muted); font-size: 12px; cursor: pointer; padding: 7px 8px; border-radius: 6px; display: flex; align-items: center; gap: 7px; transition: background .12s, color .12s; }
.ac-add-btn:hover { background: var(--surface2); color: var(--text); }
.ac-add-btn svg { width: 13px; height: 13px; }

.compose-btn { margin: 12px; background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 9px 14px; font-size: 13px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 7px; transition: background .15s; }
.compose-btn:hover { background: var(--accent-hover); }
.compose-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.nav { padding: 4px 8px; flex: 1; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; cursor: pointer; color: var(--text-muted); font-size: 13px; transition: background .12s, color .12s; user-select: none; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface3); color: var(--text); font-weight: 600; }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-badge { margin-left: auto; background: var(--accent); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; font-weight: 700; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.user-pill { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--text-muted); font-size: 13px; transition: background .12s, color .12s; }
.user-pill:hover { background: var(--surface2); color: var(--danger); }

/* Inbox list */
.inbox-panel { width: var(--inbox-width); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; background: var(--bg); }

.panel-header { padding: 16px 16px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.panel-title { font-size: 15px; font-weight: 700; }
.panel-actions { display: flex; gap: 4px; }
.icon-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 5px; border-radius: 6px; display: flex; align-items: center; transition: background .12s, color .12s; }
.icon-btn:hover { background: var(--surface2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

.search-box { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.search-box input { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 7px; padding: 7px 12px; color: var(--text); font-size: 13px; outline: none; transition: border-color .15s; }
.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--text-dim); }

.mail-list { flex: 1; overflow-y: auto; }
.mail-item { padding: 13px 14px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s; position: relative; }
.mail-item:hover { background: var(--surface); }
.mail-item.active { background: var(--surface2); }
.mail-item.unread .mail-from { font-weight: 700; color: var(--text); }
.mail-item.unread::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); border-radius: 0 2px 2px 0; }
.mail-row1 { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; }
.mail-from { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.mail-date { font-size: 11px; color: var(--text-dim); flex-shrink: 0; }
.mail-subject { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
.mail-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-tag { display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 4px; margin-top: 4px; font-weight: 600; }
.tag-inbox { background: rgba(99,102,241,.15); color: var(--accent); }
.tag-sent { background: rgba(34,197,94,.12); color: var(--success); }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-dim); gap: 10px; padding: 20px; text-align: center; }
.empty-state svg { width: 40px; height: 40px; opacity: .3; }

/* Reading pane */
.reading-pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.read-placeholder { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-dim); gap: 12px; }
.read-placeholder svg { width: 48px; height: 48px; opacity: .2; }
.read-placeholder p { font-size: 14px; }

.read-view { display: none; flex-direction: column; height: 100%; }
.read-view.visible { display: flex; }

.read-toolbar { padding: 12px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.read-toolbar .icon-btn { padding: 7px; border-radius: 7px; }

.read-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); }
.read-subject { font-size: 18px; font-weight: 700; margin-bottom: 14px; line-height: 1.3; }
.read-meta { display: flex; align-items: flex-start; gap: 12px; }
.read-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--surface3); display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; color: var(--text-muted); flex-shrink: 0; }
.read-from-block { flex: 1; }
.read-from { font-size: 14px; font-weight: 600; }
.read-addr { font-size: 12px; color: var(--text-muted); }
.read-datetime { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.read-body { flex: 1; overflow-y: auto; padding: 24px; line-height: 1.7; color: var(--text); white-space: pre-wrap; font-size: 14px; }
.read-body a { color: var(--accent); }

.read-actions { padding: 12px 24px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.btn-ghost { background: var(--surface2); border: 1px solid var(--border); color: var(--text); border-radius: 7px; padding: 8px 14px; font-size: 13px; font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 6px; transition: background .12s; }
.btn-ghost:hover { background: var(--surface3); }
.btn-ghost svg { width: 14px; height: 14px; }

/* Compose modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: flex-end; padding: 20px; z-index: 100; }
.modal-overlay.hidden { display: none !important; }

.compose-modal { width: 520px; max-height: 82vh; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; display: flex; flex-direction: column; box-shadow: 0 24px 64px rgba(0,0,0,.6); overflow: hidden; }

.modal-header { padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: var(--surface2); }
.modal-title { font-size: 14px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; border-radius: 5px; display: flex; align-items: center; transition: color .12s; }
.modal-close:hover { color: var(--text); }
.modal-close svg { width: 18px; height: 18px; }

.compose-fields { padding: 0; border-bottom: 1px solid var(--border); }
.compose-row { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.compose-row:last-child { border-bottom: none; }
.compose-row label { font-size: 12px; color: var(--text-muted); font-weight: 600; width: 32px; flex-shrink: 0; }
.compose-row input { flex: 1; background: none; border: none; color: var(--text); font-size: 14px; outline: none; }
.compose-row input::placeholder { color: var(--text-dim); }

.compose-body textarea { width: 100%; background: none; border: none; color: var(--text); font-size: 14px; outline: none; padding: 16px; resize: none; min-height: 200px; line-height: 1.6; font-family: inherit; }

.compose-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.send-btn { background: var(--accent); color: #fff; border: none; border-radius: 7px; padding: 9px 20px; font-size: 13px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 7px; transition: background .15s; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn svg { width: 15px; height: 15px; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Affichage HTML des mails + pièces jointes */
.mail-frame { width: 100%; border: 0; min-height: 240px; background: #fff; border-radius: 8px; }
.read-attachments { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 8px; }
.att-title { width: 100%; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.att-chip { display: inline-flex; align-items: center; gap: 7px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 11px; font-size: 13px; color: var(--text); text-decoration: none; transition: border-color .15s; }
.att-chip:hover { border-color: var(--accent); }
.att-chip svg { width: 15px; height: 15px; flex-shrink: 0; color: var(--text-muted); }
.att-size { color: var(--text-dim); font-size: 12px; }
.att-rm { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 0 0 2px; }
.att-rm:hover { color: var(--danger); }
.compose-attach-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px; }
.compose-attach-list:not(:empty) { padding-bottom: 10px; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .inbox-panel { width: 100%; }
  .reading-pane { display: none; }
}
