/* «Папка» проекта (public/folder.js) и просмотрщик файлов (public/viewer.js). */

/* --- значок: компьютер — в полосе над превью (.ptool), телефон — вкладкой (.folder-tab) --- */
.folder-btn { position: relative; }
.ptools .folder-btn.ptool { width: 28px; padding: 0; justify-content: center; }
.ptools .folder-btn .mdot { top: 2px; left: auto; right: 2px; }
@media (max-width: 900px) {
  .tabs .folder-tab { flex: 0 0 auto; width: 40px; padding: 0; display: flex; align-items: center; justify-content: center; }
  .tabs .folder-tab .mdot { left: calc(50% + 5px); right: auto; top: calc(50% - 13px); }
}

/* --- страница --- */
.sheet.folder-panel .page-actions .btn { display: inline-flex; align-items: center; gap: 6px; }
.folder-pane { position: relative; }
.folder-sum { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.folder-tip { color: var(--dim); font-size: 12.5px; }
.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.fdr-tile { position: relative; min-width: 0; }
.fdr-open {
  display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 6px 6px 8px; text-align: left;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
  font: inherit; cursor: pointer;
}
.fdr-open:hover { border-color: var(--dim); }
.fdr-open:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.fdr-tile.new .fdr-open { border-color: var(--accent); }
.fdr-thumb {
  /* Ширина явно: в колонке flex растянутая ширина хрому для aspect-ratio не годится. */
  flex: 0 0 auto; width: 100%; display: grid; place-items: center; aspect-ratio: 4 / 3; overflow: hidden; border-radius: 7px;
  background: var(--bg); background-image: linear-gradient(45deg, color-mix(in srgb, var(--line) 50%, transparent) 25%, transparent 25%, transparent 75%, color-mix(in srgb, var(--line) 50%, transparent) 75%), linear-gradient(45deg, color-mix(in srgb, var(--line) 50%, transparent) 25%, transparent 25%, transparent 75%, color-mix(in srgb, var(--line) 50%, transparent) 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px;
}
.fdr-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.fdr-ico { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--dim); }
.fdr-ico svg { width: 34px; height: 34px; }
.fdr-ico i { font-style: normal; font-size: 11px; font-weight: 600; letter-spacing: .04em; padding: 1px 6px; border-radius: 4px; background: var(--card); border: 1px solid var(--line); }
.fdr-name { font-size: 13px; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; padding-right: 22px; }
.fdr-meta { font-size: 11.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fdr-new {
  position: absolute; top: 10px; left: 10px; padding: 1px 7px; border-radius: 99px;
  background: var(--accent); color: var(--accent-ink, #000); font-size: 11px; font-weight: 600;
}
.fdr-more {
  position: absolute; right: 4px; bottom: 26px; width: 28px; height: 28px; display: grid; place-items: center;
  border: 0; border-radius: 6px; background: transparent; color: var(--dim); cursor: pointer;
}
.fdr-more:hover { background: var(--card-hover); color: var(--text); }
.fdr-menu {
  position: absolute; right: 4px; bottom: 56px; z-index: 5; display: flex; flex-direction: column; min-width: 150px; padding: 4px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--card); box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.fdr-menu button {
  height: 34px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text);
  font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.fdr-menu button:hover { background: var(--card-hover); }
.fdr-menu button.bad { color: var(--bad); }

.folder-ups { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.folder-ups:empty { display: none; }
.folder-up {
  position: relative; display: flex; gap: 10px; align-items: center; padding: 7px 10px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card); font-size: 13px;
}
.folder-up.bad { border-color: color-mix(in srgb, var(--bad) 50%, transparent); color: var(--bad); }
.folder-up-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-up-st { color: var(--dim); flex: 0 0 auto; }
.folder-up.bad .folder-up-st { color: var(--bad); }
.folder-up-bar { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--accent); }
.folder-paste-catch {
  min-height: 56px; margin-bottom: 10px; padding: 14px; border: 1px dashed var(--accent); border-radius: 10px;
  color: var(--dim); font-size: 14px; outline: 0;
}
.folder-paste-catch:empty::before { content: 'Нажми здесь и удерживай, затем «Вставить»'; }
.folder-drop { display: none; }
.folder-panel.dragging .folder-drop {
  display: grid; place-items: center; position: absolute; inset: 0; z-index: 30; pointer-events: none;
  background: color-mix(in srgb, var(--bg) 82%, transparent); border: 2px dashed var(--accent);
}
.folder-panel.dragging .folder-drop span { display: flex; align-items: center; gap: 10px; font-size: 16px; color: var(--text); }
.folder-panel:not(.docked).dragging .folder-drop { position: fixed; }
.folder-rename-msg.bad { color: var(--bad); }

@media (max-width: 900px) {
  /* Телефон: папка — на весь экран, как разделы «Управления». */
  .sheet.folder-panel:not(.docked) .sheet-body {
    height: 100dvh; max-height: 100dvh; max-width: none; border-radius: 0; border: 0;
    padding-top: calc(16px + env(safe-area-inset-top, 0px) + var(--tg-top, 0px));
  }
  .folder-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .folder-tip { display: none; }
  .sheet.folder-panel .page-actions .btn span { display: none; }
  .sheet.folder-panel .page-actions .btn { width: 40px; height: 40px; padding: 0; justify-content: center; }
  .fdr-more { width: 36px; height: 36px; bottom: 22px; }
}

/* Ссылки на папку в ответах строителя: [[папка:имя]] и «посмотри в папке». */
.folder-link { color: var(--accent-text, var(--accent)); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.folder-link.file { display: inline-flex; align-items: center; gap: 3px; text-decoration: none; padding: 0 5px; border-radius: 5px; background: var(--accent-soft); color: var(--accent-ink, var(--text)); }
.folder-link.file svg { flex: 0 0 auto; }

/* --- просмотрщик --- */
.fviewer {
  position: fixed; inset: 0; z-index: 150; display: flex; flex-direction: column;
  background: rgba(8, 8, 10, .97); color: #eee;
}
.fviewer ~ .sheet { z-index: 160; }   /* «Точно?» и новое имя — поверх просмотра */
.fvw-top {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top, 0px) + var(--tg-top, 0px)) 10px 8px 16px;
}
.fvw-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.fvw-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 600; }
.fvw-count { flex: 0 0 auto; color: #aaa; font-size: 13px; }
.fvw-acts { flex: 0 0 auto; display: flex; gap: 4px; }
.fvw-btn {
  width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, .08); color: #eee; font: inherit; font-size: 20px; cursor: pointer;
}
.fvw-btn:hover { background: rgba(255, 255, 255, .16); }
.fvw-btn:focus-visible, .fvw-nav:focus-visible { outline: 2px solid #9cf; outline-offset: 1px; }
.fviewer:not([data-kind="image"]) .fvw-btn[data-act^="zoom"] { display: none; }   /* у PDF свои − / + над страницами */
.fvw-stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; }
.fvw-body { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: auto; overscroll-behavior: contain; touch-action: pan-x pan-y; }
.fvw-nav {
  position: absolute; top: 50%; z-index: 2; width: 46px; height: 64px; margin-top: -32px; display: grid; place-items: center;
  border: 0; border-radius: 10px; background: rgba(255, 255, 255, .08); color: #eee; cursor: pointer;
}
.fvw-nav:hover { background: rgba(255, 255, 255, .18); }
.fvw-nav.prev { left: 10px; }
.fvw-nav.next { right: 10px; }
.fvw-nav[hidden] { display: none; }
.fvw-wait, .fvw-note { margin: auto; padding: 24px; color: #bbb; font-size: 14px; text-align: center; }
.fvw-note { margin: 12px auto; }
.fvw-dim { color: #999; }

/* картинка */
.fvw-zoom { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; cursor: zoom-in; user-select: none; }
.fvw-zoom.zoomed { cursor: grab; }
.fvw-zoom img { max-width: calc(100% - 24px); max-height: calc(100% - 24px); object-fit: contain; transform-origin: 50% 50%; will-change: transform; -webkit-user-drag: none; }

/* аудио, видео */
.fvw-media-box { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 20px; width: min(560px, 100%); }
.fvw-media-box audio { width: 100%; }
.fvw-media-box.video { width: 100%; height: 100%; padding: 0 60px 16px; }
.fvw-media-box video { max-width: 100%; max-height: 100%; background: #000; }

/* карточка «Скачать» */
.fvw-card { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 28px 24px; max-width: 420px; text-align: center; }
.fvw-card-ico svg { width: 56px; height: 56px; color: #bbb; }
.fvw-card-ico.big svg { width: 72px; height: 72px; }
.fvw-card-name { font-size: 15px; word-break: break-word; }
.fvw-card .btn { width: auto; display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; }
/* Просмотрщик всегда тёмный (в светлой теме кабинета --accent-ink тёмно-зелёный — на нём не читается): мягкий акцент в тёмных значениях темы. */
.fvw-card .btn.primary { background: color-mix(in srgb, #c6ff3d 26%, transparent); border-color: #c6ff3d; color: #c6ff3d; }
.fvw-card .btn.primary:hover { background: color-mix(in srgb, #c6ff3d 38%, transparent); border-color: #c6ff3d; color: #c6ff3d; }

/* PDF */
.fvw-pdf { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.fvw-zoombar { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 4px 0 8px; color: #bbb; font-size: 13px; }
.fvw-zbtn { width: 34px; height: 30px; border: 0; border-radius: 7px; background: rgba(255, 255, 255, .1); color: #eee; font-size: 18px; cursor: pointer; }
.fvw-zval { min-width: 48px; text-align: center; }
.fvw-pages { margin-left: 10px; color: #999; }
.fvw-pdf-pages { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 0 12px 24px; touch-action: pan-x pan-y pinch-zoom; }
.fvw-page { flex: 0 0 auto; max-width: none; background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .5); }
.fvw-page canvas { display: block; width: 100%; height: 100%; }

/* текст, Markdown, код */
.fvw-tabs { flex: 0 0 auto; display: flex; gap: 4px; padding: 0 16px 8px; justify-content: center; }
.fvw-tabs button { height: 30px; padding: 0 12px; border: 1px solid rgba(255, 255, 255, .18); border-radius: 7px; background: transparent; color: #ccc; font: inherit; font-size: 13px; cursor: pointer; }
.fvw-tabs button.on { background: rgba(255, 255, 255, .14); color: #fff; }
.fvw-sheets { justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap; }
.fvw-sheets button { flex: 0 0 auto; }
.fvw-cm, .fvw-md, .fvw-doc, .fvw-slides, .fvw-zip, .fvw-sheet {
  flex: 1 1 auto; min-height: 0; width: min(980px, calc(100% - 24px)); margin: 0 auto 16px; border-radius: 10px;
  background: var(--bg); color: var(--text); overflow: auto;
}
.fvw-cm .cm-editor { height: 100%; }
.fvw-pre { margin: 0; padding: 14px; white-space: pre-wrap; word-break: break-word; font: 13px/1.55 var(--font-code, monospace); }
.fvw-md, .fvw-doc { padding: 22px 28px; font-size: 15px; line-height: 1.6; }
.fvw-md h1, .fvw-doc h1 { font-size: 24px; } .fvw-md h2, .fvw-doc h2 { font-size: 20px; } .fvw-md h3, .fvw-doc h3 { font-size: 17px; }
.fvw-md h1, .fvw-md h2, .fvw-md h3, .fvw-doc h1, .fvw-doc h2, .fvw-doc h3 { margin: 1.1em 0 .45em; line-height: 1.3; }
.fvw-md :first-child, .fvw-doc :first-child { margin-top: 0; }
.fvw-md p, .fvw-doc p { margin: 0 0 .8em; }
.fvw-md pre { padding: 10px 12px; border-radius: 8px; background: var(--card); overflow: auto; font: 13px/1.5 var(--font-code, monospace); }
.fvw-md code { font: .9em var(--font-code, monospace); background: var(--card); padding: 1px 4px; border-radius: 4px; }
.fvw-md pre code { background: none; padding: 0; }
.fvw-md blockquote { margin: 0 0 .8em; padding: 2px 14px; border-left: 3px solid var(--line); color: var(--muted); }
.fvw-md table { border-collapse: collapse; margin: 0 0 1em; }
.fvw-md th, .fvw-md td { border: 1px solid var(--line); padding: 5px 9px; }
.fvw-md a { color: var(--accent-text, var(--accent)); }
.fvw-media-t { margin-top: 1.4em; }
.fvw-media { display: flex; flex-wrap: wrap; gap: 10px; }
.fvw-media img { max-width: 100%; max-height: 360px; border-radius: 6px; border: 1px solid var(--line); background: #fff; }

/* таблицы */
.fvw-sheet { display: flex; flex-direction: column; background: transparent; }
.fvw-sheet .fvw-tabs { padding: 0 0 8px; }
.fvw-sheet-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.fvw-table-wrap { flex: 1 1 auto; min-height: 0; overflow: auto; border-radius: 10px; background: var(--bg); }
.fvw-doc .fvw-table-wrap { margin: 0 0 1em; border: 1px solid var(--line); }
.fvw-table { border-collapse: collapse; font-size: 13px; color: var(--text); }
.fvw-table th, .fvw-table td { border: 1px solid var(--line); padding: 4px 8px; white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis; text-align: left; vertical-align: top; }
.fvw-table thead th { position: sticky; top: 0; z-index: 1; background: var(--card); color: var(--muted); font-weight: 500; }
.fvw-table th.rn { position: sticky; left: 0; background: var(--card); color: var(--dim); font-weight: 400; text-align: right; }
.fvw-table thead th.rn { z-index: 2; }
.fvw-table.doc td { white-space: normal; }

/* слайды, zip */
.fvw-slides { display: flex; flex-direction: column; gap: 12px; padding: 14px; background: transparent; }
.fvw-slide { position: relative; padding: 26px 22px 18px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); aspect-ratio: 16 / 9; overflow: auto; }
.fvw-slide h3 { margin: 0 0 10px; font-size: 20px; }
.fvw-slide p { margin: 0 0 6px; font-size: 15px; }
.fvw-slide-n { position: absolute; top: 6px; right: 10px; font-size: 11.5px; color: var(--dim); }
.fvw-zip { padding: 14px 18px; }
.fvw-zip-sum { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.fvw-zip ul { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.fvw-zip li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line-2, var(--line)); }
.fvw-zip li span:first-child { min-width: 0; overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .fvw-nav { display: none; }   /* телефон: листание свайпом */
  .fviewer[data-kind="image"] .fvw-btn[data-act^="zoom"] { display: none; }   /* картинку — щипком; имени — место */
  .fvw-top { padding-left: 12px; }
  .fvw-btn { width: 40px; height: 40px; }
  .fvw-media-box.video { padding: 0 0 12px; }
  .fvw-md, .fvw-doc { padding: 16px; }
  .fvw-cm, .fvw-md, .fvw-doc, .fvw-slides, .fvw-zip, .fvw-sheet { width: calc(100% - 16px); }
  .fvw-slide { aspect-ratio: auto; min-height: 160px; }
}
