/* Панель «Файлы» (static/js/files.js). Только переменные desk.css: обе темы сами. */

/* широкий режим панели: класс ставит панель (или ядро через onWide) */
:root.files-wide { --panel-w: min(860px, 56vw); }
@media (max-width: 1100px) { :root.files-wide { --panel-w: 100vw; } }

.files {
  position: relative; display: flex; flex-direction: column; gap: 8px; min-height: 100%;
  container-type: inline-size; font-size: 13.5px;
}
.files-note { margin: 0; font-size: 12px; }
.files-spacer { flex: 1; }
.files-banner { display: flex; align-items: center; gap: 8px; padding: 7px 10px; font-size: 12.5px; }

/* --- путь и кнопки ------------------------------------------------------------------------------------ */
.files-bar { display: flex; align-items: flex-start; gap: 6px; }
.files-crumbs { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 1px; padding-top: 5px; font-size: 13px; }
.files-crumb {
  border: 0; background: none; font: inherit; color: var(--muted); padding: 2px 5px; border-radius: 5px; cursor: pointer;
  max-width: 16em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.files-crumb:hover { background: var(--sunken); color: var(--ink); }
.files-crumb[aria-current="location"] { color: var(--ink); font-weight: 600; }
.files-crumb.is-drop { background: var(--accent-soft); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--accent-text); }
.files-sep { color: var(--line-strong); }
.files-tools { display: flex; align-items: center; gap: 1px; flex: none; }

.files-search { position: relative; display: block; }
.files-search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.files-search .input { height: 32px; padding-left: 31px; font-size: 13px; }

/* --- список -------------------------------------------------------------------------------------------- */
.files-list { display: flex; flex-direction: column; gap: 1px; }
.files-row { display: flex; align-items: center; gap: 2px; border-radius: var(--radius-sm); }
.files-row:hover, .files-row:focus-within { background: var(--sunken); }
.files-row.is-drop { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-text); }
.files-row.is-hidden .files-open { opacity: .6; }
.files-open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 5px 4px 5px 7px;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.files-open:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.files-open > .icon { flex: none; color: var(--muted); }
.files-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files-where { display: block; color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; }
.files-flag { flex: none; display: inline-flex; color: var(--muted); }
.files-meta { flex: none; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.files-row .menu-wrap { flex: none; }
.files-row .menu-wrap > .icon-btn { width: 28px; height: 28px; }
@media (hover: hover) {
  .files-row .menu-wrap { opacity: 0; }
  .files-row:hover .menu-wrap, .files-row:focus-within .menu-wrap, .files-row .menu-wrap:has(.menu) { opacity: 1; }
}
@container (max-width: 330px) { .files-date { display: none; } }

.files-empty { margin: 0; padding: 18px 8px; text-align: center; color: var(--muted); font-size: 13px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.files-empty p { margin: 0; }
.files-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 0 7px; color: var(--muted); font-size: 12px; }
.files-link { border: 0; background: none; padding: 0; font: inherit; color: var(--ink-2); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.files-link:hover { color: var(--ink); }

.files-hint {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 12px 10px; margin-top: 2px;
  border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: none; color: var(--muted);
  font: inherit; font-size: 12.5px; text-align: center; cursor: pointer;
}
.files-hint:hover { color: var(--ink); border-color: var(--ink-2); background: var(--sunken); }
.files-hint-touch { display: none; }
@media (hover: none) {
  .files-hint-mouse { display: none; }
  .files-hint-touch { display: inline; }
}

.files-drop {
  position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 16px; text-align: center; pointer-events: none; font-weight: 600;
  background: var(--accent-soft); color: var(--accent-text); border: 2px dashed var(--accent-text); border-radius: var(--radius);
}

.files-progress { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--sunken); font-size: 12.5px; }
.files-progress-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.files-progress-line span { min-width: 0; overflow-wrap: anywhere; }
.files-progress-bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.files-progress-bar span { display: block; height: 100%; background: var(--accent); transition: width .2s; }
@media (prefers-reduced-motion: reduce) { .files-progress-bar span { transition: none; } }

/* --- просмотр файла ------------------------------------------------------------------------------------ */
.files-view { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.files-head { display: flex; align-items: center; gap: 2px; }
.files-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; padding: 0 4px; }
.files-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.files-title small { font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.files-code {
  flex: 1; min-height: 200px; display: flex; align-items: flex-start; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
}
.files-code pre { margin: 0; padding: 10px; font: inherit; line-height: inherit; white-space: pre; overflow: visible; }
.files-code .files-gutter {
  position: sticky; left: 0; flex: none; min-height: 100%; padding-right: 8px; text-align: right; color: var(--muted);
  user-select: none; background: var(--raised); border-right: 1px solid var(--line);
}
.files-text { flex: 1 0 auto; color: var(--ink); tab-size: 4; }
.files-code.wrap .files-text { flex: 1 1 auto; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.files-editor {
  flex: 1; min-height: 320px; width: 100%; resize: vertical; padding: 10px; tab-size: 4;
  font-family: var(--mono); font-size: 12px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
.files-editor:focus { outline: none; border-color: var(--ink-2); box-shadow: 0 0 0 3px var(--accent-soft); }
.files-edit-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.files-image {
  overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); text-align: center;
  background: repeating-conic-gradient(var(--sunken) 0% 25%, var(--surface) 0% 50%) 50% / 16px 16px;
}
.files-image img { display: inline-block; max-width: 100%; height: auto; cursor: zoom-in; vertical-align: middle; }
.files-image.zoom img { max-width: none; cursor: zoom-out; }

.files-pdf { flex: 1; width: 100%; min-height: 480px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }

.files-md { overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; color: var(--ink); padding: 2px 4px; }
.files-md > :first-child { margin-top: 0; }
.files-md h1, .files-md h2, .files-md h3, .files-md h4 { margin: 18px 0 8px; line-height: 1.3; }
.files-md h1 { font-size: 20px; }
.files-md h2 { font-size: 17px; }
.files-md h3, .files-md h4 { font-size: 15px; }
.files-md p, .files-md ul, .files-md ol { margin: 0 0 10px; }
.files-md ul, .files-md ol { padding-left: 22px; }
.files-md a { color: var(--accent-text); }
.files-md code { font-family: var(--mono); font-size: 12.5px; background: var(--sunken); padding: 1px 5px; border-radius: 4px; }
.files-md pre { background: var(--sunken); padding: 10px 12px; border-radius: var(--radius-sm); overflow-x: auto; }
.files-md pre code { background: none; padding: 0; }
.files-md blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--line-strong); color: var(--ink-2); }
.files-md table { border-collapse: collapse; display: block; overflow-x: auto; margin: 0 0 10px; }
.files-md th, .files-md td { border: 1px solid var(--line); padding: 4px 8px; }
.files-md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

.files-table-view { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.files-sheet { display: flex; align-items: center; gap: 8px; }
.files-sheet .select { width: auto; max-width: 100%; min-width: 0; }
.files-table-wrap { overflow: auto; max-height: calc(100dvh - 230px); min-height: 120px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.files-table { border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
.files-table td {
  max-width: 22em; padding: 4px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: top;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--ink);
}
.files-table .files-num { position: sticky; left: 0; z-index: 1; text-align: right; color: var(--muted); background: var(--raised); font-variant-numeric: tabular-nums; }
/* не .files-head: так называется шапка панели (flex), строка таблицы стала бы flex и съехала */
.files-table tr.files-table-head td { position: sticky; top: 0; z-index: 2; background: var(--raised); font-weight: 600; }
.files-table tr.files-table-head .files-num { z-index: 3; }

.files-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 28px 14px; text-align: center;
  border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--ink-2);
}
.files-card .icon { color: var(--muted); }
.files-card b { color: var(--ink); overflow-wrap: anywhere; }

/* --- окно «Переместить» -------------------------------------------------------------------------------- */
.files-picker-list {
  display: flex; flex-direction: column; gap: 1px; max-height: min(50vh, 360px); min-height: 80px; overflow: auto;
  padding: 4px; border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.files-pick {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border: 0; border-radius: 6px;
  background: none; color: var(--ink); font: inherit; font-size: 13.5px; text-align: left; cursor: pointer;
}
.files-pick span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files-pick .icon { flex: none; color: var(--muted); }
.files-pick:hover:not(:disabled) { background: var(--sunken); }
.files-pick:disabled { opacity: .45; cursor: default; }
