:root {
  --bg-outer: #111111;
  --bg-app: #1c1c1c;
  --bg-panel: #222222;
  --accent: #E8E8C6;
  --accent-dim: rgba(232, 232, 198, 0.1);
  --text-main: #E8E8C6;
  --muted: #888888;
  --border-light: rgba(255, 255, 255, 0.08);
  --danger: #ff4b4b;
  --radius: 16px;
  --radius-pill: 40px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%; margin: 0; padding: 0;
  background: var(--bg-outer);
  font-family: 'Space Mono', ui-sans-serif, system-ui, sans-serif;
  color: var(--text-main);
}

a { color: inherit; text-decoration: none; }
button, input { font-family: inherit; }

body { display: flex; align-items: center; justify-content: center; padding: 2vw; }

.app {
  width: 100%; max-width: 1400px; height: 100%; max-height: 900px;
  background: var(--bg-app); border-radius: var(--radius);
  border: 1px solid var(--border-light);
  display: grid; grid-template-columns: 320px 1fr; overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,0.8);
}

/* Sidebar */
.sidebar { border-right: 1px solid var(--border-light); padding: 20px; display: flex; flex-direction: column; gap: 20px; background: #161616; }

.brand { display: flex; gap: 12px; align-items: center; }
.avatar { width: 42px; height: 42px; border-radius: 8px; background: var(--accent); color: var(--bg-app); display: flex; align-items: center; justify-content: center; font-family: 'Silkscreen', cursive; font-size: 18px; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.brandTitle { font-family: 'Silkscreen', cursive; font-size: 16px; line-height: 1.2; }
.brandSub { font-size: 12px; color: var(--muted); }

.sidebarSection { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; }
.sidebarHeader { color: var(--muted); font-size: 14px; margin-bottom: 5px; }

.homeBtn { width: 100%; display: flex; gap: 10px; align-items: center; justify-content: center; padding: 12px 14px; border: 1px solid var(--border-light); border-radius: var(--radius-pill); background: var(--bg-panel); color: var(--text-main); cursor: pointer; transition: 0.2s; font-weight: bold; }
.homeBtn:hover { background: var(--accent-dim); border-color: var(--accent); }

/* --- МАГИЯ КАРТОЧЕК ПАПОК БЕЗ ГРАДИЕНТОВ --- */
.folderList {
  overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
  padding: 5px; padding-bottom: 20px;
  counter-reset: folder-counter;
}

.folderRow {
  position: relative; display: block; width: 100%; height: 105px; padding: 0;
  border: 1px solid var(--border-light);
  border-radius: 16px; overflow: visible; /* Чтобы анимация файлов не обрезалась рамкой */
  cursor: pointer;
  counter-increment: folder-counter;
  background: var(--bg-panel);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.folderRow:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,0.5); border-color: var(--accent); z-index: 10; }
.folderRow.active { border-color: var(--accent); background: rgba(232, 232, 198, 0.05); }

/* Иконка и Контейнер для веера файлов */
.folderIcon {
  position: absolute; top: 15px; right: 30px;
  width: 44px; height: 44px; z-index: 0;
}

/* Реальные картинки, которые вставит JS */
.fan-img {
  position: absolute; top: 0; left: 0;
  width: 44px; height: 44px;
  border-radius: 6px; border: 2px solid var(--bg-panel);
  object-fit: cover; background: #333;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Расстановка веером по умолчанию */
.fan-0 { z-index: 3; transform: rotate(0deg); }
.fan-1 { z-index: 2; transform: rotate(-12deg) translate(-6px, 3px); filter: brightness(0.8); }
.fan-2 { z-index: 1; transform: rotate(12deg) translate(6px, 3px); filter: brightness(0.6); }

/* Анимация при наведении мышки на карточку папки */
.folderRow:hover .fan-0 { transform: translateY(-10px); }
.folderRow:hover .fan-1 { transform: rotate(-25deg) translate(-20px, 2px); filter: brightness(0.9); }
.folderRow:hover .fan-2 { transform: rotate(25deg) translate(20px, 2px); filter: brightness(0.9); }

/* Эмодзи заглушка, если в папке нет картинок */
.empty-folder-icon { font-size: 32px; filter: grayscale(1); opacity: 0.4; }

/* Тексты внутри папки */
.folderName {
  position: absolute; top: 54%; left: 15px; right: 80px; z-index: 2;
  font-size: 15px; font-weight: bold; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Читаем дату из атрибута data-date (ее установит JS) */
.folderName::after {
  content: attr(data-date); display: block; font-size: 10px; color: var(--muted);
  margin-top: 2px; font-weight: normal; font-family: 'Space Mono', monospace;
}

.folderMeta {
  position: absolute; bottom: 10px; right: 15px; z-index: 2;
  font-size: 13px; font-weight: bold; color: #fff;
}
.folderMeta::after { content: ' шт.'; font-weight: normal; font-size: 11px; color: rgba(255,255,255,0.5); }

.folderRow::after {
  content: "0" counter(folder-counter);
  position: absolute; bottom: 10px; left: 15px; z-index: 2;
  font-size: 16px; font-weight: bold; color: #fff; letter-spacing: 1px; opacity: 0.6;
}

.folderTrash {
  position: absolute; top: -10px; left: -10px; z-index: 5; background: var(--bg-panel); border: 1px solid var(--danger); border-radius: 50%; width: 26px; height: 26px; color: var(--danger); font-size: 12px; display: flex; align-items: center; justify-content: center; opacity: 0; transition: 0.2s; cursor: pointer; box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}
.folderRow:hover .folderTrash { opacity: 1; transform: translate(5px, 5px); }
.folderTrash:hover { background: var(--danger); color: #fff; transform: translate(5px, 5px) scale(1.1); }

.smallMuted { font-size: 12px; color: var(--muted); }

/* --- ОСТАЛЬНАЯ ЧАСТЬ ИНТЕРФЕЙСА --- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.hero-title { font-family: 'Silkscreen', cursive; font-size: clamp(30px, 5vw, 64px); text-align: center; padding: 30px 20px 20px; color: var(--accent); letter-spacing: 2px; border-bottom: 1px solid var(--border-light); line-height: 1; }

.topbar, .toolbar { padding: 15px 25px; display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.crumb { border: 1px solid var(--border-light); padding: 6px 16px; border-radius: var(--radius-pill); font-size: 14px; background: var(--bg-panel); }
.crumb strong { font-weight: bold; color: #fff;}

.topActions { display: flex; align-items: center; gap: 15px; }
.search input { width: 250px; padding: 8px 16px; border-radius: var(--radius-pill); border: 1px solid var(--border-light); background: transparent; color: var(--text-main); outline: none; transition: 0.2s; }
.search input:focus { border-color: var(--accent); background: var(--bg-panel); }

.seg { display: flex; border: 1px solid var(--border-light); border-radius: var(--radius-pill); overflow: hidden; }
.segBtn { padding: 6px 16px; border: none; background: transparent; color: var(--text-main); cursor: pointer; }
.segBtn.active { background: var(--accent); color: var(--bg-app); font-weight: bold;}

.check { display: flex; gap: 10px; align-items: center; cursor: pointer; font-size: 14px; }
.check input { appearance: none; width: 16px; height: 16px; border: 1px solid var(--accent); border-radius: 4px; background: transparent; cursor: pointer; position: relative; }
.check input:checked::after { content: '✓'; position: absolute; top: -3px; left: 2px; color: var(--accent); font-size: 14px; }
.pill { border: 1px solid var(--border-light); border-radius: var(--radius-pill); padding: 6px 12px; font-size: 12px; background: var(--bg-panel); }

.btn { padding: 8px 18px; border-radius: var(--radius-pill); border: 1px solid var(--border-light); background: var(--bg-panel); color: var(--text-main); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: 0.2s; }
.btn:hover { background: var(--accent); color: var(--bg-app); border-color: var(--accent); }
.btn.danger { border-color: rgba(255, 107, 107, 0.4); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn:disabled { opacity: 0.3; cursor: not-allowed; }

.iconBtn { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border-light); background: transparent; color: var(--text-main); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: 0.2s; }
.iconBtn:hover { background: var(--accent); color: var(--bg-app); }

.content { padding: 0 25px 25px 25px; overflow: auto; flex: 1; }
.empty { border: 1px dashed var(--border-light); border-radius: var(--radius); padding: 40px; text-align: center; margin-top: 20px; }
.emptyTitle { font-family: 'Silkscreen', cursive; font-size: 20px; margin-bottom: 10px; color: var(--accent); }

/* Сетка (Плитка) */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; }
@media (max-width: 1200px){ .grid{ grid-template-columns: repeat(3, 1fr);} }
@media (max-width: 900px){ .grid{ grid-template-columns: repeat(2, 1fr);} }
@media (max-width: 600px){ .app{ grid-template-columns: 1fr; border-radius: 0; border: none; max-height: 100vh;} .sidebar{ display:none; } .grid{ grid-template-columns: repeat(2, 1fr); } .search input { width: 150px; } }

.card { border: 1px solid var(--border-light); border-radius: var(--radius); overflow: hidden; cursor: pointer; position: relative; background: var(--bg-panel); transition: 0.2s; }
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.cardTop { position: relative; aspect-ratio: 1 / 1; background: #161616; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.thumb { width: 100%; height: 100%; object-fit: cover; }
.fileIcon { font-family: 'Silkscreen', cursive; font-size: 30px; color: var(--muted); }

.fileBadge { position: absolute; left: 10px; top: 10px; padding: 4px 8px; border-radius: var(--radius-pill); font-size: 10px; border: 1px solid var(--border-light); background: rgba(37, 37, 37, 0.8); backdrop-filter: blur(4px); }
.selBox { position: absolute; right: 10px; top: 10px; width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border-light); background: rgba(37, 37, 37, 0.8); display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 3; }
.selBox input { appearance: none; width: 14px; height: 14px; cursor: pointer; position: relative; }
.selBox input:checked::after { content: '✓'; position: absolute; top: -4px; left: 2px; color: var(--accent); font-size: 14px; }
.cardBottom { padding: 12px; }
.fileName { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: bold; }
.fileMeta { margin-top: 4px; font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }

/* Вид списком */
.list { border: 1px solid var(--border-light); border-radius: var(--radius); overflow: hidden; background: var(--bg-panel);}
.listHeader, .listRow { display: grid; grid-template-columns: 40px 60px 1fr 100px 100px 120px 180px; gap: 10px; align-items: center; padding: 12px 15px; }
.listHeader { color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border-light); background: #161616; }
.listRow { border-bottom: 1px solid var(--border-light); cursor: pointer; transition: 0.2s; }
.listRow:last-child { border-bottom: 0; }
.listRow:hover { background: var(--accent-dim); }
.listThumb { width: 50px; height: 40px; border-radius: 6px; background: #161616; overflow: hidden; display: flex; align-items: center; justify-content: center; font-size: 10px; }
.listThumb img, .listThumb video { width: 100%; height: 100%; object-fit: cover; }
.listName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: bold; }
.listCell { color: var(--muted); font-size: 12px; }
.listActions { display: flex; gap: 8px; justify-content: flex-end; }
.listActions a, .listActions button { padding: 4px 10px; border-radius: var(--radius-pill); border: 1px solid var(--border-light); background: transparent; font-size: 12px; cursor: pointer; transition: 0.2s; color: var(--text-main); }
.listActions a:hover, .listActions button:hover { background: var(--accent); color: var(--bg-app); border-color: var(--accent); }

/* Модальное окно */
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 50; }
.modalBackdrop { position: absolute; inset: 0; background: rgba(17, 17, 17, 0.85); backdrop-filter: blur(5px); }
.modalCard { position: relative; width: min(800px, 94vw); max-height: 85vh; background: var(--bg-app); border: 1px solid var(--border-light); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,0.8); }
.modalTop { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; border-bottom: 1px solid var(--border-light); background: var(--bg-panel); }
.modalTitle { font-family: 'Space Mono', monospace; font-weight: bold; font-size: 18px; color: #fff; }
.modalBody { padding: 20px; overflow: auto; min-height: 0; display: flex; justify-content: center; }
.modalBody img, .modalBody video { max-width: 100%; max-height: 60vh; border-radius: 8px; border: 1px solid var(--border-light); }
.modalBottom { padding: 15px 20px; border-top: 1px solid var(--border-light); display: flex; gap: 10px; justify-content: flex-end; background: var(--bg-panel); }

/* Скроллбар */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }
