/* ==========================================================================
   Mail Control Panel — arttadmori.org
   ========================================================================== */

:root {
  --bg:            #0f1419;
  --bg-elevated:   #161c24;
  --bg-card:       #1b232d;
  --bg-input:      #111820;
  --border:        #2a3542;
  --border-soft:   #222c37;

  --text:          #e6edf3;
  --text-muted:    #8b98a5;
  --text-dim:      #5f6b78;

  --accent:        #3b82f6;
  --accent-hover:  #2563eb;
  --accent-soft:   rgba(59, 130, 246, 0.12);

  --green:         #22c55e;
  --green-soft:    rgba(34, 197, 94, 0.12);
  --amber:         #f59e0b;
  --amber-soft:    rgba(245, 158, 11, 0.12);
  --red:           #ef4444;
  --red-soft:      rgba(239, 68, 68, 0.12);

  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 4px 16px rgba(0, 0, 0, 0.3);
  --font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                   "Helvetica Neue", Arial, sans-serif;
  --mono:          ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
                   "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

.mono { font-family: var(--mono); font-size: 0.92em; }
.small { font-size: 0.85em; }
.strong { font-weight: 600; }
.muted { color: var(--text-muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ==========================================================================
   Layout
   ========================================================================== */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border-soft);
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(59, 130, 246, 0.18);
  border-radius: 12px;
}
.brand-icon .icon { width: 23px; height: 23px; }

.brand-name {
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-domain {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.nav {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13.5px;
  transition: background 0.12s, color 0.12s;
}

.nav a:hover {
  background: var(--bg-card);
  color: var(--text);
  text-decoration: none;
}

.nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-icon {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  opacity: 0.92;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border-soft);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-dim); }

.logout-form { margin: 0; }
.logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-align: center;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12.5px;
  font-family: inherit;
  background: transparent;
  cursor: pointer;
}

.logout:hover {
  background: var(--bg-card);
  color: var(--text);
  text-decoration: none;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 30px 60px;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: 23px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.topbar-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex-wrap: wrap; }

/* ==========================================================================
   Cards & grids
   ========================================================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.card-intro { color: var(--text-muted); font-size: 13px; margin: 0 0 12px; }
.card-foot { color: var(--text-dim); font-size: 12.5px; margin: 12px 0 0; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
}

.grid-webmail {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 900px) {
  .grid-webmail { grid-template-columns: 1fr; }
  .sidebar { width: 68px; }
  .brand-name, .brand-domain, .nav a span:not(.nav-icon),
  .user-meta, .logout { display: none; }
  .nav a { justify-content: center; }
}

/* ==========================================================================
   Stats
   ========================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-card-link { color: var(--text); }
.stat-card-link:hover { border-color: var(--accent); text-decoration: none; }

.stat-warn { border-color: rgba(245, 158, 11, 0.4); }

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.stat-value {
  font-size: 27px;
  font-weight: 660;
  letter-spacing: -0.03em;
  margin: 4px 0 2px;
  font-variant-numeric: tabular-nums;
}

.stat-foot { font-size: 12px; color: var(--text-dim); }

.dashboard-welcome {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 18px;
}
.dashboard-welcome h2 { margin: 3px 0; font-size: 20px; }
.dashboard-welcome p { margin: 0; color: var(--text-muted); }
.dashboard-actions, .compose-page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dashboard-actions .button { min-height: 38px; }
.quota-progress { display: block; width: 100%; height: 7px; margin-top: 10px; accent-color: var(--accent); }
.dashboard-panels { margin-bottom: 18px; }
.security-checks { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.security-checks li { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.security-checks li > span:first-child { display: flex; align-items: center; gap: 9px; color: var(--text-muted); }
.security-checks .icon { width: 17px; height: 17px; color: var(--accent); }
.security-note { margin: 14px 0 0; color: var(--amber); font-size: 12px; }
.readiness-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.readiness-summary > div { display: grid; gap: 3px; padding: 12px; background: var(--bg-input); border-radius: var(--radius-sm); }
.readiness-summary strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.readiness-summary span { color: var(--text-muted); font-size: 11px; }
.readiness-link { display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; font-weight: 600; }
.mailbox-filters, .analytics-filters, .domain-filters, .alias-filters,
.log-filters, .delivery-filters, .audit-filters { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.mailbox-filters input[type="search"], .analytics-filters input[type="search"],
.domain-filters input[type="search"], .alias-filters input[type="search"],
.audit-filters input[type="search"] { flex: 1 1 210px; min-width: 180px; }
.mailbox-filters select, .analytics-filters select, .domain-filters select,
.alias-filters select, .log-filters select, .delivery-filters select,
.audit-filters select { width: auto; min-width: 135px; }
.mailbox-toolbar { align-items: flex-start; }
.mailbox-results-heading { padding: 14px 18px; margin: 0; }
.mailbox-stat-grid, .domain-stat-grid, .alias-stat-grid, .contact-stat-grid { margin-top: 14px; }
.domain-filters, .audit-filters { margin: 0; }
.alias-filters { width: 100%; }
.contact-page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.contact-history-header { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.contact-history-identity { display: flex; align-items: center; gap: 14px; min-width: 0; }
.contact-history-identity h2 { margin: 2px 0; }
.contact-history-identity p { margin: 0; color: var(--text-muted); overflow-wrap: anywhere; }
.contact-history-avatar { display: grid; place-items: center; width: 48px; height: 48px; flex: 0 0 auto; border-radius: 14px; color: #fff; background: var(--accent); font-weight: 700; font-size: 19px; }
.contact-history-filters { align-items: end; }
.contact-history-filters .field { flex: 1 1 200px; min-width: 180px; margin: 0; }
.contact-history-list-head { align-items: center; }
.contact-history-bulk { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.contact-message-subject { min-width: 180px; overflow-wrap: anywhere; }
.contact-history-list-head .card-intro { margin-bottom: 0; }

/* ==========================================================================
   Status list
   ========================================================================== */
.status-list { list-style: none; margin: 0; padding: 0; }

.status-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
}

.status-row:last-child { border-bottom: none; }

.status-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }

.status-name { font-weight: 560; font-size: 13.5px; }
.status-desc { font-size: 12px; color: var(--text-dim); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-ok { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dot-bad { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }

.status-state {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 20px;
}

.state-ok { color: var(--green); background: var(--green-soft); }
.state-bad { color: var(--red); background: var(--red-soft); }

/* ==========================================================================
   Tables
   ========================================================================== */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-full { font-size: 13px; }
.table-scroll { overflow-x: auto; }

.table th {
  text-align: left;
  padding: 8px 10px;
  color: var(--text-dim);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 620;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.018); }

.actions-cell { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* ==========================================================================
   Badges & pills
   ========================================================================== */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge-ok { color: var(--green); background: var(--green-soft); border-color: transparent; }
.badge-off { color: var(--text-dim); background: var(--bg-input); }
.badge-warn { color: var(--amber); background: var(--amber-soft); border-color: transparent; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
}

.pill-muted { background: var(--bg-input); color: var(--text-muted); }

/* ==========================================================================
   Usage bar
   ========================================================================== */
.usage { display: flex; flex-direction: column; gap: 4px; }

.usage-bar {
  height: 5px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.usage-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

.usage-warn { background: var(--amber); }

.usage-text { font-size: 11.5px; color: var(--text-dim); font-family: var(--mono); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 13px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #1d2732, #17212b);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.button:hover,
.btn:hover {
  background: #222f3d;
  border-color: #435367;
  color: #fff;
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.18);
}

.button.primary,
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.button.primary:hover,
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.button.danger,
.btn-danger { color: #ff8585; border-color: rgba(239, 68, 68, 0.38); background: rgba(239, 68, 68, 0.07); }
.button.danger:hover,
.btn-danger:hover { color: #fff; background: #c93636; border-color: #ef4444; }

.button.small,
.btn-small { min-height: 34px; padding: 6px 10px; font-size: 12px; border-radius: 8px; }

.btn-block { width: 100%; }
.button .icon, .btn .icon { width: 16px; height: 16px; }
.button.is-starred { color: var(--amber); border-color: rgba(245, 158, 11, 0.35); }
.button:focus-visible, .btn:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}
.button:disabled, .btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
}
.icon-button:hover { color: var(--text); background: var(--bg-elevated); }

/* ==========================================================================
   Forms
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: 5px; }

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.field-hint { font-size: 11.5px; color: var(--text-dim); }

input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
select,
textarea {
  min-height: 40px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  width: 100%;
  line-height: 1.45;
  transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}

select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b98a5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  cursor: pointer;
}

textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}

input[type="file"] {
  width: 100%;
  color: var(--text-muted);
  font: inherit;
}

input[type="file"]::file-selector-button {
  min-height: 38px;
  margin-right: 10px;
  padding: 7px 12px;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
}

input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder,
textarea::placeholder { color: var(--text-dim); opacity: 1; }
input:disabled,
select:disabled,
textarea:disabled { opacity: .6; cursor: not-allowed; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  align-items: end;
}

.field-wide { grid-column: 1 / -1; }
.field-actions { justify-content: flex-end; }

.create-panel { display: none; }
.create-panel.open { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.toolbar-filter select { width: auto; min-width: 170px; }
.search-input { min-width: 280px; flex: 1; max-width: 460px; }

/* ==========================================================================
   Flash messages
   ========================================================================== */
.flashes { margin-bottom: 18px; display: flex; flex-direction: column; gap: 9px; }

.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  border: 1px solid transparent;
}

.flash-icon { font-weight: 700; }

.flash-success { background: var(--green-soft); color: var(--green); border-color: rgba(34, 197, 94, 0.3); }
.flash-info { background: var(--bg-input); color: var(--text); border-color: var(--border); }
.flash-error { background: var(--red-soft); color: var(--red); border-color: rgba(239, 68, 68, 0.3); }

.flash-close {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.6;
  padding: 0 2px;
}

.flash-close:hover { opacity: 1; }

/* ==========================================================================
   Notices
   ========================================================================== */
.notice {
  background: var(--amber-soft);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fbbf24;
  padding: 13px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 13.5px;
}

.empty {
  color: var(--text-dim);
  text-align: center;
  padding: 26px 16px;
  margin: 0;
  font-size: 13.5px;
}

.link { font-size: 12.5px; font-weight: 550; }

/* ==========================================================================
   DNS page
   ========================================================================== */
.dns-block { margin-bottom: 12px; }
.copy-control { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.copy-status { color: var(--text-muted); font-size: 12px; }
.restore-steps { padding-left: 22px; color: var(--text-muted); }
.restore-steps li { margin: 10px 0; }
.restore-steps code { color: var(--text); overflow-wrap: anywhere; }

.dns-label {
  display: block;
  font-size: 11.5px;
  font-weight: 620;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.dns-value {
  margin: 0;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
}

.dns-expected { color: var(--green); border-color: rgba(34, 197, 94, 0.25); }

.dns-hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  padding-left: 12px;
  border-left: 2px solid var(--amber);
}

/* ==========================================================================
   Logs
   ========================================================================== */
.log-view {
  margin: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-muted);
  max-height: 66vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ==========================================================================
   Settings grid
   ========================================================================== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 8px;
}

.setting {
  display: flex;
  gap: 12px;
  padding: 9px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  font-size: 12.5px;
}

.setting-key {
  font-weight: 620;
  color: var(--text-muted);
  min-width: 76px;
  flex-shrink: 0;
}

.setting-val { color: var(--text); }

/* ==========================================================================
   Webmail
   ========================================================================== */
.folder-list ul { list-style: none; margin: 0; padding: 0; }
.email-preview {
  display: block;
  width: 100%;
  height: min(72vh, 760px);
  min-height: 360px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: #fff;
}
.email-plain { margin-top: 12px; }
.email-plain summary { cursor: pointer; color: var(--text-muted); font-size: 13px; }
.email-plain pre, .email-plain-text {
  max-width: 100%;
  margin: 10px 0 0;
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.email-plain pre {
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.email-plain-text {
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
}

.folder-list li a {
  display: flex;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
}

.folder-list li a:hover { background: var(--bg-input); color: var(--text); text-decoration: none; }
.folder-list li a.active { background: var(--accent-soft); color: var(--accent); }

.mail-workspace-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}
.mail-workspace-heading h2 { margin: 3px 0; font-size: 24px; }
.mail-workspace-heading p, .compose-header p { color: var(--text-muted); margin: 2px 0 0; }
.mail-eyebrow { color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .12em; }
.mail-account-picker { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.mail-account-picker select { width: auto; min-width: 220px; }
.mail-account-picker label { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.mail-account-picker label .icon { color: var(--accent); }
.mail-account-picker > span { color: var(--text-muted); font-size: 12px; }
.mail-workspace { align-items: start; }
.mail-sidebar { padding: 18px; }
.mail-sidebar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mail-sidebar-title h2 { margin: 0; font-size: 15px; }
.mail-sidebar-title p { margin: 0; color: var(--text-muted); font-size: 11px; overflow-wrap: anywhere; }
.mail-sidebar-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 20px; flex-shrink: 0; }
.mail-sidebar-icon .icon { width: 20px; height: 20px; }
.mail-compose-link { display: flex; margin: 20px 0; }
.mail-folder-heading { color: var(--text-dim); font-size: 10px; font-weight: 700; letter-spacing: .1em; margin: 12px 8px; }
.folder-list li a { display: flex; align-items: center; gap: 10px; }
.mail-sidebar-note { color: var(--text-muted); font-size: 11px; line-height: 1.5; margin: 20px 8px 0; overflow-wrap: anywhere; }
.mail-account-card { margin-bottom: 18px; }
.mail-account-card .mail-workspace-heading { margin: 0; }
.mail-account-picker { margin: 0; }
.eyebrow { color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .12em; }
.mail-sidebar-heading { display: grid; gap: 5px; padding: 2px 6px 16px; overflow: hidden; }
.mail-sidebar-heading strong { overflow-wrap: anywhere; }
.mail-folder-nav { display: grid; gap: 4px; }
.mail-folder-link { display: flex; align-items: center; gap: 11px; padding: 9px 10px; color: var(--text-muted); border-radius: var(--radius-sm); }
.mail-folder-link:hover, .mail-folder-link.active { background: var(--accent-soft); color: var(--text); text-decoration: none; }
.mail-folder-link.active { color: var(--accent); font-weight: 600; }
.folder-icon { display: block; width: 19px; height: 19px; flex: 0 0 auto; color: inherit; }
.folder-current { margin-left: auto; }
.folder-current::after { content: ""; display: block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.mail-sidebar-note { display: grid; gap: 3px; margin: 18px 4px 0; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.mail-sidebar-note strong { color: var(--text); font-size: 12px; }
.spam-status-note { color: var(--text-dim); }
.mail-list-card { min-width: 0; padding: 0; overflow: hidden; }
.mail-list-heading { margin: 0; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.mail-list-heading h2 { font-size: 20px; }
.mail-search-form, .mail-bulk-toolbar, .mail-reader-top, .mail-message-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.mail-search-form input[type="search"] { width: min(250px, 38vw); }
.mail-search-form label { color: var(--text-muted); font-size: 12px; }
.mail-search-form select { width: auto; min-width: 70px; }
.mail-bulk-toolbar { padding: 12px 18px; background: var(--bg-elevated); border-bottom: 1px solid var(--border-soft); }
.mail-bulk-toolbar select { width: auto; min-width: 140px; }
.mail-select-all { display: flex; align-items: center; gap: 8px; margin-right: auto; color: var(--text-muted); }
.mail-select-all input, .mail-check-col input { width: 16px; height: 16px; accent-color: var(--accent); }
.mail-table-wrap { width: 100%; overflow-x: auto; }
.mail-message-table { width: 100%; border-collapse: collapse; }
.mail-message-table th { padding: 10px 12px; color: var(--text-dim); background: var(--bg-card); text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.mail-message-table td { padding: 12px; border-top: 1px solid var(--border-soft); vertical-align: middle; }
.mail-message-table tr:hover td { background: rgba(255,255,255,.025); }
.mail-message-table tr.unread td { color: var(--text); font-weight: 600; }
.mail-check-col { width: 42px; text-align: center !important; }
.mail-sender { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-star { color: var(--amber); margin-right: 5px; }
.mail-subject a { color: inherit; }
.mail-date { color: var(--text-muted); white-space: nowrap; font-size: 12px; }
.mail-empty { color: var(--text-muted); text-align: center; padding: 36px !important; }
.mail-pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-top: 1px solid var(--border-soft); color: var(--text-muted); }
.mail-search-note { margin: 10px 18px; color: var(--amber); font-size: 12px; }
.mail-reader-top { justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border-soft); }
.mail-message-actions { justify-content: flex-end; }
.mail-message-actions form { display: flex; gap: 7px; }
.mail-read-warning { margin: 12px 18px 0; }
.mail-message-actions .button { min-height: 36px; }
.mail-message-table tr.unread .mail-subject a::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 8px 1px 0;
  border-radius: 50%;
  background: var(--accent);
}
.mail-message-view { padding: 20px; }
.mail-message-header h1 { margin: 0 0 16px; font-size: 21px; overflow-wrap: anywhere; }
.mail-message-meta { display: grid; gap: 5px; margin: 0; }
.mail-message-meta div { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 8px; }
.mail-message-meta dt { color: var(--text-muted); }
.mail-message-meta dd { margin: 0; overflow-wrap: anywhere; }
.mail-attachments { margin-top: 16px; padding: 12px; background: var(--bg-elevated); border-radius: var(--radius-sm); }
.mail-attachments ul { margin: 6px 0 0; padding-left: 20px; }
.mail-privacy-notice { margin: 16px 0; padding: 10px 12px; color: var(--text-muted); background: var(--amber-soft); border-radius: var(--radius-sm); font-size: 12px; }
.mail-privacy-notice a { margin-left: 8px; }
.mail-message-body { min-width: 0; margin-top: 16px; }
.mail-html-frame { display: block; width: 100%; min-height: min(70vh, 760px); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); background: #fff; }
.mail-message-body pre { max-width: 100%; margin: 0; padding: 16px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg-input); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.icon { display: inline-block; width: 18px; height: 18px; flex: 0 0 auto; fill: none; }
.install-app-button[hidden] { display: none; }
.install-dialog {
  width: min(460px, calc(100vw - 28px));
  padding: 22px;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}
.install-dialog::backdrop { background: rgba(3, 8, 14, 0.72); backdrop-filter: blur(3px); }
.install-dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.install-dialog-heading h2 { margin: 0; font-size: 18px; }
.install-dialog p { color: var(--text-muted); }
.install-dialog li { margin: 10px 0; }
.install-privacy-note { padding: 10px 12px; color: var(--green) !important; background: var(--green-soft); border-radius: 9px; font-size: 12px; }
@media (max-width: 700px) {
  .layout { display: block; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
  }
  .brand { min-height: 58px; padding: 8px 14px; }
  .brand-name, .brand-domain { display: block; }
  .brand-icon { width: 36px; height: 36px; }
  .nav {
    flex-direction: row;
    gap: 4px;
    padding: 6px 8px 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
  }
  .nav a {
    flex: 0 0 auto;
    justify-content: flex-start;
    gap: 8px;
    min-height: 42px;
    padding: 8px 10px;
    white-space: nowrap;
  }
  .nav a span.nav-label { display: inline; }
  .nav-icon { width: 17px; height: 17px; }
  .sidebar-footer {
    position: absolute;
    top: 9px;
    right: 12px;
    width: auto;
    padding: 0;
    border: 0;
  }
  .user-chip { display: none; }
  .logout { display: inline-flex; min-height: 36px; padding: 6px 9px; }
  .logout span:not(.icon) { display: none; }
  .topbar { gap: 12px; margin-bottom: 16px; }
  .topbar h1 { font-size: 20px; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .topbar-meta { gap: 5px; }
  .topbar-meta .pill { font-size: 10px; }
  .install-app-button { min-height: 36px; }
  .mail-account-picker { width: 100%; }
  .mail-account-picker select { width: 100%; }
  .mail-list-heading { align-items: stretch; }
  .mail-search-form { width: 100%; }
  .mail-search-form input[type="search"] { flex: 1; width: 100%; }
  .mail-bulk-toolbar select { flex: 1; min-width: 120px; }
  .mail-sender { max-width: 130px; }
  .mail-date { max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
  .mail-reader-top { align-items: stretch; }
  .mail-message-actions { justify-content: flex-start; }
  .mail-message-actions form { flex: 1 1 auto; }
  .mail-message-actions form:last-child { flex-basis: 100%; }
  .mail-message-actions .button { flex: 1 1 auto; }
  .mail-message-view { padding: 16px; }
  .mail-message-header h1 { font-size: 19px; }
  .mail-html-frame { min-height: 65vh; }
  .button.small, .btn-small { min-height: 40px; }
}
.compose-card { padding: 0; overflow: hidden; }
.compose-header { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 24px 28px; border-bottom: 1px solid var(--border); background: linear-gradient(120deg, var(--bg-card), var(--bg-elevated)); }
.compose-header-brand { display: flex; align-items: center; gap: 14px; }
.compose-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; color: var(--accent); background: var(--accent-soft); }
.compose-icon .icon { width: 22px; height: 22px; }
.compose-header h2 { margin: 2px 0; font-size: 19px; }
.compose-status { display: inline-flex; align-items: center; gap: 6px; color: var(--green); background: var(--green-soft); border: 1px solid rgba(34, 197, 94, .2); padding: 5px 10px; border-radius: 20px; font-size: 11px; white-space: nowrap; }
.compose-status .icon { width: 14px; height: 14px; }
.compose-form { display: grid; gap: 18px; padding: 24px 28px; }
.compose-from { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-input); }
.compose-from span, .compose-hint { color: var(--text-muted); font-size: 12px; font-weight: normal; }
.compose-hint { margin-left: 6px; }
.compose-form textarea { width: 100%; }
.compose-advanced { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.compose-advanced summary { color: var(--accent); cursor: pointer; font-weight: 600; }
.compose-advanced[open] summary { margin-bottom: 14px; }
.compose-advanced-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.compose-advanced-fields > .toolbar, .compose-advanced-fields > .muted { grid-column: 1 / -1; }
.compose-advanced summary { display: flex; align-items: center; gap: 8px; }
.compose-advanced summary .icon { width: 16px; height: 16px; }
.compose-attachments { display: grid; gap: 8px; border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 16px; }
.compose-attachments > span:not(.field-label), .compose-footer > span { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 12px; }
.compose-attachments .icon { width: 15px; height: 15px; color: var(--accent); }
.compose-footer { display: grid; gap: 12px; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.compose-footer > span { display: block; color: var(--text-muted); font-size: 12px; }
.compose-buttons { display: flex; flex-wrap: wrap; gap: 9px; }
.compose-page-actions .button { min-height: 40px; }
@media (max-width: 700px) {
  .mail-workspace-heading { align-items: flex-start; flex-direction: column; }
  .mail-account-picker select { width: 100%; }
  .compose-header, .compose-form { padding: 18px; }
  .compose-header { align-items: flex-start; flex-direction: column; }
  .compose-advanced-fields { grid-template-columns: 1fr; }
  .compose-advanced-fields > .toolbar, .compose-advanced-fields > .muted { grid-column: auto; }
  .dashboard-welcome { align-items: flex-start; flex-direction: column; }
  .dashboard-actions { width: 100%; }
  .dashboard-actions .button { flex: 1 1 140px; justify-content: center; }
  .security-checks li { align-items: flex-start; flex-direction: column; gap: 6px; }
  .readiness-summary { grid-template-columns: 1fr; }
  .contact-history-header { align-items: flex-start; flex-direction: column; }
  .contact-history-bulk { width: 100%; justify-content: space-between; }
  .mailbox-filters, .analytics-filters, .domain-filters, .alias-filters,
  .log-filters, .delivery-filters, .audit-filters { width: 100%; }
  .mailbox-filters > *, .analytics-filters > *, .domain-filters > *,
  .alias-filters > *, .log-filters > *, .delivery-filters > *,
  .audit-filters > * { flex: 1 1 100%; width: 100%; }
}

.folder-count {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-input);
  padding: 0 7px;
  border-radius: 10px;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(2px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.open { display: flex; }

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-head h3 { margin: 0; font-size: 16px; font-weight: 620; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 23px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover { color: var(--text); }

.modal-text { font-size: 13.5px; color: var(--text-muted); margin: 0 0 16px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 18px;
}

.modal-card .field { margin-bottom: 12px; }

@media (max-width: 700px) {
  .main { padding: 20px 14px 40px; }
  .table { min-width: 680px; }
  .toolbar-filter select, .toolbar > select { width: 100%; }
  .toolbar-filter { width: 100%; }
}

/* ==========================================================================
   Login page
   ========================================================================== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(1000px 500px at 50% -10%, rgba(59, 130, 246, 0.09), transparent 60%),
    var(--bg);
  padding: 20px;
}

.login-wrap { width: 100%; max-width: 400px; }

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 34px 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.login-head { text-align: center; margin-bottom: 24px; }

.login-logo { font-size: 38px; margin-bottom: 8px; }
.login-logo-image { display: block; width: 52px; height: 52px; margin: 0 auto 8px; border-radius: 14px; }

.login-head h1 {
  margin: 0 0 4px;
  font-size: 19px;
  font-weight: 640;
  letter-spacing: -0.02em;
}

.login-sub {
  margin: 0;
  color: var(--text-dim);
  font-size: 12.5px;
  font-family: var(--mono);
}

.login-form { display: flex; flex-direction: column; gap: 15px; }
.login-form .btn { margin-top: 5px; padding: 10px; }

.login-foot {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  margin: 20px 0 0;
}

.login-card .flash { margin-bottom: 16px; }

/* ==========================================================================
   Error page
   ========================================================================== */
.error-card { text-align: center; padding: 44px 24px; }

.error-code {
  font-size: 54px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 10px;
}

.error-message { color: var(--text-muted); margin: 0 0 22px; font-size: 14px; }

.ack-form { display: grid; gap: 7px; min-width: 190px; }
.ack-form input { width: 100%; }
.notification-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.notification-filters a { padding: 7px 12px; color: var(--text-muted); background: var(--bg-input); border: 1px solid var(--border-soft); border-radius: 999px; font-size: 12.5px; }
.notification-filters a.active { color: var(--accent); border-color: var(--accent); }
.notification-review { margin-top: 5px; color: var(--green); font-family: var(--font); font-size: 12px; overflow-wrap: anywhere; }
.telegram-form { align-items: end; }
.telegram-form > label { display: grid; gap: 6px; color: var(--text-muted); font-size: 12.5px; font-weight: 600; }
.telegram-toggles { display: grid; gap: 10px; }
.telegram-toggles label { display: flex; align-items: center; gap: 9px; color: var(--text-muted); font-size: 13px; }
.telegram-toggles input { width: auto; accent-color: var(--accent); }
.telegram-status { margin-top: 12px; }
.telegram-event-list { list-style: none; margin: 0; padding: 0; }
.telegram-event-list li { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border-soft); }
.telegram-event-list li:last-child { border-bottom: 0; }
.telegram-event-list li > span:first-child { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.telegram-event-list .muted { max-width: 65%; text-align: right; }
@media (max-width: 700px) {
  .ack-form { min-width: 150px; }
  .telegram-event-list li { display: grid; gap: 5px; }
  .telegram-event-list .muted { max-width: none; text-align: left; }
}
