:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #1f2933;
  --muted: #667085;
  --primary: #176b87;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  min-height: 56px;
  padding: 0 24px;
}

.brand {
  color: var(--primary);
  font-weight: 700;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 14px;
}

.page {
  flex: 1;
  margin: 0 auto;
  max-width: 1180px;
  padding: 28px 20px 60px;
  width: 100%;
}

.toolbar {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 18px;
}

h1,
h2 {
  margin: 0 0 16px;
}

.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.narrow {
  max-width: 460px;
}

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 18px;
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

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

.card {
  display: grid;
  gap: 6px;
}

.metric strong {
  font-size: 30px;
  line-height: 1;
}

.metric small {
  color: var(--muted);
  min-height: 34px;
}

.card span,
label,
.muted {
  color: var(--muted);
}

.compact {
  font-size: 13px;
  margin: 12px 0 0;
}

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

.compact-form {
  margin-top: 12px;
}

.inline {
  align-items: center;
  display: flex;
  gap: 8px;
}

input,
select,
textarea,
button {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  padding: 9px 10px;
}

button {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  cursor: pointer;
  font-weight: 600;
}

button.success {
  background: var(--primary);
  border-color: var(--primary);
}

button.secondary,
.button-link.secondary {
  background: #eef4f6;
  border-color: #d9dee7;
  color: var(--text);
}

.button-link {
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 6px;
  color: #ffffff;
  display: inline-block;
  font-weight: 600;
  padding: 9px 10px;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

button.ghost {
  background: transparent;
  border: 0;
  color: var(--muted);
  min-height: auto;
  padding: 0 4px;
}

button.danger-text {
  color: var(--danger);
}

.form-grid {
  align-items: center;
  display: grid;
  gap: 12px 18px;
  grid-template-columns: 220px minmax(260px, 1fr);
  max-width: 820px;
}

.email-compose,
.password-row {
  align-items: center;
  display: flex;
  gap: 8px;
}

.email-compose input,
.password-row input {
  min-width: 260px;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
}

.truncate {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.actions form {
  align-items: center;
  display: flex;
}

.mailbox-table th:nth-child(1),
.mailbox-table td:nth-child(1) {
  width: 34%;
}

.mailbox-table th:nth-child(2),
.mailbox-table td:nth-child(2) {
  width: 24%;
}

.mailbox-table th:nth-child(3),
.mailbox-table td:nth-child(3),
.mailbox-table th:nth-child(4),
.mailbox-table td:nth-child(4) {
  width: 78px;
}

.mailbox-table {
  table-layout: fixed;
}

.mailbox-table th,
.mailbox-table td {
  padding: 9px 10px;
}

.mailbox-table th:nth-child(5),
.mailbox-table td:nth-child(5) {
  width: 280px;
}

.mailbox-actions {
  align-items: center;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}

.mailbox-actions form {
  display: inline-flex;
}

.mailbox-actions button,
.mailbox-actions .button-link,
.password-panel button {
  border-radius: 5px;
  font-size: 13px;
  line-height: 1.1;
  min-height: 32px;
  padding: 7px 9px;
  white-space: nowrap;
}

.password-panel {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
}

.password-panel[hidden] {
  display: none;
}

.password-panel input {
  font-size: 13px;
  min-height: 32px;
  min-width: 180px;
  padding: 7px 9px;
  width: 180px;
}

.check-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.check-grid label,
.compact-check {
  align-items: center;
  display: flex;
  gap: 8px;
}

.check-grid input,
.compact-check input {
  height: 16px;
  padding: 0;
  width: 16px;
}

.permission-list {
  align-items: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.permission-pill {
  align-items: center;
  background: #eef4f6;
  border-radius: 999px;
  display: inline-flex;
  flex-direction: row;
  font-size: 12px;
  gap: 4px;
  padding: 4px 7px;
}

.alias-filter {
  justify-content: flex-end;
  margin-bottom: 16px;
}

.alias-filter input {
  min-width: 320px;
}

.alias-editor {
  align-items: stretch;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(260px, 1fr) 72px minmax(260px, 1fr);
}

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

.alias-box h2 {
  font-size: 16px;
  margin: 0;
}

.alias-box select {
  min-height: 420px;
  width: 100%;
}

.alias-move-actions {
  align-content: center;
  display: grid;
  gap: 10px;
  justify-items: center;
}

.alias-move-actions button {
  font-size: 18px;
  height: 42px;
  padding: 0;
  width: 48px;
}

.profile-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 10px 22px;
}

.profile-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin: 0 -10px 18px;
  padding: 12px 10px;
}

.profile-header h1 {
  font-size: 20px;
  margin: 0;
}

.profile-tabs {
  display: flex;
  gap: 8px;
}

.profile-tab {
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: var(--text);
  padding: 7px 10px;
}

.profile-tab.active {
  background: var(--primary);
  color: #ffffff;
}

.profile-form {
  align-items: center;
  display: grid;
  gap: 12px 18px;
  grid-template-columns: 236px minmax(260px, 1fr);
  max-width: 760px;
}

.profile-check {
  height: 16px;
  padding: 0;
  width: 16px;
}

.field-inline {
  align-items: center;
  display: flex;
  gap: 8px;
}

.quota-input {
  width: 88px;
}

.profile-actions {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  margin-top: 32px;
  padding-top: 18px;
}

.message {
  border-radius: 6px;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.message.success {
  background: #e7f7ee;
}

.message.error {
  background: #fdecec;
}

.pill {
  background: #eef4f6;
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  margin: 2px;
  padding: 4px 8px;
}

pre {
  background: #111827;
  border-radius: 8px;
  color: #e5e7eb;
  overflow: auto;
  padding: 16px;
}

.queue-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 240px);
  min-height: 420px;
  overflow: hidden;
}

.queue-summary {
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: -2px 0 14px;
  padding-bottom: 14px;
}

.queue-summary div {
  display: grid;
  gap: 4px;
  min-width: 150px;
}

.queue-summary strong {
  font-size: 24px;
  line-height: 1;
}

.queue-output {
  flex: 1;
  margin: 0;
  min-height: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.queue-tools {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 14px;
}

.queue-tools h2 {
  font-size: 18px;
  margin: 0;
}

.queue-tools input {
  min-width: 300px;
}

.queue-ranking {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.queue-ranking table {
  table-layout: fixed;
}

.queue-ranking th:first-child,
.queue-ranking td:first-child {
  width: 90px;
}

.site-footer {
  background: linear-gradient(180deg, var(--bg) 0%, #6f7782 100%);
  border-top: 1px solid var(--line);
  color: var(--muted);
  margin-top: 32px;
  padding: 16px 20px;
  text-align: center;
}

.site-footer img {
  display: block;
  margin: 0 auto 8px;
  max-width: 112px;
}

.site-footer p {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 10px;
}

.site-footer strong {
  color: var(--text);
  display: block;
  font-size: 12px;
}

@media (max-width: 900px) {
  .system-metrics {
    grid-template-columns: 1fr;
  }

  .mailbox-table {
    min-width: 860px;
  }

  .panel {
    overflow-x: auto;
  }

  .mailbox-actions {
    flex-wrap: wrap;
  }

  .profile-header,
  .profile-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .profile-form {
    grid-template-columns: 1fr;
  }

  .alias-editor {
    grid-template-columns: 1fr;
  }

  .alias-move-actions {
    grid-template-columns: repeat(2, 48px);
    justify-content: center;
  }
}
