*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Sidebar — Pulse navy */
  --sidebar-bg: #0b1727;
  --sidebar-text: #e2e8f0;
  --sidebar-muted: #9fb3c8;
  --sidebar-border: rgba(255,255,255,0.07);
  --sidebar-hover: rgba(255,255,255,0.05);
  --sidebar-active-bg: rgba(13,202,240,0.18);
  --sidebar-w: 320px;

  /* Accent — Pulse navy with cyan-tinted light */
  --accent: #0b1727;
  --accent-hover: #14263b;
  --accent-light: #e6f6fb;

  /* Main surface */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --hover-bg: #f8fafc;

  /* Danger */
  --danger: #ef4444;
  --danger-hover: #dc2626;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

/* ── Layout ──────────────────────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--sidebar-text);
  letter-spacing: -0.01em;
}

.header-user { display: flex; align-items: center; gap: 6px; }
.user-label { font-size: 12px; color: var(--sidebar-muted); }

/* Sidebar icon buttons */
.sidebar .btn-icon {
  color: var(--sidebar-muted);
}
.sidebar .btn-icon:hover {
  background: rgba(255,255,255,0.1);
  color: var(--sidebar-text);
}

/* Search */
.search-wrap input {
  width: 100%;
  padding: 8px 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  font-size: 13px;
  color: var(--sidebar-text);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.search-wrap input::placeholder { color: var(--sidebar-muted); }
.search-wrap input:focus {
  border-color: var(--accent);
  background: rgba(255,255,255,0.12);
}

/* ── Email list ──────────────────────────────────────────────────────── */
.email-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.email-list::-webkit-scrollbar { width: 4px; }
.email-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

.email-list li.placeholder {
  padding: 20px;
  text-align: center;
  color: var(--sidebar-muted);
  font-size: 13px;
}

.email-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  cursor: pointer;
  transition: background 0.1s;
}
.email-item:hover { background: var(--sidebar-hover); }
.email-item.active {
  background: var(--sidebar-active-bg);
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}

.email-item-avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  margin-top: 1px;
}

.email-item-content { flex: 1; min-width: 0; }

.email-item-row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 3px;
}

.email-item-from {
  font-weight: 600;
  font-size: 13px;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.email-item-date {
  font-size: 11px;
  color: var(--sidebar-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.email-item-subject {
  font-size: 12px;
  color: var(--sidebar-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-item-attachment { font-size: 11px; color: var(--sidebar-muted); }

/* ── Pagination ──────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.pagination button {
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: var(--sidebar-text);
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.1s;
}
.pagination button:hover { background: rgba(255,255,255,0.12); }
.pagination button:disabled { opacity: 0.35; cursor: default; }
.pagination .page-info { font-size: 12px; color: var(--sidebar-muted); }

/* ── Detail pane ─────────────────────────────────────────────────────── */
.detail { flex: 1; overflow-y: auto; background: var(--bg); }

.detail-empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 15px;
}

.detail-card {
  background: var(--surface);
  margin: 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.detail-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.detail-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  line-height: 1.3;
}

.detail-sender-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.detail-sender-info { flex: 1; min-width: 0; }

.detail-sender-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.detail-sender-email {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-meta {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 4px 8px;
  font-size: 13px;
  margin-bottom: 14px;
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
}
.detail-meta .label {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
}

.detail-actions { display: flex; gap: 8px; }

/* Body */
.detail-body { padding: 24px; }
.detail-body iframe { width: 100%; border: none; min-height: 400px; }
.detail-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
}

/* Attachments */
.attachments {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.attachments h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.1s;
}
.attachment-chip:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}
.attachment-chip .icon { font-size: 15px; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  padding: 7px 16px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--hover-bg); border-color: #c8d0db; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 5px;
  transition: background 0.1s, color 0.1s;
}
.btn-icon:hover { background: var(--hover-bg); color: var(--text); }

/* ── Avatar ──────────────────────────────────────────────────────────── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  user-select: none;
}
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }
.avatar--md { width: 36px; height: 36px; font-size: 13px; }
.avatar--lg { width: 44px; height: 44px; font-size: 16px; }

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface);
  border-radius: 12px;
  width: 560px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-box--sm { width: 420px; }
.modal-box--lg { width: 680px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.modal-body p { flex: none; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.field-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.field-row label { width: 56px; font-size: 13px; color: var(--text-muted); font-weight: 500; flex-shrink: 0; }
.field-row input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.field-row input:focus { border-color: var(--accent); background: #fff; }

#replyBody, #forwardBody {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  margin-top: 4px;
  box-sizing: border-box;
  color: var(--text);
  background: var(--bg);
  outline: none;
}
#replyBody { resize: vertical; }
#forwardBody { resize: none; flex: 1; min-height: 0; }
#replyBody:focus, #forwardBody:focus { border-color: var(--accent); background: #fff; }

.action-status { margin-top: 10px; padding: 8px 12px; border-radius: 7px; font-size: 13px; }
.action-status.success { background: #dcfce7; color: #166534; }
.action-status.error { background: #fee2e2; color: #991b1b; }

/* ── Typeahead ───────────────────────────────────────────────────────── */
.typeahead-wrap { position: relative; flex: 1; }
.typeahead-wrap input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  background: var(--bg);
  outline: none;
}
.typeahead-wrap input:focus { border-color: var(--accent); background: #fff; }
.typeahead-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  list-style: none;
  z-index: 200;
  max-height: 220px;
  overflow-y: auto;
}
.typeahead-dropdown.hidden { display: none; }
.typeahead-dropdown li { padding: 8px 12px; cursor: pointer; font-size: 13px; }
.typeahead-dropdown li:hover,
.typeahead-dropdown li.active { background: var(--accent-light); color: var(--accent); }
.typeahead-dropdown li .ta-name { font-weight: 500; }
.typeahead-dropdown li .ta-email { color: var(--text-muted); font-size: 12px; }

/* ── Address Book ────────────────────────────────────────────────────── */
.ab-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.ab-toolbar input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  background: var(--bg);
  outline: none;
}
.ab-toolbar input:focus { border-color: var(--accent); }

.ab-add-form { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.ab-add-form input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  background: var(--bg);
  outline: none;
}
.ab-add-form input:focus { border-color: var(--accent); }
.ab-add-form.hidden { display: none; }

.btn-sm { padding: 5px 12px; font-size: 12px; }

.ab-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ab-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ab-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ab-table tr:last-child td { border-bottom: none; }
.ab-table tr:hover td { background: var(--hover-bg); }
.ab-placeholder { text-align: center; color: var(--text-muted); padding: 24px !important; }
.ab-name { font-weight: 500; }
.ab-email { color: var(--text-muted); font-size: 12px; }
.ab-date { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.ab-actions { white-space: nowrap; display: flex; gap: 4px; align-items: center; }
.ab-table tr.editing td { background: var(--accent-light); }
.ab-table tr.editing input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--accent);
  border-radius: 5px;
  font-size: 13px;
  outline: none;
}
.ab-edit-error { color: var(--danger); font-size: 12px; margin-left: 4px; }

/* ── User status badge ───────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.badge--active   { background: #dcfce7; color: #166534; }
.badge--inactive { background: #fee2e2; color: #991b1b; }
.badge--admin    { background: #eef2ff; color: #4338ca; }

/* Admin badge in the sidebar header sits inline with the username */
.header-user .badge--admin {
  background: rgba(99,102,241,0.2);
  color: #a5b4fc;
  font-size: 10px;
  padding: 1px 6px;
}

/* User add form password field */
#userAddForm { flex-wrap: wrap; gap: 8px; }
#userNewPassword { min-width: 160px; }
