:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #334155;
  --border: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #e11d48;
  --primary-hover: #be123c;
  --secondary: #3b82f6;
  --secondary-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --topbar-bg: rgba(30, 41, 59, 0.9);
  --badge-accent: #fda4af;
  --ttl-color: #fde68a;
  --quota-color: #93c5fd;
  --suffix-bg: rgba(255, 255, 255, 0.05);
  --card-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  --radius: 12px;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-hover: #e2e8f0;
  --border: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #e11d48;
  --primary-hover: #be123c;
  --secondary: #2563eb;
  --secondary-hover: #1d4ed8;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --badge-accent: #be123c;
  --ttl-color: #b45309;
  --quota-color: #1d4ed8;
  --suffix-bg: #e2e8f0;
  --card-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}

.hidden {
  display: none !important;
}

/* Header */
.topbar {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.theme-toggle {
  white-space: nowrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.brand-badge {
  font-size: 1.4rem;
}

.brand-title {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.brand-dot {
  color: var(--primary);
}

.brand-tag {
  font-size: 0.78rem;
  background: rgba(225, 29, 72, 0.12);
  color: var(--badge-accent);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid rgba(225, 29, 72, 0.3);
}

.user-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ttl-pill,
.quota-pill {
  font-size: 0.82rem;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 999px;
  color: var(--ttl-color);
  font-weight: 600;
}

.quota-pill {
  color: var(--quota-color);
}

/* Hero & Checker */
.auth-section {
  padding: 36px 0 48px;
}

.hero-box {
  text-align: center;
  max-width: 760px;
  margin: 0 auto 36px;
}

.hero-box h1 {
  font-size: 2.3rem;
  font-weight: 800;
  margin-bottom: 12px;
  line-height: 1.2;
}

.highlight {
  color: var(--primary);
}

.hero-sub {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 24px;
}

.checker-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
}

.checker-label {
  display: block;
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.alias-input-group {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.alias-input-group:focus-within {
  border-color: var(--primary);
}

.alias-input-group input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 12px 14px;
  font-size: 1.05rem;
  outline: none;
}

.alias-input-group.compact input {
  padding: 10px 12px;
  font-size: 0.95rem;
}

.domain-suffix {
  background: var(--suffix-bg);
  color: var(--text-muted);
  padding: 12px 14px;
  font-weight: 600;
  font-size: 0.95rem;
  border-left: 1px solid var(--border);
  user-select: none;
}

.availability-status {
  margin-top: 12px;
  font-size: 0.95rem;
  min-height: 24px;
  font-weight: 600;
}

.status-free {
  color: var(--success);
}

.status-taken {
  color: var(--warning);
}

.status-invalid {
  color: var(--danger);
}

/* Auth Grid */
.auth-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card h2 {
  font-size: 1.3rem;
  margin-bottom: 6px;
}

.card-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 18px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.form-group input[type='password'],
.form-group input[type='email'],
.form-group input[type='text'] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
}

.alias-input-group input[type='text'] {
  border: none;
}

.form-group input:focus {
  border-color: var(--primary);
}

.turnstile-wrap {
  margin: 14px 0;
  min-height: 65px;
  display: flex;
  justify-content: center;
}

.rules-mini {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 0.86rem;
  color: var(--text-muted);
}

.rules-mini h3 {
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.rules-mini ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  border: none;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-secondary {
  background: var(--secondary);
  color: white;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--secondary-hover);
}

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

.btn-outline:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.3);
}

/* Alerts */
.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}

.alert-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.alert-success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

/* Webmail Layout */
.webmail-section {
  padding: 24px 0 48px;
}

.webmail-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 20px;
  min-height: 560px;
}

/* Responsive Mobile Optimizations */
@media (max-width: 768px) {
  .container {
    padding: 0 12px;
  }

  .topbar-inner {
    height: auto;
    padding: 10px 0;
    justify-content: space-between;
  }

  .brand-tag {
    display: none;
  }

  .user-header {
    width: 100%;
    justify-content: space-between;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
  }

  .ttl-pill,
  .quota-pill {
    font-size: 0.76rem;
    padding: 4px 8px;
  }

  .auth-section {
    padding: 20px 0 32px;
  }

  .hero-box {
    margin-bottom: 24px;
  }

  .hero-box h1 {
    font-size: 1.65rem;
  }

  .hero-sub {
    font-size: 0.95rem;
  }

  .checker-card {
    padding: 14px;
  }

  .alias-input-group input {
    min-width: 0;
    padding: 10px;
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  .alias-input-group.compact input,
  .form-group input[type='password'],
  .form-group input[type='email'],
  .form-group input[type='text'],
  .plain-editor {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  .domain-suffix {
    padding: 10px;
    font-size: 0.85rem;
    white-space: nowrap;
  }

  .auth-cards-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .card {
    padding: 18px 14px;
  }

  .turnstile-wrap {
    overflow-x: auto;
  }

  .webmail-section {
    padding: 14px 0 32px;
  }

  .webmail-layout {
    grid-template-columns: 1fr;
    gap: 14px;
    min-height: auto;
  }

  .webmail-sidebar {
    padding: 12px;
    gap: 10px;
  }

  .folder-nav {
    flex-direction: row;
    gap: 8px;
  }

  .folder-btn {
    flex: 1;
    text-align: center;
    padding: 10px 8px;
    font-size: 0.9rem;
  }

  .webmail-main {
    padding: 14px 12px;
    min-width: 0;
  }

  .panel-header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .message-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 12px;
  }

  .msg-main {
    width: 100%;
  }

  .msg-date {
    align-self: flex-end;
    font-size: 0.74rem;
  }

  .read-subject {
    font-size: 1.15rem;
    word-break: break-word;
  }

  .read-meta {
    font-size: 0.82rem;
    word-break: break-word;
  }

  .read-body-html {
    padding: 12px;
    font-size: 0.92rem;
  }

  .read-body-html img,
  .read-body-html table {
    max-width: 100% !important;
    height: auto !important;
  }

  .editor-mode-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .rich-toolbar button {
    padding: 6px 10px;
    font-size: 0.85rem;
  }

  .compose-footer .btn {
    width: 100%;
  }
}

@media (max-width: 400px) {
  .alias-input-group {
    flex-wrap: nowrap;
  }

  .domain-suffix {
    padding: 10px 8px;
    font-size: 0.78rem;
  }

  .ttl-pill,
  .quota-pill {
    font-size: 0.72rem;
  }
}

.webmail-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.current-address-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.address-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.address-value {
  font-size: 0.92rem;
  word-break: break-all;
  color: var(--badge-accent);
}

.btn-link-copy {
  background: none;
  border: none;
  color: var(--secondary);
  font-size: 0.8rem;
  text-align: left;
  cursor: pointer;
  margin-top: 2px;
}

.folder-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.folder-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.folder-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.folder-btn.active {
  background: rgba(225, 29, 72, 0.12);
  color: var(--badge-accent);
  border: 1px solid rgba(225, 29, 72, 0.35);
}

.webmail-main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.badge {
  font-size: 0.8rem;
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--text-muted);
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s;
}

.message-item:hover {
  border-color: var(--primary);
}

.message-item.unread {
  border-left: 4px solid var(--primary);
  background: rgba(225, 29, 72, 0.06);
}

.msg-main {
  flex: 1;
  min-width: 0;
}

.msg-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.msg-peer {
  font-weight: 700;
  font-size: 0.92rem;
}

.msg-subject {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-preview {
  font-size: 0.83rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-date {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

/* Read View */
.read-subject {
  font-size: 1.35rem;
  margin-bottom: 12px;
}

.read-meta {
  background: var(--bg);
  padding: 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.view-mode-tabs {
  display: inline-flex;
  background: var(--bg);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
}

.read-body-html {
  background: #ffffff;
  color: #0f172a;
  padding: 20px;
  border-radius: 8px;
  min-height: 220px;
  overflow-x: auto;
}

.read-body-text {
  background: var(--bg);
  color: var(--text);
  padding: 16px;
  border-radius: 8px;
  min-height: 220px;
  white-space: pre-wrap;
  font-family: monospace;
  font-size: 0.9rem;
}

/* Compose & Rich Editor */
.editor-mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.rich-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 8px;
  border-radius: 8px 8px 0 0;
}

.rich-toolbar button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.rich-toolbar button:hover {
  background: var(--surface-hover);
}

.rich-editor {
  background: #ffffff;
  color: #0f172a;
  min-height: 220px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  outline: none;
}

.rich-editor:empty:before {
  content: attr(data-placeholder);
  color: #94a3b8;
}

.plain-editor {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  margin-bottom: 14px;
}

.compose-footer {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 20px 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}
