/* babak-drop: one dark shell around two dashboards and a drawer of files. */
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-var.woff2") format("woff2-variations"), url("fonts/Vazirmatn-var.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0f1214;
  --surface: #171b1f;
  --surface-2: #1e2429;
  --line: #2b333a;
  --line-strong: #3a444d;
  --text: #eef1f3;
  --text-2: #a3adb6;
  --text-3: #6f7a84;
  --accent: #38c5a4;
  --accent-ink: #06211b;
  --accent-2: #f2c14e;
  --danger: #ef7b7b;
  --danger-bg: #3a1f22;
  --ok: #6fd39b;
  --ok-bg: #1c3327;
  --focus: #8fe3cc;
  --font: "Vazirmatn", "Segoe UI", "SF Arabic", system-ui, sans-serif;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px;
  --r-1: 6px; --r-2: 12px; --r-full: 999px;
  --side-w: 240px;
  --bar-h: 48px;
  --top-h: 52px;
  --dur: 120ms;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); color-scheme: dark; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 400 15px/1.7 var(--font); letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, p, ul, ol, pre, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button, input, label { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
time { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.grow { flex: 1 1 auto; }
.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; }
.only-mobile { display: none !important; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.btn.primary:focus-visible { outline-color: var(--text); }
.skip {
  position: absolute; inset-inline-start: var(--s-3); top: -100px; z-index: 100;
  padding: var(--s-2) var(--s-4); background: var(--accent); color: var(--accent-ink);
  border-radius: var(--r-1); font-weight: 600;
}
.skip:focus { top: var(--s-3); }

/* Icons */
.i { width: 20px; height: 20px; flex: 0 0 auto; }
.i.big { width: 40px; height: 40px; color: var(--text-3); }
[dir="rtl"] .i.flip { transform: scaleX(-1); }
.mark { width: 28px; height: 28px; border-radius: 7px; flex: 0 0 auto; }
.mark.big { width: 56px; height: 56px; border-radius: 14px; margin: 0 auto var(--s-4); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 40px; padding: 0 var(--s-4); border: 1px solid transparent; border-radius: var(--r-1);
  background: var(--surface-2); color: var(--text); font-weight: 600; cursor: pointer;
  white-space: nowrap; text-decoration: none;
  transition-property: background-color, border-color, color, transform; transition-duration: var(--dur); transition-timing-function: ease-out;
}
.btn:hover { background: var(--line); }
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #4ad3b3; }
.btn.quiet { background: transparent; border-color: var(--line); }
.btn.quiet:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn.quiet.danger { color: var(--danger); }
.btn.quiet.danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn.icon { width: 40px; padding: 0; background: transparent; color: var(--text-2); }
.btn.icon:hover { background: var(--surface-2); color: var(--text); }
.btn.wide { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: default; pointer-events: none; }

/* Shell grid: sidebar first in DOM, on the inline-start (right) edge. */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100dvh; }
.side {
  position: sticky; top: 0; height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface);
  padding: var(--s-4) var(--s-3) max(var(--s-4), var(--safe-b)); padding-inline-end: max(var(--s-3), var(--safe-r));
}
.side nav, .sheet nav { display: flex; flex-direction: column; min-height: 100%; }
.topbar { display: none; }
.main { min-width: 0; display: flex; flex-direction: column; }

/* Navigation content (shared by sidebar and sheet) */
.brand { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2); font-weight: 700; font-size: 18px; line-height: 1.4; border-radius: var(--r-1); }
.brand:hover { background: var(--surface-2); }
.nav-label { font-size: 12px; font-weight: 600; color: var(--text-3); margin: var(--s-5) var(--s-2) var(--s-1); }
.nav-row {
  display: flex; align-items: center; gap: var(--s-3); min-height: 40px; padding: var(--s-2);
  border-radius: var(--r-1); color: var(--text); position: relative;
  transition: background-color var(--dur) ease-out;
}
.nav-row .i { color: var(--text-3); }
.nav-row:hover { background: var(--surface-2); }
.nav-row[aria-current="page"] { color: var(--accent); background: var(--surface-2); }
.nav-row[aria-current="page"] .i { color: var(--accent); }
.nav-row[aria-current="page"]::before { content: ""; position: absolute; inset-inline-start: 0; top: 8px; bottom: 8px; width: 3px; border-radius: var(--r-full); background: var(--accent); }
.tree-root ul { border-inline-start: 1px solid var(--line); margin-inline-start: var(--s-4); }
.dot { width: 10px; height: 10px; border-radius: var(--r-full); background: var(--dot, var(--accent)); flex: 0 0 auto; }
.nav-foot { margin-top: auto; padding-top: var(--s-5); display: grid; gap: var(--s-3); }
.meter { display: grid; gap: var(--s-2); padding: var(--s-2); font-size: 13px; }
.meter-label { display: grid; gap: 2px; }
.meter-label > span:first-child { font-weight: 600; }
.meter-bar { height: 6px; background: var(--line-strong); border-radius: var(--r-full); overflow: hidden; }
.meter-bar span { display: block; height: 100%; background: var(--accent); border-radius: var(--r-full); }
.meter.warn .meter-bar span { background: var(--accent-2); }
.meter-warn { display: flex; gap: var(--s-2); align-items: flex-start; color: var(--accent-2); font-size: 13px; line-height: 1.5; }
.meter-warn .i { width: 18px; height: 18px; }

/* Nav sheet (mobile) */
.sheet { border: 0; padding: 0; margin: 0; max-width: none; max-height: none; width: min(320px, 88vw); height: 100dvh;
  inset-inline-start: 0; inset-inline-end: auto; background: var(--surface); color: var(--text); }
.sheet::backdrop { background: rgba(0, 0, 0, .55); }
.sheet nav { padding: var(--s-4) var(--s-3) max(var(--s-4), var(--safe-b)); height: 100%; overflow-y: auto; overscroll-behavior: contain; }
.sheet-close { position: absolute; top: var(--s-3); inset-inline-end: var(--s-3); z-index: 1; }

/* Page (home / folder / trash) */
.page { padding: var(--s-5) var(--s-6) calc(var(--s-7) + var(--safe-b)); max-width: 1120px; width: 100%; display: grid; gap: var(--s-6); align-content: start; }
.page-head { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; min-height: 40px; }
.page-actions { display: flex; gap: var(--s-2); }
.page-title { font-size: 22px; line-height: 1.3; font-weight: 700; }
.hint { font-size: 13px; }

/* Crumbs */
.crumbs ol { display: flex; flex-wrap: wrap; align-items: center; font-size: 18px; font-weight: 600; line-height: 1.4; }
.crumbs li { display: flex; align-items: center; min-height: 40px; }
.crumbs li + li::before { content: "‹"; color: var(--text-3); padding: 0 var(--s-2); font-weight: 400; }
.crumbs a { color: var(--text-2); padding: var(--s-1) 0; border-radius: var(--r-1); }
.crumbs a:hover { color: var(--text); }
.crumbs [aria-current="page"] { color: var(--text); }

/* Dashboard tiles: the instruments on the desk */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--s-4); }
.tile {
  position: relative; display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; column-gap: var(--s-3); row-gap: var(--s-1);
  padding: var(--s-5); background: var(--surface); border: 1px solid transparent; border-radius: var(--r-2);
  transition: background-color var(--dur) ease-out, border-color var(--dur) ease-out;
}
.tile:hover { background: var(--surface-2); border-color: var(--line); }
.tile .dot { grid-row: 1; margin-top: 10px; width: 12px; height: 12px; box-shadow: 0 0 0 4px color-mix(in srgb, var(--dot) 18%, transparent); }
.tile-title { grid-column: 2; font-size: 22px; line-height: 1.3; font-weight: 700; text-wrap: balance; }
.tile-meta { grid-column: 2; display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-3); color: var(--text-2); font-size: 13px; line-height: 1.6; }
.tile-cta { grid-column: 3; grid-row: 1 / span 2; align-self: center; margin: 0; min-height: 36px; }
.tile.hero { padding: var(--s-6) var(--s-5); }

/* File list: one quiet list, whole-row links */
.list { display: grid; gap: var(--s-2); }
.list-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); padding: 0 var(--s-2); }
.list-title { font-size: 15px; font-weight: 600; line-height: 1.4; color: var(--text-2); }
.rows { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: var(--s-2); min-height: 48px; border-bottom: 1px solid var(--line); padding-inline-start: var(--s-1); }
.row:hover { background: var(--surface); }
.row.selected { background: var(--surface-2); }
.row-link { display: flex; align-items: center; gap: var(--s-3); flex: 1 1 auto; min-width: 0; min-height: 48px; padding: var(--s-1) var(--s-2); border-radius: var(--r-1); }
.row-link .i { color: var(--text-3); }
.row-main { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: var(--s-2); }
.row-name { overflow-wrap: anywhere; }
.row-meta { font-size: 13px; }
.row-side { display: flex; gap: var(--s-4); color: var(--text-2); font-size: 13px; white-space: nowrap; }
.row-path { white-space: normal; overflow-wrap: anywhere; }
.row-dl { flex: 0 0 40px; width: 40px; }
.badge { font-size: 12px; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: var(--r-full); padding: 0 var(--s-2); line-height: 20px; }
.selbox { display: grid; place-items: center; width: 40px; height: 40px; flex: 0 0 auto; cursor: pointer; }
.sel { appearance: none; width: 18px; height: 18px; margin: 0; border: 1.5px solid var(--line-strong); border-radius: 4px; background: transparent; cursor: pointer; display: grid; place-items: center; }
.sel:checked { background: var(--accent); border-color: var(--accent); }
.sel:checked::before { content: ""; width: 10px; height: 6px; border: 2px solid var(--accent-ink); border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.row:not(:hover):not(.selected) .sel:not(:focus-visible) { opacity: .55; }
[data-trash] .row-link { cursor: default; }

/* Empty state doubles as the drop target */
.empty { display: grid; justify-items: center; gap: var(--s-2); padding: var(--s-7) var(--s-4); text-align: center; border: 1px solid var(--line); border-radius: var(--r-2); color: var(--text-2); }
.empty.drop-target { border: 1px dashed var(--line-strong); }
.empty-title { font-size: 18px; font-weight: 600; color: var(--text); }
.empty .btn { margin-top: var(--s-3); }
label.empty { cursor: pointer; }
label.empty:hover { background: var(--surface); }
.error-page { border: 0; padding-top: 12vh; }
.err-code { font-size: 48px; font-weight: 700; color: var(--text-3); line-height: 1; }

/* Uploader */
.uploader { display: grid; gap: var(--s-2); padding: var(--s-4); background: var(--surface); border-radius: var(--r-2); }
.up-head { display: flex; align-items: center; gap: var(--s-2); min-height: 32px; font-weight: 600; }
progress { width: 100%; height: 6px; appearance: none; border: 0; background: var(--line-strong); border-radius: var(--r-full); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--line-strong); }
progress::-webkit-progress-value { background: var(--accent); transition: width var(--dur) ease-out; }
progress::-moz-progress-bar { background: var(--accent); }
.up-list { display: grid; gap: var(--s-1); font-size: 13px; }
.up-list li { display: flex; gap: var(--s-2); align-items: center; }
.up-list .ok { color: var(--ok); }
.up-list .err, .up-head .err { color: var(--danger); }
.up-list .i { width: 16px; height: 16px; }
.up-hint { font-size: 13px; color: var(--text-3); }

/* Drop overlay */
.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(15, 18, 20, .85); border: 3px dashed var(--accent); border-radius: var(--r-2);
  font-size: 22px; font-weight: 700; text-align: center; pointer-events: none;
}
.drop-overlay > div { display: grid; justify-items: center; gap: var(--s-3); }
.drop-overlay .i.big { color: var(--accent); width: 56px; height: 56px; }

/* Selection action bar */
.actbar {
  position: sticky; bottom: 0; z-index: 20; margin-top: auto;
  padding: var(--s-2) 0 max(var(--s-2), var(--safe-b));
  background: var(--surface); border-top: 1px solid var(--line); font-weight: 600;
}
.actbar-in { display: flex; align-items: center; gap: var(--s-2); max-width: 1120px; width: 100%; padding-inline: var(--s-6); }

/* Flash */
.flashes { display: grid; gap: var(--s-2); padding: var(--s-3) var(--s-6) 0; }
.flash { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); border-radius: var(--r-1); font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--danger-bg); color: var(--danger); }
.flash span { flex: 1 1 auto; }
.flash .btn.icon { color: inherit; }
.flash.leaving { opacity: 0; transform: translateY(-4px); transition: opacity 160ms ease-out, transform 160ms ease-out; }

/* Viewer bar and bodies */
.vbar { display: flex; align-items: center; gap: var(--s-2); height: var(--bar-h); padding: 0 var(--s-3); background: var(--surface); border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.vtitle { font-size: 18px; font-weight: 600; line-height: 1.4; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vmeta { font-size: 13px; white-space: nowrap; }
.view-html .main { height: 100dvh; overflow: hidden; }
.view-html .frame { display: block; width: 100%; height: calc(100dvh - var(--bar-h)); border: 0; background: var(--bg); }
.view-file .main { height: 100dvh; overflow: hidden; }
.vbody { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.tabs { display: flex; gap: var(--s-1); padding: var(--s-2) var(--s-3) 0; border-bottom: 1px solid var(--line); overflow-x: auto; flex: 0 0 auto; }
.tab { padding: var(--s-2) var(--s-3); min-height: 40px; border-bottom: 2px solid transparent; color: var(--text-2); white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.table-wrap { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; padding-bottom: var(--safe-b); }
table.preview { border-collapse: separate; border-spacing: 0; font-size: 13px; line-height: 1.6; width: max-content; max-width: none; }
table.preview th, table.preview td { padding: var(--s-1) var(--s-3); border-bottom: 1px solid var(--line); white-space: nowrap; text-align: start; vertical-align: top; }
table.preview th { position: sticky; top: 0; z-index: 2; background: var(--surface); color: var(--text-2); font-weight: 600; }
/* Cells carry dir="auto", so logical start/end would follow each cell's own script and a
   Persian value in a Latin table (or a number in a Persian one) would drift away from its
   header. Align physically, by the table's direction. */
table.preview[dir="ltr"] th, table.preview[dir="ltr"] td { text-align: left; }
table.preview[dir="rtl"] th, table.preview[dir="rtl"] td { text-align: right; }
table.preview td.num, table.preview th.num { font-variant-numeric: tabular-nums; }
table.preview[dir="ltr"] td.num, table.preview[dir="ltr"] th.num { text-align: right; }
table.preview[dir="rtl"] td.num, table.preview[dir="rtl"] th.num { text-align: left; }
table.preview tbody tr:hover td { background: var(--surface); }
.code { flex: 1 1 auto; min-height: 0; overflow: auto; margin: var(--s-4) var(--s-6); padding: var(--s-4); background: var(--surface); border-radius: var(--r-2); font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.pad { padding: var(--s-4) var(--s-6); overflow: auto; }
.pic { border-radius: var(--r-1); outline: 1px solid rgba(255, 255, 255, .1); }
.frame.pdf { flex: 1 1 auto; width: 100%; border: 0; background: var(--bg); }

/* Zen: hide the sidebar, shrink the bar. */
body.zen { grid-template-columns: 1fr; --bar-h: 36px; }
body.zen .side, body.zen .topbar { display: none; }
body.zen .vbar { padding: 0 var(--s-2); }
body.zen .vbar .btn { min-height: 32px; }
body.zen .vbar .btn.icon { width: 32px; }
body.zen .vbar .vtitle { font-size: 15px; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100dvh; padding: var(--s-4); }
.login { width: min(400px, 100%); padding: var(--s-6); background: var(--surface); border-radius: var(--r-2); text-align: center; }
.login-title { font-size: 28px; font-weight: 700; line-height: 1.2; margin-bottom: var(--s-1); }
.login form { display: grid; gap: var(--s-2); margin-top: var(--s-5); text-align: start; }
.login label { font-size: 13px; font-weight: 600; color: var(--text-2); margin-top: var(--s-2); }
.login input:not([type="hidden"]) { width: 100%; min-height: 44px; padding: var(--s-2) var(--s-3); background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-1); font-size: 16px; }
.login input:focus-visible { border-color: var(--line-strong); }
.login input[aria-invalid="true"] { border-color: var(--danger); }
.login .btn { margin-top: var(--s-4); min-height: 44px; }
.form-err { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3); background: var(--danger-bg); color: var(--danger); border-radius: var(--r-1); font-weight: 500; }

/* Mobile: no sidebar. Top bar plus the nav sheet. */
@media (max-width: 899px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { display: none; }
  .only-desktop { display: none !important; }
  .only-mobile { display: inline-flex !important; }
  .topbar { display: flex; align-items: center; gap: var(--s-2); height: calc(var(--top-h) + var(--safe-t)); padding: var(--safe-t) max(var(--s-2), var(--safe-r)) 0 max(var(--s-2), var(--safe-l)); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
  .topbar .brand { flex: 1 1 auto; justify-content: center; font-size: 16px; padding: var(--s-1) var(--s-2); }
  .topbar .btn { min-height: 44px; }
  .topbar .btn.icon { width: 44px; }
  .view-html .topbar, .view-file .topbar { display: none; }
  .page { padding: var(--s-4) max(var(--s-4), var(--safe-r)) calc(var(--s-7) + var(--safe-b)) max(var(--s-4), var(--safe-l)); gap: var(--s-5); }
  .page-actions .btn span { display: none; }
  .page-actions .btn { width: 44px; padding: 0; }
  .page-actions .btn.primary { width: auto; padding: 0 var(--s-4); }
  .page-actions .btn.primary span { display: inline; }
  .crumbs ol { font-size: 16px; }
  .crumbs li.mid { display: none; }
  .crumbs li.mid + li:not(.mid)::before { content: "‹ … ‹"; }
  .tile.hero { padding: var(--s-5) var(--s-4); }
  .tile-title { font-size: 20px; }
  .tile-cta { display: none; }
  .row { min-height: 56px; }
  .row-link { min-height: 56px; display: grid; grid-template-columns: auto 1fr; column-gap: var(--s-3); row-gap: 0; align-items: center; padding: var(--s-2); }
  .row-link > .i { grid-row: 1 / span 2; }
  .row-main { flex-wrap: wrap; }
  .row-side { grid-column: 2; flex-wrap: wrap; gap: 0 var(--s-3); font-size: 12px; line-height: 1.5; }
  .row-dl { flex-basis: 44px; width: 44px; }
  .btn.icon { width: 44px; min-height: 44px; }
  .selbox { width: 44px; height: 44px; }
  .sel { width: 20px; height: 20px; }
  .nav-row { min-height: 44px; }
  .flashes { padding: var(--s-3) var(--s-4) 0; }
  .vbar { padding: 0 var(--s-2); }
  .vtitle { font-size: 16px; }
  .vbar .vmeta.ltr { display: none; }
  .vbar .btn.quiet { width: 44px; min-height: 44px; padding: 0; background: transparent; border-color: transparent; color: var(--text-2); }
  .vbar .btn.quiet:hover { background: var(--surface-2); color: var(--text); }
  .vbar .btn.quiet span { display: none; }
  table.preview { font-size: 14px; }
  table.preview th:first-child, table.preview td:first-child { position: sticky; inset-inline-start: 0; z-index: 1; background: var(--surface); }
  table.preview th:first-child { z-index: 3; }
  .code { margin: var(--s-3); }
  .pad { padding: var(--s-3); }
  input, select, textarea { font-size: 16px; }
  .actbar-in { padding-inline: max(var(--s-4), var(--safe-r)) max(var(--s-4), var(--safe-l)); }
  .actbar .btn span { display: none; }
  .actbar .btn { width: 44px; padding: 0; }
  .actbar .btn.primary { width: auto; padding: 0 var(--s-4); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation: none !important; }
  .btn:active { transform: none; }
}
