:root {
  --brand: #6366f1;
  --brand-soft: rgba(99, 102, 241, 0.14);
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg-app: #090d16;
  --bg-rail: #060911;
  --bg-sidebar: #0e1422;
  --bg-surface: #131b2e;
  --bg-elevated: #1a243d;
  --bg-hover: rgba(255, 255, 255, 0.05);
  --border: rgba(148, 163, 184, 0.13);
  --text-main: #f8fafc;
  --text-sec: #94a3b8;
  --text-muted: #64748b;
  --shadow-lg: 0 22px 50px rgba(0, 0, 0, 0.45);
  --radius-lg: 16px;
  --radius-md: 11px;
  --radius-sm: 8px;
}

[data-theme="light"] {
  --bg-app: #f1f5f9;
  --bg-rail: #0f172a;
  --bg-sidebar: #ffffff;
  --bg-surface: #ffffff;
  --bg-elevated: #f8fafc;
  --bg-hover: rgba(15, 23, 42, 0.045);
  --border: rgba(15, 23, 42, 0.09);
  --text-main: #0f172a;
  --text-sec: #475569;
  --text-muted: #64748b;
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--text-main);
  font-family: 'Inter', 'Vazirmatn', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

[dir="rtl"] body {
  font-family: 'Vazirmatn', 'Inter', Tahoma, sans-serif;
}

.hidden {
  display: none !important;
}

/* ================= LOGIN SCREEN ================= */
.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 18% 20%, rgba(99, 102, 241, 0.22), transparent 42%),
    radial-gradient(circle at 82% 80%, rgba(6, 182, 212, 0.18), transparent 42%),
    var(--bg-app);
  z-index: 100;
  padding: 20px;
}

.auth-topbar {
  position: fixed;
  top: 20px;
  inset-inline-end: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-card {
  width: 100%;
  max-width: 450px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 36px 34px;
  box-shadow: var(--shadow-lg);
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  margin-bottom: 16px;
  box-shadow: 0 10px 25px rgba(99, 102, 241, 0.35);
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
}

.auth-card p.sub {
  margin: 0 0 24px;
  color: var(--text-sec);
  line-height: 1.55;
  font-size: 13px;
}

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

.form-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-sec);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand), #4f46e5);
  color: #fff;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.28);
}

.btn-primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), #0284c7);
  color: #fff;
}

.btn-ghost {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text-main);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  border-color: var(--brand);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}

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

.btn-block {
  width: 100%;
  padding: 11px 16px;
}

.auth-hint {
  margin-top: 16px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: var(--brand-soft);
  color: var(--text-sec);
  font-size: 12px;
  line-height: 1.55;
}

.error-box {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 12.5px;
}

/* ================= MAIN APP SHELL ================= */
.app-shell {
  display: grid;
  grid-template-columns: 68px 260px 1fr;
  height: 100vh;
  width: 100vw;
}

.app-shell.no-rail {
  grid-template-columns: 260px 1fr;
}

/* 1. Leftmost Site/Domain Dock Rail (10+ Websites Switcher) */
.site-rail {
  background: var(--bg-rail);
  border-inline-end: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 10px;
  overflow-y: auto;
}

.rail-item {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
  color: #e2e8f0;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.18s ease;
  flex-shrink: 0;
}

.rail-item:hover {
  border-radius: 12px;
  transform: scale(1.05);
}

.rail-item.active {
  border-color: #fff;
  box-shadow: 0 0 18px rgba(99, 102, 241, 0.55);
}

.rail-badge {
  position: absolute;
  top: -4px;
  inset-inline-end: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rail-divider {
  width: 30px;
  height: 1px;
  background: rgba(255, 255, 255, 0.12);
  margin: 2px 0;
}

/* 2. Navigation Sidebar */
.sidebar {
  background: var(--bg-sidebar);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-brand .glyph {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-brand .titles {
  min-width: 0;
}

.sidebar-brand .titles strong {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-brand .titles span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mailbox-picker {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  margin-bottom: 12px;
}

.mailbox-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.compose-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.nav-section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
  padding: 10px 8px 5px;
}

.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-sec);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: start;
  transition: all 0.14s;
}

.nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

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

.nav-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--brand);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

/* 3. Workspace Main Area */
.workspace-main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-app);
}

.topbar {
  height: 58px;
  padding: 0 20px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.site-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 99px;
  background: var(--brand-soft);
  border: 1px solid rgba(99, 102, 241, 0.3);
  font-weight: 600;
  font-size: 12.5px;
}

.site-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-switch {
  display: inline-flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--text-sec);
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
}

.lang-btn.active {
  background: var(--brand);
  color: #fff;
}

/* ================= WEBMAIL 2-PANE SPLIT VIEW ================= */
.webmail-view {
  flex: 1;
  display: grid;
  grid-template-columns: 390px 1fr;
  overflow: hidden;
}

.mail-list-pane {
  background: var(--bg-sidebar);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-list-toolbar {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.filter-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-sec);
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

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

.mail-row {
  padding: 13px 15px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.14s;
  display: flex;
  gap: 11px;
  align-items: flex-start;
}

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

.mail-row.selected {
  background: var(--brand-soft);
  border-inline-start: 3px solid var(--brand);
}

.mail-row.unread .mail-sender,
.mail-row.unread .mail-subj {
  font-weight: 700;
  color: var(--text-main);
}

.mail-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mail-meta {
  flex: 1;
  min-width: 0;
}

.mail-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.mail-sender {
  font-size: 13px;
  color: var(--text-sec);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-date {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.mail-subj {
  font-size: 13px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.mail-snip {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-reader-pane {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 22px 26px;
  background: var(--bg-app);
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
}

.reader-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.14);
}

.reader-toolbar {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--bg-elevated);
}

.reader-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.reader-header h2 {
  margin: 0 0 12px;
  font-size: 19px;
  line-height: 1.4;
}

.reader-addresses {
  display: grid;
  gap: 4px;
  font-size: 12.5px;
  color: var(--text-sec);
}

.reader-atts {
  padding: 12px 24px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.att-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 500;
}

.att-pill:hover {
  border-color: var(--brand);
}

.reader-iframe {
  width: 100%;
  min-height: 440px;
  border: none;
  background: #ffffff;
  display: block;
}

/* ================= CONTENT PANELS (MARKETING & ADMIN) ================= */
.page-view {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.page-header h2 {
  margin: 0 0 5px;
  font-size: 21px;
}

.page-header p {
  margin: 0;
  color: var(--text-sec);
  font-size: 13px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.kpi-card .kpi-label {
  font-size: 12px;
  color: var(--text-sec);
  margin-bottom: 8px;
}

.kpi-card .kpi-val {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.card-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: start;
  font-size: 13px;
}

.data-table th {
  font-size: 11.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.site-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.badge-status {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
}

.badge-ok {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
}

.badge-warn {
  background: rgba(245, 158, 11, 0.16);
  color: #fbbf24;
}

.progress-bar {
  width: 100%;
  height: 7px;
  border-radius: 99px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.progress-bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

/* ================= MODALS & RICH COMPOSER ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 17, 0.72);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 18px;
}

.modal-box {
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-box.modal-xl {
  max-width: 940px;
}

.modal-head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h3 {
  margin: 0;
  font-size: 16.5px;
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-elevated);
}

.editor-toolbar {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  padding: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.rich-editor {
  min-height: 220px;
  max-height: 340px;
  overflow-y: auto;
  padding: 14px;
  background: #ffffff;
  color: #0f172a;
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  outline: none;
  line-height: 1.65;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.code-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
  background: var(--bg-elevated);
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
}

/* Toast */
.toast-stack {
  position: fixed;
  bottom: 22px;
  inset-inline-end: 22px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid var(--brand);
  padding: 11px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 600;
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 58px 210px 1fr;
  }
  .webmail-view {
    grid-template-columns: 310px 1fr;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
}
