:root {
  --bg: #eef4ff;
  --bg2: #f8fbff;
  --text: #101828;
  --muted: #64748b;
  --line: rgba(15, 23, 42, .10);
  --card: rgba(255, 255, 255, .82);
  --card-solid: #ffffff;
  --brand: #2563eb;
  --brand2: #7c3aed;
  --ok: #059669;
  --danger: #dc2626;
  --shadow: 0 24px 80px rgba(15, 23, 42, .12);
  --radius: 26px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% 4%, rgba(37, 99, 235, .20), transparent 30%),
    radial-gradient(circle at 92% 10%, rgba(124, 58, 237, .16), transparent 28%),
    linear-gradient(135deg, #eef5ff 0%, #f8fbff 48%, #f1f5ff 100%);
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
code { padding: 2px 7px; border-radius: 8px; background: rgba(37, 99, 235, .08); }

.page-bg, .orb, .noise { position: fixed; inset: 0; pointer-events: none; z-index: -1; }
.page-bg::before, .page-bg::after {
  content: "";
  position: absolute;
  width: 340px;
  height: 340px;
  border-radius: 999px;
  filter: blur(32px);
  opacity: .38;
}
.page-bg::before { left: -110px; top: 120px; background: #60a5fa; }
.page-bg::after { right: -100px; bottom: 70px; background: #c084fc; }
.orb-one { background: radial-gradient(circle at 10% 10%, rgba(59, 130, 246, .22), transparent 28%); }
.orb-two { background: radial-gradient(circle at 90% 0%, rgba(168, 85, 247, .18), transparent 30%); }

.topbar {
  width: min(1180px, calc(100% - 28px));
  margin: 18px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(255,255,255,.70);
  background: rgba(255,255,255,.64);
  backdrop-filter: blur(18px);
  border-radius: 22px;
  box-shadow: 0 12px 40px rgba(15,23,42,.08);
}
.app-logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 900; letter-spacing: -.03em; }
.app-logo span, .logo-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  color: white;
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  box-shadow: 0 10px 24px rgba(37,99,235,.28);
}
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-user span { color: var(--muted); font-size: .92rem; }

.mail-page, .admin-layout, .auth-wrap {
  width: min(1180px, calc(100% - 28px));
  margin: 22px auto 54px;
}
.mail-page { display: grid; gap: 18px; }
.panel-card, .glass-card, .admin-card, .brand-panel, .login-card {
  border: 1px solid rgba(255,255,255,.78);
  background: var(--card);
  backdrop-filter: blur(20px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.eyebrow {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: .75rem;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.muted, .hint { color: var(--muted); }
.hint { margin: 8px 0 0; font-size: .88rem; line-height: 1.5; }

.compose-panel {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 18px;
  padding: 22px;
  align-items: stretch;
  animation: rise .38s ease both;
}
.compose-copy h1 { margin: 0; font-size: clamp(2rem, 5vw, 4.3rem); line-height: .94; letter-spacing: -.07em; }
.compose-copy p:last-child { margin: 14px 0 0; color: var(--muted); line-height: 1.55; }
.address-box, .custom-box {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255,255,255,.66);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}
.mini-label { color: var(--muted); font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.address-line, .custom-line { display: flex; align-items: center; gap: 8px; }
.address-line input, .custom-line input, .stack-form input, .login-form input, .settings-form input, .settings-form select {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(15,23,42,.12);
  background: rgba(255,255,255,.92);
  border-radius: 16px;
  padding: 13px 14px;
  color: var(--text);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.address-line input { font-weight: 900; letter-spacing: -.02em; }
.custom-line input:focus, .address-line input:focus, .login-form input:focus, .settings-form input:focus, .settings-form select:focus {
  border-color: rgba(37,99,235,.55);
  box-shadow: 0 0 0 4px rgba(37,99,235,.10);
}
.domain-chip {
  flex: none;
  padding: 12px 13px;
  border-radius: 16px;
  background: #0f172a;
  color: white;
  font-weight: 800;
}
.status-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: .88rem; }
#syncState { color: var(--ok); font-weight: 900; }
#syncState.active { color: var(--brand); }
#syncState.error { color: var(--danger); }

.primary-btn, .secondary-btn, .ghost-btn, .toolbar-btn {
  border: 0;
  border-radius: 15px;
  padding: 12px 16px;
  font-weight: 900;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease, opacity .16s ease;
}
.primary-btn { color: white; background: linear-gradient(135deg, var(--brand), var(--brand2)); box-shadow: 0 12px 28px rgba(37,99,235,.25); }
.secondary-btn { color: var(--brand); background: rgba(37,99,235,.10); }
.ghost-btn { color: var(--text); background: rgba(15,23,42,.06); }
.small-btn { padding: 9px 12px; border-radius: 12px; font-size: .86rem; }
.full { width: 100%; }
.primary-btn:hover, .secondary-btn:hover, .ghost-btn:hover, .toolbar-btn:hover { transform: translateY(-1px); }
button:disabled, .toolbar-btn[disabled] { opacity: .45; cursor: not-allowed; transform: none !important; }

.inbox-panel, .detail-panel { padding: 20px; animation: rise .42s ease both; }
.inbox-top, .detail-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.inbox-top h2 { margin: 0; font-size: clamp(1.7rem, 3vw, 2.4rem); letter-spacing: -.05em; }
.count-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--brand);
  background: rgba(37,99,235,.10);
  font-weight: 900;
}
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-btn { background: rgba(15,23,42,.06); color: var(--text); }
.toolbar-btn.accent { color: white; background: linear-gradient(135deg, var(--brand), var(--brand2)); }
.toolbar-btn.danger { color: #991b1b; background: rgba(220,38,38,.10); }

.message-table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255,255,255,.76);
}
.message-table-head, .message-row {
  display: grid;
  grid-template-columns: minmax(180px, .9fr) minmax(180px, 1.2fr) 140px;
  gap: 16px;
  align-items: center;
}
.message-table-head {
  padding: 13px 16px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .10em;
  border-bottom: 1px solid var(--line);
  background: rgba(248,250,252,.86);
}
.message-table-body { display: grid; }
.message-row {
  width: 100%;
  padding: 15px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.55);
  color: var(--text);
  text-align: left;
  animation: fadeRow .20s ease both;
}
.message-row:last-child { border-bottom: 0; }
.message-row:hover, .message-row.selected { background: rgba(37,99,235,.07); }
.sender-cell, .subject-cell, .message-row time {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sender-cell { font-weight: 900; color: #0f172a; }
.subject-cell { color: #334155; }
.message-row time { color: var(--muted); text-align: right; }
.empty-state {
  padding: 42px 18px;
  text-align: center;
  color: var(--muted);
}
.empty-state h3 { margin: 0 0 7px; color: var(--text); font-size: 1.25rem; }
.empty-state p { margin: 0; }

.detail-panel { display: grid; gap: 16px; }
.detail-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.detail-meta div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.65);
  min-width: 0;
}
.detail-meta span { display: block; color: var(--muted); font-size: .78rem; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; }
.detail-meta strong { display: block; overflow-wrap: anywhere; }
.message-render {
  min-height: 240px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: white;
  line-height: 1.65;
  overflow-x: auto;
}
.message-render img { max-width: 100%; height: auto; border-radius: 12px; }
.plain-email { white-space: pre-wrap; }
.html-email table { max-width: 100%; border-collapse: collapse; }
.html-email a { color: var(--brand); text-decoration: underline; }

.auth-wrap { display: grid; place-items: center; min-height: calc(100vh - 120px); }
.login-card {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  padding: 18px;
  gap: 18px;
  animation: rise .35s ease both;
}
.login-copy {
  border-radius: 22px;
  padding: 28px;
  color: white;
  min-height: 470px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background:
    radial-gradient(circle at 10% 10%, rgba(255,255,255,.24), transparent 28%),
    linear-gradient(135deg, #1d4ed8, #7c3aed);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.login-copy .logo-mark { background: rgba(255,255,255,.18); box-shadow: none; }
.login-copy .eyebrow, .login-copy p { color: rgba(255,255,255,.82); }
.login-copy h1 { margin: 14px 0 10px; font-size: clamp(2.2rem, 5vw, 4rem); line-height: .95; letter-spacing: -.07em; }
.feature-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.feature-row span { padding: 8px 10px; border-radius: 999px; background: rgba(255,255,255,.16); font-weight: 800; font-size: .86rem; }
.login-form { padding: 28px; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.login-form h2 { margin: 0; font-size: 2rem; letter-spacing: -.05em; }
.login-form label, .stack-form label, .settings-form label { display: grid; gap: 7px; color: var(--muted); font-weight: 800; font-size: .9rem; }
.alert { padding: 12px 14px; border-radius: 16px; font-weight: 800; }
.alert-error { color: #991b1b; background: rgba(220,38,38,.10); }
.alert-success { color: #065f46; background: rgba(5,150,105,.10); }

.admin-layout { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 18px; align-items: start; }
.brand-panel { padding: 24px; position: sticky; top: 18px; display: grid; gap: 20px; }
.brand-panel h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.5rem); line-height: .95; letter-spacing: -.06em; }
.admin-card { padding: 22px; display: grid; gap: 18px; }
.admin-head, .section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.admin-head h2, .form-section h3 { margin: 0; letter-spacing: -.04em; }
.settings-form, .stack-form, .compact-form { display: grid; gap: 16px; }
.form-section {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255,255,255,.55);
}
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.time-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.toggle-row { display: grid; gap: 10px; }
.check { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 8px; color: var(--text) !important; }
.check input { width: auto !important; }
.inline-check { align-content: end; padding-top: 25px; }
.user-list { display: grid; gap: 10px; }
.user-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px; border-radius: 16px; background: rgba(255,255,255,.65); border: 1px solid var(--line); }
.user-row span { display: block; margin-top: 3px; color: var(--muted); font-size: .86rem; }
.user-actions, .action-row { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-text { color: #991b1b; }
.status-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.status-card { padding: 13px; border-radius: 16px; background: rgba(255,255,255,.62); border: 1px solid var(--line); min-width: 0; }
.status-card span { display: block; color: var(--muted); font-size: .78rem; font-weight: 900; text-transform: uppercase; margin-bottom: 4px; }
.status-card strong { display: block; overflow-wrap: anywhere; font-size: .9rem; }
.code-panel { padding: 16px; border-radius: 18px; background: #0f172a; color: white; display: grid; gap: 12px; }
.code-panel p { color: rgba(255,255,255,.72); margin: 0; }
.code-panel code { display: block; overflow-wrap: anywhere; background: rgba(255,255,255,.10); color: white; }
.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mini-grid span { padding: 10px; border-radius: 14px; background: rgba(37,99,235,.08); color: var(--brand); font-weight: 800; font-size: .85rem; }

@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeRow { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 960px) {
  .compose-panel, .admin-layout, .login-card { grid-template-columns: 1fr; }
  .brand-panel { position: static; }
  .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-meta { grid-template-columns: 1fr; }
  .login-copy { min-height: 320px; }
}

@media (max-width: 680px) {
  .topbar, .mail-page, .admin-layout, .auth-wrap { width: min(100% - 18px, 1180px); }
  .topbar { margin-top: 9px; border-radius: 18px; }
  .compose-panel, .inbox-panel, .detail-panel, .admin-card, .brand-panel, .login-card { border-radius: 20px; padding: 14px; }
  .compose-copy h1 { font-size: 2.25rem; }
  .address-line, .custom-line { flex-direction: column; align-items: stretch; }
  .domain-chip { text-align: center; }
  .toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .message-table-head { display: none; }
  .message-row {
    grid-template-columns: 1fr;
    gap: 5px;
    padding: 15px;
  }
  .message-row time { text-align: left; }
  .sender-cell { font-size: .98rem; }
  .subject-cell { white-space: normal; }
  .field-grid, .time-grid, .status-grid { grid-template-columns: 1fr; }
  .admin-head, .inbox-top, .detail-actions, .user-row { align-items: stretch; flex-direction: column; }
  .user-actions, .action-row { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .login-copy, .login-form { padding: 20px; }
  .login-copy h1 { font-size: 2.35rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
