/* ============================ Базовое ============================ */
:root {
  --bg: #0b0d12;
  --bg-soft: #11141b;
  --panel: #151924;
  --panel-2: #1b2030;
  --line: #262c3d;
  --text: #e7eaf3;
  --muted: #8b93a9;
  --accent: #6b8afd;
  --accent-2: #a06bfd;
  --accent-soft: rgba(107, 138, 253, .14);
  --danger: #f2545b;
  --ok: #2ecc8f;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-soft: #ffffff;
  --panel: #ffffff;
  --panel-2: #f0f3fa;
  --line: #e2e7f2;
  --text: #131722;
  --muted: #6d768d;
  --accent: #4260e8;
  --accent-2: #8a45e0;
  --accent-soft: rgba(66, 96, 232, .1);
  --shadow: 0 18px 44px rgba(31, 45, 82, .14);
  color-scheme: light;
}

* { box-sizing: border-box; }

/* display в классах перебивает браузерный [hidden] — возвращаем приоритет */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
::selection { background: var(--accent-soft); }

/* Скроллбары */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* ============================ Кнопки ============================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--panel-2); cursor: pointer; font-weight: 500; font-size: 14px;
  transition: .15s transform, .15s background, .15s border-color, .15s opacity;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 6px 18px rgba(107, 138, 253, .28); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: var(--panel-2); }
.btn-danger { background: rgba(242, 84, 91, .12); color: var(--danger); border-color: rgba(242, 84, 91, .3); }
.btn-danger:hover { background: rgba(242, 84, 91, .2); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 9px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border-radius: 10px; border: 1px solid transparent; background: transparent;
  color: var(--muted); cursor: pointer; transition: .15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ============================ Вход ============================ */
.auth-body { display: grid; place-items: center; overflow: auto; padding: 24px; }
.aurora {
  position: fixed; inset: -30%; z-index: 0; pointer-events: none;
  background:
    radial-gradient(40% 40% at 20% 25%, rgba(107, 138, 253, .35), transparent 70%),
    radial-gradient(35% 35% at 78% 30%, rgba(160, 107, 253, .32), transparent 70%),
    radial-gradient(45% 45% at 55% 85%, rgba(46, 204, 143, .18), transparent 70%);
  filter: blur(30px);
  animation: drift 22s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate3d(3%, -3%, 0) scale(1.08); } }

.auth-card {
  position: relative; z-index: 1; width: min(400px, 100%);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: 20px;
  padding: 34px 30px; box-shadow: var(--shadow);
  display: grid; gap: 16px;
}
.auth-logo {
  width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 10px 24px rgba(107, 138, 253, .35);
}
.auth-card h1 { margin: 4px 0 0; font-size: 23px; letter-spacing: -.02em; }
.auth-sub { margin: -10px 0 6px; color: var(--muted); font-size: 14px; }

.field { display: grid; gap: 7px; }
.field > span { font-size: 13px; color: var(--muted); }
.field input {
  width: 100%; padding: 12px 14px; border-radius: 11px;
  background: var(--panel-2); border: 1px solid var(--line); outline: none;
  transition: .15s border-color, .15s box-shadow;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 44px; }
.eye { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 8px; }
.eye:hover { color: var(--text); background: var(--panel); }

.auth-error {
  background: rgba(242, 84, 91, .12); border: 1px solid rgba(242, 84, 91, .3);
  color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: 14px;
}
.shake { animation: shake .34s; }
@keyframes shake { 25% { transform: translateX(-7px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }

/* ============================ Каркас ============================ */
.app { display: grid; grid-template-columns: 268px 1fr; height: 100%; }

.sidebar {
  background: var(--bg-soft); border-right: 1px solid var(--line);
  display: grid; grid-template-rows: auto auto 1fr auto; min-height: 0;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 18px 18px 14px; }
.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}
.brand strong { display: block; font-size: 15px; letter-spacing: -.01em; }
.brand small { color: var(--muted); font-size: 12.5px; }
.sidebar-close { display: none; margin-left: auto; }

.side-actions { display: grid; gap: 8px; padding: 0 16px 14px; }

.side-scroll { overflow: auto; padding: 4px 10px 10px; min-height: 0; }
.side-title { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); padding: 6px 8px; }

.tree { display: grid; gap: 1px; }
.tree-item {
  display: flex; align-items: center; gap: 7px; padding: 7px 9px; border-radius: 9px;
  cursor: pointer; color: var(--muted); font-size: 14px; user-select: none;
  transition: .12s background, .12s color;
}
.tree-item:hover { background: var(--panel-2); color: var(--text); }
.tree-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.tree-item.drag-over { background: var(--accent-soft); outline: 1px dashed var(--accent); }
.tree-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-caret { width: 16px; flex: 0 0 16px; display: grid; place-items: center; transition: .15s transform; opacity: .6; }
.tree-caret.open { transform: rotate(90deg); }
.tree-caret.no-children { visibility: hidden; }
.tree-children { margin-left: 13px; border-left: 1px solid var(--line); padding-left: 5px; }

.side-foot { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.stats { display: grid; gap: 2px; font-size: 12.5px; color: var(--muted); flex: 1; }
.stats span { color: var(--text); font-weight: 600; }
.stat-size { color: var(--accent) !important; font-weight: 600; }
.side-foot-btns { display: flex; gap: 4px; }

/* ============================ Верхняя панель ============================ */
/* minmax(0,1fr): иначе колонка растягивается под max-content топбара и страница едет вбок */
.main { display: grid; grid-template-rows: auto auto 1fr; grid-template-columns: minmax(0, 1fr); min-width: 0; position: relative; }

.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  border-bottom: 1px solid var(--line); background: var(--bg-soft); min-height: 62px;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }

.crumbs { display: flex; align-items: center; gap: 2px; overflow: auto; scrollbar-width: none; min-width: 0; }
.crumbs::-webkit-scrollbar { display: none; }
.crumb {
  padding: 6px 10px; border-radius: 8px; cursor: pointer; color: var(--muted);
  font-size: 14px; white-space: nowrap; background: transparent; border: 0;
}
.crumb:hover { background: var(--panel-2); color: var(--text); }
.crumb.current { color: var(--text); font-weight: 600; }
.crumb-sep { color: var(--muted); opacity: .5; }

.search { position: relative; display: flex; align-items: center; min-width: 0; }
.search svg { position: absolute; left: 11px; color: var(--muted); pointer-events: none; }
.search input {
  width: 220px; min-width: 0; padding: 8px 12px 8px 34px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); outline: none; font-size: 14px;
  transition: .15s;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  width: 32px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); cursor: pointer; transition: .15s;
}
.seg button.active { background: var(--panel); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.2); }

/* ============================ Панель выделения ============================ */
.selectbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 20px; flex-wrap: wrap;
  background: var(--accent-soft); border-bottom: 1px solid var(--line); font-size: 14px;
}
.selectbar .spacer { flex: 1; }

/* ============================ Контент ============================ */
.content { overflow: auto; padding: 20px; position: relative; }

.section-title {
  font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
  margin: 4px 2px 12px;
}
.section-title:not(:first-child) { margin-top: 26px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }

.card {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  transition: .16s transform, .16s border-color, .16s box-shadow;
  animation: pop .22s ease both;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.card.drag-over { border-color: var(--accent); background: var(--accent-soft); }

.thumb { aspect-ratio: 4 / 3; background: var(--panel-2); display: grid; place-items: center; overflow: hidden; position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: .3s transform; }
.card:hover .thumb img { transform: scale(1.04); }
.thumb .ext { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; margin-top: 6px; }
.thumb .file-ico { color: var(--muted); }
.folder-thumb { background: linear-gradient(135deg, var(--accent-soft), transparent); color: var(--accent); }

.card-body { padding: 10px 12px; }
.card-name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; }

.card-check {
  position: absolute; top: 9px; left: 9px; width: 22px; height: 22px; border-radius: 7px;
  background: rgba(10, 12, 18, .6); border: 1.5px solid rgba(255, 255, 255, .5);
  display: grid; place-items: center; opacity: 0; transition: .15s; backdrop-filter: blur(4px);
  color: #fff; z-index: 2;
}
.card:hover .card-check, .card.selected .card-check { opacity: 1; }
.card.selected .card-check { background: var(--accent); border-color: var(--accent); }
.card-check svg { opacity: 0; }
.card.selected .card-check svg { opacity: 1; }

.card-more {
  position: absolute; top: 9px; right: 9px; width: 26px; height: 26px; border-radius: 8px;
  background: rgba(10, 12, 18, .6); backdrop-filter: blur(4px); border: 0; color: #fff;
  display: grid; place-items: center; opacity: 0; transition: .15s; cursor: pointer; z-index: 2;
}
.card:hover .card-more { opacity: 1; }
.card-more:hover { background: var(--accent); }

/* Список */
.list { display: grid; gap: 2px; }
.row {
  display: grid; grid-template-columns: 40px 1fr 110px 150px 34px; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 10px; cursor: pointer; transition: .12s background;
}
.row:hover { background: var(--panel); }
.row.selected { background: var(--accent-soft); }
.row.drag-over { background: var(--accent-soft); outline: 1px dashed var(--accent); }
.row-ico { width: 40px; height: 40px; border-radius: 8px; overflow: hidden; display: grid; place-items: center; background: var(--panel-2); color: var(--muted); }
.row-ico img { width: 100%; height: 100%; object-fit: cover; }
.row-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { font-size: 13px; color: var(--muted); }
.row-head { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 4px 12px; }
.row-head:hover { background: transparent; cursor: default; }

/* Пустая папка / загрузка */
.empty { display: grid; place-items: center; gap: 10px; padding: 70px 20px; text-align: center; color: var(--muted); }
.empty b { color: var(--text); font-size: 16px; }
.empty svg { opacity: .35; }

.loader { display: grid; place-items: center; padding: 70px; }
.loader span { width: 26px; height: 26px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ Drag & drop ============================ */
.dropzone {
  position: absolute; inset: 0; z-index: 30; display: none; place-items: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(4px);
  padding: 24px;
}
.dropzone.show { display: grid; }
.dropzone-inner {
  display: grid; place-items: center; gap: 8px; padding: 50px 70px;
  border: 2px dashed var(--accent); border-radius: 22px; color: var(--accent);
  background: var(--accent-soft); text-align: center;
}
.dropzone-inner span { color: var(--muted); font-size: 13px; font-family: ui-monospace, monospace; }

/* ============================ Загрузчик ============================ */
.uploader {
  position: fixed; right: 22px; bottom: 22px; z-index: 60; width: 320px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; box-shadow: var(--shadow); animation: slideUp .25s ease both;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } }
.uploader-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 14px; }
.progress { height: 6px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; border-radius: 6px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: .2s width; }
.uploader small { display: block; margin-top: 8px; color: var(--muted); font-size: 12.5px; }

/* ============================ Просмотрщик ============================ */
.lightbox {
  position: fixed; inset: 0; z-index: 80; background: rgba(5, 6, 10, .93);
  display: grid; grid-template-rows: auto 1fr auto; align-items: center;
  animation: fade .18s ease both; backdrop-filter: blur(6px);
}
@keyframes fade { from { opacity: 0; } }
.lb-top { display: flex; align-items: center; gap: 12px; padding: 14px 18px; color: #fff; }
.lb-title { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-tools { margin-left: auto; display: flex; gap: 4px; }
.lb-tools .icon-btn { color: rgba(255,255,255,.65); }
.lb-tools .icon-btn:hover { color: #fff; background: rgba(255,255,255,.12); }
#lb-img { max-width: min(1400px, 92vw); max-height: calc(100vh - 170px); margin: 0 auto; display: block; border-radius: 10px; object-fit: contain; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px;
  border-radius: 50%; border: 0; background: rgba(255,255,255,.1); color: #fff;
  display: grid; place-items: center; cursor: pointer; transition: .15s; backdrop-filter: blur(6px);
}
.lb-nav:hover { background: rgba(255,255,255,.22); }
.lb-nav.prev { left: 20px; }
.lb-nav.next { right: 20px; }
.lb-foot { padding: 14px 18px; display: grid; place-items: center; }
.lb-foot code {
  font-size: 12.5px; color: rgba(255,255,255,.72); background: rgba(255,255,255,.08);
  padding: 7px 14px; border-radius: 9px; cursor: pointer; max-width: 92vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, monospace;
}
.lb-foot code:hover { color: #fff; background: rgba(255,255,255,.15); }

/* ============================ Контекстное меню ============================ */
.ctx {
  position: fixed; z-index: 90; min-width: 196px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); animation: pop .12s ease both;
}
.ctx button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px;
  border: 0; border-radius: 8px; background: transparent; cursor: pointer;
  font-size: 14px; text-align: left; color: var(--text);
}
.ctx button:hover { background: var(--panel-2); }
.ctx button.danger { color: var(--danger); }
.ctx button.danger:hover { background: rgba(242, 84, 91, .12); }
.ctx hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }

/* ============================ Модалка ============================ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background: rgba(5, 6, 10, .6); backdrop-filter: blur(4px); animation: fade .15s ease both;
}
.modal {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 24px; box-shadow: var(--shadow); animation: pop .18s ease both;
}
.modal h3 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.modal input {
  width: 100%; padding: 11px 13px; border-radius: 10px; margin-bottom: 18px;
  background: var(--panel-2); border: 1px solid var(--line); outline: none;
}
.modal input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; }

/* ============================ Тосты ============================ */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 120; display: grid; gap: 8px; justify-items: center; }
.toast {
  display: flex; align-items: center; gap: 9px; padding: 11px 17px; border-radius: 11px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: 14px; animation: slideUp .2s ease both;
}
.toast.ok { border-color: rgba(46, 204, 143, .4); }
.toast.ok::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.toast.err { border-color: rgba(242, 84, 91, .4); }
.toast.err::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.toast.hide { animation: fadeOut .2s ease both; }
@keyframes fadeOut { to { opacity: 0; transform: translateY(8px); } }

/* Без анимаций элементы с `animation-fill-mode: both` остались бы прозрачными */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ============================ Адаптив ============================ */
.only-mobile { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 70;
    transform: translateX(-100%); transition: .22s transform; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .sidebar-close { display: grid; }
  .only-mobile { display: grid; }
  .only-desktop { display: none; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 10px; }
  .content { padding: 14px; }
  .topbar { padding: 10px 14px; }
  .row { grid-template-columns: 36px 1fr 34px; }
  .row-meta { display: none; }
  .uploader { left: 14px; right: 14px; width: auto; }
  .lb-nav { width: 40px; height: 40px; }
  .lb-nav.prev { left: 8px; }
  .lb-nav.next { right: 8px; }
}
