:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --border: #e6e8ec;
  --text: #1a1d29;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

/* Scope RTL layout to Arabic; addresses, API examples and message bodies retain
   their own reading direction instead of inheriting a page-wide reversal. */
html[dir="rtl"] th, html[dir="rtl"] td, html[dir="rtl"] .mail-open { text-align: start; }
html[dir="rtl"] .prose ul, html[dir="rtl"] .prose ol { padding-left: 0; padding-inline-start: 22px; }
html[dir="rtl"] .callout { border-left: 0; border-inline-start: 3px solid var(--primary); }
html[dir="rtl"] .callout.warn { border-inline-start-color: var(--warning); }
html[dir="rtl"] .endpoint-tag { margin-right: 0; margin-inline-end: 8px; }
html[dir="rtl"] .modal .close { right: auto; inset-inline-end: 10px; }
html[dir="rtl"] .modal h3 { margin-right: 0; margin-inline-end: 48px; }
html[dir="rtl"] :is(code, pre, .addr, #emailInput, #domainSelect, #customDomain, #checkDomainInput, #addDomainInput, #urlEmail) { direction: ltr; unicode-bidi: isolate; }
html[dir="rtl"] :is(pre, #emailInput, #customDomain, #checkDomainInput, #addDomainInput) { text-align: left; }
html[dir="rtl"] :is(.sender-cell, .subject-cell, #modalSubject, #modalMeta, .body-content) { unicode-bidi: plaintext; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  background: var(--bg);
  margin: 0;
  color: var(--text);
  line-height: 1.6;
}

/* ---------- Navbar ---------- */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
}
.brand .logo {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 16px;
}
.nav-links { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  transition: all 0.15s ease;
}
.nav-links a:hover { background: var(--primary-light); color: var(--primary); }
.nav-links a.active { background: var(--primary-light); color: var(--primary); }

/* ---------- Layout ---------- */
.container { max-width: 1040px; margin: 0 auto; padding: 32px 24px 64px; }
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 28px; margin: 0 0 6px; }
.page-header p { color: var(--text-muted); margin: 0; font-size: 15px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

/* ---------- Inputs ---------- */
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: stretch; }
input, select, button, textarea {
  font-family: inherit;
  padding: 11px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
input[type="text"] { flex: 1; min-width: 220px; }
select { cursor: pointer; }

button {
  cursor: pointer;
  border: none;
  font-weight: 600;
  transition: transform 0.08s ease, opacity 0.15s ease;
  white-space: nowrap;
}
button:hover { opacity: 0.92; }
button:active { transform: scale(0.97); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); opacity: 1; }
.btn-secondary { background: var(--primary-light); color: var(--primary); }
.btn-ghost { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.domain-guide-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
  text-decoration: none;
  transition: background-color .15s, border-color .15s;
}
.domain-guide-link:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-success { background: var(--success-light); color: #047857; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 7px; }

/* ---------- Email display ---------- */
.email-display {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--primary-light);
  border-radius: 9px;
  padding: 12px 16px;
  margin-top: 14px;
}
.email-display .addr {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 600;
  color: var(--primary-dark);
  font-size: 15px;
  word-break: break-all;
}
.url-hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; word-break: break-all; }

.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

.email-control-row { align-items: center; }
.email-label {
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; font-size: 14px; }
thead th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
tbody tr:hover { background: var(--bg); }
tbody tr:last-child { border-bottom: none; }
.sender-cell { font-weight: 600; }
.subject-cell { color: var(--text-muted); }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 10px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-online { background: var(--success-light); color: #047857; }
.badge-offline { background: var(--danger-light); color: #b91c1c; }

.domain-status {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.2s ease;
}
.domain-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
}
.domain-status.online {
  color: #047857;
  border-color: #a7f3d0;
  background: #f0fdf4;
}
.domain-status.online .domain-status-dot {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}
.domain-status.offline {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fff7f7;
}
.domain-status.offline .domain-status-dot { background: var(--danger); }
.domain-status.checking .domain-status-dot {
  background: var(--warning);
  animation: status-pulse 1.2s ease-in-out infinite;
}
@keyframes status-pulse {
  50% { opacity: 0.35; transform: scale(0.8); }
}

.status-msg { margin-top: 10px; font-size: 13px; font-weight: 500; }
.status-ok { color: #047857; }
.status-err { color: var(--danger); }

/* ---------- Modal ---------- */
.modal-bg {
  display: none; position: fixed; inset: 0; background: rgba(17,17,27,0.5);
  align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 28px;
  max-width: 680px; width: 100%; max-height: 82vh; overflow-y: auto;
  box-shadow: var(--shadow-lg); position: relative;
}
.modal .close {
  position: absolute; top: 18px; right: 18px;
  background: var(--bg); border-radius: 50%; width: 32px; height: 32px;
  font-size: 18px; color: var(--text-muted); padding: 0; line-height: 1;
}
.modal h3 { margin: 0 24px 6px 0; font-size: 19px; }
.modal .meta { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.modal .body-content { font-size: 14px; }
.modal .body-content pre { white-space: pre-wrap; font-family: inherit; }
.email-html-frame {
  display: block;
  width: 100%;
  min-height: 320px;
  border: 0;
  background: var(--surface);
}

/* ---------- Homepage content ---------- */
.home-section { margin-top: 32px; }
.prose .home-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin: 16px 0; padding: 0; }
.home-grid > * { min-width: 0; border: 1px solid var(--border); border-radius: 10px; padding: 18px; background: var(--bg); overflow-wrap: anywhere; }
.prose .home-grid li { margin: 0; }
.prose .home-grid h3 { margin: 0 0 8px; }
.prose .home-grid p { margin: 0; font-size: 14px; }
.home-steps { list-style-position: inside; }
.home-steps li::marker { color: var(--primary-dark); font-weight: 700; }
.prose .home-steps h3 { margin-top: 8px; }
.home-use-cases { list-style: none; }
.home-guide { display: block; color: var(--primary-dark); text-decoration: none; }
.home-guide:hover { background: var(--primary-light); border-color: var(--primary); }
.home-guide:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
@media (min-width: 641px) {
  .prose .home-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  .prose .home-steps, .prose .home-use-cases { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- Docs / policy pages ---------- */
.prose h2 { font-size: 20px; margin: 32px 0 12px; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-size: 16px; margin: 20px 0 8px; }
.prose p { margin: 8px 0; color: var(--text); }
.prose ul, .prose ol { margin: 8px 0; padding-left: 22px; }
.prose li { margin: 4px 0; }
.prose code {
  background: var(--bg); padding: 2px 6px; border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
}
.prose pre {
  background: #1a1d29; color: #e5e7eb; padding: 16px; border-radius: 9px;
  overflow-x: auto; font-size: 13px; line-height: 1.55;
}
.prose pre code { background: none; padding: 0; color: inherit; }
.prose table { margin: 12px 0; }
.prose th, .prose td { border-bottom: 1px solid var(--border); }
.callout {
  background: var(--primary-light); border-left: 3px solid var(--primary);
  padding: 12px 16px; border-radius: 8px; font-size: 14px; margin: 14px 0;
}
.callout.warn { background: #fffbeb; border-left-color: var(--warning); }

.endpoint-tag {
  display: inline-block; font-family: ui-monospace, monospace; font-weight: 700;
  font-size: 12px; padding: 3px 8px; border-radius: 6px; margin-right: 8px;
}
.tag-get { background: #dbeafe; color: #1d4ed8; }
.tag-post { background: #d1fae5; color: #047857; }
.tag-delete { background: #fee2e2; color: #b91c1c; }

.toc { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.toc a {
  font-size: 13px; color: var(--primary); text-decoration: none;
  background: var(--primary-light); padding: 6px 12px; border-radius: 999px;
}

footer {
  text-align: center; color: var(--text-muted); font-size: 13px;
  padding: 32px 24px; border-top: 1px solid var(--border); margin-top: 40px;
}
footer a { color: var(--primary); text-decoration: none; }

/* Shared accessible controls and intrinsically wrapping content. */
body { overflow-wrap: anywhere; }
input, select, textarea { min-width: 0; max-width: 100%; font-size: 16px; }
input[type="text"] { min-width: 0; }
button, input, select, .nav-links a, .brand, a.btn-ghost { min-height: 44px; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.row > * { max-width: 100%; }
.nav-toggle { display: none; }
.nav-links a { display: inline-flex; align-items: center; }
.email-display { margin-top: 0; padding: 20px; flex-wrap: nowrap; }
.address-summary { flex: 1; min-width: 0; display: grid; gap: 6px; }
.email-display .addr { font-size: clamp(19px, 3vw, 26px); }
.primary-actions button { min-height: 48px; }
.email-control-row { margin-top: 20px; }
.email-control-row input { flex: 2; }
.email-control-row select { flex: 1; }
.privacy-hint { color: var(--text-muted); font-size: 13px; margin-bottom: 0; }
.inbox-heading { font-size: 20px; margin: 0; }
.inbox-table { table-layout: fixed; }
.inbox-table th:last-child { width: 80px; }
.mail-open { text-align: left; white-space: normal; background: transparent; color: var(--primary-dark); width: 100%; padding: 6px 0; overflow-wrap: anywhere; }
.date-cell { font-size: 13px; color: var(--text-muted); }
.reader-open { overflow: hidden; }
.modal .close { width: 48px; height: 48px; top: 10px; right: 10px; }
.modal h3 { margin-right: 48px; }
.modal { overscroll-behavior: contain; }
.modal pre { overflow-wrap: anywhere; }
.prose table { display: block; overflow-x: auto; }
@media (max-width: 640px) {
  .container { padding: 20px 12px 40px; }
  .card { padding: 16px; margin-bottom: 16px; }
  .page-header { margin-bottom: 18px; }
  .page-header h1 { font-size: 24px; }
  .nav-inner { padding: 8px 12px; gap: 6px; }
  .nav-toggle { display: block; }
  .nav-links { display: none; width: 100%; max-height: 65dvh; overflow-y: auto; }
  .navbar.expanded .nav-links { display: grid; grid-template-columns: 1fr 1fr; }
  .email-display { flex-wrap: wrap; padding: 14px; }
  .address-summary { flex-basis: 100%; }
  .email-display > button { width: 100%; min-height: 48px; }
  .primary-actions { display: grid; grid-template-columns: 1fr; }
  .email-control-row { display: grid; grid-template-columns: 1fr; }
  .email-control-row input, .email-control-row select { width: 100%; }
  .row > input[type="text"] { flex-basis: 100%; }
  .inbox-table, .inbox-table tbody { display: block; width: 100%; }
  .inbox-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .inbox-table .mail-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; border: 1px solid var(--border); border-radius: 10px; margin-top: 12px; padding: 12px; gap: 4px 8px; }
  .mail-row td { display: block; padding: 0; min-width: 0; }
  .mail-row .sender-cell, .mail-row .subject-cell { grid-column: 1 / -1; }
  .mail-row .date-cell { align-self: center; }
  .mail-row .delete-cell { grid-column: 2; }
  .empty-state { padding: 32px 8px; }
  .modal-bg { padding: 0; }
  .modal { border-radius: 0; max-width: none; height: 100dvh; max-height: 100dvh; padding: 20px 16px max(20px, env(safe-area-inset-bottom)); }
  .email-html-frame { min-height: 65dvh; }
  footer { padding: 24px 16px; }
}
/* Header disclosures: language remains independent of the collapsed navigation. */
.nav-inner { max-width: 1400px; flex-wrap: nowrap; position: relative; gap: 16px; }
.brand { flex-shrink: 0; min-height: 44px; }
.nav-links { flex: 1; justify-content: center; }
.primary-links { display: flex; align-items: center; justify-content: center; gap: 4px; list-style: none; margin: 0; padding: 0; }
.primary-links > li > a { min-height: 44px; }
.more-menu, .language-switch { position: relative; }
.more-toggle, .language-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; padding: 8px 10px; white-space: nowrap; }
.language-switch { flex-shrink: 0; }
.locale-flag { flex-shrink: 0; border: 1px solid var(--border); border-radius: 3px; }
.more-links, .language-links { position: absolute; inset-block-start: calc(100% + 8px); inset-inline-end: 0; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 32px #20103a22; z-index: 110; }
.more-links { width: 250px; }
.more-links a { display: flex; min-height: 44px; }
.language-links { width: 340px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.language-links a { display: flex; gap: 6px; align-items: center; min-height: 44px; padding: 8px 6px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 14px; }
.language-links a:hover, .language-links a[aria-current="true"] { color: var(--primary); background: var(--primary-light); }
.language-links a > span[dir] { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.locale-check { width: 12px; flex-shrink: 0; }
.navbar [hidden] { display: none !important; }
@media (max-width: 1199px) {
  .nav-inner { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .brand { margin-inline-end: auto; }
  .nav-toggle { display: block; min-width: 44px; padding: 8px; }
  .nav-links { display: none; order: 4; flex-basis: 100%; width: 100%; max-height: 65dvh; overflow-y: auto; }
  .navbar.expanded .nav-links { display: block; }
  .primary-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
  .primary-links > li > a { display: flex; height: 100%; }
  .more-menu { grid-column: 1 / -1; }
  .more-links { position: static; width: auto; box-shadow: none; margin-block-start: 4px; }
  .language-switch { position: static; }
  .language-links { inset-inline: 12px; width: auto; max-width: 340px; margin-inline-start: auto; inset-block-start: calc(100% + 4px); max-height: 75dvh; overflow-y: auto; }
}
.catalog-address-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 20px; }
.catalog-address-row input { width: 100%; min-width: 0; min-height: 46px; box-sizing: border-box; }
.catalog-selector-row { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto auto; gap: 10px; margin-top: 12px; }
.catalog-selector-row > * { min-width: 0; }
.catalog-selector-row select, .catalog-selector-row #checkInboxBtn, .catalog-selector-row .domain-status { height: 46px; box-sizing: border-box; }
.catalog-selector-row .domain-status { justify-content: center; padding-inline: 12px; }
.catalog-selector-row select { width: 100%; text-overflow: ellipsis; direction: ltr; }
.suffix-selector { position: relative; }
#suffixTrigger { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; height: 46px; padding: 8px 12px; box-sizing: border-box; border: 1px solid var(--border); background: var(--bg); text-align: start; white-space: normal; font-size: 13px; line-height: 1.2; }
#suffixTrigger::after { content: ''; flex: 0 0 6px; width: 6px; height: 6px; border-inline-end: 2px solid currentColor; border-block-end: 2px solid currentColor; transform: rotate(45deg); margin-block-start: -4px; }
[dir="rtl"] #suffixTrigger::after { transform: rotate(-45deg); }
#suffixTrigger:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.suffix-popup { position: absolute; inset-inline-start: 0; top: calc(100% + 6px); z-index: 30; width: min(300px, calc(100vw - 80px)); min-width: 100%; padding: 8px; box-sizing: border-box; background: var(--surface, #fff); color: var(--text); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px #0002; }
.suffix-popup[hidden] { display: none; }
#suffixSearch { width: 100%; min-width: 0; box-sizing: border-box; }
#suffixOptions { max-height: 240px; overflow-y: auto; margin-top: 6px; }
#suffixOptions [role="option"] { padding: 10px; cursor: pointer; border-radius: 6px; overflow-wrap: anywhere; }
#suffixOptions [aria-selected="true"] { font-weight: 700; }
#suffixOptions .active, #suffixOptions [role="option"]:hover { background: var(--border); }
.catalog-privacy { font-size: 12px; line-height: 1.5; color: var(--text-muted); border-top: 1px solid var(--border); padding-top: 12px; margin-block: 14px 0; }
.address-card .url-hint, .address-card .privacy-hint { font-size: 12px; line-height: 1.5; margin-block: 6px 0; }
#catalogEmpty:empty { display: none; }
@media (max-width: 700px) {
 .catalog-selector-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
 .catalog-selector-row .suffix-selector, .catalog-selector-row select { grid-column: 1 / -1; }
 .catalog-selector-row > *, .catalog-address-row input { width: 100%; box-sizing: border-box; }
 .catalog-selector-row .domain-status { width: 100%; }
 .catalog-selector-row #checkInboxBtn { white-space: normal; padding-inline: 8px; }
 .catalog-address-row { display: grid; grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
