/* CloudBox — тема в духе shadcn/ui: нейтральная палитра, тонкие границы,
   минимум теней, никаких градиентов и свечений. Токены ниже — те же, что
   в shadcn (zinc), только значения заданы как HSL-триплеты. */

:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 72.2% 50.6%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 71% 35%;
  --warning: 38 92% 40%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --radius: 0.5rem;
}

html[data-theme="dark"] {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 10% 5.5%;
  --card-foreground: 0 0% 98%;
  --popover: 240 10% 5.5%;
  --popover-foreground: 0 0% 98%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 3.7% 15.9%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 62.8% 48%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 69% 45%;
  --warning: 38 92% 55%;
  --border: 240 3.7% 15.9%;
  --input: 240 3.7% 15.9%;
  --ring: 240 4.9% 83.9%;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font: 14px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  width: 16px;
  height: 16px;
  flex: none;
}

/* Спрайт иконок: нулевой размер, а не display:none — так надёжнее в Safari и Firefox. */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; pointer-events: none; }

.hidden { display: none !important; }
.spacer { flex: 1 1 auto; }
.muted { color: hsl(var(--muted-foreground)); }
.hide-sm { display: inline; }

::selection { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }

/* ---------------------------------------------------------------- шапка */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 20px;
  background: hsl(var(--background));
  border-bottom: 1px solid hsl(var(--border));
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-icon { width: 20px; height: 20px; }
.brand span { font-size: 15px; }

.search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  max-width: 420px;
  margin: 0 auto;
}

.search .search-icon {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: hsl(var(--muted-foreground));
  pointer-events: none;
}

.search input { padding-left: 32px; padding-right: 34px; }
.search .icon-btn { position: absolute; right: 4px; width: 28px; height: 28px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  font-size: 12.5px;
  font-weight: 500;
}

.user-chip svg { width: 14px; height: 14px; opacity: 0.7; }

/* --------------------------------------------------------------- кнопки */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid transparent;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover { background: hsl(var(--accent)); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring)); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { background: hsl(var(--primary) / 0.9); }

.btn-outline { background: transparent; border-color: hsl(var(--input)); }
.btn-outline:hover { background: hsl(var(--accent)); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: hsl(var(--accent)); }

.btn-danger { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn-danger:hover { background: hsl(var(--destructive) / 0.9); }

.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.icon-btn:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px hsl(var(--ring)); }
.icon-btn.tiny { width: 28px; height: 28px; }
.icon-btn.tiny svg { width: 14px; height: 14px; }
.icon-btn.danger:hover { background: hsl(var(--destructive) / 0.12); color: hsl(var(--destructive)); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.theme-light-icon { display: none; }
html[data-theme="light"] .theme-dark-icon { display: none; }
html[data-theme="light"] .theme-light-icon { display: block; }

/* -------------------------------------------------------------- поля */

input[type="text"], input[type="search"], input[type="password"], input:not([type]) {
  height: 36px;
  width: 100%;
  padding: 0 12px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--input));
  background: transparent;
  color: hsl(var(--foreground));
  font: inherit;
  font-size: 13.5px;
  outline: none;
  transition: box-shadow 0.15s, border-color 0.15s;
}

input:focus-visible { border-color: hsl(var(--ring)); box-shadow: 0 0 0 1px hsl(var(--ring)); }
input::placeholder { color: hsl(var(--muted-foreground)); }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: hsl(var(--primary)); cursor: pointer; }

select {
  height: 36px;
  padding: 0 10px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--input));
  background: transparent;
  color: hsl(var(--foreground));
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}

/* ---------------------------------------------------------------- вкладки */

.tabs {
  display: flex;
  gap: 4px;
  width: fit-content;
  margin: 16px auto 0;
  padding: 4px;
  border-radius: var(--radius);
  background: hsl(var(--muted));
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 14px;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: hsl(var(--muted-foreground));
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.tab:hover { color: hsl(var(--foreground)); }
.tab.active { background: hsl(var(--background)); color: hsl(var(--foreground)); box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); }
html[data-theme="dark"] .tab.active { background: hsl(var(--accent)); box-shadow: none; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ макет */

.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 20px 56px;
  width: 100%;
}

.panel { position: relative; min-height: 60vh; }

/* ------------------------------------------------------------ крошки/тулбар */

.crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: 12px;
  min-height: 32px;
  font-size: 13.5px;
}

.crumb {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 8px;
  border: none;
  border-radius: calc(var(--radius) - 3px);
  background: transparent;
  color: hsl(var(--muted-foreground));
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.crumb:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.crumb.current { color: hsl(var(--foreground)); font-weight: 600; cursor: default; }
.crumb.drag-over { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.crumb-sep { color: hsl(var(--border)); user-select: none; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  border-bottom: 1px solid hsl(var(--border));
}

.sort-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
}

/* ------------------------------------------------------------- прогрессы */

.uploads {
  margin: 12px 0 4px;
  padding: 10px 14px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
}

.upload-row { display: grid; gap: 6px; padding: 7px 0; }
.upload-row + .upload-row { border-top: 1px solid hsl(var(--border)); }

.upload-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
}

.upload-meta .upload-name {
  color: hsl(var(--foreground));
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 55%;
}

.bar {
  height: 4px;
  border-radius: 999px;
  background: hsl(var(--secondary));
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: hsl(var(--primary));
  transition: width 0.2s ease;
}

.bar-fill.failed { background: hsl(var(--destructive)); }
.bar.indeterminate .bar-fill { width: 30%; animation: bar-slide 1.6s ease-in-out infinite; }

@keyframes bar-slide {
  0% { margin-left: 0; }
  50% { margin-left: 70%; }
  100% { margin-left: 0; }
}

/* ---------------------------------------------------------------- таблица */

.table-wrap { position: relative; min-height: 240px; }

/* fixed: колонки не разъезжаются от длинных имён и панели действий */
table.files { width: 100%; border-collapse: collapse; font-size: 13.5px; table-layout: fixed; }

table.files th {
  text-align: left;
  height: 40px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  border-bottom: 1px solid hsl(var(--border));
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

table.files th[aria-sort] { color: hsl(var(--foreground)); }
table.files td { padding: 8px 12px; vertical-align: middle; }

table.files th.col-size, table.files td.col-size { width: 110px; }
table.files th.col-date, table.files td.col-date { width: 160px; }
table.files th.col-check, table.files td.col-check { width: 34px; }
table.files th.col-actions, table.files td.col-actions { width: 178px; text-align: right; }

table.files tbody tr { border-bottom: 1px solid hsl(var(--border)); transition: background-color 0.12s; }
table.files tbody tr:hover { background: hsl(var(--muted) / 0.6); }
table.files tbody tr.selected { background: hsl(var(--muted)); }
table.files tbody tr.dragging { opacity: 0.45; }
table.files tbody tr.drop-target { background: hsl(var(--primary) / 0.08); box-shadow: inset 2px 0 0 0 hsl(var(--primary)); }

.name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }

.file-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: calc(var(--radius) - 3px);
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  flex: none;
}

.file-icon svg { width: 15px; height: 15px; }
.file-icon.t-dir { color: hsl(var(--foreground)); }
.file-icon.t-image { color: hsl(262 60% 55%); }
.file-icon.t-video { color: hsl(330 60% 55%); }
.file-icon.t-audio { color: hsl(160 50% 40%); }
.file-icon.t-archive { color: hsl(38 80% 45%); }
.file-icon.t-pdf { color: hsl(0 65% 55%); }
.file-icon.t-doc { color: hsl(215 65% 55%); }
.file-icon.t-sheet { color: hsl(142 55% 40%); }
.file-icon.t-code { color: hsl(190 70% 42%); }
.file-icon.t-torrent { color: hsl(275 55% 58%); }

html[data-theme="dark"] .file-icon.t-image { color: hsl(262 70% 72%); }
html[data-theme="dark"] .file-icon.t-video { color: hsl(330 70% 72%); }
html[data-theme="dark"] .file-icon.t-audio { color: hsl(160 55% 62%); }
html[data-theme="dark"] .file-icon.t-archive { color: hsl(38 80% 65%); }
html[data-theme="dark"] .file-icon.t-pdf { color: hsl(0 70% 70%); }
html[data-theme="dark"] .file-icon.t-doc { color: hsl(215 70% 72%); }
html[data-theme="dark"] .file-icon.t-sheet { color: hsl(142 55% 62%); }
html[data-theme="dark"] .file-icon.t-code { color: hsl(190 70% 65%); }
html[data-theme="dark"] .file-icon.t-torrent { color: hsl(275 65% 75%); }

.name-link {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.name-link:hover { text-decoration: underline; text-underline-offset: 2px; }
.name-sub { display: block; font-size: 12px; font-weight: 400; color: hsl(var(--muted-foreground)); }

.row-actions { display: inline-flex; gap: 2px; justify-content: flex-end; opacity: 0; transition: opacity 0.15s; }
tr:hover .row-actions, tr.selected .row-actions, tr:focus-within .row-actions { opacity: 1; }
.row-actions .icon-btn { width: 30px; height: 30px; border-radius: calc(var(--radius) - 3px); }
.row-actions .icon-btn svg { width: 15px; height: 15px; }

@media (hover: none) { .row-actions { opacity: 1; } }

.col-size, .col-date {
  color: hsl(var(--muted-foreground));
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ------------------------------------------------------- пустые состояния */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 72px 20px;
  text-align: center;
  color: hsl(var(--muted-foreground));
}

.empty svg { width: 28px; height: 28px; opacity: 0.5; margin-bottom: 8px; }
.empty p { margin: 0; font-size: 14px; font-weight: 500; color: hsl(var(--foreground)); }
.empty span { font-size: 13px; max-width: 46ch; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: hsl(var(--background) / 0.7);
  color: hsl(var(--muted-foreground));
  font-size: 13px;
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid hsl(var(--border));
  border-top-color: hsl(var(--foreground));
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------- выделение и статусбар */

.selection-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 8px 8px 8px 14px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  font-size: 13px;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
}

.statusbar > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.statusbar svg { width: 14px; height: 14px; vertical-align: -2px; }

/* -------------------------------------------------------------- drag&drop */

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 1px dashed hsl(var(--border));
  background: hsl(var(--background) / 0.85);
}

.drop-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 28px 40px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  text-align: center;
}

.drop-card svg { width: 24px; height: 24px; color: hsl(var(--muted-foreground)); margin-bottom: 6px; }
.drop-card p { margin: 0; font-size: 14px; font-weight: 500; }
.drop-card span { font-size: 12.5px; color: hsl(var(--muted-foreground)); }

/* --------------------------------------------------------------- карточки */

.card {
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
}

.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }

.card-head h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
}

.engine-status {
  margin-left: auto;
  padding: 3px 10px;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}

.engine-status.ok { color: hsl(var(--success)); border-color: hsl(var(--success) / 0.35); }
.engine-status.err { color: hsl(var(--destructive)); border-color: hsl(var(--destructive) / 0.35); }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 12.5px; font-weight: 500; color: hsl(var(--muted-foreground)); }
.field .hint { margin: 0; font-size: 12px; color: hsl(var(--muted-foreground)); }

.field code, .search-note code {
  padding: 1px 5px;
  border-radius: 4px;
  background: hsl(var(--muted));
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-bottom: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.file-name {
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.file-name.chosen { color: hsl(var(--foreground)); }

.search-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  padding: 8px 8px 8px 14px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  font-size: 13px;
}

/* -------------------------------------------------------------- загрузки */

.torrents-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin: 4px 0 14px;
}

.torrents-head h2 { margin: 0; font-size: 14.5px; font-weight: 600; }
.torrents-head .muted { margin-left: auto; font-size: 12.5px; }

.filters {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: hsl(var(--muted));
}

.filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: hsl(var(--muted-foreground));
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.filter:hover { color: hsl(var(--foreground)); }
.filter.active { background: hsl(var(--background)); color: hsl(var(--foreground)); box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); }
html[data-theme="dark"] .filter.active { background: hsl(var(--accent)); box-shadow: none; }

.filter .count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: hsl(var(--secondary));
  color: hsl(var(--muted-foreground));
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.torrent-list { display: grid; gap: 8px; }

.torrent {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
}

.torrent.state-error { border-color: hsl(var(--destructive) / 0.4); }
.torrent-top { display: flex; align-items: center; gap: 10px; }
.torrent-title { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 auto; }
.torrent-title .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.torrent-actions { display: inline-flex; gap: 2px; }
.torrent-actions .icon-btn { width: 30px; height: 30px; border-radius: calc(var(--radius) - 3px); }

.state-chip {
  padding: 2px 8px;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  background: hsl(var(--secondary));
  color: hsl(var(--muted-foreground));
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.state-chip.active { color: hsl(var(--foreground)); }
.state-chip.waiting { color: hsl(var(--warning)); border-color: hsl(var(--warning) / 0.4); }
.state-chip.complete { color: hsl(var(--success)); border-color: hsl(var(--success) / 0.4); }
.state-chip.error { color: hsl(var(--destructive)); border-color: hsl(var(--destructive) / 0.4); }

.torrent-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  font-variant-numeric: tabular-nums;
}

.torrent-stats b { color: hsl(var(--foreground)); font-weight: 500; }
.torrent-stats .err { color: hsl(var(--destructive)); }

.torrent-files { max-height: 128px; overflow: auto; font-size: 12px; color: hsl(var(--muted-foreground)); }
.torrent-files div { padding: 2px 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.torrent-kind { display: inline-flex; color: hsl(var(--muted-foreground)); }
.torrent-kind svg { width: 14px; height: 14px; }
.torrent-actions-hint { font-size: 12.5px; }
.source-hint { max-width: 44ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-hint b { color: hsl(var(--foreground)); font-weight: 400; }

/* ------------------------------------------------------------ уведомления */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 80;
  display: grid;
  gap: 8px;
  max-width: min(400px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--popover));
  color: hsl(var(--popover-foreground));
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.08);
  font-size: 13px;
  animation: toast-in 0.16s ease-out;
}

.toast svg { margin-top: 1px; }
.toast.ok svg { color: hsl(var(--success)); }
.toast.err svg { color: hsl(var(--destructive)); }
.toast.info svg { color: hsl(var(--muted-foreground)); }
.toast.fade { opacity: 0; transform: translateY(4px); transition: opacity 0.2s, transform 0.2s; }

@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* --------------------------------------------------------------- модалки */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: hsl(240 10% 4% / 0.7);
  animation: fade-in 0.12s ease-out;
}

@keyframes fade-in { from { opacity: 0; } }

.modal {
  width: 100%;
  max-width: 420px;
  padding: 24px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--background));
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);
  animation: modal-in 0.14s ease-out;
}

@keyframes modal-in { from { opacity: 0; transform: scale(0.98); } }

.modal h3 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.modal p { margin: 0 0 16px; font-size: 13px; color: hsl(var(--muted-foreground)); white-space: pre-line; }
.modal .field { margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal .warn-text { color: hsl(var(--destructive)); }
.modal-head { display: flex; align-items: flex-start; gap: 12px; }
.modal-head .modal-close { margin-left: auto; }

/* ---------------------------------------------------------- выбор папки */

.move-browser {
  margin: 4px 0 0;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  overflow: hidden;
}

.move-path {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 12px;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.5);
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
}

.move-path b { color: hsl(var(--foreground)); font-weight: 500; }
.move-list { max-height: 240px; overflow: auto; }

.move-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-bottom: 1px solid hsl(var(--border));
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}

.move-row:last-child { border-bottom: none; }
.move-row:hover { background: hsl(var(--accent)); }
.move-row svg { color: hsl(var(--muted-foreground)); }
.move-row .move-row-arrow { margin-left: auto; color: hsl(var(--muted-foreground)); }

/* ------------------------------------------------------------ просмотр */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  flex-direction: column;
  background: hsl(240 10% 3% / 0.96);
  color: hsl(0 0% 98%);
}

.viewer-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid hsl(0 0% 100% / 0.1);
}

.viewer-head .viewer-name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-head .viewer-meta { font-size: 12px; color: hsl(0 0% 100% / 0.55); }
.viewer-head .icon-btn { color: hsl(0 0% 100% / 0.7); }
.viewer-head .icon-btn:hover { background: hsl(0 0% 100% / 0.1); color: #fff; }

.viewer-body {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 16px;
}

/* В режиме плеера видео занимает всю площадь, а элементы управления лежат поверх него. */
.viewer-body.player-mode { padding: 0; }

.player {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

.player-media {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  cursor: pointer;
}

/* Звук держим в DOM для воспроизведения, но не показываем. */
.player-media.is-audio {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.viewer-stage { position: relative; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; min-height: 0; }
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: calc(var(--radius) - 2px); cursor: zoom-in; }
.viewer-stage img.zoomed { max-width: none; max-height: none; cursor: zoom-out; }

.viewer-text {
  width: min(880px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 20px 22px;
  border: 1px solid hsl(0 0% 100% / 0.1);
  border-radius: var(--radius);
  background: hsl(240 10% 6%);
  color: hsl(0 0% 92%);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.viewer-audio { display: flex; flex-direction: column; align-items: center; gap: 14px; color: hsl(0 0% 100% / 0.85); }
.viewer-audio svg { width: 56px; height: 56px; opacity: 0.5; }

.viewer-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.viewer-center button {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 999px;
  background: hsl(0 0% 100% / 0.12);
  color: #fff;
  cursor: pointer;
  transition: background-color 0.15s;
}

.viewer-center button:hover { background: hsl(0 0% 100% / 0.2); }
.viewer-center svg { width: 26px; height: 26px; }

.player-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 28px 16px 12px;
  background: linear-gradient(to top, rgb(0 0 0 / 0.85), rgb(0 0 0 / 0.45) 55%, transparent);
  transition: opacity 0.2s;
}

.player-controls.idle { opacity: 0; pointer-events: none; }
.player-controls .icon-btn { width: 34px; height: 34px; color: hsl(0 0% 100% / 0.85); }
.player-controls .icon-btn:hover { background: hsl(0 0% 100% / 0.14); color: #fff; }

/* Объяснение, почему файл не воспроизводится: кодек, который браузер не умеет. */
.player-notice {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 32px;
  text-align: center;
  background: rgb(0 0 0 / 0.78);
  color: #fafafa;
}

.player-notice svg { width: 26px; height: 26px; opacity: 0.7; margin-bottom: 4px; }
.player-notice p { margin: 0; font-size: 15px; font-weight: 600; }
.player-notice span { max-width: 56ch; font-size: 13px; line-height: 1.5; color: rgb(255 255 255 / 0.72); }
.player-notice .btn { margin-top: 16px; }

.player-time { font-size: 12.5px; color: hsl(0 0% 100% / 0.75); font-variant-numeric: tabular-nums; white-space: nowrap; }

.player-seek {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  height: 18px;
  cursor: pointer;
}

.player-seek .seek-track {
  position: relative;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: hsl(0 0% 100% / 0.18);
  overflow: hidden;
}

.player-seek .seek-buffer,
.player-seek .seek-fill { position: absolute; top: 0; left: 0; height: 100%; width: 0; }
.player-seek .seek-buffer { background: hsl(0 0% 100% / 0.28); }
.player-seek .seek-fill { background: #fff; }

.player-seek .seek-knob {
  position: absolute;
  top: 50%;
  width: 11px;
  height: 11px;
  margin-left: -5.5px;
  border-radius: 999px;
  background: #fff;
  transform: translateY(-50%) scale(0);
  transition: transform 0.12s;
}

.player-seek:hover .seek-knob, .player-seek.active .seek-knob { transform: translateY(-50%) scale(1); }

.player-volume { display: inline-flex; align-items: center; gap: 6px; }
.player-volume svg { width: 16px; height: 16px; }
.player-volume input[type="range"] {
  width: 84px;
  height: 4px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: hsl(0 0% 100% / 0.2);
  accent-color: #fff;
  cursor: pointer;
}

.player-speed {
  height: 28px;
  padding: 0 6px;
  border: 1px solid hsl(0 0% 100% / 0.18);
  border-radius: 6px;
  background: transparent;
  color: hsl(0 0% 100% / 0.85);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.player-speed option { color: #111; }

/* ------------------------------------------------------------------ вход */

.auth-body { display: flex; align-items: center; justify-content: center; padding: 24px; }

.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 28px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.06);
}

.auth-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 24px; font-size: 15px; font-weight: 600; }
.auth-brand .brand-icon { width: 20px; height: 20px; }
.auth-card h1 { margin: 0 0 6px; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.auth-hint { margin: 0 0 22px; font-size: 13px; color: hsl(var(--muted-foreground)); }
.field-label { display: block; margin: 14px 0 6px; font-size: 12.5px; font-weight: 500; color: hsl(var(--muted-foreground)); }
.auth-card .btn-block { margin-top: 22px; }

.auth-error {
  margin: 14px 0 0;
  padding: 10px 12px;
  border: 1px solid hsl(var(--destructive) / 0.3);
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--destructive) / 0.08);
  color: hsl(var(--destructive));
  font-size: 13px;
}

.auth-foot { margin: 22px 0 0; font-size: 12px; color: hsl(var(--muted-foreground)); text-align: center; }

/* -------------------------------------------------------------- адаптив */

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  table.files th.col-date, table.files td.col-date { display: none; }
}

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
  .search { order: 3; width: 100%; max-width: none; margin: 0; }
  .tabs { margin-top: 12px; }
  .layout { padding: 12px 14px 40px; }
  table.files th.col-size, table.files td.col-size { display: none; }
  table.files th.col-check, table.files td.col-check { width: 30px; padding: 0 4px 0 8px; }
  table.files th.col-actions, table.files td.col-actions { width: 104px; padding-right: 8px; }
  table.files td { padding: 8px 6px; }
  .name-cell { gap: 8px; }
  /* Кнопок в строке стало больше, на узком экране разрешаем переносить их на вторую строку. */
  .row-actions { flex-wrap: wrap; }
  .row-actions .icon-btn { width: 26px; height: 26px; }
  .row-actions .icon-btn svg { width: 14px; height: 14px; }
  #selection-info { flex: 1 1 100%; }
  .toolbar .btn span { display: none; }
  .toolbar .btn { padding: 0 10px; }
  .upload-meta .upload-name { max-width: 55%; }
  .torrents-head .muted { display: none; }
  .modal { padding: 18px; }
  .player-volume input[type="range"] { display: none; }
  .player-speed { display: none; }
  .viewer-head .viewer-meta { display: none; }
}
