/* ==================================================================
   Tokens
   ================================================================== */
:root {
  /* surfaces & text */
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --text: #1b1f27;
  --mute: #6b7280;
  --line: #e5e7eb;
  --line-2: #eef0f3;

  /* accent */
  --acc: #3b6df0;
  --acc-t: #ffffff;
  --acc-soft: #e8efff;

  /* states */
  --hover: #eef1f6;
  --sel: #e4ecff;
  --warn-bg: #fff4e0;
  --warn: #a85d00;
  --warn-line: #f0b050;
  --ok: #1f9d55;
  --ok-bg: #e3f6ec;
  --bad: #d1334a;
  --bad-bg: #ffe7ea;

  /* shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .06);
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 6px 20px rgba(0, 0, 0, .05);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, .2);

  /* radii */
  --r-sm: 8px;
  --r: 10px;
  --r-md: 12px;
  --r-lg: 16px;

  /* motion */
  --t-fast: 120ms;
  --t: 160ms;
  --ease: cubic-bezier(.2, .6, .3, 1);

  /* layout */
  --top-h: 58px;
  --top-total: calc(var(--top-h) + env(safe-area-inset-top, 0));

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #0f1218;
    --panel: #181c24;
    --panel-2: #1c2029;
    --text: #e6e9ef;
    --mute: #9aa3b2;
    --line: #272d38;
    --line-2: #222831;
    --acc: #6b93ff;
    --acc-t: #0b1020;
    --acc-soft: #1c2a4d;
    --hover: #212733;
    --sel: #1d2a4d;
    --warn-bg: #33270f;
    --warn: #f0b050;
    --warn-line: #6b5423;
    --ok: #3fc07a;
    --ok-bg: #122a1d;
    --bad: #ff6b81;
    --bad-bg: #341820;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

:root[data-theme=dark] {
  --bg: #0f1218;
  --panel: #181c24;
  --panel-2: #1c2029;
  --text: #e6e9ef;
  --mute: #9aa3b2;
  --line: #272d38;
  --line-2: #222831;
  --acc: #6b93ff;
  --acc-t: #0b1020;
  --acc-soft: #1c2a4d;
  --hover: #212733;
  --sel: #1d2a4d;
  --warn-bg: #33270f;
  --warn: #f0b050;
  --warn-line: #6b5423;
  --ok: #3fc07a;
  --ok-bg: #122a1d;
  --bad: #ff6b81;
  --bad-bg: #341820;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ==================================================================
   Base
   ================================================================== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }

body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.mute { color: var(--mute); }
.sm { font-size: 12px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.t {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.err { color: var(--bad); min-height: 1.4em; margin: 0; font-size: 14px; }
.warn-text { color: var(--warn); }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.row:focus-visible { outline-offset: -2px; }

mark {
  background: rgba(255, 213, 0, .35);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
:root[data-theme=dark] mark { background: rgba(255, 213, 0, .25); }

/* ==================================================================
   Icons
   ================================================================== */
.ic {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}
.ic.sm { width: 16px; height: 16px; }

/* ==================================================================
   Buttons & inputs
   ================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.btn:hover { background: var(--hover); }
.btn.pri {
  background: var(--acc);
  color: var(--acc-t);
  border-color: var(--acc);
}
.btn.pri:hover { filter: brightness(1.08); }
.btn.ib-ish { padding: 8px 10px; }
.btn .ic:only-child { margin: 0; }

.ib {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  flex: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.ib:hover { background: var(--hover); }
.ib:disabled { opacity: .4; cursor: default; }
.ib.sm { width: 28px; height: 28px; border-radius: 6px; }
.ib.sm .ic { width: 14px; height: 14px; }

select {
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}
select:hover { background: var(--hover); }

input[type=search], input[type=text], input[type=password] {
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  width: 100%;
}

/* ==================================================================
   Icons-as-file-type
   ================================================================== */
.ficon {
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  background: var(--hover);
  color: var(--mute);
  flex-shrink: 0;
}
.ficon .ic { width: 18px; height: 18px; }
.ficon.dir { background: transparent; }
.ficon.dir .ic { width: 22px; height: 22px; color: var(--acc); }
.ficon.img .ic { color: #2a9d8f; }
.ficon.vid .ic { color: #e76f51; }
.ficon.aud .ic { color: #9c6ade; }
.ficon.doc .ic { color: #3b6df0; }
.ficon.sheet .ic { color: #1f9d55; }
.ficon.pdf .ic { color: #d1334a; }
.ficon.arc .ic { color: #a85d00; }
.ficon.code .ic { color: #6b7280; }
.ficon.big {
  width: 72px;
  height: 72px;
  border-radius: var(--r-md);
}
.ficon.big .ic { width: 36px; height: 36px; }

/* ==================================================================
   Login
   ================================================================== */
#login {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 20px;
}
.logincard {
  background: var(--panel);
  padding: 32px 28px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
}
.logincard h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -.01em;
}
.logincard p { margin: 0; }

/* ==================================================================
   App shell
   ================================================================== */
#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.top {
  flex: none;
  height: var(--top-total);
  padding-top: env(safe-area-inset-top, 0);
  padding-left: 12px;
  padding-right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 20;
}

#navbtn { display: none; }

#crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: auto;
  white-space: nowrap;
  min-width: 0;
  scrollbar-width: none;
  font-size: 14px;
}
#crumbs::-webkit-scrollbar { display: none; }
#crumbs .sep { color: var(--mute); flex-shrink: 0; }
#crumbs a { color: var(--mute); flex-shrink: 0; }
#crumbs a:hover { color: var(--acc); text-decoration: none; }
#crumbs b { color: var(--text); font-weight: 500; flex-shrink: 0; }

/* search box */
#searchbox {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}
#searchbox .search-ic {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--mute);
  pointer-events: none;
  display: flex;
}
#searchbox input[type=search] {
  padding-left: 36px;
  width: 240px;
}
#searchclose { display: none; }
.chk {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--mute);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.chk input { margin: 0; accent-color: var(--acc); }

/* overflow menu */
#moremenu {
  position: absolute;
  top: calc(100% - 4px);
  right: 12px;
  z-index: 35;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  padding: 6px;
  display: grid;
  gap: 2px;
}
#moremenu[hidden] { display: none; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: var(--r-sm);
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  width: 100%;
  transition: background var(--t-fast);
}
.menu-item:hover { background: var(--hover); }
.menu-item .ic { color: var(--mute); }

/* ==================================================================
   Two-column body
   ================================================================== */
.body {
  flex: 1;
  display: flex;
  min-height: 0;
}

#side {
  flex: none;
  width: 260px;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 10px 8px;
}
#side h4 {
  margin: 4px 8px 6px;
  color: var(--mute);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 600;
}
#side a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  transition: background var(--t-fast);
  min-height: 36px;
}
#side a:hover { background: var(--hover); text-decoration: none; }
#side a.on { background: var(--sel); font-weight: 500; }
#side a.sub {
  padding-left: 22px;
  font-size: 13px;
}
.side-ic {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  color: var(--mute);
  flex: none;
}
.side-ic .ic { width: 16px; height: 16px; }
.side-hint { padding: 8px; margin: 8px 0; line-height: 1.5; }
.side-foot {
  margin-top: 16px;
  padding: 12px 0 0;
  border-top: 1px solid var(--line-2);
}
.side-foot a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--mute);
  text-decoration: none;
}
.side-foot a:hover { background: var(--hover); color: var(--text); }

#sidebackdrop {
  position: fixed;
  inset: 0;
  top: var(--top-total);
  z-index: 24;
  background: rgba(0, 0, 0, .4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t) var(--ease);
  display: none;
}

#main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 96px; /* room for selection bar */
}

/* dot indicator */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mute);
  flex: none;
  display: inline-block;
  opacity: .5;
}
.dot.on { background: var(--ok); opacity: 1; }
.dot.off { background: var(--mute); opacity: .4; }
.dot.warn { background: var(--warn-line); opacity: 1; }

/* ==================================================================
   Cards: clients & folders
   ================================================================== */
h2.title {
  margin: 0 0 14px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.01em;
}

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

.cardx {
  background: var(--panel);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: 16px;
  cursor: pointer;
  position: relative;
  display: grid;
  gap: 6px;
  border: 1px solid transparent;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.cardx:hover { border-color: var(--acc); }
.cardx.paused { border-color: var(--warn-line); }
.cardx h3 {
  margin: 0;
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 15px;
  font-weight: 600;
}
.cardx h3 .t { min-width: 0; }
.cardx .st {
  color: var(--mute);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cardx .cardmenu {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  background: transparent;
  border-color: transparent;
  opacity: 0;
  transition: opacity var(--t-fast), background var(--t-fast);
}
.cardx:hover .cardmenu,
.cardx:focus-within .cardmenu { opacity: 1; background: var(--hover); border-color: var(--line); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 999px;
  width: max-content;
  white-space: nowrap;
}
.badge .ic { width: 13px; height: 13px; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }

/* ==================================================================
   Banners / notes
   ================================================================== */
.banner {
  border-radius: var(--r-md);
  padding: 14px 16px;
  margin-bottom: 14px;
  display: grid;
  gap: 8px;
}
.banner.warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--text);
}
.banner-head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--warn);
  font-weight: 600;
}
.banner-head .ic { width: 20px; height: 20px; }
.banner p { margin: 0; }
.banner .acts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 4px;
}
.countdown {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.note {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--hover);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--mute);
}
.note .ic { color: var(--warn); flex-shrink: 0; }

/* ==================================================================
   Toolbar + filter chips
   ================================================================== */
.tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.chips {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--mute);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.chip:hover { background: var(--hover); color: var(--text); }
.chip.on {
  background: var(--acc);
  color: var(--acc-t);
  border-color: var(--acc);
}

/* ==================================================================
   File list
   ================================================================== */
.list {
  background: var(--panel);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hdr {
  display: grid;
  grid-template-columns: 28px 36px minmax(0, 1fr) 90px 150px 34px;
  gap: 10px;
  padding: 8px 12px;
  color: var(--mute);
  font-size: 12px;
  border-bottom: 1px solid var(--line);
  align-items: center;
}
.hdr .th {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
}
.hdr .th:hover { color: var(--text); }
.hdr .th.on { color: var(--text); font-weight: 600; }
.hdr .th-arrow {
  width: 12px;
  height: 12px;
  opacity: 0;
  transition: opacity var(--t-fast);
}
.hdr .th.on .th-arrow { opacity: 1; }

.row {
  display: grid;
  grid-template-columns: 28px 36px minmax(0, 1fr) 90px 150px 34px;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-2);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background var(--t-fast);
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--hover); }
.row.sel { background: var(--sel); }
.row.hl {
  outline: 2px solid var(--acc);
  outline-offset: -2px;
}
.row .nm { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row .nm .t {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row .nm .sub {
  display: block;
  font-size: 12px;
  color: var(--mute);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row .sz, .row .dt {
  color: var(--mute);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.row .rowmenu {
  width: 30px;
  height: 30px;
  border-color: transparent;
  background: transparent;
  opacity: .5;
  transition: opacity var(--t-fast), background var(--t-fast);
}
.row:hover .rowmenu,
.row.sel .rowmenu { opacity: 1; }
.row .rowmenu:hover { background: var(--hover); border-color: var(--line); }

.cb {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--acc);
  cursor: pointer;
}

.link-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: var(--acc);
  cursor: pointer;
  padding: 2px 0;
  font-size: 12px;
  text-align: left;
  width: max-content;
}
.link-inline .ic { width: 12px; height: 12px; }
.link-inline:hover { text-decoration: underline; }

/* grid view */
.list.grid {
  background: none;
  box-shadow: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  overflow: visible;
}
.grid .hdr { display: none; }
.grid .row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 8px;
  position: relative;
  text-align: center;
}
.grid .row .cb {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  width: 18px;
  height: 18px;
  background: var(--panel);
  border-radius: 4px;
  opacity: 0;
  transition: opacity var(--t-fast);
}
.grid .row:hover .cb,
.grid .row.sel .cb,
body.selecting .grid .row .cb { opacity: 1; }
.grid .row .rowmenu {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  background: var(--panel);
  border-color: var(--line);
  opacity: 0;
}
.grid .row:hover .rowmenu { opacity: 1; }
.grid .row .ficon {
  width: 100%;
  height: 100px;
  border-radius: var(--r-sm);
}
.grid .row .ficon.dir .ic { width: 40px; height: 40px; }
.grid .row .th {
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--hover);
}
.grid .row .sz,
.grid .row .dt { display: none; }
.grid .row .nm { text-align: center; }
.grid .row .link-inline { justify-content: center; }

/* ==================================================================
   Selection bar
   ================================================================== */
#selbar {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%);
  z-index: 30;
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 10px 14px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100vw - 20px);
}
#selbar b { font-variant-numeric: tabular-nums; }

/* ==================================================================
   Empty / error / skeleton
   ================================================================== */
.empty {
  display: grid;
  justify-items: center;
  gap: 6px;
  text-align: center;
  color: var(--mute);
  padding: 56px 20px;
}
.empty-ic {
  width: 48px;
  height: 48px;
  color: var(--mute);
  opacity: .55;
  margin-bottom: 4px;
}
.empty h3 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
}
.empty p { margin: 0; max-width: 420px; line-height: 1.5; }

.errorcard {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 40px 24px;
  text-align: center;
  background: var(--panel);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  margin: 24px auto;
  max-width: 480px;
}
.error-ic { width: 40px; height: 40px; color: var(--bad); }
.errorcard h2 { margin: 0; font-size: 18px; }
.errorcard p { margin: 0; max-width: 380px; }

.skeleton { display: grid; gap: 8px; }
.skeleton.row .sk-line {
  height: 44px;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--hover) 0%, var(--panel-2) 50%, var(--hover) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton.banner .sk-line {
  height: 72px;
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--hover) 0%, var(--panel-2) 50%, var(--hover) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  margin-bottom: 12px;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ==================================================================
   Spinner
   ================================================================== */
.spin {
  width: 30px;
  height: 30px;
  border: 3px solid var(--line);
  border-top-color: var(--acc);
  border-radius: 50%;
  animation: sp .8s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
.spin.sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}
@keyframes sp { to { transform: rotate(360deg); } }

/* ==================================================================
   Row context menu
   ================================================================== */
.row-menu {
  position: fixed;
  z-index: 60;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  min-width: 190px;
  padding: 6px;
  display: grid;
  gap: 2px;
}

/* ==================================================================
   Viewer
   ================================================================== */
#viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.vbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top, 0));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.vtitle {
  display: grid;
  min-width: 0;
  gap: 2px;
}
.vtitle b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

#vbody {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
#vbody > iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
#vbody .center {
  margin: auto;
  text-align: center;
  padding: 24px;
  display: grid;
  gap: 14px;
  justify-items: center;
  max-width: 500px;
}
#vbody img.pv {
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  object-fit: contain;
  cursor: zoom-in;
}
#vbody img.pv.zoom {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
  margin: 0;
}
#vbody video, #vbody audio {
  max-width: 100%;
  max-height: 100%;
  margin: auto;
}
#vbody pre {
  margin: 0;
  padding: 16px;
  width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  font: 13px/1.6 ui-monospace, Consolas, "SF Mono", monospace;
  background: var(--panel);
  color: var(--text);
}

/* markdown */
#vbody .md {
  max-width: 820px;
  padding: 24px;
  width: 100%;
  line-height: 1.6;
}
#vbody .md h1, #vbody .md h2, #vbody .md h3 {
  margin: 1.2em 0 .4em;
  line-height: 1.2;
}
#vbody .md h1 { font-size: 1.6em; }
#vbody .md h2 { font-size: 1.35em; }
#vbody .md h3 { font-size: 1.15em; }
#vbody .md p { margin: .6em 0; }
#vbody .md code {
  background: var(--hover);
  padding: 2px 6px;
  border-radius: 4px;
  font: 13px ui-monospace, Consolas, monospace;
}
#vbody .md pre {
  background: var(--hover);
  padding: 12px;
  border-radius: var(--r-sm);
  overflow: auto;
  white-space: pre;
}
#vbody .md pre code { background: none; padding: 0; }
#vbody .md img { max-width: 100%; }
#vbody .md blockquote {
  border-left: 3px solid var(--line);
  padding-left: 12px;
  color: var(--mute);
  margin: .6em 0;
}
#vbody .md table { border-collapse: collapse; }
#vbody .md th, #vbody .md td {
  border: 1px solid var(--line);
  padding: 6px 10px;
}

/* docx */
#vbody .docwrap {
  width: 100%;
  overflow: auto;
  padding: 12px;
  background: #d9dce1;
}

/* spreadsheet */
#vbody .xl {
  width: 100%;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  height: 100%;
}
#vbody .xl .tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
#vbody .xl .tabs .tab {
  padding: 5px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-size: 13px;
}
#vbody .xl .tabs .tab.on {
  background: var(--acc);
  color: var(--acc-t);
  border-color: var(--acc);
}
#vbody .xl .tw {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel);
  flex: 1;
  min-height: 200px;
}
#vbody table {
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
#vbody td {
  border: 1px solid var(--line);
  padding: 4px 8px;
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* pdf pages */
.pdfwrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  align-items: center;
  width: 100%;
  background: #d9dce1;
}
.pdfpage {
  max-width: 100%;
  height: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .15);
  background: #fff;
  border-radius: 2px;
}

/* ==================================================================
   Toast
   ================================================================== */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%);
  z-index: 80;
  display: grid;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  pointer-events: auto;
  animation: slideUp 200ms var(--ease);
}
.toast.info .toast-ic { color: var(--acc); }
.toast.success .toast-ic { color: var(--ok); }
.toast.error .toast-ic { color: var(--bad); }
.toast.warn .toast-ic { color: var(--warn); }
.toast-msg { flex: 1; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ==================================================================
   Modal
   ================================================================== */
#modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, .5);
  display: grid;
  place-items: center;
  padding: 16px;
}
.dlg {
  background: var(--panel);
  border-radius: var(--r-lg);
  padding: 20px;
  width: min(440px, 100%);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 12px;
  animation: slideUp 180ms var(--ease);
}
.dlg h3 { margin: 0; font-size: 17px; }
.dlg p { margin: 0; }
.modal-body { display: grid; gap: 10px; }
.dlgb {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

/* ==================================================================
   Status pill
   ================================================================== */
#status {
  position: fixed;
  top: calc(var(--top-total) + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 13px;
  color: var(--mute);
  white-space: nowrap;
  animation: slideDown 200ms var(--ease);
}
#status.err { color: var(--bad); border-color: var(--bad); }
@keyframes slideDown {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ==================================================================
   Activity log
   ================================================================== */
.tw2 { overflow: auto; border-radius: var(--r-md); }
.logt {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 13px;
}
.logt td, .logt th {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line-2);
  vertical-align: top;
}
.logt th {
  color: var(--mute);
  font-weight: 500;
  font-size: 12px;
  border-bottom-color: var(--line);
}
.logt tr.warn td { background: var(--warn-bg); }
.logt tr.error td { color: var(--bad); }
.lvl {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: .04em;
}
.lvl .ic { width: 13px; height: 13px; }
.lvl.info { color: var(--acc); }
.lvl.warn { color: var(--warn); }
.lvl.error { color: var(--bad); }

/* ==================================================================
   Scrollbars
   ================================================================== */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--mute);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* ==================================================================
   Motion preferences
   ================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==================================================================
   Mobile (≤ 800px)
   ================================================================== */
@media (max-width: 800px) {
  #navbtn { display: inline-grid; }

  /* drawer sidebar */
  #side {
    position: fixed;
    top: var(--top-total);
    left: 0;
    bottom: 0;
    z-index: 25;
    width: min(280px, 85vw);
    transform: translateX(-100%);
    transition: transform var(--t) var(--ease);
    box-shadow: var(--shadow-lg);
    border-right: 1px solid var(--line);
  }
  body.nav #side { transform: none; }

  #sidebackdrop { display: block; }
  body.nav #sidebackdrop { opacity: 1; pointer-events: auto; }

  /* main padding */
  #main { padding: 12px; padding-bottom: 120px; }

  /* search toggle becomes a full-width overlay when open */
  #searchbox { display: none; }
  body.search-open #searchbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-total);
    padding-top: env(safe-area-inset-top, 0);
    padding-left: 12px;
    padding-right: 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  body.search-open #searchbox input[type=search] {
    width: 100%;
    flex: 1;
  }
  #searchclose { display: inline-grid; }
  body.search-open .chk { display: none; }

  /* hide desktop crumbs in favor of a compact crumb */
  #crumbs { font-size: 13px; }

  /* toolbar tighter */
  .tools { gap: 6px; }
  .tools select { min-height: 36px; }

  /* list rows: drop size + date columns */
  .row {
    grid-template-columns: 24px 36px minmax(0, 1fr) 30px;
    gap: 8px;
    padding: 10px 12px;
    min-height: 52px;
  }
  .row .sz, .row .dt { display: none; }
  .hdr { display: none; }
  .cb { width: 18px; height: 18px; }

  /* touch targets */
  .ib, .btn, select { min-height: 40px; }
  .ib { width: 40px; height: 40px; }
  .row .rowmenu { width: 34px; height: 34px; opacity: 1; }

  /* grid: 2 columns on phones */
  .list.grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .grid .row .ficon, .grid .row .th { height: 96px; }

  /* card menu always visible on touch */
  .cardx .cardmenu { opacity: 1; background: var(--hover); border-color: var(--line); }

  /* hide button labels but keep icon */
  .hide-sm { display: none; }

  /* banner padding */
  .banner { padding: 12px 14px; }
}

/* Small phones */
@media (max-width: 420px) {
  .cards { grid-template-columns: 1fr; }
  .list.grid { grid-template-columns: repeat(2, 1fr); }
  .logincard { padding: 24px 20px; }
  h2.title { font-size: 18px; }
}

/* Desktop: keep search always visible */
@media (min-width: 801px) {
  #searchtoggle, #searchclose { display: none; }
  #searchbox { display: flex; }
}