/* Galerie - vzhled */
:root {
  --bg: #0f1116;
  --bg-2: #161922;
  --bg-3: #1d212c;
  --line: #272c3a;
  --fg: #e9ebf2;
  --fg-dim: #99a0b3;
  --accent: #6b8afd;
  --accent-soft: rgba(107, 138, 253, .16);
  --danger: #ef5b6b;
  --heart: #ff5470;
  --radius: 14px;
  --topbar-h: 60px;
  --sidebar-w: 274px;
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* --------------------------------------------------------------- tlacitka */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 11px; border: 1px solid transparent;
  background: var(--bg-3); cursor: pointer; font-weight: 500;
  transition: background .15s, border-color .15s, transform .06s;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: #0c1020; font-weight: 600; }
.btn-primary:hover { background: #7f9bff; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--fg-dim); }
.btn-ghost:hover { color: var(--fg); border-color: #3a4258; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; flex: 0 0 auto;
  border: 0; background: transparent; color: var(--fg-dim); border-radius: 10px; cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-3); color: var(--fg); }
.icon-btn.on { color: var(--heart); }
.icon-btn.on svg { fill: var(--heart); stroke: var(--heart); }
.mini-btn {
  width: 24px; height: 24px; border-radius: 7px; border: 1px solid var(--line);
  background: transparent; color: var(--fg-dim); cursor: pointer; line-height: 1;
}
.mini-btn:hover { color: var(--fg); border-color: var(--accent); }
.link-btn { background: none; border: 0; color: var(--fg-dim); cursor: pointer; padding: 6px 0; text-align: left; }
.link-btn:hover { color: var(--accent); }
.select {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; cursor: pointer;
}
.select.wide { width: 100%; }

/* ------------------------------------------------------------ prihlaseni */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.gate-card {
  width: min(400px, 100%); background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 20px; padding: 30px 26px 26px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.2px; }
.brand-mark { color: var(--accent); }
.brand-lg { font-size: 22px; justify-content: center; margin-bottom: 24px; }
.brand-lg .brand-mark { width: 30px; height: 30px; }
.gate-note {
  margin: -8px 0 18px; padding: 12px 14px; border-radius: 11px;
  background: var(--accent-soft); border: 1px solid rgba(107,138,253,.35);
  color: var(--fg); font-size: 13.5px; line-height: 1.5;
}

.tabs { display: flex; gap: 4px; background: var(--bg-3); padding: 4px; border-radius: 12px; margin-bottom: 20px; }
.tab { flex: 1; padding: 9px; border: 0; border-radius: 9px; background: transparent; color: var(--fg-dim); cursor: pointer; }
.tab.is-active { background: var(--bg); color: var(--fg); font-weight: 600; }
.gate-form { display: grid; gap: 14px; }
.gate-form label { display: grid; gap: 6px; font-size: 13px; color: var(--fg-dim); }
.gate-form input {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 11px;
  padding: 12px 14px; font-size: 15px;
}
.gate-form input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.gate-form .btn { margin-top: 4px; padding: 13px; }
.hint { opacity: .65; }
.gate-error { margin: 16px 0 0; padding: 11px 14px; border-radius: 11px; background: rgba(239,91,107,.13); color: #ffb0ba; font-size: 14px; }

/* ---------------------------------------------------------------- topbar */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: rgba(15,17,22,.88); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar .brand { width: calc(var(--sidebar-w) - 24px); font-size: 17px; }
.search { position: relative; flex: 1; max-width: 620px; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--fg-dim); }
.search input {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 36px 10px 38px; font-size: 14px;
}
.search input:focus { outline: none; border-color: var(--accent); background: var(--bg-3); }
.search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border: 0; border-radius: 7px; background: transparent; color: var(--fg-dim); font-size: 20px; cursor: pointer; }

/* --------------------------------------------------------------- layout */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 auto; padding: 16px 12px 24px;
  border-right: 1px solid var(--line); overflow-y: auto;
  position: sticky; top: var(--topbar-h); height: calc(100dvh - var(--topbar-h));
}
.btn-add { width: 100%; margin-bottom: 18px; }
.nav { display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 11px;
  border: 0; border-radius: 10px; background: transparent; color: var(--fg-dim);
  cursor: pointer; text-align: left;
}
.nav-item svg { width: 19px; height: 19px; flex: 0 0 auto; }
.nav-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item em { font-style: normal; font-size: 12px; opacity: .6; }
.nav-item:hover { background: var(--bg-2); color: var(--fg); }
.nav-item.is-active { background: var(--accent-soft); color: var(--fg); font-weight: 550; }
.nav-item.is-active svg { color: var(--accent); }

.side-head { display: flex; align-items: center; justify-content: space-between; margin: 22px 4px 8px; }
.side-head h2 { margin: 0; font-size: 11.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--fg-dim); }
.tree { display: grid; gap: 1px; }
.tree-row { display: flex; align-items: center; gap: 2px; border-radius: 10px; }
.tree-row.is-active { background: var(--accent-soft); }
.tree-row.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }
.twisty { width: 20px; height: 28px; border: 0; background: none; color: var(--fg-dim); cursor: pointer; padding: 0; }
.twisty svg { width: 13px; height: 13px; transition: transform .15s; }
.twisty.open svg { transform: rotate(90deg); }
.tree-btn {
  flex: 1; display: flex; align-items: center; gap: 9px; padding: 7px 9px 7px 0;
  border: 0; background: none; color: var(--fg-dim); cursor: pointer; text-align: left; min-width: 0;
}
.tree-row.is-active .tree-btn { color: var(--fg); font-weight: 550; }
.tree-btn:hover { color: var(--fg); }
.tree-btn svg { width: 17px; height: 17px; flex: 0 0 auto; color: #8d97b5; }
.tree-btn span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-btn em { font-style: normal; font-size: 11.5px; opacity: .55; }
.tree-more { width: 26px; height: 28px; border: 0; background: none; color: var(--fg-dim); cursor: pointer; opacity: 0; }
.tree-row:hover .tree-more { opacity: 1; }
.tree-more svg { width: 15px; height: 15px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 4px; }
.tag-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--fg-dim);
  font-size: 12.5px; cursor: pointer;
}
.tag-pill .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.tag-pill.is-active { border-color: var(--accent); color: var(--fg); background: var(--accent-soft); }
.side-foot { margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--line); display: grid; gap: 2px; }

.scrim { display: none; }

/* --------------------------------------------------------------- obsah */
.content { flex: 1; min-width: 0; padding: 20px 22px 90px; }
.content-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.content-head h1 { margin: 0; font-size: 23px; letter-spacing: -.4px; }
.crumbs { margin: 4px 0 0; font-size: 13px; color: var(--fg-dim); }
.head-actions { display: flex; gap: 8px; align-items: center; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 8px 5px 11px;
  border-radius: 999px; background: var(--bg-3); border: 1px solid var(--line); font-size: 12.5px;
}
.chip button { border: 0; background: none; color: var(--fg-dim); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; }

.grid {
  display: grid; gap: 6px;
  grid-template-columns: repeat(auto-fill, minmax(clamp(104px, 15vw, 190px), 1fr));
}
.cell {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: var(--bg-2); cursor: pointer; border: 2px solid transparent;
}
.cell img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; }
.cell img.loaded { opacity: 1; }
.cell.is-selected { border-color: var(--accent); }
.cell.is-selected img { transform: scale(.93); transition: transform .12s; }
.cell-fav {
  position: absolute; right: 4px; bottom: 4px; width: 32px; height: 32px;
  display: grid; place-items: center; border: 0; border-radius: 50%; cursor: pointer;
  background: rgba(10,12,18,.45); color: #fff; backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .15s;
}
.cell:hover .cell-fav, .cell-fav.on { opacity: 1; }
.cell-fav svg { width: 17px; height: 17px; }
.cell-fav.on svg { fill: var(--heart); stroke: var(--heart); }
.cell-check {
  position: absolute; left: 5px; top: 5px; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.8); background: rgba(10,12,18,.35); display: none;
}
body.selecting .cell-check { display: block; }
.cell.is-selected .cell-check { background: var(--accent); border-color: var(--accent); }
.cell-video { position: absolute; left: 6px; bottom: 6px; color: #fff; filter: drop-shadow(0 1px 3px rgba(0,0,0,.6)); }
.cell-video svg { width: 18px; height: 18px; }

.empty { padding: 60px 20px; text-align: center; color: var(--fg-dim); }
.empty strong { display: block; font-size: 17px; color: var(--fg); margin-bottom: 6px; }
.more { display: block; margin: 22px auto 0; }

/* --------------------------------------------------------- vyberova lista */
.selbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 60; display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 12px 34px rgba(0,0,0,.5); max-width: calc(100vw - 24px); overflow-x: auto;
}
.selbar strong { font-size: 13.5px; white-space: nowrap; }
.selbar-actions { display: flex; gap: 6px; }
.chip-btn {
  padding: 7px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-2); cursor: pointer; font-size: 13px; white-space: nowrap;
}
.chip-btn:hover { border-color: var(--accent); }
.chip-btn.danger { color: #ff9aa5; }
.chip-btn.danger:hover { border-color: var(--danger); }

/* -------------------------------------------------------------- lightbox */
.viewer { position: fixed; inset: 0; z-index: 90; background: #06070b; display: flex; flex-direction: column; }
.viewer-top {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: linear-gradient(#0a0c12ee, #0a0c1200); position: absolute; inset: 0 0 auto; z-index: 6;
}
.viewer-name { flex: 1; font-size: 14px; color: var(--fg-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-tools { display: flex; gap: 2px; }
.viewer-tools .icon-btn { color: #cfd4e2; }
.viewer-stage { flex: 1; display: grid; place-items: center; padding: 60px 12px 20px; min-height: 0;
  transition: padding-right .2s; }
.viewer.panel-open .viewer-stage { padding-right: 342px; }
.viewer.panel-open .nav-arrow.right { right: 354px; }
.viewer-stage img, .viewer-stage video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.nav-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 3;
  width: 46px; height: 46px; display: grid; place-items: center; cursor: pointer;
  border: 0; border-radius: 50%; background: rgba(255,255,255,.07); color: #fff;
}
.nav-arrow:hover { background: rgba(255,255,255,.15); }
.nav-arrow.left { left: 12px; }
.nav-arrow.right { right: 12px; }
.viewer-panel {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(330px, 86vw); z-index: 4;
  background: var(--bg-2); border-left: 1px solid var(--line); padding: 74px 18px 24px;
  overflow-y: auto;
}
.viewer-panel h3 { margin: 20px 0 8px; font-size: 11.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--fg-dim); }
.viewer-panel h3:first-of-type { margin-top: 0; }
.viewer-panel dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 13.5px; }
.viewer-panel dt { color: var(--fg-dim); }
.viewer-panel dd { margin: 0; overflow-wrap: anywhere; }
.viewer-panel textarea {
  width: 100%; background: var(--bg-3); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; resize: vertical; font-size: 14px;
}
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }

/* --------------------------------------------------------------- dialogy */
.dlg {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--fg);
  border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 32px));
  box-shadow: 0 22px 60px rgba(0,0,0,.6);
}
.dlg::backdrop { background: rgba(5,6,10,.66); backdrop-filter: blur(3px); }
.dlg-body { padding: 22px 22px 18px; }
.dlg h2 { margin: 0 0 4px; font-size: 18px; }
.dlg p.sub { margin: 0 0 16px; color: var(--fg-dim); font-size: 13.5px; }
.dlg label { display: grid; gap: 6px; font-size: 13px; color: var(--fg-dim); margin-bottom: 14px; }
.dlg input[type=text], .dlg input[type=password], .dlg input[type=url], .dlg select {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; font-size: 15px; width: 100%;
}
.dlg .row { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; font-size: 14px; color: var(--fg); }
.dlg .row input { width: auto; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 20px; }
.share-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.share-tile {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 6px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg-3); color: var(--fg); font-size: 12.5px; cursor: pointer;
  text-decoration: none; transition: border-color .15s, transform .06s;
}
.share-tile:hover { border-color: var(--accent); }
.share-tile:active { transform: scale(.97); }
.share-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; }
.share-icon svg { width: 20px; height: 20px; }

.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; font-size: 13px; }
.opt-list { display: grid; gap: 8px; margin-bottom: 16px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg-3);
}
.opt:hover { border-color: var(--accent); }
.opt svg { width: 21px; height: 21px; color: var(--accent); flex: 0 0 auto; margin-top: 1px; }
.opt > span { flex: 1; min-width: 0; }
.opt b { display: block; font-weight: 600; }
.opt small { color: var(--fg-dim); }
.add-folder { margin: -6px 0 14px; color: var(--accent); font-size: 13.5px; }
.add-folder:hover { color: #9db2ff; }
.pick-tree { max-height: 260px; overflow-y: auto; margin-bottom: 16px; }

.ctx-menu {
  position: fixed; z-index: 150; min-width: 210px; padding: 6px;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 16px 44px rgba(0,0,0,.55);
}
.ctx-menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 8px; }
.ctx-item {
  display: block; width: 100%; text-align: left; padding: 9px 12px;
  border: 0; border-radius: 8px; background: none; color: var(--fg);
  cursor: pointer; font-size: 14px; white-space: nowrap;
}
.ctx-item:hover { background: var(--accent-soft); }
.ctx-item.danger { color: #ff9aa5; }
.ctx-item.danger:hover { background: rgba(239,91,107,.15); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; z-index: 200;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 18px; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  max-width: calc(100vw - 32px);
}
.toast.err { border-color: var(--danger); color: #ffb0ba; }

.spinner {
  width: 17px; height: 17px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- responzivni */
.only-mobile { display: none; }
@media (max-width: 860px) {
  .only-mobile { display: grid; }
  .only-desktop { display: none; }
  .topbar { gap: 6px; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; height: 100dvh; z-index: 70;
    width: 290px; background: var(--bg-2); transform: translateX(-102%);
    transition: transform .22s ease; padding-top: calc(18px + env(safe-area-inset-top));
  }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(5,6,10,.6); }
  .content { padding: 16px 12px 110px; }
  .content-head h1 { font-size: 19px; }
  .grid { gap: 3px; }
  .cell { border-radius: 7px; }
  .cell-fav { opacity: 1; background: rgba(10,12,18,.32); }
  .nav-arrow { display: none; }
  .viewer-panel { width: 100%; top: auto; height: 62dvh; border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; padding-top: 20px; }
}
