:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: #0b0b0b;
  --panel-2: #121212;
  --line: #292929;
  --line-soft: #1d1d1d;
  --text: #f5f5f5;
  --muted: #8b8b8b;
  --soft: #c9c9c9;
  --accent: #f1f1f1;
  --accent-ink: #050505;
  --danger: #ff8a8a;
}

* { box-sizing: border-box; }

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

button, input { font: inherit; }

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 44px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  font-weight: 720;
  padding: 0.72rem 0.95rem;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

button:hover { background: #ffffff; border-color: #ffffff; transform: translateY(-1px); }
button:disabled { cursor: wait; opacity: 0.62; transform: none; }

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
  background: #080a0a;
  color: var(--text);
  padding: 0.78rem 0.85rem;
}

input::placeholder { color: #5f6964; }
input:focus { border-color: #8a8a8a; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06); }
label { color: var(--soft); font-size: 0.9rem; font-weight: 650; }
h1, h2, h3, p { margin-top: 0; }
.hidden { display: none !important; }
.shell { min-height: 100vh; }

.login-view {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 1.25rem;
  background: transparent;
}

.login-wrap { width: min(100%, 360px); }
.login-brand { margin: 0 0 2.3rem; }
.login-brand span { color: #e5e5e5; font-size: 1.05rem; font-weight: 750; letter-spacing: 0.02em; }

.login-panel {
  border-top: 1px solid var(--line);
  background: transparent;
  padding: 1.45rem 0 0;
}
h1 { margin: 0 0 0.55rem; font-size: 1.75rem; font-weight: 680; line-height: 1.08; }
.muted { color: var(--muted); line-height: 1.55; margin-bottom: 1.35rem; }
.stack { display: grid; gap: 0.65rem; margin-top: 1.15rem; }
.button-arrow { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.35; }
.notice { min-height: 1.4rem; margin-top: 1rem; color: var(--muted); font-size: 0.94rem; line-height: 1.45; }
.notice.error { color: var(--danger); }
.link-button { min-height: 30px; border: 0; background: transparent; color: var(--muted); font-size: 0.86rem; padding: 0.2rem; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 0.2em; }
.link-button:hover { border: 0; background: transparent; color: var(--text); text-decoration-color: currentColor; transform: none; }
.login-panel button[type="submit"] { border-color: #e8e8e8; background: #e8e8e8; color: #0a0a0a; }
.login-panel button[type="submit"]:hover { border-color: #ffffff; background: #ffffff; }

.portal-view { display: grid; min-height: 100vh; grid-template-columns: 208px minmax(0, 1fr); }
.rail { display: flex; flex-direction: column; justify-content: space-between; border-right: 1px solid var(--line-soft); background: #070707; padding: 1.25rem 1rem; }
.brand-row { display: flex; align-items: center; gap: 0.72rem; padding: 0.35rem 0.3rem; }
.brand-row strong { letter-spacing: 0.04em; }
.brand-row span { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 0.15rem; }
.nav { display: grid; gap: 0.2rem; margin-top: 2.5rem; }
.nav-item, .ghost { border: 0; border-radius: 0; background: transparent; color: var(--muted); text-align: left; }
.nav-item { justify-content: flex-start; min-height: 38px; font-weight: 650; padding-left: 0.75rem; }
.nav-item.active { box-shadow: inset 2px 0 0 #ffffff; color: var(--text); }
.nav-item:hover, .ghost:hover { border-color: transparent; background: transparent; color: var(--text); transform: none; }
.rail-footer { display: grid; gap: 0.7rem; }

.workspace { display: grid; min-width: 0; grid-template-rows: auto auto auto 1fr; padding: 1.6rem clamp(1.4rem, 3vw, 4rem); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line-soft); padding: 0.4rem 0 1rem; }
.actions { display: flex; align-items: center; gap: 0.55rem; }
.eyebrow { color: var(--muted); font-size: 0.76rem; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; }
.eyebrow span { color: var(--soft); letter-spacing: 0; text-transform: none; }
h2 { margin: 0.4rem 0 0; font-size: 1.7rem; font-weight: 730; }
.status-bar { min-height: 1.7rem; color: var(--muted); padding: 0.65rem 0; }
.status-bar.error { color: var(--danger); }
.stats-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem; margin: 0.1rem 0 1rem; }
.stat-card { display: grid; gap: 0.3rem; border: 1px solid var(--line-soft); border-radius: 6px; background: #090909; padding: 0.7rem 0.85rem; }
.stat-card span { color: var(--muted); font-size: 0.78rem; }
.stat-card strong { font-size: 1.18rem; font-weight: 740; }
.stat-card.quiet strong { color: var(--soft); font-size: 0.98rem; }

.content-grid { display: grid; min-height: 0; grid-template-columns: minmax(360px, 0.82fr) minmax(0, 1.45fr); gap: 0.75rem; }
.list-pane, .detail-pane, .aliases-pane { min-height: 0; border: 1px solid var(--line-soft); border-radius: 6px; background: var(--panel); overflow: hidden; }
.aliases-pane { grid-column: 1 / -1; }
.list-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line-soft); color: var(--soft); font-weight: 700; padding: 0.85rem 1rem; }
.count-pill { display: inline-grid; min-width: 1.6rem; min-height: 1.6rem; place-items: center; border-radius: 999px; background: var(--panel-2); color: var(--soft); font-size: 0.78rem; }
.message-list, .alias-list { max-height: calc(100vh - 300px); overflow: auto; }
.message-item, .alias-item { width: 100%; min-height: auto; border: 0; border-bottom: 1px solid var(--line-soft); border-radius: 0; background: transparent; color: var(--text); display: grid; gap: 0.38rem; padding: 0.95rem 1rem; text-align: left; }
.message-item:hover, .message-item.active { background: var(--panel-2); transform: none; }
.message-item.unread { box-shadow: inset 2px 0 0 #ffffff; }
.message-meta, .alias-meta { color: var(--muted); font-size: 0.82rem; }
.message-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-pane { display: flex; flex-direction: column; }
.message-full { display: grid; gap: 0.9rem; padding: 1.1rem; }
.message-body { border-top: 1px solid var(--line-soft); color: var(--soft); line-height: 1.65; margin-top: 0.3rem; padding-top: 1rem; white-space: pre-wrap; word-break: break-word; }
.empty-state { display: grid; min-height: 100%; place-content: center; padding: 2rem; text-align: center; }
.empty-state p { color: var(--muted); line-height: 1.55; }
.empty-state h3 { margin-bottom: 0.5rem; }

.addresses-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line-soft); padding: 1.1rem 1.2rem; }
.addresses-toolbar h3 { margin: 0 0 0.25rem; }
.addresses-toolbar p { margin: 0; color: var(--muted); }
.alias-table-head { display: grid; grid-template-columns: minmax(240px, 2fr) 110px minmax(160px, 1fr) minmax(160px, 1fr) 80px; gap: 1rem; border-bottom: 1px solid var(--line-soft); color: var(--muted); font-size: 0.78rem; padding: 0.75rem 1rem; }
.alias-input { display: grid; grid-template-columns: 1fr auto; align-items: center; margin-top: 0.45rem; border: 1px solid var(--line); border-radius: 7px; background: #080a0a; }
.alias-input input { border: 0; box-shadow: none; }
.alias-input span { color: var(--muted); padding-right: 0.85rem; }
.alias-item { grid-template-columns: minmax(240px, 2fr) 110px minmax(160px, 1fr) minmax(160px, 1fr) 80px; align-items: center; gap: 1rem; }
.alias-address { min-width: 0; }
.alias-address strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alias-stat { color: var(--soft); font-size: 0.88rem; }
.alias-item button { min-height: 34px; border-color: #3a3a3a; background: transparent; color: #d0d0d0; font-size: 0.82rem; padding: 0.35rem 0.6rem; }
.alias-item button:hover { border-color: #666666; background: #151515; color: #ffffff; transform: none; }

.modal-open { overflow: hidden; }
.modal-overlay { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; background: rgba(0, 0, 0, 0.76); padding: 1rem; }
.modal-card { width: min(100%, 440px); border: 1px solid #303030; border-radius: 8px; background: #0b0b0b; box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line-soft); padding: 1rem 1.1rem; }
.modal-header h3 { margin: 0; }
.modal-close { min-height: auto; border: 0; border-radius: 0; background: transparent; color: var(--muted); font-size: 0.84rem; padding: 0.25rem; }
.modal-close:hover { border: 0; background: transparent; color: var(--text); transform: none; }
.modal-form { padding: 1.1rem; }
.field-help { margin: 0.55rem 0 0; color: var(--muted); font-size: 0.82rem; }
.modal-notice { min-height: 1.35rem; margin-top: 0.75rem; color: var(--muted); font-size: 0.86rem; }
.modal-notice.error { color: var(--danger); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.55rem; margin-top: 0.85rem; }
.modal-actions .ghost { border: 1px solid var(--line); border-radius: 7px; padding: 0.65rem 0.9rem; }
.modal-actions .ghost:hover { border-color: #4a4a4a; background: #111111; }

@media (max-width: 900px) {
  .portal-view { grid-template-columns: 1fr; }
  .rail { border-right: 0; border-bottom: 1px solid var(--line-soft); flex-direction: row; gap: 1rem; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 1rem; }
  .rail-footer { align-content: space-between; }
  .content-grid { grid-template-columns: 1fr; }
  .detail-pane { min-height: 340px; }
  .message-list, .alias-list { max-height: 420px; }
  .alias-table-head { display: none; }
  .alias-item { grid-template-columns: 1fr auto; gap: 0.7rem 1rem; }
  .alias-address { grid-column: 1 / -1; }
  .alias-stat { display: flex; align-items: center; justify-content: space-between; grid-column: 1 / -1; }
  .alias-stat::before { content: attr(data-label); color: var(--muted); }
  .alias-item button { grid-column: 1 / -1; justify-self: start; }
}

@media (max-width: 620px) {
  .login-panel { padding: 1.1rem; }
  h1 { font-size: 1.7rem; }
  h2 { font-size: 1.4rem; }
  .workspace { padding: 1rem; }
  .topbar, .rail, .actions, .addresses-toolbar { align-items: stretch; flex-direction: column; grid-template-columns: 1fr; }
  .actions { width: 100%; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .stat-card.quiet { display: none; }
}
