:root {
  --accent: #d97757;
  --bg0: #faf7f4;
  --bg1: #efe8e1;
  --ink: #1c1917;
  --muted: #57534e;
  --line: #e7e0d8;
  --sidebar: #2c241f;
  --sidebar-ink: #f5f0eb;
  --ok: #065f46;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(ellipse 70% 45% at 10% -10%, rgba(217, 119, 87, 0.22), transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1));
}

#app { min-height: 100vh; }

.hero-brand {
  text-align: center;
  padding: 3.5rem 1.25rem 1rem;
}
.hero-brand h1 {
  margin: 0;
  font-size: clamp(2.1rem, 6vw, 3rem);
  color: var(--accent);
  letter-spacing: -0.02em;
}
.hero-brand p { color: var(--muted); margin: 0.4rem 0 0; }

.login-card {
  max-width: 24rem;
  margin: 0.5rem auto 3rem;
  padding: 1.25rem;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(28, 25, 23, 0.06);
}
.login-form, .stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.login-hint {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
}
label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 600; }
.field-row {
  display: flex;
  gap: 0.4rem;
  align-items: stretch;
}
.field-row input { flex: 1; }
input, textarea, select {
  font: inherit;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
input:focus, textarea:focus {
  outline: 2px solid rgba(217, 119, 87, 0.35);
  border-color: var(--accent);
}
.btn {
  font: inherit;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 0.6rem 0.95rem;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: wait; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--sidebar-ink);
  text-decoration: underline;
  padding-inline: 0.4rem;
}
.btn.danger {
  color: var(--danger);
  border-color: #fecaca;
}
.linkish {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  font: inherit;
}
.form-error {
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  margin: 0;
}
.hint { color: var(--muted); font-size: 0.95rem; text-align: center; }

.mail-shell {
  display: grid;
  grid-template-columns: 14rem 23rem 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.brand-mini {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--accent);
}
.account-chip {
  font-size: 0.82rem;
  color: rgba(245, 240, 235, 0.75);
  word-break: break-all;
  line-height: 1.35;
  margin-bottom: 0.35rem;
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.35rem; }
.sidebar nav button, .admin-tabs button {
  text-align: start;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.sidebar nav button.on, .admin-tabs button.on {
  background: rgba(217, 119, 87, 0.28);
  color: #fff;
}
.badge {
  display: inline-flex;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}
.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 1rem;
}
.status-pill {
  font-size: 0.8rem;
  color: rgba(245, 240, 235, 0.7);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.status-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2);
  animation: pulse 2s ease infinite;
}
@keyframes pulse {
  50% { opacity: 0.55; }
}

.list-pane {
  border-inline-end: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.list-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0.75rem;
}
.list-toolbar #search {
  flex: 1;
  width: auto;
  margin: 0;
}
.list-toolbar .btn { white-space: nowrap; }
.retention-banner, .retention-line {
  margin: 0 0.75rem 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.msg-list { overflow: auto; flex: 1; }
.msg-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem 0.5rem;
  text-align: start;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 0.8rem 0.85rem;
  cursor: pointer;
  font: inherit;
}
.msg-row:hover { background: rgba(217, 119, 87, 0.06); }
.msg-row.unread { background: rgba(217, 119, 87, 0.07); }
.msg-row.unread .subj { font-weight: 700; }
.msg-row.active { background: rgba(217, 119, 87, 0.14); }
.msg-row .from {
  color: var(--muted);
  font-size: 0.9rem;
  grid-column: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-row .when {
  grid-column: 2;
  grid-row: 1;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}
.msg-row .subj {
  grid-column: 1 / -1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-row .preview {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-row .meta {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.8rem;
}
.empty-state {
  padding: 2.25rem 1.25rem;
  text-align: center;
  color: var(--muted);
}
.empty-state h3 {
  margin: 0 0 0.4rem;
  color: var(--ink);
  font-size: 1.1rem;
}
.empty-state p { margin: 0; font-size: 0.95rem; line-height: 1.5; }

.read-pane { background: #fff; min-height: 100vh; }
.reader { display: flex; flex-direction: column; height: 100%; }
.reader-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  align-items: center;
}
.reader-bar strong {
  flex: 1;
  min-width: 12rem;
  word-break: break-word;
}
.reader-meta {
  padding: 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.reader iframe {
  border: 0;
  width: 100%;
  flex: 1;
  min-height: 60vh;
}
.empty { padding: 2rem; color: var(--muted); text-align: center; }
.mobile-back { display: none; }

.help-box, .ok-box, .warn-box {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  margin: 0 0 1rem;
  line-height: 1.5;
}
.help-box { background: #fff7ed; border: 1px solid #fed7aa; color: #7c2d12; }
.ok-box { background: #ecfdf5; border: 1px solid #a7f3d0; color: var(--ok); }
.warn-box { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.labeled label { font-weight: 600; gap: 0.35rem; }
.admin-actions { max-width: 28rem; margin: 0 0 1rem; padding: 0; }
.domain-list { max-width: 36rem; margin: 0 0 1rem; gap: 0.65rem; }
.domain-card strong { font-size: 1.05rem; }
.domain-picker {
  display: grid;
  gap: 0.35rem;
  margin: 0 0 1rem;
  font-weight: 600;
  max-width: 28rem;
}
.domain-picker select {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.simple-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}
.simple-list li {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 0.45rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.email-preview {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 600;
}
.creds-share-preview {
  margin: 0.5rem 0 0;
  padding: 0.75rem;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #fed7aa;
  white-space: pre-wrap;
  font: 0.9rem/1.55 ui-monospace, Consolas, "Noto Sans Arabic", sans-serif;
  color: #1c1917;
  max-height: 16rem;
  overflow: auto;
  text-align: start;
  direction: rtl;
}
.creds-card {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 12px;
  padding: 1rem;
  margin: 0 0 1rem;
  display: grid;
  gap: 0.35rem;
}
.creds-card code {
  font-size: 1.05rem;
  word-break: break-all;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}
.user-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.user-status { font-size: 0.85rem; color: var(--muted); }
.user-status.on { color: var(--ok); }
.user-status.off { color: #991b1b; }
.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.user-actions .btn { padding: 0.4rem 0.65rem; font-size: 0.85rem; }
.bulk-result {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 14rem;
  overflow: auto;
}
.pass-dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem;
  max-width: min(92vw, 26rem);
  background: var(--bg, #faf7f4);
  color: var(--ink);
}
.pass-dialog::backdrop { background: rgba(28, 25, 23, 0.45); }
.status-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.admin-shell { max-width: 720px; margin: 0 auto; padding: 1.25rem; }
.admin-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.admin-top h1 { color: var(--accent); margin: 0; font-size: clamp(1.4rem, 4vw, 1.85rem); }
.admin-tabs { display: flex; gap: 0.35rem; margin: 1rem 0; flex-wrap: wrap; }
.admin-tabs button {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
}
.admin-tabs button.on {
  background: rgba(217, 119, 87, 0.15);
  border-color: var(--accent);
  color: var(--ink);
}

#toast {
  position: fixed;
  inset-inline: 0;
  bottom: 1.25rem;
  margin: 0 auto;
  width: fit-content;
  max-width: min(92vw, 26rem);
  padding: 0.7rem 1rem;
  border-radius: 999px;
  background: #1c1917;
  color: #faf7f4;
  font-size: 0.95rem;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.toast-ok { background: #065f46; }
#toast.toast-err { background: #991b1b; }

@media (max-width: 900px) {
  .mail-shell { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
  }
  .brand-mini { width: 100%; margin: 0; }
  .account-chip { width: 100%; margin: 0; }
  .sidebar nav {
    flex-direction: row;
    flex: 1;
  }
  .sidebar-foot {
    margin-top: 0;
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    padding-top: 0.25rem;
  }
  .list-pane { min-height: auto; max-height: none; }
  .read-pane { min-height: 50vh; }
  .mobile-back { display: inline-flex; }

  .mail-shell.viewing-msg .list-pane,
  .mail-shell.viewing-msg .sidebar { display: none; }
  .mail-shell:not(.viewing-msg) .read-pane { display: none; }

  .reader-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
  }
  .reader-bar .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
  }
  .reader-bar .actions .btn { flex: 1 1 auto; }
  .user-actions { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, #toast, .status-dot { transition: none; animation: none; }
}
