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

:root {
  --bg:        #0d0d0f;
  --surface:   #16161a;
  --surface2:  #1c1c22;
  --surface3:  #222228;
  --accent:    #4f8ef7;
  --accent-dim:#2d5ab8;
  --danger:    #e05252;
  --text:      #e8e8f0;
  --text-muted:#8888a0;
  --border:    #2a2a35;
  --radius:    8px;
  --mono:      'JetBrains Mono', monospace;
  --sans:      'Inter', system-ui, sans-serif;
}

html, body, #root { height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; }

/* ── Scrollbars ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius); border: none; cursor: pointer; font-size: 13px; font-family: var(--sans); font-weight: 500; transition: all .15s; text-decoration: none; white-space: nowrap; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #3d7ae8; }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface3); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 16px; padding: 4px; line-height: 1; transition: color .15s; }
.btn-icon:hover { color: var(--text); }
.btn-icon-only { padding: 6px 8px; display: flex; align-items: center; justify-content: center; }
.btn-text { background: none; border: none; cursor: pointer; color: var(--accent); font-size: 12px; padding: 0 4px; }

/* ── Inputs ──────────────────────────────────────────────── */
.input { width: 100%; padding: 8px 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 13px; font-family: var(--sans); transition: border-color .15s; outline: none; }
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-muted); }

/* ── Misc ────────────────────────────────────────────────── */
.error-msg { color: var(--danger); font-size: 12px; margin-top: 6px; }
.loading { color: var(--text-muted); padding: 24px; text-align: center; font-size: 13px; }
.loading-screen { display: flex; align-items: center; justify-content: center; height: 100vh; }
.empty-state { color: var(--text-muted); text-align: center; padding: 32px; font-size: 13px; }
.empty-state-center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; height: 100%; color: var(--text-muted); }
.empty-state-center svg { opacity: .3; }
.empty-state-center p { font-size: 13px; }

/* ── Login ───────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 40px; width: 360px; display: flex; flex-direction: column; gap: 20px; }
.login-logo { display: flex; align-items: center; gap: 12px; }
.login-logo h1 { font-size: 20px; font-weight: 600; }
.login-subtitle { color: var(--text-muted); font-size: 13px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }
.mail-link { color: var(--text-muted); font-size: 12px; text-align: center; text-decoration: none; margin-top: 4px; }
.mail-link:hover { color: var(--accent); }

/* ── Admin Panel ─────────────────────────────────────────── */
.admin-panel { min-height: 100vh; background: var(--bg); }
.admin-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 32px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.admin-title { display: flex; align-items: center; gap: 10px; }
.admin-title h1 { font-size: 17px; font-weight: 600; }
.admin-header-actions { display: flex; gap: 8px; }
.admin-content { max-width: 900px; margin: 0 auto; padding: 32px 24px; }
.accounts-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.accounts-header h2 { font-size: 16px; font-weight: 600; }
.accounts-list { display: flex; flex-direction: column; gap: 12px; }
.account-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; align-items: flex-start; gap: 14px; }
.account-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--accent-dim); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 15px; flex-shrink: 0; letter-spacing: .5px; }
.account-info { flex: 1; min-width: 0; }
.account-name { font-weight: 600; font-size: 14px; }
.account-email { color: var(--text-muted); font-size: 12px; margin-top: 2px; font-family: var(--mono); }
.account-servers { color: var(--text-muted); font-size: 11px; margin-top: 6px; font-family: var(--mono); }
.account-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.test-results { display: flex; gap: 10px; font-size: 11px; font-family: var(--mono); }
.test-ok { color: #4ade80; }
.test-fail { color: var(--danger); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: 560px; max-width: 100%; max-height: 90vh; overflow-y: auto; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 16px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 16px; font-weight: 600; }
.account-form { padding: 20px 24px; display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-row label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.form-row-2 { display: grid; grid-template-columns: 1fr 100px; gap: 12px; }
.form-section-label { font-size: 11px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--border); }
.checkbox-row label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
.checkbox-row input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 8px; border-top: 1px solid var(--border); margin-top: 8px; }

/* ── Webmail layout ──────────────────────────────────────── */
.webmail { display: flex; height: 100vh; overflow: hidden; }
.webmail-empty { display: flex; align-items: center; justify-content: center; height: 100vh; }
.webmail-empty .empty-state-center { gap: 16px; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar { width: 260px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-brand { display: flex; align-items: center; gap: 9px; padding: 16px 16px 12px; font-weight: 600; font-size: 15px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.account-switcher { padding: 10px 8px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.account-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius); cursor: pointer; transition: background .12s; position: relative; }
.account-chip:hover { background: var(--surface2); }
.account-chip.active { background: var(--surface3); }
.account-chip-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-dim); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; letter-spacing: .5px; }
.account-chip.active .account-chip-avatar { background: var(--accent); }
.account-chip-info { flex: 1; min-width: 0; }
.account-chip-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-chip-email { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); }
.unread-badge { background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 10px; min-width: 18px; text-align: center; flex-shrink: 0; }
.folder-list { flex: 1; overflow-y: auto; padding: 8px; }
.folder-item { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: var(--radius); cursor: pointer; transition: background .12s; }
.folder-item:hover { background: var(--surface2); }
.folder-item.active { background: var(--surface3); color: var(--accent); }
.folder-icon { font-size: 14px; flex-shrink: 0; }
.folder-name { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-badge { background: var(--surface3); color: var(--text-muted); font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 10px; font-family: var(--mono); }
.folder-item.active .folder-badge { background: rgba(79,142,247,.2); color: var(--accent); }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
.sidebar-admin-link { color: var(--text-muted); font-size: 12px; text-decoration: none; }
.sidebar-admin-link:hover { color: var(--text); }

/* ── Main content ────────────────────────────────────────── */
.main-content { flex: 1; display: flex; overflow: hidden; }

/* ── Message list column ─────────────────────────────────── */
.message-list-col { width: 380px; flex-shrink: 0; border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.message-list-top-bar { padding: 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.compose-btn { width: 100%; justify-content: center; }
.message-list-pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.message-list-header { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.folder-title { font-size: 13px; font-weight: 600; flex: 1; }
.search-form { display: flex; gap: 4px; }
.search-input { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 9px; color: var(--text); font-size: 12px; width: 130px; outline: none; }
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }
.search-btn { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 9px; cursor: pointer; color: var(--text); font-size: 12px; }
.message-list { flex: 1; overflow-y: auto; }
.message-item { display: flex; align-items: flex-start; gap: 10px; padding: 12px; cursor: pointer; border-bottom: 1px solid rgba(42,42,53,.6); transition: background .1s; position: relative; }
.message-item:hover { background: var(--surface2); }
.message-item.selected { background: var(--surface3); }
.message-item.unread .message-item-from { font-weight: 700; }
.message-item.unread .message-item-subject { color: var(--text); font-weight: 500; }
.message-item-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--surface3); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; letter-spacing: .5px; }
.message-item-content { flex: 1; min-width: 0; }
.message-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.message-item-from { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.message-item-date { font-size: 11px; color: var(--text-muted); font-family: var(--mono); flex-shrink: 0; }
.message-item-subject { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.unread-dot { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 10px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); flex-shrink: 0; }

/* ── Message view column ─────────────────────────────────── */
.message-view-col { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.message-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
.message-view.empty { align-items: center; justify-content: center; }
.message-view-header { padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.message-view-actions { display: flex; gap: 6px; margin-bottom: 12px; }
.message-subject { font-size: 17px; font-weight: 600; margin-bottom: 12px; line-height: 1.4; }
.message-meta { display: flex; align-items: center; gap: 10px; }
.message-from-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-dim); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; letter-spacing: .5px; }
.message-from-info { flex: 1; min-width: 0; }
.message-from-name { font-size: 13px; font-weight: 600; }
.message-from-email { font-size: 11px; color: var(--text-muted); font-family: var(--mono); }
.message-date { font-size: 11px; color: var(--text-muted); font-family: var(--mono); flex-shrink: 0; }
.message-to { font-size: 11px; color: var(--text-muted); margin-top: 6px; padding-left: 46px; }
.message-body { flex: 1; overflow: hidden; }
.email-iframe { width: 100%; height: 100%; border: none; background: #fff; }
.email-text { flex: 1; overflow-y: auto; padding: 20px; font-family: var(--mono); font-size: 13px; line-height: 1.7; white-space: pre-wrap; color: var(--text); }
.message-attachments { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.attachments-label { font-size: 11px; color: var(--text-muted); font-weight: 600; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .06em; }
.attachment-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 12px; }
.attachment-name { flex: 1; color: var(--accent); }
.attachment-size { color: var(--text-muted); font-family: var(--mono); font-size: 11px; }

/* ── Compose ─────────────────────────────────────────────── */
.compose-overlay { position: fixed; inset: 0; z-index: 200; pointer-events: none; display: flex; align-items: flex-end; justify-content: flex-end; padding: 20px; }
.compose-window { pointer-events: all; width: 560px; height: 520px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.compose-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px; flex-shrink: 0; }
.compose-fields { border-bottom: 1px solid var(--border); flex-shrink: 0; }
.compose-field { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--border); }
.compose-field:last-child { border-bottom: none; }
.compose-label { font-size: 12px; color: var(--text-muted); width: 50px; flex-shrink: 0; }
.compose-input { flex: 1; background: none; border: none; padding: 9px 0; color: var(--text); font-size: 13px; font-family: var(--sans); outline: none; }
.compose-input::placeholder { color: var(--text-muted); }
.compose-field-actions { display: flex; gap: 2px; }
.compose-toolbar { display: flex; align-items: center; gap: 2px; padding: 6px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.toolbar-btn { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px 8px; border-radius: 4px; font-size: 13px; transition: all .12s; }
.toolbar-btn:hover { background: var(--surface2); color: var(--text); }
.toolbar-sep { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }
.compose-body { flex: 1; padding: 12px 16px; overflow-y: auto; font-size: 13px; line-height: 1.6; outline: none; color: var(--text); }
.compose-body:empty::before { content: 'Write your message...'; color: var(--text-muted); pointer-events: none; }
.compose-error { padding: 6px 16px; font-size: 12px; color: var(--danger); flex-shrink: 0; }
.compose-footer { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
.compose-attach-btn { margin-left: auto; }
.compose-attach-input { display: none; }

/* ── Responsive (mobile) ─────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 240px; position: fixed; left: -240px; top: 0; bottom: 0; z-index: 50; transition: left .2s; }
  .sidebar.open { left: 0; }
  .main-content { flex-direction: column; }
  .message-list-col { width: 100%; border-right: none; }
  .message-view-col { display: none; }
  .main-content.mobile-message .message-list-col { display: none; }
  .main-content.mobile-message .message-view-col { display: flex; }
  .compose-window { width: 100%; height: 100%; border-radius: 0; }
  .compose-overlay { padding: 0; }
}
@media (max-width: 1024px) {
  .message-list-col { width: 320px; }
}
