:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-hover: #f8f9fb;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --muted: #667085;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --accent-hover: #1d4ed8;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.12);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --sidebar-w: 248px;
  --list-w: 400px;
  --top-h: 56px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

button,
input,
textarea {
  font: inherit;
}

/* —— App shell —— */
.mail-app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-top {
  height: var(--top-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.mail-top .brand-mini {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.95rem;
  min-width: 140px;
}

.mail-top .brand-mini img,
.mail-top .brand-mini .brand-icon {
  height: 28px;
  width: auto;
}

.mail-search {
  flex: 1;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
}

.mail-search input {
  width: 100%;
  padding: 0.55rem 1rem 0.55rem 2.35rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
}

.mail-search input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
  background: var(--surface);
}

.mail-search svg {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.mail-top-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.mail-workspace {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) var(--list-w) minmax(0, 1fr);
  min-height: 0;
}

/* —— Sidebar —— */
.mail-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.btn-compose {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.65rem 1rem;
  margin-bottom: 0.75rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.btn-compose:hover {
  background: var(--accent-hover);
}

.nav-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.75rem 0.65rem 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--surface-hover);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-item svg {
  flex-shrink: 0;
  opacity: 0.75;
}

.tag-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.nav-count {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.tag-dot.dot-inbox {
  background: #2563eb;
}
.tag-dot.dot-drafts {
  background: #64748b;
}
.tag-dot.dot-sent {
  background: #059669;
}
.tag-dot.dot-junk {
  background: #f79009;
}
.tag-dot.dot-trash {
  background: #f04438;
}
.tag-dot.dot-archive {
  background: #7a5af8;
}
.tag-dot.dot-personal {
  background: #6366f1;
}
.tag-dot.dot-promotions {
  background: #ee46bc;
}
.tag-dot.dot-social {
  background: #7a5af8;
}
.tag-dot.dot-finance {
  background: #12b76a;
}
.tag-dot.dot-shopping {
  background: #f79009;
}
.tag-dot.dot-newsletters {
  background: #2e90fa;
}
.tag-dot.dot-notifications {
  background: #06aed4;
}
.tag-dot.dot-folder {
  background: #98a2b3;
}
.tag-dot.dot-category {
  background: #94a3b8;
}

.tag-dot.green {
  background: #12b76a;
}
.tag-dot.pink {
  background: #ee46bc;
}
.tag-dot.purple {
  background: #7a5af8;
}
.tag-dot.blue {
  background: #2e90fa;
}
.tag-dot.orange {
  background: #f79009;
}
.tag-dot.gray {
  background: #98a2b3;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
}

/* —— Message list —— */
.mail-list-pane {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: opacity 0.15s ease;
}

.mail-list-pane.is-loading {
  opacity: 0.72;
  pointer-events: none;
}

.mail-read-pane {
  transition: opacity 0.15s ease;
}

.mail-read-pane.is-loading {
  opacity: 0.85;
}

.mail-read-pane.is-loading-only {
  opacity: 0.92;
}

.list-header {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.list-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.list-header span {
  font-size: 0.8rem;
  color: var(--muted);
}

.mail-list {
  overflow-y: auto;
  flex: 1;
}

.mail-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: start;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.mail-row:hover {
  background: var(--surface-hover);
}

.mail-row.active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.mail-row-unread .mail-row-from,
.mail-row-unread .mail-row-subject {
  font-weight: 700;
  color: var(--text);
}

.mail-row-unread .mail-row-from::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 0.35rem;
  vertical-align: middle;
}

.mail-row-new {
  animation: mail-row-new-pulse 1.8s ease-out 2;
  background: #ecfdf3;
}

@keyframes mail-row-new-pulse {
  0% {
    background: #d1fae5;
  }
  100% {
    background: transparent;
  }
}

.mail-new-banner {
  margin: 0.65rem 1rem 0;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid rgba(37, 99, 235, 0.25);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.mail-new-banner[hidden] {
  display: none !important;
}

.mail-new-banner button {
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
}

.mail-list-pane.is-polling-soft .list-header-count::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 0.35rem;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
  vertical-align: middle;
  animation: mail-poll-dot 1s ease-in-out infinite;
}

@keyframes mail-poll-dot {
  50% {
    opacity: 1;
  }
}

.mail-row input[type="checkbox"] {
  margin-top: 0.25rem;
  accent-color: var(--accent);
}

.mail-row-body {
  min-width: 0;
}

.mail-row-from {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-row-subject {
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-row-preview {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-row-date {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

/* —— Reading pane —— */
.mail-read-pane {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.read-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 0.5rem;
  padding: 2rem;
}

.read-empty svg {
  opacity: 0.35;
}

.read-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 2rem;
}

.read-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.read-meta {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.read-meta .avatar {
  width: 44px;
  height: 44px;
  font-size: 1rem;
}

.read-meta h3 {
  margin: 0;
  font-size: 1rem;
}

.read-meta .sub {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.read-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.chip-btn {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  color: var(--muted);
  cursor: default;
}

.read-body {
  margin-top: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  line-height: 1.65;
  white-space: pre-wrap;
  font-size: 0.92rem;
  box-shadow: var(--shadow-sm);
}

/* —— Compose modal —— */
.compose-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(16, 24, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.compose-window {
  width: min(720px, 100%);
  max-height: min(90vh, 820px);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.compose-window form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.compose-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.compose-fields {
  padding: 0.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.compose-field-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}

.compose-field-row:last-child {
  border-bottom: none;
}

.compose-field-row label {
  font-size: 0.8rem;
  color: var(--muted);
}

.compose-field-row input {
  border: none;
  padding: 0.35rem 0;
  outline: none;
  width: 100%;
}

.compose-editor,
.compose-editor-rich {
  flex: 1;
  min-height: 220px;
  max-height: 40vh;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  border: none;
  resize: none;
  outline: none;
  line-height: 1.55;
}

.compose-editor-rich:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

.compose-editor-rich ul {
  margin: 0.5rem 0 0.5rem 1.25rem;
}

.compose-attachments {
  padding: 0.35rem 1.25rem 0.5rem;
  border-top: 1px solid var(--border);
}

.compose-attachments input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.compose-attach-hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.attachment-list {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.82rem;
}

.attachment-list .attachment-total {
  font-weight: 600;
  list-style: none;
  margin-left: -1.1rem;
}

.attachment-list .muted {
  color: var(--muted);
}

.compose-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface-hover);
}

.format-bar {
  display: flex;
  gap: 0.35rem;
  color: var(--muted);
}

.format-bar span,
.format-btn,
.attach-label {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-size: 0.85rem;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-family: inherit;
}

.format-btn:hover,
.attach-label:hover {
  background: var(--surface);
}

.emoji-wrap {
  position: relative;
}

.emoji-panel {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 0.35rem;
  display: grid;
  grid-template-columns: repeat(8, 1.75rem);
  gap: 0.15rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 5;
}

.emoji-item {
  border: none;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 4px;
}

.emoji-item:hover {
  background: var(--surface-hover);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.btn-send {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.btn-send:hover {
  background: var(--accent-hover);
}

.icon-close {
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
}

/* —— Auth & portal —— */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: #f4f6fb;
}

.auth-shell {
  width: min(1040px, 100%);
  min-height: min(640px, calc(100vh - 2.5rem));
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  border-radius: 24px;
  overflow: hidden;
  box-shadow:
    0 24px 48px rgba(15, 23, 42, 0.12),
    0 0 0 1px rgba(15, 23, 42, 0.06);
  background: var(--surface);
}

.auth-showcase {
  position: relative;
  padding: 2.5rem 2.25rem;
  display: flex;
  align-items: flex-end;
  color: #fff;
}

.auth-showcase--mail {
  background:
    radial-gradient(ellipse 120% 80% at 0% 0%, rgba(255, 255, 255, 0.18), transparent 55%),
    linear-gradient(145deg, #1d4ed8 0%, #2563eb 42%, #0ea5e9 100%);
}

.auth-showcase--admin {
  background:
    radial-gradient(circle at 100% 0%, rgba(99, 102, 241, 0.35), transparent 45%),
    linear-gradient(155deg, #0f172a 0%, #1e293b 55%, #312e81 100%);
}

.auth-showcase-inner {
  position: relative;
  z-index: 1;
  max-width: 22rem;
}

.auth-showcase .brand-lockup,
.auth-showcase .brand-icon {
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.2));
  margin-bottom: 1.25rem;
}

.auth-showcase--mail .brand-lockup {
  max-height: 88px;
}

.auth-showcase--admin .brand-icon {
  height: 48px;
  width: auto;
}

.auth-showcase-title {
  margin: 0 0 0.5rem;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-showcase-tagline {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.55;
  opacity: 0.92;
}

.auth-showcase-points {
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.88rem;
  opacity: 0.9;
}

.auth-showcase-points li {
  padding: 0.35rem 0 0.35rem 1.35rem;
  position: relative;
}

.auth-showcase-points li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.65rem;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
}

.auth-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem 2rem 1.5rem;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

.auth-card--modern {
  animation: auth-fade-in 0.45s ease-out;
}

@keyframes auth-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.auth-brand--compact {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.auth-brand--compact .brand-icon {
  height: 40px;
  width: auto;
}

.auth-product-hint {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.auth-form {
  margin-top: 0.25rem;
}

.btn-auth {
  margin-top: 0.35rem;
  padding: 0.72rem 1rem;
  font-size: 0.95rem;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn-auth:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.32);
}

.auth-legal {
  margin: 1.5rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

.auth-page--admin .auth-panel {
  background: linear-gradient(180deg, #fff 0%, #f1f5f9 100%);
}

@media (max-width: 860px) {
  .auth-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .auth-showcase {
    min-height: 200px;
    padding: 1.75rem 1.5rem;
    align-items: center;
  }

  .auth-showcase-points {
    display: none;
  }

  .auth-panel {
    padding: 1.75rem 1.25rem 1.25rem;
  }
}

.auth-brand {
  margin-bottom: 1.25rem;
}

.auth-brand .brand-lockup {
  display: block;
  width: min(100%, 220px);
  height: auto;
  max-height: 72px;
  margin-bottom: 0.75rem;
}

.auth-product-name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.auth-foot-link {
  margin-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.home-hero .brand-lockup {
  max-height: 88px;
  width: min(90vw, 240px);
}

.brand-lockup {
  display: block;
  width: min(100%, 360px);
  height: auto;
  max-height: 56px;
}

.brand-icon {
  height: 28px;
  width: auto;
  display: block;
}

.auth-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
}

.auth-card .sub {
  color: var(--muted);
  margin: 0 0 1.5rem;
  font-size: 0.9rem;
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.field input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
}

.field input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  border: none;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

.alert {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.88rem;
}

.alert-error {
  background: #fef3f2;
  border: 1px solid #fecdca;
  color: #b42318;
}

.alert-ok {
  background: #ecfdf3;
  border: 1px solid #abefc6;
  color: #067647;
}

.home-hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  background: linear-gradient(160deg, #eff4ff 0%, #f0f2f5 100%);
}

.home-hero .brand-lockup {
  max-height: 64px;
  width: min(90vw, 380px);
  margin-bottom: 1.25rem;
}

.home-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 1.75rem;
}

.home-actions .btn {
  min-width: 160px;
}

@media (max-width: 1100px) {
  .mail-workspace {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }
  .mail-read-pane {
    display: none;
  }
}

@media (max-width: 768px) {
  .mail-workspace {
    grid-template-columns: 1fr;
  }
  .mail-sidebar {
    display: none;
  }
  .mail-search {
    display: none;
  }
}
