:root {
  --ink: #16141f;
  --muted: #5c5668;
  --line: #e6e0d6;
  --paper: #f4efe6;
  --paper-2: #fffdf8;
  --sidebar: #10131b;
  --sidebar-2: #181c27;
  --accent: #c45c26;
  --accent-2: #e8a87c;
  --ok: #2f6f4e;
  --danger: #b42318;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "Vazirmatn", "IBM Plex Sans", system-ui, sans-serif;
  --serif: "Vazirmatn", "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
}

button, input, a { font: inherit; }
button { cursor: pointer; }
.ghost {
  background: transparent;
  border: 1px solid #3a3f50;
  color: #d7d3c8;
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.ghost:hover { border-color: var(--accent-2); color: #fff; }

.progress {
  position: fixed;
  inset: 0 0 auto;
  height: 2px;
  z-index: 40;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), transparent);
  background-size: 200% 100%;
  animation: progress-slide 1.1s linear infinite;
}
@keyframes progress-slide {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

/* ——— login ——— */
.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 500px at 80% -10%, #3a2418 0%, transparent 55%),
    var(--sidebar);
  color: #f4efe6;
}
.login-card {
  width: min(28rem, calc(100% - 2rem));
  background: #1a1d28;
  border: 1px solid #2c3142;
  border-radius: 18px;
  padding: 2rem 1.75rem 1.75rem;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.login-kicker {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: var(--accent-2);
}
.login-card h1 {
  margin: 0.45rem 0 0;
  font-size: 1.8rem;
  font-weight: 700;
}
.login-lead { color: #b7b1a6; margin: 0.5rem 0 1.25rem; line-height: 1.7; }
.login-error {
  background: #3a1515;
  color: #ffc9c2;
  border: 1px solid #7a2e2e;
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
}
.login-card label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  font-size: 0.86rem;
  color: #cfc8bc;
}
.login-card input {
  background: #12141c;
  border: 1px solid #3a3f50;
  color: #fff;
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
}
.login-card button[type="submit"] {
  width: 100%;
  margin-top: 0.4rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 0.75rem;
  font-weight: 600;
}

/* ——— app shell ——— */
.app-body {
  display: grid;
  grid-template-columns: minmax(280px, 22vw) minmax(0, 1fr);
  min-height: 100%;
}
.sidebar {
  background: var(--sidebar);
  color: #ece7dc;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-left: 1px solid #2a2e3c;
}
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.15rem 1.15rem 0.55rem;
  gap: 0.75rem;
}
.brand-link { color: inherit; text-decoration: none; }
.brand-kicker {
  margin: 0;
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-2);
}
.brand { margin: 0.15rem 0 0; font-size: 1.15rem; }
.admin-chip {
  margin: 0.4rem 0 0;
  font-size: 0.72rem;
  color: #9a9488;
  word-break: break-all;
}
.root-form, .search-form { padding: 0.4rem 1.15rem 0.2rem; }
.root-form label, .search-form label {
  display: block;
  font-size: 0.75rem;
  color: #9a9488;
  margin-bottom: 0.3rem;
}
.root-row, .search-row { display: flex; gap: 0.4rem; align-items: center; }
.root-row input, .search-form input {
  width: 100%;
  background: var(--sidebar-2);
  border: 1px solid #34384a;
  color: #fff;
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  direction: ltr;
  text-align: left;
}
.root-row button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 0 0.8rem;
  white-space: nowrap;
}
.kbd {
  flex: none;
  min-width: 1.4rem;
  text-align: center;
  border: 1px solid #3a3f50;
  border-bottom-width: 2px;
  border-radius: 6px;
  color: #9a9488;
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.15rem 0.35rem;
}
.roots-hint { font-size: 0.75rem; color: #8e887c; margin: 0.45rem 0 0; }
.root-chip {
  background: #262a38;
  color: #eadfcf;
  border: 1px solid #3a3f50;
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  margin-inline-start: 0.25rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  direction: ltr;
}
.root-chip:hover { border-color: var(--accent-2); }
.tree-toolbar {
  padding: 0.7rem 1.15rem 0.25rem;
  font-size: 0.72rem;
  color: #8e887c;
  direction: ltr;
  text-align: left;
  word-break: break-all;
}
.tree {
  overflow: auto;
  flex: 1;
  padding: 0.3rem 0.55rem 1.2rem;
}
.tree details { margin: 0; }
.tree summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  padding: 0.3rem 0.45rem;
  border-radius: 8px;
  color: #d9d3c7;
}
.tree summary::-webkit-details-marker { display: none; }
.tree summary:hover, .tree button.file:hover { background: #262a38; }
.tree details.is-current > summary {
  background: #2a2218;
  color: #ffd7bc;
}
.tree .twisty {
  width: 0.7rem;
  color: #8a8478;
  font-size: 0.65rem;
}
.tree button.file {
  display: flex;
  width: 100%;
  text-align: right;
  background: none;
  border: 0;
  color: #ece7dc;
  padding: 0.3rem 0.45rem 0.3rem 0.4rem;
  border-radius: 8px;
  gap: 0.4rem;
  align-items: center;
}
.tree button.file.is-active {
  background: #3a261c;
  color: #ffd7bc;
}
.tree .kind {
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8ab4ff;
  font-family: var(--mono);
}
.tree .kind.md { color: #e8a87c; }
.tree .kind.html { color: #8ab4ff; }
.tree .kind.txt,
.tree .kind.log { color: #b7c4a1; }
.tree .kind.pdf { color: #e07a7a; }
.tree .kind.doc,
.tree .kind.docx { color: #7db3e8; }
.tree .kind.dir,
.index-item .kind.dir { color: #d7c39a; }
.tree .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
}
.tree .nested {
  padding-right: 0.75rem;
  margin-right: 0.55rem;
  border-right: 1px solid #2a2e3c;
}
.tree .empty-node { color: #6f6a60; font-size: 0.78rem; padding: 0.2rem 0.8rem; }

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background:
    linear-gradient(180deg, #fffdf8 0, #f4efe6 9rem);
}
.stage-bar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.05rem 1.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.crumbs {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  direction: ltr;
  text-align: left;
  word-break: break-all;
}
.crumbs a {
  color: inherit;
  text-decoration: none;
}
.crumbs a:hover { color: var(--accent); }
#docTitle { margin: 0.25rem 0 0; font-size: 1.45rem; letter-spacing: -0.02em; }
.stage-sub { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.82rem; }
.stage-actions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.stage-actions .ghost { color: var(--ink); border-color: var(--line); }
.badge {
  font-size: 0.72rem;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  background: #efe4d6;
  color: #6a3b16;
}
.badge-kind { background: #e4ecf7; color: #1d4e89; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 16rem);
  min-height: 0;
  flex: 1;
}
.workspace:has(#toc[hidden]) { grid-template-columns: 1fr; }
.preview {
  overflow: auto;
  padding: 1.5rem 1.9rem 3.5rem;
}
.preview:has(.diagram-wrap) {
  padding-inline: 1.1rem;
}
.empty {
  max-width: 36rem;
  color: var(--muted);
  line-height: 1.8;
  margin: 12vh auto 0;
  text-align: center;
}
.empty-error { color: var(--danger); }
.html-frame {
  width: 100%;
  min-height: calc(100vh - 8rem);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.folder-view { max-width: 52rem; margin: 0 auto; }
.index-heading {
  margin: 1.4rem 0 0.55rem;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.index-list { display: grid; gap: 0.45rem; }
.index-item {
  width: 100%;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  text-align: right;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  color: inherit;
}
.index-item:hover {
  border-color: #d2b394;
  box-shadow: 0 8px 24px rgba(80, 50, 20, 0.05);
}
.index-up { background: #f3eee6; }
.index-body { display: grid; gap: 0.15rem; min-width: 0; }
.index-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.index-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-family: var(--mono);
  direction: ltr;
  text-align: left;
}
.index-empty { color: var(--muted); }
.folder-readme {
  margin-top: 2rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}
.readme-kicker {
  margin: 0 0 0.8rem;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.toc {
  border-right: 1px solid var(--line);
  padding: 1.2rem 1rem 2rem;
  overflow: auto;
  background: rgba(243, 238, 230, 0.7);
  position: sticky;
  top: 0;
  max-height: 100vh;
}
.toc h3 {
  margin: 0 0 0.6rem;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.toc a {
  display: block;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.8rem;
  padding: 0.22rem 0;
  line-height: 1.4;
}
.toc a:hover { color: var(--accent); }
.toc .l2 { padding-right: 0.7rem; }
.toc .l3, .toc .l4 { padding-right: 1.3rem; opacity: 0.85; }

/* ——— markdown prose ——— */
.prose {
  max-width: 68rem;
  margin: 0 auto;
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.85;
}
.folder-readme .prose { max-width: none; }
.prose[dir="rtl"] { font-family: "Vazirmatn", var(--serif); }
.prose[dir="ltr"] { text-align: left; font-family: "Source Serif 4", var(--serif); }
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--sans);
  line-height: 1.3;
  margin: 1.6rem 0 0.6rem;
}
.prose h1 { font-size: 2rem; margin-top: 0; }
.prose h2 {
  font-size: 1.4rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--line);
}
.prose p, .prose ul, .prose ol { margin: 0.7rem 0; }
.prose a { color: #8a3b12; }
.prose blockquote {
  margin: 1rem 0;
  padding: 0.2rem 1rem;
  border-right: 3px solid var(--accent);
  color: #4b4654;
  background: #efe8dc;
}
.prose[dir="ltr"] blockquote { border-right: 0; border-left: 3px solid var(--accent); }
.prose code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: #ece6db;
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.prose pre {
  direction: ltr;
  text-align: left;
  overflow: auto;
  background: #16141f;
  color: #f4efe6;
  border-radius: 12px;
  padding: 0.9rem 1rem;
}
.prose pre code { background: none; color: inherit; padding: 0; }
.prose .codehilite { background: transparent; }
.prose .code-block {
  margin: 1rem 0 1.4rem;
  background: #16141f;
  border: 1px solid #2a2733;
  border-radius: 12px;
  overflow: hidden;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}
.prose .code-block-meta {
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0.38rem 0.9rem;
  background: #1c1a26;
  border-bottom: 1px solid #2a2733;
}
.prose .code-block-lang {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
}
.prose .code-block .codehilite {
  margin: 0;
  background: transparent;
}
.prose .code-block pre {
  margin: 0;
  background: transparent;
  border-radius: 0;
}
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.6rem 0; }

.prose .diagram-wrap {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: center;
  overflow: auto;
  margin: 1.4rem 0 1.8rem;
  padding: 1.15rem 1.2rem 1.3rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  max-width: none;
}
.prose .diagram-wrap[data-kind="flowchart"],
.prose .diagram-wrap[data-kind="gantt"],
.prose .diagram-wrap[data-kind="xychart-beta"] {
  text-align: left;
}
.prose .diagram-wrap[data-kind="pie"],
.prose .diagram-wrap[data-kind="quadrantchart"] {
  min-height: 22rem;
}
.prose pre.mermaid,
.prose .diagram-wrap .mermaid {
  background: transparent;
  color: var(--ink);
  margin: 0;
  padding: 0;
  overflow: visible;
  font-family: var(--sans);
  font-size: 0.92rem;
  line-height: 1.45;
  display: inline-block;
  min-width: min-content;
}
.prose .diagram-wrap svg {
  display: block;
  max-width: none;
  height: auto;
}
.prose .diagram-wrap .flowchart-link,
.prose .diagram-wrap .edge-thickness-normal {
  stroke-width: 1.4px;
}
.prose .diagram-error,
.prose pre.mermaid.diagram-error,
.prose .diagram-wrap .diagram-error {
  display: block;
  text-align: left;
  color: var(--danger);
  white-space: pre-wrap;
}
.prose .diagram-error-msg {
  margin: 0 0 0.6rem;
  font-family: var(--sans);
  font-size: 0.86rem;
}
.prose .diagram-error pre {
  margin: 0;
  background: #16141f;
  color: #f4efe6;
}

.table-wrap {
  overflow-x: auto;
  margin: 1rem 0 1.4rem;
  border: 1px solid #d8d0c4;
  border-radius: 12px;
  background: #fff;
}
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.92rem;
  line-height: 1.45;
  min-width: 24rem;
}
.prose thead th {
  position: sticky;
  top: 0;
  background: #efe6d8;
  font-weight: 600;
  text-align: inherit;
  white-space: nowrap;
}
.prose th, .prose td {
  border-bottom: 1px solid #e7e0d4;
  padding: 0.55rem 0.75rem;
  vertical-align: top;
}
.prose tbody tr:nth-child(even) td { background: #faf7f1; }
.prose[dir="rtl"] th, .prose[dir="rtl"] td { text-align: right; }
.prose[dir="ltr"] th, .prose[dir="ltr"] td { text-align: left; }
.prose .contains-task-list { list-style: none; padding: 0; }
.prose img { max-width: 100%; border-radius: 10px; }
.plain-view {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.65;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.1rem;
}
.log-view {
  font-size: 0.8rem;
  background: #16141f;
  color: #e8e2d6;
  border-color: #2a2e3c;
}
.prose[dir="rtl"] .plain-view { font-family: "Vazirmatn", var(--mono); }

@media (max-width: 960px) {
  .app-body { grid-template-columns: 1fr; }
  .sidebar { max-height: 42vh; }
  .workspace { grid-template-columns: 1fr; }
  .toc { display: none; }
  .stage-bar { position: static; }
}
