/* ==========================================================================
   پِلّه — استایل
   RTL، مینیمال، با تمرکز روی خوانایی متن فارسی بلند.
   ========================================================================== */

:root {
  --indigo:      #4F46E5;
  --indigo-dark: #4338CA;
  --teal:        #0D9488;
  --amber:       #B45309;

  --ink:      #1A1C23;
  --ink-soft: #565B6B;
  --ink-mute: #868CA0;

  --bg:       #FBFBFD;
  --surface:  #FFFFFF;
  --line:     #E4E6EE;
  --line-soft:#F0F1F6;

  --ok-bg:   #ECFDF5; --ok-fg:   #065F46;
  --warn-bg: #FFFBEB; --warn-fg: #92400E;
  --bad-bg:  #FEF2F2; --bad-fg:  #991B1B;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20,22,35,.05), 0 4px 16px rgba(20,22,35,.05);

  /* ارتفاع خط بلند، چون فارسی با line-height کوتاه سخت خوانده می‌شود */
  --lh: 2;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #E8EAF2; --ink-soft: #A8AEC2; --ink-mute: #767D94;
    --bg: #14161D; --surface: #1B1E27; --line: #2C303D; --line-soft: #23262F;
    --ok-bg: #06281E; --ok-fg: #6EE7B7;
    --warn-bg: #2B1F06; --warn-fg: #FCD34D;
    --bad-bg: #2B1113; --bad-fg: #FCA5A5;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Vazirmatn, "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  line-height: var(--lh);
}

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

h1, h2, h3 { line-height: 1.5; margin: 0 0 .6em; font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }

p { margin: 0 0 1em; }

.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.hint  { color: var(--ink-mute); font-weight: 400; font-size: .8rem; }
.lead  { font-size: 1.08rem; color: var(--ink-soft); }

/* ----------------------------------------------------------------- نوار بالا */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 700; color: var(--ink); font-size: 1.05rem;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--indigo); display: inline-flex; }

.topnav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topnav > a {
  padding: 7px 11px; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-size: .92rem;
}
.topnav > a:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }

.menu { position: relative; }
.menu-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 7px 12px; border-radius: var(--radius-sm); cursor: pointer;
  font: inherit; font-size: .9rem; max-width: 190px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.menu-list {
  position: absolute; inset-inline-start: 0; top: calc(100% + 6px);
  min-width: 160px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 5px; z-index: 50;
}
.menu-list a { display: block; padding: 8px 11px; border-radius: 6px; color: var(--ink); }
.menu-list a:hover { background: var(--line-soft); text-decoration: none; }

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

.wrap { max-width: 1060px; margin: 0 auto; padding: 26px 20px 60px; }
.page-reader .wrap { max-width: 1480px; }

.page-head { margin-bottom: 20px; }
.page-head h1 { margin-bottom: .25em; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

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

.footer {
  border-top: 1px solid var(--line); padding: 20px;
  text-align: center; color: var(--ink-mute); font-size: .85rem;
}

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

label { display: block; margin: 14px 0 6px; font-weight: 500; font-size: .92rem; }

input[type=text], input[type=email], input[type=password],
input[type=search], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--indigo); outline-offset: 1px; border-color: transparent;
}
input:disabled { background: var(--line-soft); color: var(--ink-mute); }

.btn {
  display: inline-block; padding: 10px 18px; font: inherit; font-weight: 500;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--radius-sm); cursor: pointer; text-align: center;
}
.btn:hover { background: var(--line-soft); text-decoration: none; }
.btn-primary { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn-primary:hover { background: var(--indigo-dark); }
.btn-block { width: 100%; margin-top: 18px; }
.btn-sm, a.btn-sm {
  padding: 6px 12px; font-size: .87rem; border-radius: 6px;
  background: var(--indigo); color: #fff; border: 0;
}
.btn-sm:hover { background: var(--indigo-dark); text-decoration: none; }

form .btn { margin-top: 18px; }

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

.flash {
  padding: 11px 14px; border-radius: var(--radius-sm);
  margin-bottom: 14px; font-size: .92rem;
}
.flash-ok    { background: var(--ok-bg);   color: var(--ok-fg); }
.flash-warn  { background: var(--warn-bg); color: var(--warn-fg); }
.flash-error { background: var(--bad-bg);  color: var(--bad-fg); }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: .8rem; font-weight: 500; white-space: nowrap;
}
.badge-ok   { background: var(--ok-bg);   color: var(--ok-fg); }
.badge-work { background: #EEF2FF;        color: var(--indigo-dark); }
.badge-wait { background: var(--line-soft); color: var(--ink-soft); }
.badge-bad  { background: var(--bad-bg);  color: var(--bad-fg); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge-work { background: #1E2140; color: #A5B4FC; }
}

.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: var(--line-soft); color: var(--ink-soft);
  font-size: .8rem; font-weight: 400;
}
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 1em; }

/* ----------------------------------------------------------------- پیشرفت */

.progress {
  height: 6px; background: var(--line-soft);
  border-radius: 999px; overflow: hidden; margin: 7px 0;
}
.progress > span {
  display: block; height: 100%; background: var(--indigo);
  border-radius: 999px; transition: width .4s ease;
}
.progress-lg { height: 10px; margin: 14px 0; }

/* ------------------------------------------------------------------- ورود */

.page-auth .wrap { max-width: 420px; padding-top: 48px; }
.auth-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 30px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 1.35rem; }
.auth-alt { margin: 18px 0 0; text-align: center; font-size: .9rem; color: var(--ink-soft); }

/* ------------------------------------------------------------------ لندینگ */

.hero { text-align: center; padding: 48px 0 36px; }
.hero h1 { font-size: 2.3rem; margin-bottom: .4em; }
.hero .lead { max-width: 620px; margin: 0 auto 28px; }
.hero-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.level-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 12px; margin-bottom: 44px;
}
.level-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.level-card h3 { margin-bottom: .35em; }
.level-card p { font-size: .88rem; margin-bottom: .7em; }
.level-tag {
  display: inline-block; font-weight: 700; color: var(--indigo);
  font-size: .78rem; letter-spacing: .06em; margin-bottom: 6px;
}
.level-time { font-size: .78rem; color: var(--ink-mute); }

.why-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 20px;
}
.why-grid h3 { font-size: .98rem; }
.why-grid p { font-size: .9rem; }

/* ----------------------------------------------------------------- کتابخانه */

.searchbar { display: flex; gap: 8px; margin-bottom: 18px; align-items: center; }
.searchbar input { flex: 1; }

.doc-list { display: flex; flex-direction: column; gap: 10px; }
.doc-card {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 18px;
}
.doc-card:hover { border-color: var(--indigo); }
.doc-main { flex: 1; min-width: 0; color: inherit; }
.doc-main:hover { text-decoration: none; }
.doc-main h3 { margin-bottom: .2em; font-size: 1rem; }
.doc-meta { margin: 0; font-size: .85rem; }
.doc-status { text-align: center; min-width: 155px; }
.doc-status .progress { margin: 8px 0 4px; }

@media (max-width: 620px) {
  .doc-card { flex-direction: column; align-items: stretch; }
  .doc-status { text-align: start; min-width: 0; }
}

.empty { text-align: center; padding: 44px 20px; }
.empty h2 { font-size: 1.1rem; }

.dropzone {
  position: relative; border: 2px dashed var(--line);
  border-radius: var(--radius); padding: 34px 20px; text-align: center;
  background: var(--line-soft); transition: border-color .2s, background .2s;
}
.dropzone.is-over { border-color: var(--indigo); background: #EEF2FF; }
.dropzone input[type=file] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}
.dropzone-inner { display: flex; flex-direction: column; gap: 5px; pointer-events: none; }

/* ------------------------------------------------------------------ خواننده */

.reader {
  display: grid; grid-template-columns: 250px minmax(0, 1fr) 265px;
  gap: 24px; align-items: start;
}
@media (max-width: 1180px) {
  .reader { grid-template-columns: 220px minmax(0, 1fr); }
  .reader-side { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .reader { grid-template-columns: 1fr; }
  .reader-nav { order: 2; }
}

.reader-nav, .reader-side {
  position: sticky; top: 76px; max-height: calc(100vh - 100px);
  overflow-y: auto; font-size: .9rem;
}
@media (max-width: 820px) {
  .reader-nav, .reader-side { position: static; max-height: none; }
}

.nav-head h2 { font-size: 1rem; margin-bottom: .2em; }
.nav-head { padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }

.outline ul { list-style: none; margin: 0; padding: 0; }
.outline ul ul { padding-inline-start: 12px; }
.outline a {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 5px 8px; border-radius: 6px; color: var(--ink-soft);
  border-inline-start: 2px solid transparent;
}
.outline a:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.outline a.is-active { border-inline-start-color: var(--indigo); color: var(--ink); font-weight: 500; }
.o-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.o-pages { flex-shrink: 0; font-size: .78rem; }

/* اسلایدر عمق */
.level-bar {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; flex-wrap: wrap;
  position: sticky; top: 72px; z-index: 20;
}
.level-bar-label { display: flex; flex-direction: column; gap: 1px; font-size: .88rem; }

.level-steps { display: flex; align-items: center; gap: 0; }
.level-step {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 2px 14px; color: var(--ink-mute); font-size: .76rem; position: relative;
}
.level-step:hover { text-decoration: none; color: var(--ink); }
/* خط رابط بین پله‌ها */
.level-step::before {
  content: ''; position: absolute; top: 6px;
  inset-inline-start: 50%; width: 100%; height: 2px;
  background: var(--line); z-index: 0;
}
.level-step:last-child::before { display: none; }
.level-step.is-on::before { background: var(--indigo); }
.level-step:last-child.is-on::before { background: transparent; }

.step-dot {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--line);
  position: relative; z-index: 1;
}
.level-step.is-on .step-dot { border-color: var(--indigo); background: var(--indigo); }
.level-step.is-current .step-dot {
  box-shadow: 0 0 0 4px rgba(79,70,229,.18); transform: scale(1.15);
}
.level-step.is-current { color: var(--indigo); font-weight: 700; }

/* متن اصلی */
.content { max-width: 74ch; }
.content h1 { font-size: 1.45rem; margin-bottom: .8em; }
.section { margin-bottom: 36px; scroll-margin-top: 150px; }
.section h2 { font-size: 1.15rem; margin-bottom: .2em; }
.section .h-sub { font-size: 1rem; color: var(--ink-soft); }
.pages { margin: 0 0 .9em; }
.body { white-space: pre-wrap; }
.subsection {
  margin: 18px 0 0; padding-inline-start: 14px;
  border-inline-start: 2px solid var(--line-soft); scroll-margin-top: 150px;
}
.subsection h3 { font-size: .98rem; margin-bottom: .3em; }

.bullets { margin: 0 0 1.1em; padding-inline-start: 20px; }
.bullets li { margin-bottom: .45em; }
.bullets.tight li { margin-bottom: .2em; font-size: .93rem; }

.factgrid {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 18px;
  margin: 0 0 1.4em; font-size: .93rem;
}
.factgrid dt { color: var(--ink-soft); }
.factgrid dd { margin: 0; }

/* واژه‌نامه */
.glossary { margin: 0; }
.glossary dt { font-weight: 700; margin-top: 13px; font-size: .9rem; }
.glossary dd {
  margin: 2px 0 0; color: var(--ink-soft);
  font-size: .85rem; line-height: 1.8;
}

/* ------------------------------------------------------------------ جدول‌ها */

.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td {
  text-align: start; padding: 9px 10px; border-bottom: 1px solid var(--line);
}
.table th { color: var(--ink-soft); font-weight: 500; font-size: .86rem; }
.table tbody tr:hover { background: var(--line-soft); }

.loglist { list-style: none; margin: 10px 0 0; padding: 0; font-size: .87rem; }
.loglist li {
  display: flex; gap: 10px; padding: 6px 0;
  border-bottom: 1px solid var(--line-soft);
}
.loglist .log-error { color: var(--bad-fg); }
.loglist .log-warn  { color: var(--warn-fg); }

details > summary { cursor: pointer; font-weight: 500; }

.processing .row-between { margin-bottom: 4px; }

/* ------------------------------------------------------------------- چاپ */

@media print {
  .topbar, .footer, .reader-nav, .reader-side, .level-bar { display: none; }
  .reader { grid-template-columns: 1fr; }
  body { background: #fff; }
}
