:root {
  --bg: #f4f5f8; --card: #fff; --text: #1d2230; --muted: #6b7385; --line: #e3e6ee;
  --accent: #3b5bdb; --accent-2: #edf1ff; --ok: #2b8a3e; --err: #c92a2a; --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12141a; --card: #1b1e27; --text: #e8eaf0; --muted: #959cad; --line: #2b2f3b; --accent: #748ffc; --accent-2: #232a45; --ok: #69db7c; --err: #ff8787; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
button, input, .btn { font: inherit; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand img { width: 28px; height: 28px; }
nav { display: flex; gap: 6px; flex-wrap: wrap; }
main { max-width: 1100px; margin: 0 auto; padding: 20px; }
h1 { font-size: 22px; margin: 0 0 8px; } h2 { font-size: 18px; margin: 24px 0 10px; } .card h2 { margin-top: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.narrow { max-width: 380px; margin: 40px auto; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.error { color: var(--err); min-height: 1.2em; } .ok { color: var(--ok); }
.row { display: flex; gap: 8px; align-items: center; } .between { justify-content: space-between; }
label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); }
input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
button, .btn { cursor: pointer; border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; background: transparent; color: var(--text); text-decoration: none; display: inline-block; }
.primary { background: var(--accent); color: #fff; } .primary:hover { filter: brightness(1.08); }
.ghost { border-color: var(--line); background: var(--card); } .ghost:hover { background: var(--accent-2); }
.danger { border-color: var(--err); color: var(--err); background: transparent; }
.tab { border-color: transparent; } .tab.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.wide { width: 100%; margin-top: 16px; }

.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 220px; padding: 30px; border: 2px dashed var(--line); border-radius: var(--radius); background: var(--card); cursor: pointer; text-align: center; color: var(--text); font-size: 15px; transition: .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-2); }
.drop-icon { font-size: 40px; color: var(--accent); } .drop-title { font-size: 18px; font-weight: 600; }
.queue { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.queue li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.queue .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 70%; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 8px 0 4px; }
.bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.queue li.done .bar { background: var(--ok); } .queue li.failed .bar { background: var(--err); }
.status { font-size: 13px; } .status.error { color: var(--err); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tile { position: relative; padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); aspect-ratio: 1; display: flex; flex-direction: column; }
.tile img, .tile video { width: 100%; flex: 1; min-height: 0; object-fit: cover; display: block; background: #000; }
.tile-name { font-size: 12px; padding: 5px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.badge { position: absolute; top: 6px; left: 6px; font-size: 11px; background: rgba(0,0,0,.6); color: #fff; padding: 2px 6px; border-radius: 6px; max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.play { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); font-size: 28px; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.6); pointer-events: none; }
.fileicon { flex: 1; display: flex; align-items: center; justify-content: center; font-size: 42px; background: var(--accent-2); } .fileicon.big { font-size: 80px; padding: 40px; background: none; }

.link-form { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 10px; align-items: end; }
.link-form label { margin: 0; } .link-form button { height: 42px; }
.new-link { margin-top: 14px; padding: 14px; background: var(--accent-2); border-radius: 10px; } .new-link input { margin: 0; }
.links { list-style: none; padding: 0; display: grid; gap: 8px; }
.links li { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.links li.inactive { opacity: .6; }

.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 10; display: flex; flex-direction: column; }
.viewer-body { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; min-height: 0; padding: 12px; color: #fff; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-bar { display: flex; gap: 10px; align-items: center; padding: 12px 16px; background: #000; color: #fff; }
.viewer-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar .ghost { background: transparent; color: #fff; border-color: #555; }

@media (max-width: 720px) {
  main { padding: 12px; }
  .link-form { grid-template-columns: 1fr 1fr; } .link-form label:first-child, .link-form button { grid-column: 1 / -1; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .top { padding: 10px 12px; }
}

/* ---- альбом ---- */
select { font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); max-width: 100%; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar #album-count { margin-left: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg button { border-radius: 0; padding: 8px 14px; } .seg button.on { background: var(--accent); color: #fff; }
.new-banner { display: block; margin: 0 auto 12px; background: var(--accent); color: #fff; border-radius: 20px; padding: 8px 18px; position: sticky; top: 70px; z-index: 4; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.month { font-size: 16px; margin: 22px 0 10px; position: sticky; top: 58px; background: var(--bg); padding: 6px 0; z-index: 3; }
#album .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }
#album .tile { border-radius: 6px; border: 0; background: var(--line); }
#album .tile img { object-fit: cover; height: 100%; }
.sentinel { height: 1px; } .center { text-align: center; } .center-row { justify-content: center; margin: 10px 0 4px; } .wrap { flex-wrap: wrap; }
.drop { cursor: default; }

/* ---- просмотр ---- */
.nav-btn { position: absolute; top: 45%; z-index: 11; font-size: 42px; line-height: 1; color: #fff; background: rgba(0,0,0,.35); border-radius: 50%; width: 56px; height: 56px; padding: 0; }
.nav-btn.prev { left: 12px; } .nav-btn.next { right: 12px; } .nav-btn:disabled { opacity: .15; }
.viewer-info { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-info .muted { color: #aaa; }
.viewer-body { user-select: none; }

/* ---- статистика ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat-big { font-size: 28px; font-weight: 700; } .stat-label { font-weight: 500; }
.disks { display: grid; gap: 10px; } .disk { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.progress.big { height: 12px; border-radius: 6px; margin: 10px 0 6px; } .progress.warn .bar { background: var(--err); }
.years { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 6px; }
.yrow { display: grid; grid-template-columns: 50px 1fr 70px; gap: 10px; align-items: center; }
.ybar { height: 14px; background: var(--accent-2); border-radius: 4px; overflow: hidden; } .ybar div { height: 100%; background: var(--accent); border-radius: 4px; }
.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); } .table th { color: var(--muted); font-weight: 500; font-size: 13px; }

/* ---- папки ---- */
.crumbs { margin: 8px 0; font-size: 14px; }
.fs { list-style: none; padding: 0; margin: 0 0 12px; max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.fs li { border-bottom: 1px solid var(--line); } .fs li:last-child { border: 0; } .fs li.muted { padding: 10px 14px; }
.linkish { width: 100%; text-align: left; border-radius: 0; padding: 9px 14px; } .crumbs .linkish { width: auto; padding: 2px 4px; color: var(--accent); }
.linkish:hover { background: var(--accent-2); }
#folder-add .row input { flex: 1; min-width: 200px; margin: 0; }
.note { background: var(--accent-2); border-radius: 10px; padding: 12px 14px; }
.links li .row { flex-wrap: wrap; justify-content: flex-end; }

@media (max-width: 720px) {
  #album .grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 2px; }
  .nav-btn { width: 44px; height: 44px; font-size: 32px; }
  .toolbar { gap: 8px; } .toolbar select { flex: 1; } #album-refresh { display: none; }
  .toolbar #album-count { margin-left: auto; }
  nav { width: 100%; overflow-x: auto; flex-wrap: nowrap; } nav button { white-space: nowrap; }
  .month { top: 104px; }
}
