:root {
  color-scheme: dark;
  --bg: #0b1120;
  --panel: #131c31;
  --panel-alt: #1a2742;
  --border: #2a3859;
  --text: #e5ecff;
  --muted: #9db0d3;
  --accent: #7cc4ff;
  --accent-strong: #54a9ff;
  --success: #3dd598;
  --warning: #ffb020;
  --danger: #ff7b91;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #08101d 0%, #0f1830 100%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 24px;
  border-right: 1px solid var(--border);
  background: rgba(9, 15, 29, 0.78);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #09101c;
  font-weight: 900;
}

.brand h1,
.page-header h2,
.panel h2,
.panel h3 {
  margin: 0;
}

.brand p,
.page-header p,
.hint,
.muted,
.empty-state,
dt {
  color: var(--muted);
}

.panel {
  background: rgba(19, 28, 49, 0.9);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel + .panel {
  margin-top: 16px;
}

form,
label {
  display: grid;
  gap: 10px;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0d1528;
  color: var(--text);
}

textarea {
  resize: vertical;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  margin-top: 12px;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #07111e;
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button.danger-button {
  background: linear-gradient(135deg, #ff9aa9, var(--danger));
  color: #1b0910;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.content {
  padding: 24px;
  display: grid;
  gap: 20px;
}

.page-header,
.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-status {
  margin: 0;
}

.banner {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(26, 39, 66, 0.85);
}

.banner.error {
  border-color: rgba(255, 123, 145, 0.45);
  color: #ffd2da;
}

.banner.success {
  border-color: rgba(61, 213, 152, 0.45);
  color: #caffeb;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 8, 18, 0.72);
  backdrop-filter: blur(6px);
  z-index: 50;
}

.modal-card {
  width: min(520px, 100%);
}

.stats-grid,
.grid,
.stats-stack,
.details-stack {
  display: grid;
  gap: 16px;
}

.admin-section {
  scroll-margin-top: 24px;
}

.stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid {
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
}

.stats-stack {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.details-stack {
  grid-template-columns: 1fr;
}

.compact-field {
  margin-bottom: 14px;
}

.stack-form {
  display: grid;
  gap: 12px;
}

.stack-form h4,
.inset-panel h4 {
  margin: 0;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox input {
  width: auto;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.alias-list {
  display: grid;
  gap: 10px;
}

.queue-list {
  display: grid;
  gap: 10px;
}

.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.72;
}

.loading::after {
  content: "";
  position: absolute;
  top: 16px;
  right: 16px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid rgba(124, 196, 255, 0.25);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

.loading-message {
  color: var(--muted);
  font-style: italic;
}

.section-nav {
  display: grid;
  gap: 10px;
}

.nav-button {
  width: 100%;
  margin-top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  text-align: left;
}

.nav-button.active {
  border-color: rgba(124, 196, 255, 0.45);
  background: rgba(124, 196, 255, 0.12);
}

.panel-toggle {
  margin-top: 0;
  padding: 8px 12px;
  font-size: 0.9rem;
}

.panel-collapsed [data-collapsible-body] {
  display: none !important;
}

.panel-collapsed {
  padding-bottom: 14px;
}

.subtle-badge {
  background: rgba(157, 176, 211, 0.12);
  color: var(--muted);
}

.mailbox-browser {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(0, 1.4fr);
  gap: 14px;
}

.mailbox-list,
.message-list {
  display: grid;
  gap: 8px;
}

.mailbox-item,
.message-item {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(13, 21, 40, 0.72);
  cursor: pointer;
}

.mailbox-item.selected,
.message-item.selected,
.mailbox-item:hover,
.message-item:hover {
  border-color: rgba(124, 196, 255, 0.45);
  background: rgba(124, 196, 255, 0.08);
}

.message-item strong,
.mailbox-item strong {
  display: block;
}

.message-detail {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(13, 21, 40, 0.72);
}

.message-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.message-preview {
  margin: 0;
  white-space: pre-wrap;
  color: var(--muted);
  background: rgba(8, 16, 29, 0.9);
  border-radius: 12px;
  padding: 14px;
  min-height: 120px;
}

.raw-source {
  max-height: 280px;
  overflow: auto;
}

.compact {
  margin-bottom: 10px;
}

.alias-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(13, 21, 40, 0.72);
}

.queue-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(13, 21, 40, 0.72);
}

.alias-actions {
  display: flex;
  gap: 8px;
}

.queue-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.alias-status {
  font-size: 0.9rem;
  color: var(--muted);
}

.inset-panel {
  background: rgba(14, 24, 44, 0.7);
  box-shadow: none;
}

.stat-card {
  padding: 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(20, 34, 62, 0.95), rgba(14, 24, 44, 0.95));
  border: 1px solid var(--border);
}

.stat-card .label {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.summary-grid dd {
  margin: 4px 0 0;
  font-weight: 600;
}

.stat-card strong {
  font-size: 2rem;
}

.badge {
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(124, 196, 255, 0.14);
  color: var(--accent);
  font-size: 0.9rem;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid rgba(157, 176, 211, 0.12);
}

tbody tr {
  cursor: pointer;
  transition: background 0.16s ease;
}

tbody tr:hover,
tbody tr.selected {
  background: rgba(124, 196, 255, 0.08);
}

dd {
  margin: 0;
  font-weight: 600;
}

dl > div + div {
  margin-top: 10px;
}

.hidden {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 980px) {
  .app-shell,
  .grid,
  .stats-grid,
  .stats-stack,
  .summary-grid,
  .inline-form,
  .mailbox-browser,
  .message-meta {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .page-actions {
    width: 100%;
    justify-content: space-between;
  }
}
