:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --side: #12213b;
  --side-text: #b9c4d8;
  --accent: #2f6fed;
  --accent-dark: #1e56c8;
  --text: #1c2433;
  --muted: #7a879c;
  --line: #e3e8f2;
  --danger: #d64545;
  --radius: 10px;
  font-size: 15px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ── Auth ──────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #12213b 0%, #1e3a6e 100%);
  padding: 24px;
}
.auth-card {
  width: 420px; max-width: 100%;
  background: var(--panel);
  border-radius: 16px;
  padding: 34px 36px 26px;
  box-shadow: 0 24px 70px rgba(6, 16, 38, .45);
}
.brand { text-align: center; margin-bottom: 18px; }
.brand-mark {
  width: 54px; height: 54px; margin: 0 auto 10px;
  border-radius: 14px;
  background: var(--accent); color: #fff;
  font-size: 28px; line-height: 54px;
}
.brand h1 { margin: 0; font-size: 26px; }
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.tabs {
  display: flex; gap: 6px;
  background: #eef1f8; padding: 4px; border-radius: 10px; margin-bottom: 18px;
}
.tab {
  flex: 1; border: 0; background: transparent; padding: 9px 6px;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted);
}
.tab.active { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.form label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 5px; }
.form input, .form textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fbfcfe;
}
.form input:focus, .form textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.mailbox-preview { display: flex; gap: 6px; align-items: center; }
.mailbox-preview input { width: 120px; }
.at { font-weight: 700; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }
.ok { color: #178a4c; font-size: 13px; margin-top: 10px; }
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 8px; padding: 10px 16px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; margin-top: 16px; }
.btn.primary:hover { background: var(--accent-dark); }
.lang-switch { display: flex; gap: 6px; justify-content: center; margin-top: 18px; }
.lang-switch button {
  border: 1px solid var(--line); background: #fff; border-radius: 20px;
  padding: 4px 14px; cursor: pointer; font-size: 12px; font-weight: 700;
}
.lang-switch button.active { background: var(--side); color: #fff; border-color: var(--side); }

/* ── Mail shell ────────────────────────────── */
.mail-shell {
  display: grid;
  grid-template-columns: 240px 400px 1fr;
  height: 100vh;
}
.sidebar {
  background: var(--side); color: var(--side-text);
  display: flex; flex-direction: column; padding: 16px 14px;
}
.side-brand { color: #fff; font-size: 19px; font-weight: 700; margin-bottom: 16px; }
.compose { margin-bottom: 16px; }
.folders { flex: 1; }
.folder {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
  margin-bottom: 2px;
}
.folder:hover { background: rgba(255,255,255,.07); }
.folder.active { background: var(--accent); color: #fff; }
.folder .badge {
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 10px; padding: 1px 7px;
}
.folder.active .badge { background: rgba(255,255,255,.28); }
.folder .factions { display: none; gap: 6px; }
.folder:hover .factions { display: inline; }
.folder .factions button {
  border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 12px;
}
.side-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6b7c9c; margin: 14px 0 6px; }
.mailbox-item {
  padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
  display: flex; flex-direction: column; gap: 1px;
}
.mailbox-item:hover { background: rgba(255,255,255,.07); }
.mailbox-item.active { background: rgba(47,111,237,.25); color: #fff; }
.mailbox-item .co { font-size: 11px; color: #7f93b8; }
.storage { margin-top: 14px; }
.bar { height: 6px; border-radius: 4px; background: rgba(255,255,255,.12); overflow: hidden; }
.fill { height: 100%; background: var(--accent); width: 0%; transition: width .3s; }
.storage .muted { font-size: 11px; display: block; margin-top: 5px; }
/* The storage label is always an LTR "X B / Y GB" string — isolate it so an
   RTL document doesn't reorder the mixed-direction text. */
#storage-label { direction: ltr; unicode-bidi: isolate; text-align: start; }

.list-pane {
  border-right: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column;
}
.list-head {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.list-head h2 { margin: 0; font-size: 17px; flex: 1; }
.list-actions { display: flex; gap: 6px; align-items: center; }
.list-actions input {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 13px; width: 150px;
}
.list-actions button {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.messages { overflow-y: auto; flex: 1; }
.msg {
  padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
}
.msg:hover { background: #f7f9fd; }
.msg.active { background: #eef4ff; }
.msg .from { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread .from::before { content: "●"; color: var(--accent); margin-inline-end: 6px; font-size: 10px; }
.msg .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.msg .subject { grid-column: 1 / 2; font-size: 13px; color: #404c63; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .snippet { grid-column: 1 / 3; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .star { font-size: 13px; color: #c9a227; }

.read-pane { overflow-y: auto; background: var(--bg); padding: 22px 28px; }
.read-pane .empty {
  height: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.read-head { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 22px; }
.read-head h2 { margin: 0 0 10px; font-size: 19px; }
.read-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.read-actions { margin-top: 12px; display: flex; gap: 8px; }
.read-actions button, .att button {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.read-actions button.danger { color: var(--danger); }
.read-body {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  margin-top: 14px; padding: 22px; line-height: 1.65; overflow-wrap: break-word;
}
.read-body.plain { white-space: pre-wrap; font-family: inherit; }
.attachments { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.att {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; font-size: 13px; display: flex; gap: 8px; align-items: center;
}

/* ── Compose modal ─────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(10, 18, 34, .55);
  display: flex; align-items: center; justify-content: center; z-index: 40;
}
.modal-card {
  width: 640px; max-width: calc(100vw - 32px);
  background: var(--panel); border-radius: 14px; padding: 20px 24px;
  max-height: 92vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; gap: 12px; }
.modal-head h3 { margin: 0; flex: 1; }
.icon-btn { border: 0; background: transparent; font-size: 16px; cursor: pointer; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.modal-foot .btn.primary { width: auto; margin-top: 0; }
.modal-foot .btn { width: auto; }

.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--side); color: #fff; padding: 10px 22px; border-radius: 24px;
  font-size: 14px; z-index: 60; box-shadow: 0 8px 30px rgba(0,0,0,.3);
}
.toast.error { background: var(--danger); }

/* ── RTL ───────────────────────────────────── */
html[dir="rtl"] .msg .from::before { margin-inline-end: 0; margin-inline-start: 6px; }

@media (max-width: 1080px) {
  .mail-shell { grid-template-columns: 200px 1fr; }
  .read-pane { display: none; }
  .read-pane.open {
    display: block; position: fixed; inset: 0; z-index: 30; background: var(--bg);
  }
}

/* ── Plans, banners, company admin ─────────── */
.small { font-size: 12px; }
.plan { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 6px; margin: 14px 0 0; }
.plan legend { font-weight: 700; font-size: 13px; padding: 0 4px; }
.plan-row { display: flex; gap: 10px; }
.plan-row label { flex: 1; font-size: 12px; color: var(--muted); }
.plan-row input { width: 100%; }
.interval { display: flex; gap: 14px; margin: 8px 0; font-size: 13px; }
.price { font-size: 20px; font-weight: 700; color: var(--accent-dark); min-height: 26px; }
.price .per { font-size: 13px; font-weight: 400; color: var(--muted); }
.banner { padding: 10px 18px; font-size: 13px; background: #eef4ff; border-bottom: 1px solid var(--line); line-height: 1.6; overflow-wrap: anywhere; }
.banner button, .banner a { margin-inline-start: 8px; }
.banner.warn { background: #fff4e5; }
.banner a, .banner button { color: var(--accent-dark); font-weight: 600; background: none; border: 0; cursor: pointer; padding: 0; font: inherit; }
.side-btn { width: 100%; margin-top: 8px; background: rgba(255,255,255,.08); color: #fff; border-color: transparent; }
.mailbox-item .viewing { font-size: 11px; color: #f3c969; }
.modal-card.wide { width: 720px; max-width: 96vw; max-height: 90vh; overflow-y: auto; }
.admin-block { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.admin-block h4 { margin: 0 0 8px; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.inline-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.company-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.company-table td { padding: 7px 6px; border-bottom: 1px solid var(--line); }
.company-table td:nth-child(4) { white-space: nowrap; }
.company-table .actions { text-align: end; white-space: nowrap; }
.company-table button { margin-inline-start: 6px; }
.status-suspended { color: var(--danger); }
