/* =====================================================================
   Frazil MailCatcher — sidebar + topbar layout
   ===================================================================== */

:root {
  --color-primary: #0050a0;
  --color-primary-dark: #003d7a;
  --color-primary-light: #1e6bba;
  --color-accent: #60b0e0;
  --color-accent-light: #d0e8f5;
  --color-bg: #f4f7fb;
  --color-surface: #ffffff;
  --color-sidebar-bg: #ffffff;
  --color-text: #1a2638;
  --color-text-muted: #5a6878;
  --color-text-faint: #8895a8;
  --color-border: #dfe6ef;
  --color-border-strong: #c8d3e0;
  --color-danger: #c0392b;
  --color-danger-dark: #962d22;
  --color-success: #198754;

  --sidebar-width: 240px;
  --topbar-height: 56px;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 30, 60, 0.06);
  --shadow-md: 0 2px 8px rgba(15, 30, 60, 0.08);
  --shadow-lg: 0 8px 24px rgba(15, 30, 60, 0.12);
  --shadow-dropdown: 0 4px 16px rgba(15, 30, 60, 0.14);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-dark); text-decoration: underline; }

/* ============================================================
   App layout: sidebar (fixed left) + topbar + content
   ============================================================ */

body.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar content";
  min-height: 100vh;
}

/* ----- Sidebar ----- */
.sidebar {
  grid-area: sidebar;
  background: var(--color-sidebar-bg);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-brand {
  /* Match the topbar height exactly so the bottom border continues across as one line */
  height: var(--topbar-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.sidebar-brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.sidebar-brand-link:hover { text-decoration: none; }
.sidebar-logo { height: 30px; width: auto; display: block; }
.sidebar-product {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-primary);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.sidebar-section { padding: 12px 8px 4px; }
.sidebar-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-faint);
  font-weight: 600;
  padding: 8px 12px 6px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.sidebar-link:hover {
  background: var(--color-accent-light);
  color: var(--color-primary-dark);
  text-decoration: none;
}
.sidebar-link.active {
  background: var(--color-primary);
  color: #fff;
}
.sidebar-link.active:hover { background: var(--color-primary-dark); color: #fff; }
.sidebar-link.active .sidebar-link-badge {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}
.sidebar-link-icon { display: inline-flex; align-items: center; }
.sidebar-link-label { flex: 1; text-transform: capitalize; }
.sidebar-link-badge {
  background: var(--color-accent-light);
  color: var(--color-primary-dark);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
}

/* ----- Topbar ----- */
.topbar {
  grid-area: topbar;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 100;
}
.topbar-spacer { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* ----- User menu ----- */
.user-menu { position: relative; }
.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 6px 12px 6px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.user-menu-trigger:hover {
  border-color: var(--color-primary);
  background: var(--color-surface);
}
.user-menu.open .user-menu-trigger {
  border-color: var(--color-primary);
  background: var(--color-surface);
}
.user-menu-icon, .user-menu-caret { display: inline-flex; align-items: center; color: var(--color-text-muted); }
.user-menu-name { font-weight: 500; }

.user-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 200px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-dropdown);
  padding: 6px;
  z-index: 200;
}
.user-menu.open .user-menu-dropdown { display: block; }

.user-menu-header {
  padding: 8px 12px 10px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 4px;
}
.user-menu-name-line {
  font-weight: 600;
  color: var(--color-text);
  font-size: 14px;
}
.user-menu-role-line {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: 14px;
  text-decoration: none;
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}
.user-menu-item:hover {
  background: var(--color-accent-light);
  color: var(--color-primary-dark);
  text-decoration: none;
}
.user-menu-item-button { font-size: 14px; }
.user-menu-form { margin: 0; }

/* role pill in the user menu trigger */
.role-pill {
  display: inline-block;
  background: var(--color-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
}

/* ----- Content area ----- */
.content {
  grid-area: content;
  padding: 24px 28px;
  overflow-y: auto;
  max-width: 100%;
}

h1, h2, h3 { color: var(--color-text); letter-spacing: -0.01em; }
h2 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-header-info { display: flex; flex-direction: column; }
.page-subtitle { color: var(--color-text-muted); font-size: 13px; }

.count {
  display: inline-block;
  background: var(--color-accent-light);
  color: var(--color-primary-dark);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
  vertical-align: middle;
}

/* ----- Admin tabs ----- */
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--color-border);
}
.admin-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s, border-color 0.12s;
}
.admin-tab:hover { color: var(--color-primary); text-decoration: none; }
.admin-tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* ----- Buttons ----- */
button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-primary);
  color: #fff;
  border: 1px solid var(--color-primary);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: background 0.12s, border-color 0.12s;
  text-decoration: none;
}
button:hover, .btn:hover {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
  text-decoration: none;
  color: #fff;
}
button.secondary, .btn.secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border-color: var(--color-border);
}
button.secondary:hover, .btn.secondary:hover {
  background: var(--color-accent-light);
  border-color: var(--color-accent);
  color: var(--color-primary-dark);
}
button.danger, .btn.danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: #fff;
}
button.danger:hover, .btn.danger:hover {
  background: var(--color-danger-dark);
  border-color: var(--color-danger-dark);
}
button.danger.ghost, .btn.danger.ghost {
  background: transparent;
  color: var(--color-danger);
}
button.danger.ghost:hover { background: var(--color-danger); color: #fff; }
button.small, .btn.small { padding: 5px 9px; font-size: 12px; }

/* ----- Tables ----- */
table {
  width: 100%;
  background: var(--color-surface);
  border-collapse: separate;
  border-spacing: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}
thead th {
  background: var(--color-bg);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--color-border);
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; transition: background 0.1s; }
tbody tr.clickable:hover { background: var(--color-accent-light); }
.col-when { white-space: nowrap; color: var(--color-text-muted); font-size: 13px; }
.col-actions { white-space: nowrap; text-align: right; }
.col-actions > * + * { margin-left: 6px; }

.empty {
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  color: var(--color-text-muted);
}
.empty-icon { color: var(--color-text-faint); margin-bottom: 12px; }

/* ----- Cards ----- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.card h3 { margin: 0 0 16px; font-size: 15px; font-weight: 600; }
.card-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.field { display: flex; flex-direction: column; flex: 1; min-width: 160px; }
.field label {
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
input[type="text"], input[type="password"], input[type="email"], select {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0,80,160,0.12);
}

/* ----- Message detail ----- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--color-text-muted);
  font-size: 13px;
  margin-bottom: 16px;
}
.back-link:hover { color: var(--color-primary); }
.msg-meta {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.meta-row {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 8px 16px;
  padding: 4px 0;
  font-size: 14px;
}
.meta-row .label {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  align-self: center;
}
.meta-row .value { color: var(--color-text); word-break: break-word; }
.meta-actions { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--color-border); }

.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--color-border);
}
.tab {
  background: transparent;
  color: var(--color-text-muted);
  border: none;
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  transition: color 0.12s, border-color 0.12s;
}
.tab:hover { color: var(--color-primary); background: transparent; }
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); background: transparent; }
.tab-pane {
  display: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.tab-pane.active { display: block; }
.tab-pane iframe {
  width: 100%;
  min-height: 480px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fff;
}
.tab-pane pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 13px;
  margin: 0;
  color: var(--color-text);
}

/* ----- Alerts ----- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-error { background: #fff0ee; border: 1px solid #f5c2bb; color: var(--color-danger-dark); }
.alert-success { background: #e8f5ee; border: 1px solid #b4dec5; color: #1e6a40; }

/* ----- Token reveal ----- */
.token-reveal {
  background: var(--color-accent-light);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 20px;
}
.token-reveal h4 { margin: 0 0 8px; color: var(--color-primary-dark); font-size: 14px; }
.token-reveal p { margin: 0 0 12px; color: var(--color-text); font-size: 13px; }
.token-value {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  word-break: break-all;
}
.token-value-text { flex: 1; user-select: all; }

/* ----- Pills ----- */
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pill-admin { background: var(--color-primary); color: #fff; }
.pill-tester { background: var(--color-bg); color: var(--color-text-muted); border: 1px solid var(--color-border); }
.pill-inbox { background: var(--color-accent-light); color: var(--color-primary-dark); }

/* ----- Login page (no sidebar/topbar chrome) ----- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(96, 176, 224, 0.18), transparent 50%),
    radial-gradient(circle at 85% 80%, rgba(0, 80, 160, 0.10), transparent 50%),
    var(--color-bg);
}
.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  border: 1px solid var(--color-border);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand img { height: 56px; width: auto; margin-bottom: 12px; }
.login-title { font-size: 18px; font-weight: 600; color: var(--color-text); margin: 0; }
.login-subtitle { font-size: 13px; color: var(--color-text-muted); margin-top: 4px; }
.login-form .field { margin-bottom: 16px; min-width: 0; }
.login-form input { width: 100%; padding: 10px 12px; font-size: 15px; }
.login-form button {
  width: 100%; justify-content: center;
  padding: 11px 16px; font-size: 14px; font-weight: 600; margin-top: 4px;
}
.login-footer { margin-top: 20px; font-size: 12px; color: var(--color-text-faint); text-align: center; }

/* ----- Inline forms ----- */
.inline-form { display: inline-flex; gap: 4px; align-items: center; }
.inline-form input { padding: 4px 8px; font-size: 12px; width: 140px; }

code {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-primary-dark);
}

/* ----- Responsive: collapse sidebar to icons on narrow screens ----- */
@media (max-width: 820px) {
  :root { --sidebar-width: 64px; }
  .sidebar-brand { padding: 0 8px; justify-content: center; }
  .sidebar-brand-link { gap: 0; }
  .sidebar-product { display: none; }
  .sidebar-logo { height: 28px; }
  .sidebar-section-label { display: none; }
  .sidebar-link { justify-content: center; padding: 10px 8px; position: relative; }
  .sidebar-link-label { display: none; }
  .sidebar-link-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 10px;
    padding: 0 5px;
    min-width: 16px;
  }
  .user-menu-name { display: none; }
  .content { padding: 16px 14px; }
  .meta-row { grid-template-columns: 70px 1fr; }
}

/* ----- Topbar search ----- */
.topbar-search {
  flex: 1;
  max-width: 520px;
  margin: 0 16px;
  display: flex;
  align-items: center;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0 10px;
  height: 36px;
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}
.topbar-search:focus-within {
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 0 0 3px rgba(0,80,160,0.10);
}
.topbar-search-icon {
  display: inline-flex;
  align-items: center;
  color: var(--color-text-faint);
  margin-right: 8px;
}
.topbar-search:focus-within .topbar-search-icon {
  color: var(--color-primary);
}
.topbar-search input[type="search"] {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0;
  font-size: 14px;
  color: var(--color-text);
  outline: none;
  min-width: 0;
}
.topbar-search input[type="search"]::placeholder {
  color: var(--color-text-faint);
}
/* Hide the browser's built-in clear button for type=search — we provide our own */
.topbar-search input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.topbar-search-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: var(--color-text-muted);
  text-decoration: none;
  margin-left: 4px;
  transition: background 0.12s, color 0.12s;
}
.topbar-search-clear:hover {
  background: var(--color-border);
  color: var(--color-text);
  text-decoration: none;
}

@media (max-width: 820px) {
  .topbar-search { margin: 0 8px; }
  .topbar-search-icon { margin-right: 6px; }
}

/* ----- Token usage box (SMTP creds + HTTP example shown after token creation) ----- */
.token-usage {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}
.token-usage-block {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.token-usage-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}
.token-usage-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 4px 12px;
}
.kv { display: contents; }
.kv .k {
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 500;
}
.kv .v {
  color: var(--color-text);
  font-size: 13px;
  font-family: var(--font-mono);
  word-break: break-all;
}

/* ----- Admin Settings page ----- */
.settings-help {
  color: var(--color-text-muted);
  font-size: 13px;
  margin: 0 0 16px;
  line-height: 1.55;
}
.settings-help-inline {
  color: var(--color-text-muted);
  font-size: 12px;
  margin-left: 10px;
}
.settings-divider {
  border-top: 1px solid var(--color-border);
  margin: 20px 0 16px;
}

/* ----- Message detail toolbar (back link + prev/next nav) ----- */
.msg-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.msg-toolbar .back-link { margin-bottom: 0; }
.msg-nav {
  display: inline-flex;
  gap: 6px;
}
/* Disabled "button" (rendered as a span when there's no neighbor) */
.btn.disabled, .btn[aria-disabled="true"] {
  background: var(--color-surface);
  color: var(--color-text-faint);
  border-color: var(--color-border);
  cursor: not-allowed;
  opacity: 0.6;
}
.btn.disabled:hover, .btn[aria-disabled="true"]:hover {
  background: var(--color-surface);
  color: var(--color-text-faint);
  border-color: var(--color-border);
}

/* ----- Attachments section on message detail ----- */
.attachments-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 12px 16px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.attachments-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}
.attachments-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.attachment-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  text-decoration: none;
  color: var(--color-text);
  transition: border-color 0.12s, background 0.12s;
}
.attachment-item:hover {
  border-color: var(--color-primary);
  background: var(--color-accent-light);
  text-decoration: none;
}
.attachment-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-primary);
  flex-shrink: 0;
}
.attachment-item:hover .attachment-icon {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.attachment-info { flex: 1; min-width: 0; }
.attachment-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-meta {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 2px;
}
.attachment-download {
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.attachment-item:hover .attachment-download { color: var(--color-primary); }

.inline-paperclip {
  display: inline-flex;
  align-items: center;
  color: var(--color-text-muted);
  margin-right: 4px;
  vertical-align: -3px;
}

/* ----- Auto-refresh toggle ----- */
.page-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.auto-refresh-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  user-select: none;
  transition: border-color 0.12s, background 0.12s;
}
.auto-refresh-toggle:hover { border-color: var(--color-primary); }
.auto-refresh-toggle input[type="checkbox"] {
  /* Hide the native checkbox; use the dot below as the indicator */
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.auto-refresh-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-faint);
  transition: background 0.12s, box-shadow 0.12s;
}
.auto-refresh-toggle input:checked ~ .auto-refresh-dot {
  background: var(--color-success);
  box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.18);
  animation: auto-refresh-pulse 2s ease-in-out infinite;
}
@keyframes auto-refresh-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.18); }
  50%      { box-shadow: 0 0 0 5px rgba(25, 135, 84, 0.10); }
}
.auto-refresh-label { color: var(--color-text); font-weight: 500; }
.auto-refresh-toggle input:checked ~ .auto-refresh-label { color: var(--color-success); }

/* ----- Resend panel (Send copy to...) ----- */
.resend-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.resend-help {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}
.resend-panel .card-row { gap: 10px; }
.resend-panel button.secondary { margin-left: 6px; }

/* ----- Checkbox column + row checkboxes ----- */
.col-checkbox {
  width: 36px;
  padding-left: 14px;
  padding-right: 0;
  text-align: center;
}
.col-checkbox input[type="checkbox"] {
  cursor: pointer;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--color-primary);
  vertical-align: middle;
}
tbody tr.clickable .col-checkbox {
  cursor: default;
}

/* ----- Bulk-action toolbar ----- */
.bulk-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--color-accent-light);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.bulk-toolbar-info {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-primary-dark);
}
.bulk-toolbar-info #bulk-count {
  font-size: 16px;
  margin-right: 2px;
}
.bulk-toolbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ----- Pagination ----- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding: 8px 4px;
  flex-wrap: wrap;
}
.pagination-info {
  font-size: 13px;
  color: var(--color-text-muted);
}
.pagination-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.page-link:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  text-decoration: none;
  background: var(--color-accent-light);
}
.page-link.disabled {
  color: var(--color-text-faint);
  background: var(--color-bg);
  cursor: not-allowed;
  opacity: 0.6;
}
.page-link.disabled:hover {
  border-color: var(--color-border);
  color: var(--color-text-faint);
  background: var(--color-bg);
}
.page-indicator {
  padding: 0 12px;
  font-size: 13px;
  color: var(--color-text);
}

/* Message detail: Raw + Headers tabs (v20) */
.raw-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 8px 0;
}
.raw-toolbar .settings-help-inline {
  margin: 0;
}
.button-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
pre.raw-eml {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--color-text);
}
.headers-table {
  margin-top: 12px;
  width: 100%;
}
.headers-table th {
  text-align: left;
  font-weight: 600;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
  padding: 6px 12px 6px 0;
  vertical-align: top;
  width: 1%;
}
.headers-table td {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  padding: 6px 0;
  vertical-align: top;
}
.headers-table tr + tr th,
.headers-table tr + tr td {
  border-top: 1px solid var(--color-border);
}

/* Search highlight + body snippet (v17) */
mark {
  background: var(--color-accent-light);
  color: var(--color-text);
  padding: 0 2px;
  border-radius: 2px;
}
.search-snippet {
  margin-top: 4px;
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-snippet mark {
  background: var(--color-accent-light);
  color: var(--color-text);
}
