:root {
  color-scheme: dark;
  --bg: #07110f;
  --surface: #0e1b18;
  --surface-2: #13231f;
  --border: #284139;
  --border-soft: #1d312b;
  --text: #f2f7f5;
  --muted: #91a9a1;
  --accent: #43d7a2;
  --accent-strong: #25b984;
  --danger: #ff7d79;
  --warning: #f6c56d;
  --shadow: 0 24px 70px rgba(0, 0, 0, .32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 18% -8%, rgba(67, 215, 162, .13), transparent 30rem),
    linear-gradient(180deg, #091512 0%, var(--bg) 36rem);
}
button, input { font: inherit; }
button { cursor: pointer; }

.login-page { display: grid; place-items: center; padding: 24px; }
.login-shell { width: min(100%, 430px); }
.login-card {
  padding: 42px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(19, 35, 31, .96), rgba(10, 24, 20, .96));
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 8px 0 8px; font-size: 30px; letter-spacing: -.03em; }
.login-card > .muted { margin: 0 0 30px; }

.brand-mark {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(67, 215, 162, .45);
  border-radius: 15px;
  background: rgba(67, 215, 162, .09);
  box-shadow: inset 0 0 22px rgba(67, 215, 162, .08);
}
.brand-mark span {
  width: 20px;
  height: 14px;
  border: 2px solid var(--accent);
  border-radius: 3px;
  position: relative;
}
.brand-mark span::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: -2px;
  height: 8px;
  border-bottom: 2px solid var(--accent);
  transform: rotate(32deg) skewX(-20deg);
}
.brand-mark.small { width: 42px; height: 42px; border-radius: 12px; }

.eyebrow {
  margin: 18px 0 0;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
}
.muted, .panel-help, .mailbox-row p { color: var(--muted); }

.stack-form, .create-form { display: grid; gap: 18px; }
label { display: grid; gap: 8px; color: #c9d7d2; font-size: 13px; font-weight: 650; }
input {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: #081410;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(67, 215, 162, .13); }
.password-field, .address-field { display: flex; align-items: center; position: relative; }
.password-field input { padding-right: 66px; }
.password-field button { position: absolute; right: 10px; }
.address-field input { border-radius: 10px 0 0 10px; }
.address-field span {
  align-self: stretch;
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 10px 10px 0;
  background: #0c1b17;
  white-space: nowrap;
}

.primary-button, .secondary-button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  font-weight: 750;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.primary-button { color: #032019; border: 1px solid var(--accent); background: var(--accent); }
.primary-button:hover { background: #67e5b7; transform: translateY(-1px); }
.secondary-button { color: var(--text); border: 1px solid var(--border); background: var(--surface-2); }
.secondary-button:hover { border-color: #45665d; background: #182c27; }
.compact { min-height: 34px; padding: 0 12px; font-size: 12px; }
.text-button { padding: 5px; color: var(--accent); border: 0; background: transparent; font-size: 12px; font-weight: 750; }
.text-button.danger { color: var(--danger); }
.security-note { margin: 22px 0 0; color: #6f8980; text-align: center; font-size: 12px; }

.topbar {
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid var(--border-soft);
  background: rgba(7, 17, 15, .78);
  backdrop-filter: blur(18px);
}
.brand-row, .top-actions { display: flex; align-items: center; gap: 14px; }
.brand-row h1 { margin: 2px 0 0; font-size: 18px; }
.brand-row .eyebrow { margin: 0; }
.server-state { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.server-state i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }

.page-shell { width: min(1180px, calc(100% - 40px)); margin: 38px auto 70px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stats-grid article {
  min-height: 112px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  background: rgba(14, 27, 24, .78);
}
.stats-grid span { color: var(--muted); font-size: 13px; }
.stats-grid strong { font-size: 30px; letter-spacing: -.04em; }

.panel {
  margin-top: 18px;
  padding: 24px;
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  background: rgba(14, 27, 24, .88);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .12);
}
.panel-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.panel-heading .eyebrow { margin: 0 0 5px; }
.panel h2 { margin: 0; font-size: 19px; }
.panel-help { margin: 0; font-size: 12px; }
.create-form { grid-template-columns: minmax(250px, 1.3fr) minmax(220px, 1fr) auto; align-items: end; }
.count-pill, .status-pill {
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}
.count-pill { color: var(--muted); background: var(--surface-2); }
.status-pill.enabled { color: var(--accent); background: rgba(67, 215, 162, .10); }
.status-pill.disabled { color: var(--warning); background: rgba(246, 197, 109, .10); }

.mailbox-list { border-top: 1px solid var(--border-soft); }
.mailbox-row {
  min-height: 82px;
  display: grid;
  grid-template-columns: 1fr auto minmax(245px, auto);
  align-items: center;
  gap: 20px;
  border-bottom: 1px solid var(--border-soft);
}
.mailbox-row:last-child { border-bottom: 0; }
.mailbox-identity { display: flex; align-items: center; gap: 13px; min-width: 0; }
.avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 15px;
  font-weight: 850;
}
.mailbox-row h3 { margin: 0; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.mailbox-row p { margin: 5px 0 0; font-size: 12px; }
.mailbox-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
details { position: relative; }
summary { list-style: none; display: flex; align-items: center; }
summary::-webkit-details-marker { display: none; }
.popover-form {
  position: absolute;
  z-index: 5;
  right: 0;
  top: calc(100% + 8px);
  width: 260px;
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0d1d19;
  box-shadow: var(--shadow);
}
.empty-state { padding: 44px; color: var(--muted); text-align: center; }

.alias-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.alias-grid div {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: #0a1714;
}
.alias-grid code { overflow: hidden; color: #c9d7d2; text-overflow: ellipsis; font-size: 12px; }
.alias-grid span { color: var(--accent); }

.credential-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
  padding: 22px 24px;
  border: 1px solid rgba(67, 215, 162, .42);
  border-radius: 18px;
  background: linear-gradient(110deg, rgba(67, 215, 162, .12), rgba(14, 27, 24, .92));
}
.credential-card .eyebrow { margin: 0 0 5px; }
.credential-card h2 { margin: 0; font-size: 18px; }
.credential-card p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.credential-value { display: flex; align-items: center; gap: 10px; }
.credential-value code { padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: #06100d; color: #dff8ef; }

.notice { margin-bottom: 16px; padding: 12px 14px; border-radius: 10px; font-size: 13px; }
.notice-error { color: #ffd1cf; border: 1px solid rgba(255, 125, 121, .35); background: rgba(255, 125, 121, .10); }
.notice-success { color: #caffec; border: 1px solid rgba(67, 215, 162, .35); background: rgba(67, 215, 162, .10); }

@media (max-width: 800px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .create-form { grid-template-columns: 1fr; }
  .mailbox-row { grid-template-columns: 1fr auto; padding: 15px 0; }
  .mailbox-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .alias-grid { grid-template-columns: 1fr; }
  .credential-card { align-items: flex-start; flex-direction: column; }
  .credential-value { width: 100%; align-items: stretch; flex-direction: column; }
  .credential-value code { overflow-wrap: anywhere; }
}

@media (max-width: 520px) {
  .login-card { padding: 30px 24px; }
  .page-shell { width: min(100% - 24px, 1180px); margin-top: 20px; }
  .topbar { height: 70px; padding: 0 14px; }
  .server-state { display: none; }
  .stats-grid { gap: 9px; }
  .stats-grid article { min-height: 96px; padding: 15px; }
  .panel { padding: 18px 15px; }
  .panel-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .address-field { flex-direction: column; align-items: stretch; }
  .address-field input { border-radius: 10px 10px 0 0; }
  .address-field span { min-height: 40px; border: 1px solid var(--border); border-top: 0; border-radius: 0 0 10px 10px; }
}
