/* --- tokens, monochrome, dark + light via data-theme --- */
:root {
  --bg: #121212; --panel: #1b1b1b; --panel-2: #222; --border: #333;
  --text: #e8e8e8; --muted: #9a9a9a; --row-hover: #262626;
  --btn: #2a2a2a; --btn-hover: #383838; --input: #1a1a1a;
  --accent: #6b9bd1; --sel: rgba(120,160,220,.22); --danger: #e05656;
}
:root[data-theme="light"] {
  --bg: #f4f4f5; --panel: #fff; --panel-2: #f6f6f7; --border: #dcdcdc;
  --text: #1a1a1a; --muted: #6a6a6a; --row-hover: #eee;
  --btn: #ececec; --btn-hover: #e0e0e0; --input: #fff;
  --sel: rgba(90,140,210,.18); --danger: #c23a3a;
}
* { box-sizing: border-box; }
html, body { height: 100%; background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
.hidden { display: none !important; }

button, input, select { font: inherit; color: var(--text); }
button { background: var(--btn); border: 1px solid var(--border); padding: 6px 12px; cursor: pointer; border-radius: 7px; }
button:hover { background: var(--btn-hover); }
input, select { background: var(--input); border: 1px solid var(--border); padding: 7px 10px; border-radius: 7px; }
input:focus, button:focus, select:focus { outline: 1px solid var(--muted); }
.iconbtn { background: transparent; border: 0; padding: 6px; border-radius: 8px; color: var(--text); display: inline-flex; }
.iconbtn:hover { background: var(--row-hover); }
.btn-primary { background: #f2f2f4; border: 1px solid rgba(0,0,0,.14); color: #1a1a1a; font-weight: 600; }
.btn-primary:hover { background: #fff; box-shadow: 0 0 0 2px var(--sel); }
.btn-danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn-ghost { background: transparent; }

/* --- login: just the QR --- */
.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; }
.login-qr { width: 300px; height: 300px; }
.login-qr svg { width: 100%; height: 100%; display: block; }
.login-loading { display: flex; align-items: center; justify-content: center; width: 300px; height: 300px; }
.spinner { width: 46px; height: 46px; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- topbar --- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; background: var(--panel); border-bottom: 1px solid var(--border); padding: 0 14px; height: 50px; }
.tb-left { display: flex; align-items: center; gap: 12px; }
.tb-right { display: flex; align-items: center; gap: 4px; }
.brand { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.vault-btn { display: inline-flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--border); padding: 5px 10px; border-radius: 9px; font-weight: 600; }
.swatch { width: 16px; height: 16px; border-radius: 6px; border: 1px solid rgba(0,0,0,.25); display: inline-block; }

/* --- main / toolbar --- */
.main { flex: 1; width: 100%; max-width: 1150px; margin: 0 auto; padding: 14px 16px 60px; display: flex; flex-direction: column; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.toolbar #view-menu { flex: none; }
.crumbs { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.crumbs a { color: var(--text); text-decoration: none; cursor: pointer; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { color: var(--muted); }

/* --- file area --- */
.filearea { position: relative; flex: 1; min-height: 300px; border: 1px solid transparent; border-radius: 10px; }
.filearea.dropping { border: 2px dashed var(--accent); background: var(--sel); }
table.files { width: 100%; border-collapse: collapse; }
.files th, .files td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
.files th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.files td.num, .files th.num { text-align: right; }
.files tbody tr { cursor: default; user-select: none; }
.files tbody tr:hover { background: var(--row-hover); }
.files tbody tr.sel { background: var(--sel); }
.files .name { display: flex; align-items: center; gap: 9px; }
.files .name .icon { width: 20px; height: 20px; flex: none; }
.files th.chk, .files td.chk { width: 30px; text-align: center; padding-right: 0; }
.rowchk { display: none; width: auto; }
.filearea.has-selection .rowchk { display: inline-block; }

/* grid */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 4px; }
.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: 10px; cursor: default; user-select: none; text-align: center; }
.tile:hover { background: var(--row-hover); }
.tile.sel { background: var(--sel); }
.tile-icon { height: 54px; display: flex; align-items: center; }
.tile-icon img { width: 54px; height: 54px; }
.tile-name { font-size: 13px; word-break: break-word; line-height: 1.25; }
.tile-chk { position: absolute; top: 6px; left: 6px; display: none; }
.filearea.has-selection .tile-chk { display: inline-block; }

.select-box { position: absolute; border: 1px solid var(--accent); background: var(--sel); pointer-events: none; z-index: 5; border-radius: 3px; }
.msg { margin-top: 10px; color: var(--muted); min-height: 18px; }

/* --- corner controls --- */
.corner { position: fixed; bottom: 16px; z-index: 30; }
.corner-theme { left: 16px; background: var(--panel); border: 1px solid var(--border); }
.corner-logout { right: 16px; background: transparent; border: 0; color: var(--danger); }
.corner-logout:hover { background: var(--row-hover); }

/* --- context menu --- */
.ctx { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 5px; min-width: 180px; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.ctx-item { padding: 8px 12px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.ctx-item:hover { background: var(--row-hover); }
.ctx-item.danger { color: var(--danger); }
.ctx-item.disabled { color: var(--muted); cursor: default; }
.ctx-sep { height: 1px; background: var(--border); margin: 5px 6px; }

/* --- modal --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 70; padding: 20px; }
.modal-box { width: 100%; max-width: 420px; }
.modal-content { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 12px; max-height: 86vh; overflow: auto; }
.modal-content.modal-wide { max-width: none; width: min(560px, 92vw); }
.modal-box:has(.modal-wide) { max-width: 560px; }
.modal-content h3 { margin: 0; font-size: 17px; }
.modal-msg { color: var(--muted); margin: 0; }
.modal-content input, .modal-content select { width: 100%; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.modal-qr { width: 230px; height: 230px; align-self: center; }
.modal-qr svg { width: 100%; height: 100%; }
.tdirs { list-style: none; margin: 6px 0 0; padding: 0; max-height: 36vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.tdirs li { padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.tdirs li:last-child { border-bottom: 0; }
.tdirs li:hover { background: var(--row-hover); }
.tdirs li.muted { color: var(--muted); cursor: default; }

/* settings */
.settings { gap: 18px; }
.set-group { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.set-group:first-of-type { border-top: 0; padding-top: 0; }
.set-h { font-weight: 600; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.set-row > span { flex: none; color: var(--muted); }
.set-row input:not([type=checkbox]), .set-row select { max-width: 60%; }
.set-row.check { justify-content: flex-start; }
.set-row.check input { width: auto; }
.qr-reveal { width: 200px; height: 200px; align-self: center; position: relative; cursor: pointer; background: #fff; border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.qr-reveal svg { width: 100%; height: 100%; }
.qr-reveal.blurred svg { filter: blur(10px); }
.qr-reveal .qr-hint { position: absolute; color: #333; font-size: 13px; }
.qr-reveal[data-loaded] .qr-hint { display: none; }

/* trash + color grid */
.trash-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
.trash-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.tr-name { font-weight: 600; }
.tr-meta { color: var(--muted); font-size: 12px; margin-left: 8px; flex: 1; }
.trash-actions { display: flex; gap: 6px; flex: none; }
.color-grid { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.color-sw { width: 40px; height: 40px; border-radius: 13px; border: 3px solid transparent; padding: 0; }
.color-sw.sel { border-color: var(--text); }

/* search bar */
.search-bar { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 65; display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.search-bar input { width: 320px; }
.search-nav { display: flex; align-items: center; gap: 4px; }
.search-nav button { padding: 4px 10px; }
.search-nav #s-count { color: var(--muted); min-width: 40px; text-align: center; }

/* wipe animation layer */
.wipe { position: fixed; inset: 0; background: var(--bg); transform: translateX(-100%); z-index: 90; pointer-events: none; }

/* editor/viewer overlay */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 75; }
.overlay-box { background: var(--panel); border: 1px solid var(--border); width: 100%; max-width: 960px; height: 85vh; display: flex; flex-direction: column; border-radius: 12px; overflow: hidden; }
.overlay-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.overlay-actions { display: flex; gap: 6px; }
.overlay-body { flex: 1; overflow: hidden; min-height: 0; }
.overlay-body textarea { width: 100%; height: 100%; border: 0; resize: none; background: var(--input); color: var(--text); padding: 12px; font-family: "SF Mono", "Consolas", monospace; font-size: 13px; }
.overlay-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }

@media (max-width: 640px) {
  .files th:nth-child(5), .files td:nth-child(5) { display: none; }
  .search-bar input { width: 180px; }
}

/* sicherheits-log */
.audit-log { list-style: none; margin: 8px 0 0; padding: 0; max-height: 240px; overflow-y: auto; font-size: 13px; border: 1px solid var(--border); border-radius: 8px; }
.audit-log li { display: grid; grid-template-columns: 150px 130px 100px 1fr; gap: 8px; padding: 5px 8px; border-bottom: 1px solid var(--border); }
.audit-log li:last-child { border-bottom: 0; }
.audit-log li.suspicious { color: var(--danger); font-weight: 600; }
.audit-log .a-ts { opacity: 0.7; }
.audit-log .a-ev { font-family: ui-monospace, monospace; }
.audit-log .a-ip { opacity: 0.7; }
@media (max-width: 640px) { .audit-log li { grid-template-columns: 1fr; gap: 2px; } }

/* smooth circular theme reveal (View Transitions) */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-old(root) { z-index: 0; }
::view-transition-new(root) { z-index: 1; }
/* night: old (light) layer shrinks inward on top, dark revealed beneath */
:root[data-vt="dark"]::view-transition-old(root) { z-index: 1; }
:root[data-vt="dark"]::view-transition-new(root) { z-index: 0; }

/* ".." up entry */
.up-row td, .up-tile { color: var(--muted); }
.up-row { cursor: pointer; }
.up-row:hover { background: var(--row-hover); }
.up-ico { display: inline-block; width: 20px; text-align: center; opacity: .8; }
.up-tile { cursor: pointer; }
.up-tile .tile-icon { font-size: 30px; color: var(--muted); }

/* breadcrumb current (trash) */
.crumb-current { color: var(--muted); }
.trash-orig { color: var(--muted); font-size: 12px; }

/* context menu: header, active, arrow, submenu */
.ctx-header { padding: 6px 12px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.ctx-item { display: flex; align-items: center; gap: 6px; }
.ctx-check { width: 14px; flex: none; color: var(--accent); font-size: 12px; }
.ctx-label { flex: 1; }
.ctx-item.active { color: var(--accent); font-weight: 600; }
.ctx-arrow { color: var(--text); font-size: 13px; font-weight: 800; margin-left: 2px; }
.ctx-chevron { color: var(--muted); font-size: 11px; }
.ctx-submenu { position: fixed; z-index: 61; }

/* trash toggle (topbar) */
#trash-btn.on { color: var(--accent); }

/* centered loading spinner while a folder/trash is loading */
.loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 8; }
.loading .spinner { width: 40px; height: 40px; }

/* nicer frosted QR reveal (just a rounded blur, no lock) */
.qr-reveal { overflow: hidden; border-radius: 16px; }
.qr-reveal.blurred::after {
  content: ""; position: absolute; inset: 0; cursor: pointer; border-radius: inherit;
  -webkit-backdrop-filter: blur(14px) brightness(1.02); backdrop-filter: blur(14px) brightness(1.02);
  background: rgba(130,130,130,.12);
}
.qr-reveal.blurred svg { filter: none; }

/* theme switch: circular reveal overlay (works both directions) */
.theme-reveal { position: fixed; inset: 0; z-index: 2000; pointer-events: none; }

/* empty state, centered in the file area */
.empty-state { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; pointer-events: none; }

/* drag & drop move */
.files tbody tr.dragging, .tile.dragging { opacity: .45; }
.files tbody tr.drop-target { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--sel); }
.tile.drop-target { outline: 2px solid var(--accent); background: var(--sel); border-radius: 10px; }
.crumbs a.drop-target { background: var(--sel); outline: 2px solid var(--accent); border-radius: 6px; }

/* settings: header row with action, danger zone */
.set-h-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.btn-small { padding: 3px 9px; font-size: 12px; }
.danger-zone { border: 1px solid var(--danger); border-radius: 10px; padding: 12px; margin-top: 6px; }
.danger-zone .set-h { color: var(--danger); }
.danger-zone .btn-danger { align-self: flex-start; }

/* conflict prompt: space the three choices out */
.conflict-actions { justify-content: space-between; }
