/* =====================================================================
   پنل مدیریت ایمیل — شیوه‌نامه‌ی اصلی
   راست‌چین، واکنش‌گرا، با حالت روشن و تیره
   ===================================================================== */

:root {
  color-scheme: light;

  --bg:            #f5f6f8;
  --bg-elevated:   #ffffff;
  --bg-subtle:     #eef0f4;
  --bg-hover:      #e8ebf0;
  --border:        #dcdfe6;
  --border-strong: #c3c8d2;

  --text:          #1b1f27;
  --text-muted:    #626b7b;
  --text-faint:    #8b94a3;

  --primary:       #2563c8;
  --primary-hover: #1d4ea8;
  --primary-soft:  #e7eefb;

  --success:       #15803d;
  --success-soft:  #e3f5e9;
  --warning:       #a1660a;
  --warning-soft:  #fdf3e0;
  --danger:        #c02626;
  --danger-hover:  #9c1d1d;
  --danger-soft:   #fcebeb;
  --info:          #0e7490;
  --info-soft:     #e2f4f8;

  --radius:        10px;
  --radius-sm:     7px;
  --radius-lg:     16px;
  --shadow:        0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
  --shadow-lg:     0 8px 32px rgba(16, 24, 40, .14);

  --sidebar-width: 254px;
  --font: "Vazirmatn", "Vazir", "IRANSans", "Segoe UI", Tahoma, system-ui, sans-serif;
}

/* حالت تیره: خودکار با تنظیمات سیستم، قابل بازنویسی با data-theme */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg:            #11141a;
    --bg-elevated:   #191d26;
    --bg-subtle:     #212632;
    --bg-hover:      #272d3a;
    --border:        #2e3542;
    --border-strong: #3d4454;

    --text:          #e8ebf1;
    --text-muted:    #9aa4b4;
    --text-faint:    #727d8e;

    --primary:       #6c9bf0;
    --primary-hover: #86aef5;
    --primary-soft:  #1c2740;

    --success:       #4ade80;
    --success-soft:  #16291d;
    --warning:       #fbbf24;
    --warning-soft:  #2c2412;
    --danger:        #f87171;
    --danger-hover:  #fb9191;
    --danger-soft:   #2e1818;
    --info:          #38bdf8;
    --info-soft:     #112833;

    --shadow:        0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg:     0 8px 32px rgba(0, 0, 0, .45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #11141a;
  --bg-elevated:   #191d26;
  --bg-subtle:     #212632;
  --bg-hover:      #272d3a;
  --border:        #2e3542;
  --border-strong: #3d4454;

  --text:          #e8ebf1;
  --text-muted:    #9aa4b4;
  --text-faint:    #727d8e;

  --primary:       #6c9bf0;
  --primary-hover: #86aef5;
  --primary-soft:  #1c2740;

  --success:       #4ade80;
  --success-soft:  #16291d;
  --warning:       #fbbf24;
  --warning-soft:  #2c2412;
  --danger:        #f87171;
  --danger-hover:  #fb9191;
  --danger-soft:   #2e1818;
  --info:          #38bdf8;
  --info-soft:     #112833;

  --shadow:        0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg:     0 8px 32px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.75;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .6rem; font-weight: 700; line-height: 1.45; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }

p { margin: 0 0 .8rem; }

code, kbd, .ltr {
  direction: ltr;
  unicode-bidi: embed;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

code {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .1rem .35rem;
  font-size: .86em;
}

/* ------------------------------------------------------------------ */
/*  چیدمان اصلی                                                       */
/* ------------------------------------------------------------------ */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--bg-elevated);
  border-inline-start: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar__brand {
  padding: 1.15rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .6rem;
}

.sidebar__brand strong { font-size: 1.02rem; }

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  flex: 0 0 34px;
}

.sidebar__nav { padding: .75rem; overflow-y: auto; flex: 1; }

.nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .58rem .7rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  margin-bottom: .18rem;
  font-size: .94rem;
  transition: background .12s, color .12s;
}

.nav-link:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }

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

.nav-link svg { flex: 0 0 18px; }

.sidebar__footer {
  padding: .85rem;
  border-top: 1px solid var(--border);
  font-size: .85rem;
  color: var(--text-faint);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: .7rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__spacer { flex: 1; }

/* روی صفحه‌های باریک، برچسب دکمه‌های نوار بالا جا نمی‌شد و کل صفحه را
   چند پیکسل افقی می‌لغزاند. نشانه‌ها می‌مانند و متنشان برداشته می‌شود؛
   aria-label در قالب سر جایش است تا صفحه‌خوان چیزی از دست ندهد. */
@media (max-width: 600px) {
  .topbar { padding-inline: .7rem; gap: .5rem; }
  .topbar [data-theme-toggle] span,
  .topbar [data-no-lock] span { display: none; }
  .topbar__user > a { display: none; }
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-size: .9rem;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .85rem;
}

.content { padding: 1.5rem; max-width: 1400px; width: 100%; }

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.page-head__text { flex: 1; min-width: 240px; }
.page-head__text p { color: var(--text-muted); margin: 0; font-size: .92rem; }
.page-head__actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ------------------------------------------------------------------ */
/*  کارت‌ها                                                            */
/* ------------------------------------------------------------------ */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.1rem;
  overflow: hidden;
}

.card__head {
  padding: .9rem 1.15rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .7rem;
  flex-wrap: wrap;
}

.card__head h2, .card__head h3 { margin: 0; }
.card__head .spacer { flex: 1; }
.card__body { padding: 1.15rem; }
.card__body > :last-child { margin-bottom: 0; }

.grid { display: grid; gap: 1.1rem; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.05rem 1.15rem;
  box-shadow: var(--shadow);
}

.stat__label { color: var(--text-muted); font-size: .86rem; margin-bottom: .3rem; }
.stat__value { font-size: 1.75rem; font-weight: 700; line-height: 1.25; }
.stat__hint  { color: var(--text-faint); font-size: .8rem; margin-top: .2rem; }

/* ------------------------------------------------------------------ */
/*  دکمه‌ها                                                            */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem .95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: .91rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}

.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn--danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }

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

.btn--sm { padding: .32rem .6rem; font-size: .84rem; }
.btn--icon { padding: .42rem; }
.btn--block { width: 100%; }

.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------------ */
/*  فرم‌ها                                                             */
/* ------------------------------------------------------------------ */

.field { margin-bottom: 1.05rem; }

.field__label {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  margin-bottom: .35rem;
}

.field__label .req { color: var(--danger); }

.field__hint { color: var(--text-muted); font-size: .82rem; margin-top: .3rem; }

.input, .select, .textarea {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: .94rem;
  transition: border-color .12s, box-shadow .12s;
}

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

.input[readonly] { background: var(--bg-subtle); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.7; }
.input--ltr { direction: ltr; text-align: left; font-family: ui-monospace, Consolas, monospace; }

.input-group { display: flex; gap: .4rem; align-items: stretch; }
.input-group .input { flex: 1; }

.field-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

.email-compose {
  display: grid;
  grid-template-columns: 1fr auto 1.2fr;
  gap: .4rem;
  align-items: center;
}

.email-compose__at {
  color: var(--text-muted);
  font-weight: 700;
  direction: ltr;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  padding: .5rem .6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.check:hover { background: var(--bg-subtle); }
.check input { margin-top: .35rem; flex: 0 0 auto; width: 16px; height: 16px; accent-color: var(--primary); }
.check__text { font-size: .9rem; }
.check__text small { display: block; color: var(--text-muted); font-size: .8rem; line-height: 1.6; }

.check-grid { display: grid; gap: .15rem; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .8rem 1rem 1rem;
  margin: 0 0 1.1rem;
}

legend { font-weight: 700; font-size: .92rem; padding: 0 .4rem; }

/* سنجه‌ی قدرت رمز */
.strength { margin-top: .5rem; }

.strength__bar {
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 99px;
  overflow: hidden;
}

.strength__fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: var(--danger);
  transition: width .2s, background .2s;
}

.strength__fill[data-level="2"] { background: var(--warning); }
.strength__fill[data-level="3"] { background: var(--info); }
.strength__fill[data-level="4"] { background: var(--success); }

.strength__text { font-size: .82rem; color: var(--text-muted); margin-top: .28rem; }

/* ------------------------------------------------------------------ */
/*  جدول                                                               */
/* ------------------------------------------------------------------ */

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

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .91rem;
}

.table th, .table td {
  padding: .7rem .8rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table thead th {
  background: var(--bg-subtle);
  font-weight: 700;
  font-size: .85rem;
  color: var(--text-muted);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.table tbody tr:hover { background: var(--bg-subtle); }
.table tbody tr:last-child td { border-bottom: none; }

.table a.sort {
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: .25rem;
}

.table a.sort:hover { color: var(--primary); text-decoration: none; }

/* اعداد فارسی همراه واحد، متن راست‌چین‌اند؛ فقط از شکستن خط جلوگیری می‌کنیم */
.table .num { white-space: nowrap; }

.cell-email { font-weight: 600; direction: ltr; text-align: right; }
.cell-note { color: var(--text-muted); min-width: 230px; max-width: 320px; }
.cell-actions { white-space: nowrap; }

/* نوار مصرف فضا */
.usage { min-width: 150px; }

.usage__bar {
  height: 5px;
  background: var(--bg-subtle);
  border-radius: 99px;
  overflow: hidden;
  margin-top: .3rem;
}

.usage__fill { height: 100%; background: var(--success); border-radius: 99px; }
.usage__fill--warn { background: var(--warning); }
.usage__fill--danger { background: var(--danger); }
.usage__text { font-size: .82rem; color: var(--text-muted); }

/* ------------------------------------------------------------------ */
/*  نشان‌ها و پیام‌ها                                                   */
/* ------------------------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .13rem .5rem;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--bg-subtle);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--info    { background: var(--info-soft);    color: var(--info); }
.badge--primary { background: var(--primary-soft); color: var(--primary); }

.alert {
  display: flex;
  gap: .65rem;
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  margin-bottom: 1rem;
  font-size: .92rem;
}

.alert svg { flex: 0 0 18px; margin-top: .22rem; }
.alert__body { flex: 1; }
.alert__body > :last-child { margin-bottom: 0; }
.alert ul { margin: .3rem 0 0; padding-inline-start: 1.1rem; }

.alert--success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 35%, transparent); color: var(--success); }
.alert--error   { background: var(--danger-soft);  border-color: color-mix(in srgb, var(--danger) 35%, transparent);  color: var(--danger); }
.alert--warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 35%, transparent); color: var(--warning); }
.alert--info    { background: var(--info-soft);    border-color: color-mix(in srgb, var(--info) 35%, transparent);    color: var(--info); }

.demo-banner {
  background: var(--warning-soft);
  color: var(--warning);
  border-bottom: 1px solid color-mix(in srgb, var(--warning) 40%, transparent);
  padding: .45rem 1.4rem;
  font-size: .86rem;
  font-weight: 600;
  text-align: center;
}

/* حالت خالی */
.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty svg { color: var(--text-faint); margin-bottom: .8rem; }
.empty h3 { color: var(--text); }
.empty p { max-width: 420px; margin: 0 auto .9rem; font-size: .92rem; }

/* ------------------------------------------------------------------ */
/*  صفحه‌بندی و فیلترها                                                */
/* ------------------------------------------------------------------ */

.filters {
  display: grid;
  gap: .7rem;
  grid-template-columns: minmax(200px, 2fr) repeat(auto-fit, minmax(140px, 1fr));
  align-items: end;
}

.filters .field { margin-bottom: 0; }

.pagination {
  display: flex;
  align-items: center;
  gap: .3rem;
  flex-wrap: wrap;
  padding: .85rem 1.15rem;
  border-top: 1px solid var(--border);
}

.pagination__info { color: var(--text-muted); font-size: .86rem; margin-inline-end: auto; }

.page-link {
  min-width: 34px;
  height: 34px;
  padding: 0 .5rem;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: .86rem;
}

.page-link:hover { background: var(--bg-hover); text-decoration: none; color: var(--text); }
.page-link--active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-link--disabled { opacity: .45; pointer-events: none; }

/* ------------------------------------------------------------------ */
/*  صفحه‌های ورود / نصب                                                 */
/* ------------------------------------------------------------------ */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.9rem;
}

.auth-card--wide { max-width: 620px; }

.auth-card__head { text-align: center; margin-bottom: 1.5rem; }
.auth-card__head .brand-mark { margin: 0 auto .8rem; width: 44px; height: 44px; }
.auth-card__head p { color: var(--text-muted); font-size: .9rem; margin: 0; }

.auth-foot {
  text-align: center;
  margin-top: 1.2rem;
  font-size: .83rem;
  color: var(--text-faint);
}

/* ------------------------------------------------------------------ */
/*  جزئیات حساب                                                        */
/* ------------------------------------------------------------------ */

.detail-grid { display: grid; gap: 1.1rem; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; font-size: .91rem; }
.kv dt { color: var(--text-muted); white-space: nowrap; }
.kv dd { margin: 0; font-weight: 500; }

.settings-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.settings-table th, .settings-table td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); text-align: right; }
.settings-table th { color: var(--text-muted); font-weight: 600; white-space: nowrap; }

.copy-line {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .3rem .3rem .3rem .6rem;
}

.copy-line code { background: none; border: none; flex: 1; overflow-x: auto; white-space: nowrap; }

.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.danger-zone .card__head { background: var(--danger-soft); color: var(--danger); }

.qr-box {
  background: #fff;
  padding: .7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  width: fit-content;
  margin: 0 auto .8rem;
  min-height: 60px;
}

.secret-box {
  direction: ltr;
  text-align: center;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.02rem;
  letter-spacing: .06em;
  background: var(--bg-subtle);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: .6rem;
  word-break: break-all;
}

.code-input {
  direction: ltr;
  text-align: center;
  letter-spacing: .5em;
  font-size: 1.4rem;
  font-family: ui-monospace, Consolas, monospace;
  padding: .6rem;
}

/* ------------------------------------------------------------------ */
/*  دیالوگ تأیید                                                       */
/* ------------------------------------------------------------------ */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 20, .58);
  display: none;
  place-items: center;
  padding: 1.2rem;
  z-index: 100;
}

.modal[open], .modal.is-open { display: grid; }

.modal__panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  padding: 1.5rem;
}

.modal__panel h3 { display: flex; align-items: center; gap: .5rem; color: var(--danger); }

/* ------------------------------------------------------------------ */
/*  کمکی‌ها                                                             */
/* ------------------------------------------------------------------ */

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: .85rem; }
.tiny  { font-size: .78rem; }
.ltr-inline { direction: ltr; display: inline-block; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: .6rem; }
.mt-2 { margin-top: 1.1rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .6rem; }
.mb-2 { margin-bottom: 1.1rem; }
.nowrap { white-space: nowrap; }
.flex { display: flex; gap: .5rem; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.tag-list { display: flex; flex-wrap: wrap; gap: .3rem; }

/*
  سیاست امنیتی محتوا (CSP) اجازه‌ی style درون‌خطی نمی‌دهد، بنابراین
  هر حالت ظاهری یک کلاس دارد و مقادیر پویا (عرض نوارها) با
  data-bar-width و اسکریپت تنظیم می‌شوند.
*/
.flex-between {
  display: flex;
  gap: .5rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.btn-row--center { justify-content: center; }
.card--narrow { max-width: 480px; }
.empty--compact { padding: 1.5rem 0; }
.textarea--tall { min-height: 130px; }

.pre-wrap {
  white-space: pre-wrap;
  overflow-x: auto;
  margin: .3rem 0 0;
}

[data-bar-width] { width: 0; }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

.is-loading { position: relative; pointer-events: none; opacity: .65; }

/* ------------------------------------------------------------------ */
/*  واکنش‌گرایی                                                         */
/* ------------------------------------------------------------------ */

.sidebar-toggle { display: none; }

@media (max-width: 1000px) {
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  /*
    منوی کناری در موبایل از لبه‌ی راست (شروع متن در RTL) بیرون می‌آید.
    اینجا عمداً از right فیزیکی استفاده شده است: پنل همیشه راست‌چین
    است و inset-inline-end در RTL به لبه‌ی چپ اشاره می‌کند.
  */
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    left: auto;
    max-width: 86vw;
    z-index: 60;
    transform: translateX(100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }

  :root[data-sidebar="open"] .sidebar { transform: translateX(0); }

  .sidebar-toggle { display: inline-flex; }

  .content { padding: 1rem; }

  .table thead { display: none; }

  .table tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: .7rem;
    padding: .3rem .5rem;
  }

  .table td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px dashed var(--border);
    padding: .45rem .3rem;
  }

  .table td:last-child { border-bottom: none; }

  .table td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: .82rem;
    font-weight: 600;
    flex: 0 0 auto;
  }

  .cell-note { max-width: none; }
  .filters { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  body { font-size: 14.5px; }
  .auth-card { padding: 1.35rem; }
  .email-compose { grid-template-columns: 1fr; }
  .email-compose__at { display: none; }
}

@media print {
  .sidebar, .topbar, .page-head__actions, .cell-actions, .pagination { display: none; }
  .card { box-shadow: none; }
}

/* =====================================================================
   صندوق ایمیل
   ===================================================================== */

.mailbox {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.mailbox__folders {
  display: flex;
  flex-direction: column;
  gap: .18rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem;
  box-shadow: var(--shadow);
}

.folder {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .52rem .6rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: .9rem;
}

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

.folder--active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.folder__name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder__count {
  flex: 0 0 auto;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  padding: .04rem .42rem;
  font-size: .72rem;
  font-weight: 700;
}

.mailbox__list {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.mailbox__search {
  display: flex;
  gap: .5rem;
  padding: .7rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.mailbox__search .input { flex: 1 1 200px; }

.messages {
  list-style: none;
  margin: 0;
  padding: 0;
}

.message {
  display: flex;
  align-items: center;
  gap: .3rem;
  border-bottom: 1px solid var(--border);
  padding: 0 .55rem;
}

.message:last-child { border-bottom: 0; }
.message:hover { background: var(--bg-hover); }

.message--unread { background: var(--bg-elevated); }
.message--unread .message__from,
.message--unread .message__subject { font-weight: 700; color: var(--text); }

.message--unread::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  flex: 0 0 auto;
}

.message:not(.message--unread)::before {
  content: "";
  width: 6px;
  flex: 0 0 auto;
}

.message__link {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(7rem, 15%) minmax(0, 1fr) auto;
  gap: .75rem;
  align-items: center;
  padding: .62rem .4rem;
  min-width: 0;
  color: var(--text-muted);
  text-decoration: none;
}

.message__from,
.message__subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .9rem;
}

.message__subject { color: var(--text); }

.message__meta {
  display: flex;
  align-items: center;
  gap: .55rem;
  flex: 0 0 auto;
  font-size: .76rem;
  color: var(--text-faint);
}

.message__date { white-space: nowrap; }
.message__size { white-space: nowrap; }

.message__star,
.message__trash { flex: 0 0 auto; display: flex; }

.star {
  background: none;
  border: 0;
  cursor: pointer;
  padding: .3rem;
  border-radius: var(--radius-sm);
  color: var(--text-faint);
  display: flex;
}

.star:hover { background: var(--bg-subtle); color: var(--warning); }
.star--on { color: #d19a00; }
.star--on svg { fill: currentColor; }

.btn--icon {
  padding: .3rem;
  background: none;
  border-color: transparent;
  color: var(--text-faint);
}

.btn--icon:hover { color: var(--danger); border-color: var(--border); }

/* متن پیام — محتوای بیرونی، پس مهار می‌شود */
.mail-body {
  font-size: .94rem;
  line-height: 1.85;
  overflow-wrap: anywhere;
  overflow-x: auto;
}

.mail-body img { max-width: 100%; height: auto; }

/* تصویر بارگذاری‌نشده نباید به شکل «عکس شکسته» دیده شود */
.mail-body img[data-blocked-src] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.2rem;
  min-height: 1.6rem;
  max-width: 100%;
  padding: .35rem .6rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--text-faint);
  font-size: .76rem;
}
.mail-body table { max-width: 100%; border-collapse: collapse; }
.mail-body td, .mail-body th { padding: .3rem .5rem; border: 1px solid var(--border); }
.mail-body blockquote {
  margin: .6rem 0;
  padding: .2rem .9rem;
  border-inline-start: 3px solid var(--border-strong);
  color: var(--text-muted);
}
.mail-body pre {
  background: var(--bg-subtle);
  padding: .6rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.mail-body a { color: var(--primary); }

.message-title {
  overflow-wrap: anywhere;
}

.kv--tight dd { margin-bottom: .35rem; }

.attachments {
  list-style: none;
  margin: 0 0 .7rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.attachment {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.attachment__name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .88rem;
}

.attachment__size {
  flex: 0 0 auto;
  font-size: .76rem;
  color: var(--text-faint);
}

/* ---------------------------------------------------------------- */
/*  دسته‌بندی حساب‌ها                                                  */
/* ---------------------------------------------------------------- */

/* رنگ‌ها عمداً محدود و از پیش تعریف‌شده‌اند؛ رنگ دلخواه کاربر یعنی
   احتمال متن ناخوانا روی زمینه. */
.category--slate  { --cat: #64748b; }
.category--blue   { --cat: #3b82f6; }
.category--green  { --cat: #22c55e; }
.category--amber  { --cat: #f59e0b; }
.category--red    { --cat: #ef4444; }
.category--purple { --cat: #a855f7; }
.category--teal   { --cat: #14b8a6; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
  gap: .8rem;
}

.category {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: inherit;
  text-decoration: none;
  transition: border-color .15s, transform .15s;
}

.category:hover {
  border-color: var(--cat, var(--primary));
  transform: translateY(-1px);
}

.category__dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--cat, #64748b);
}

.category__dot--slate  { background: #64748b; }
.category__dot--blue   { background: #3b82f6; }
.category__dot--green  { background: #22c55e; }
.category__dot--amber  { background: #f59e0b; }
.category__dot--red    { background: #ef4444; }
.category__dot--purple { background: #a855f7; }
.category__dot--teal   { background: #14b8a6; }

.category__body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}

.category__name { font-weight: 600; }

.category__desc,
.category__meta {
  font-size: .8rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* نشان دسته در فهرست حساب‌ها */
.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .1rem .45rem;
  margin: .1rem .15rem .1rem 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .74rem;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}

.cat-chip:hover { border-color: var(--cat, var(--primary)); color: var(--text); }

.cat-chip::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cat, #64748b);
}

/* شبکه‌ی فیلدها در فرم تنظیمات اتصال */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
  gap: 0 1rem;
  align-items: start;
}

/* نشان کلیک‌شدنی (مثل دامنه‌های پیشنهادی) */
.badge--clickable {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font: inherit;
  font-size: .76rem;
}

.badge--clickable:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* فهرست بلند تیک‌ها در فرم دسته */
.check-grid--scroll {
  max-height: 24rem;
  overflow-y: auto;
  padding-inline-end: .3rem;
}

.input--sm { padding: .3rem .5rem; font-size: .82rem; max-width: 16rem; }

/* نوشتن پیام */
.compose textarea {
  resize: vertical;
  min-height: 2.6rem;
}

/* متن پیام با فونت یکنواخت نوشته می‌شود: نقل‌قول‌های «>» و متن
   از‌پیش‌قالب‌بندی‌شده این‌طور هم‌تراز می‌مانند. */
.compose__body {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: .88rem;
  line-height: 1.8;
  min-height: 14rem;
}

.compose__more > summary {
  cursor: pointer;
  padding: .35rem 0;
  font-size: .85rem;
  color: var(--text-muted);
}

.compose__more > summary:hover { color: var(--primary); }

.compose__actions {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
}

.compose input[type="file"] {
  padding: .45rem .55rem;
  font-size: .85rem;
}

@media (max-width: 860px) {
  .mailbox { grid-template-columns: 1fr; }

  .mailbox__folders {
    flex-direction: row;
    overflow-x: auto;
    padding: .4rem;
  }

  .folder { flex: 0 0 auto; }
  .folder__name { max-width: 9ch; }

  .message__link { grid-template-columns: minmax(0, 1fr); gap: .15rem; }
  .message__meta { justify-content: flex-start; }
  .message__size { display: none; }
}
