:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4ea;
  --text: #1c2129;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #e8efff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #15803d;
  --success-soft: #dcfce7;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2a3039;
    --text: #e7eaee;
    --muted: #9aa3b0;
    --primary: #4f8cff;
    --primary-hover: #6ea0ff;
    --primary-soft: #1a2740;
    --danger: #f87171;
    --danger-soft: #3b1d1d;
    --success: #4ade80;
    --success-soft: #16301f;
    --warning: #fbbf24;
    --warning-soft: #3a2c10;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; font-weight: 600; }
p { margin: 0 0 0.75rem; }
code { background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 5px; font-size: 0.9em; }

.container { max-width: 1040px; margin: 0 auto; padding: 24px 16px 64px; }
.container.narrow { max-width: 460px; padding-top: 48px; }

/* ---------- шапка ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--primary);
  display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 14px; font-weight: 800;
}
.nav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.nav a, .nav button { color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: 0.93rem; }
.nav a:hover, .nav button:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav .user-email { color: var(--muted); font-size: 0.85rem; padding: 0 6px; }
@media (max-width: 600px) { .nav .user-email { display: none; } }

/* ---------- карточки ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.crumbs { color: var(--muted); font-size: 0.9rem; margin-bottom: 6px; }

/* ---------- формы ---------- */
label { display: block; font-size: 0.88rem; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 72px; resize: vertical; }
.input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 180px; }
.row > .auto { flex: 0 0 auto; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }
.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 0.95rem; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 0.86rem; border-radius: 7px; }
.btn-block { width: 100%; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 0.93rem; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-info { background: var(--primary-soft); color: var(--primary); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
td.num { white-space: nowrap; color: var(--muted); }
td.name { word-break: break-word; min-width: 180px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap;
}
.badge-active { background: var(--success-soft); color: var(--success); }
.badge-expired { background: var(--warning-soft); color: var(--warning); }
.badge-disabled { background: var(--surface-2); color: var(--muted); }
.badge-admin { background: var(--primary-soft); color: var(--primary); }

/* ---------- папки (плитки) ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.tile {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; color: var(--text); box-shadow: var(--shadow); transition: border-color 0.12s, transform 0.12s;
}
.tile:hover { border-color: var(--primary); text-decoration: none; transform: translateY(-1px); }
.tile-name { font-weight: 600; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; word-break: break-word; }
.tile-meta { color: var(--muted); font-size: 0.85rem; display: flex; gap: 12px; flex-wrap: wrap; }
.folder-icon { color: var(--primary); flex: 0 0 auto; }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* ---------- раскрывающиеся панели ---------- */
details.panel { border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); margin-top: 10px; }
details.panel > summary { cursor: pointer; padding: 10px 14px; font-weight: 500; list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before { content: "▸ "; color: var(--muted); }
details.panel[open] > summary::before { content: "▾ "; }
details.panel > .panel-body { padding: 4px 14px 14px; }
.inline-panel { display: none; margin-top: 8px; padding: 12px; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--border); }
.inline-panel.open { display: block; }

/* ---------- пары «название — значение», варианты выбора (страница HTTPS) ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; font-size: 0.93rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv .badge { vertical-align: middle; margin-right: 6px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.86em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; cursor: pointer; color: var(--text); font-size: 0.95rem; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice input { margin-top: 3px; flex: 0 0 auto; }
.choice > span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.choice.disabled { opacity: 0.55; cursor: default; }
@media (max-width: 640px) {
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
  .kv dt:first-child { margin-top: 0; }
}

/* ---------- ссылка (строка) ---------- */
.link-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.link-row:last-child { border-bottom: none; }
.link-top { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.link-title { font-weight: 600; }
.link-url { display: flex; gap: 6px; align-items: center; margin: 6px 0; }
.link-url input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
.link-meta { color: var(--muted); font-size: 0.85rem; display: flex; gap: 14px; flex-wrap: wrap; }

/* ---------- загрузчик ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  transition: border-color 0.12s, background 0.12s;
  cursor: pointer;
}
.dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dropzone strong { color: var(--text); }
.dropzone input[type=file] { display: none; }
.dropzone-icon { font-size: 34px; line-height: 1; margin-bottom: 8px; }
.upload-list { list-style: none; padding: 0; margin: 14px 0 0; }
.upload-item { padding: 8px 0; border-bottom: 1px solid var(--border); }
.upload-item:last-child { border-bottom: none; }
.upload-item-head { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; }
.upload-item-name { word-break: break-word; }
.upload-item-status { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.upload-item.done .upload-item-status { color: var(--success); }
.upload-item.error .upload-item-status { color: var(--danger); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; width: 0; background: var(--primary); transition: width 0.15s; }
.upload-item.done .progress > div { background: var(--success); }
.upload-item.error .progress > div { background: var(--danger); }
.upload-summary { margin-top: 12px; font-size: 0.93rem; }

/* ---------- публичная страница ---------- */
.public-wrap { max-width: 640px; margin: 0 auto; padding: 40px 16px 64px; }
.public-brand { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; margin-bottom: 24px; }
.public-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.public-card h1 { font-size: 1.35rem; }
.public-message { background: var(--surface-2); border-left: 3px solid var(--primary); padding: 10px 14px; border-radius: 6px; margin-bottom: 18px; white-space: pre-line; }
.public-note { color: var(--muted); font-size: 0.85rem; margin-top: 16px; }
.big-icon { font-size: 44px; line-height: 1; margin-bottom: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25); opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 50;
}
.toast.show { opacity: 1; }

.stats { display: flex; gap: 24px; flex-wrap: wrap; color: var(--muted); font-size: 0.9rem; }
.stats b { color: var(--text); font-weight: 600; }
.footer { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 40px; }


td > .actions { flex-wrap: nowrap; }
.link-actions .btn { flex: 0 0 auto; }
[hidden] { display: none !important; }

/* ---------- иконки ---------- */
.icon { width: 22px; height: 22px; display: inline-block; vertical-align: middle; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- нижняя навигация (телефон) ---------- */
.bottom-nav { display: none; }
.mobile-only { display: none; }

/* ---------- планшет и телефон: крупные элементы управления ---------- */
@media (max-width: 900px), (pointer: coarse) {
  .input, select, textarea { font-size: 16px; padding: 11px 12px; }  /* 16px: iOS не приближает страницу при фокусе */
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn-sm { min-height: 40px; padding: 8px 12px; font-size: 0.9rem; }
  .nav a, .nav button { min-height: 40px; display: inline-flex; align-items: center; }
  .desktop-only { display: none; }
  .mobile-only { display: inline; }
  .dropzone { padding: 22px 12px; }
  .dropzone-icon { font-size: 30px; }
  .upload-extra { display: flex; gap: 8px; margin-top: 10px; }
  .upload-extra .btn { flex: 1 1 auto; }
  .upload-extra input[type=file] { display: none; }
}
@media (min-width: 901px) and (pointer: fine) {
  .upload-extra { display: none; }
}

/* ---------- телефон ---------- */
@media (max-width: 700px) {
  body { font-size: 15.5px; }
  h1 { font-size: 1.3rem; word-break: break-word; }
  .container { padding: 14px 12px 40px; }
  .container.narrow { padding-top: 24px; }
  .card { padding: 14px; border-radius: 12px; margin-bottom: 14px; }
  .topbar .nav { display: none; }
  .topbar-inner { height: 52px; }
  .page-head { gap: 10px; }
  .page-head .actions { width: 100%; }
  .page-head > .btn { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; }
  .card-head .btn { flex: 1 1 auto; }
  .stats { gap: 6px 16px; }
  .inline-panel { padding: 12px 10px; }

  /* нижняя панель навигации кабинета */
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 56px; padding: 6px 4px; color: var(--muted); font-size: 0.72rem; font-family: inherit;
    background: none; border: 0; cursor: pointer; text-decoration: none;
  }
  .bottom-nav a:hover, .bottom-nav a.active { color: var(--primary); text-decoration: none; }
  body.has-bottom-nav main.container { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(74px + env(safe-area-inset-bottom)); width: calc(100% - 24px); text-align: center; }
  body:not(.has-bottom-nav) .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }

  /* ссылки для загрузки */
  .link-row { padding: 14px 0; }
  .link-url { flex-wrap: wrap; }
  .link-url input { flex: 1 1 100%; }
  .link-url .btn { flex: 1 1 auto; }
  .link-meta { flex-direction: column; gap: 2px; }
  .link-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .link-actions .btn { width: 100%; }

  /* таблицы превращаются в карточки */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: var(--surface); }
  table.responsive tr:last-child td { border-bottom: 0; }
  table.responsive td { border: 0; padding: 2px 0; white-space: normal; }
  table.responsive td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 0.82rem; }
  table.responsive td.name { font-weight: 600; font-size: 1rem; padding-bottom: 4px; min-width: 0; }
  table.responsive td.name::before { content: none; }
  table.responsive td.cell-actions { padding-top: 10px; }
  table.responsive td.cell-actions::before { content: none; }
  td > .actions { flex-wrap: wrap; }
  td > .actions .btn { flex: 1 1 auto; }
  td > .actions .inline-panel { flex: 1 1 100%; }

  /* публичная страница */
  .public-wrap { padding: 20px 12px 48px; }
  .public-card { padding: 20px 16px; border-radius: 12px; }
  .public-card h1 { font-size: 1.2rem; }
  .public-brand { margin-bottom: 14px; }
  .upload-item-head { flex-direction: column; gap: 2px; align-items: flex-start; }
  .upload-item-status { white-space: normal; }
  .grid { gap: 10px; }
}

/* ---------- планшет: две колонки плиток, обычная верхняя навигация ---------- */
@media (min-width: 701px) and (max-width: 1024px) {
  .container { padding: 20px 16px 56px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- v2: выбор файлов, панель загрузки, предпросмотр, корзина, ошибки ---------- */
.cell-check { width: 32px; }
.cell-check input { width: 18px; height: 18px; cursor: pointer; }
.selection-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--primary-soft); color: var(--primary);
  position: sticky; top: 8px; z-index: 5;
}
.selection-bar b { color: var(--primary); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

.upload-extra-all { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.upload-extra-all input[type=file] { display: none; }
.upload-extra-all .btn { flex: 1 1 auto; }
.mobile-only-flex { display: none; }
@media (max-width: 900px), (pointer: coarse) { .mobile-only-flex { display: inline-flex; } }
.upload-panel { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.upload-panel-text { font-weight: 600; margin-bottom: 6px; }
.upload-panel .progress { height: 8px; }
.upload-panel .btn { margin-top: 10px; }
.upload-panel-sub { margin-top: 6px; }
.quota-bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.quota-bar > div { height: 100%; background: var(--primary); }
.push-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* предпросмотр */
.preview-bar .topbar-inner { gap: 12px; }
.preview-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.preview-nav { margin-left: 0; }
.preview-wrap { max-width: none; padding: 0; height: calc(100vh - 56px); height: calc(100dvh - 56px); }
body.has-bottom-nav main.preview-wrap { padding-bottom: 0; }
.preview-frame { display: block; width: 100%; height: 100%; border: 0; background: var(--surface); }
.preview-frame-text { background: #fff; }
.preview-stage { height: 100%; display: flex; align-items: center; justify-content: center; padding: 12px; background: #0f1216; }
.preview-image { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.preview-media { max-width: 100%; max-height: 100%; }
.preview-stage-audio { flex-direction: column; gap: 16px; background: var(--bg); }
.preview-wrap .error-card { max-width: 460px; margin: 40px auto; }

/* страницы ошибок */
.error-card { text-align: center; }
.error-card .illus { max-width: 100%; height: auto; color: var(--text); margin-bottom: 4px; }
.error-code { font-size: 0.85rem; font-weight: 700; letter-spacing: 0.12em; color: var(--muted); margin-bottom: 4px; }
.error-card h1 { margin-bottom: 8px; }

@media (max-width: 700px) {
  .selection-bar { top: 0; }
  .selection-bar .actions { width: 100%; }
  .selection-bar .actions .btn { flex: 1 1 auto; }
  .cell-check { display: inline-block !important; width: auto; padding: 0 8px 0 0 !important; float: left; }
  table.responsive td.cell-check::before { content: none; }
  .preview-wrap { height: auto; min-height: calc(100vh - 52px); }
  .preview-frame { height: 80vh; }
  .preview-stage { min-height: 60vh; height: auto; }
  .preview-title { font-size: 0.9rem; }
  .pager { justify-content: center; }
}
