:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1b1f24;
  --muted: #667085;
  --border: #e3e6eb;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #d92d20;
  --folder: #f2b33d;
  --shadow: 0 8px 30px rgba(16, 24, 40, .14);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #242a32;
    --text: #e8eaed;
    --muted: #98a2b3;
    --border: #2c333c;
    --accent: #5b8ff5;
    --danger: #f97066;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; background: transparent; border-radius: 50%; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.light { color: #fff; }
.icon-btn.light:hover { background: rgba(255,255,255,.12); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 32px 24px; display: grid; gap: 12px; text-align: center;
  box-shadow: var(--shadow);
}
.login-card img { margin: 0 auto; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: 0 0 8px; }
.login-card input {
  padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg);
}
.login-card .btn { justify-content: center; padding: 12px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 650; font-size: 17px; }
.search { flex: 1; }
.search input {
  width: 100%; padding: 9px 14px; border-radius: 999px;
  border: 1px solid transparent; background: var(--surface-2);
}
.search input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.menu {
  position: absolute; right: 12px; top: calc(100% + 4px); min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; display: grid;
}
.menu button { text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.menu-note { padding: 8px 12px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-note:empty { display: none; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

/* Breadcrumbs + toolbar */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 14px 16px 4px; font-size: 18px; font-weight: 600; }
.crumbs a { color: var(--muted); text-decoration: none; padding: 2px 6px; border-radius: 6px; }
.crumbs a:hover { background: var(--surface-2); color: var(--text); }
.crumbs a:last-child { color: var(--text); }
.crumbs .sep { color: var(--muted); }
.crumbs.small { font-size: 14px; padding: 4px 0 8px; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px 12px; flex-wrap: wrap; }
.toolbar #count { margin-left: auto; font-size: 13px; }

/* List view */
.list { padding: 0 16px 120px; }
.row-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--border); border-top: 0; cursor: pointer;
  user-select: none;
}
.row-item:first-child { border-top: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.row-item:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.row-item:only-child { border-radius: var(--radius); }
.row-item:hover { background: var(--surface-2); }
.row-item.drop-target { outline: 2px solid var(--accent); outline-offset: -2px; }
.thumb {
  width: 40px; height: 40px; border-radius: 8px; flex: none;
  display: grid; place-items: center; background: var(--surface-2); overflow: hidden;
}
.thumb { position: relative; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--surface-2); }
.thumb svg { width: 24px; height: 24px; }
.name { flex: 1; min-width: 0; }
.name b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name small { color: var(--muted); font-size: 12.5px; }
.more { opacity: .7; }

/* Grid view */
.list.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.list.grid .row-item {
  flex-direction: column; align-items: stretch; gap: 0; padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; position: relative;
}
.list.grid .thumb { width: 100%; height: auto; aspect-ratio: 4/3; border-radius: 0; }
.list.grid .thumb svg { width: 44px; height: 44px; }
.list.grid .name { padding: 8px 36px 10px 10px; }
.list.grid .more { position: absolute; right: 2px; bottom: 6px; }

.empty { text-align: center; padding: 64px 16px; color: var(--muted); }
.empty svg { width: 64px; height: 64px; opacity: .5; }
.loading { padding: 48px; text-align: center; color: var(--muted); }

/* Icons colours */
.ic-folder { color: var(--folder); }
.ic-image { color: #12b76a; }
.ic-video { color: #e04f5f; }
.ic-audio { color: #9e77ed; }
.ic-pdf { color: #f04438; }
.ic-doc { color: #2f6fed; }
.ic-sheet { color: #16a34a; }
.ic-file { color: var(--muted); }

/* Drop hint */
.drop-hint {
  position: fixed; inset: 12px; z-index: 40; border: 3px dashed var(--accent); border-radius: 20px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  display: grid; place-items: center; font-size: 22px; font-weight: 600; color: var(--accent);
  pointer-events: none;
}

/* Upload progress panel */
.uploads {
  position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 30;
  width: min(360px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px; display: grid; gap: 8px;
  max-height: 50vh; overflow: auto;
}
.up { font-size: 13px; }
.up .bar { margin-top: 4px; }
.up.done .bar > i { background: #12b76a; }
.up.fail .bar > i { background: var(--danger); }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

/* Bottom sheet / dialogs */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 440px; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 10px 10px max(14px, env(safe-area-inset-bottom)); display: grid; gap: 2px;
}
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 18px; padding-bottom: 10px; }
}
.sheet-title { padding: 10px 12px 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.sheet > button { text-align: left; padding: 13px 14px; border: 0; background: none; border-radius: 10px; cursor: pointer; font-size: 16px; }
.sheet > button:hover { background: var(--surface-2); }
.sheet .danger { color: var(--danger); }
.mover { padding: 10px 14px 14px; }
.mover-list { max-height: 50vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; min-height: 120px; }
.mover-list button { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 11px 12px; border: 0; border-bottom: 1px solid var(--border); background: none; cursor: pointer; }
.mover-list button:last-child { border-bottom: 0; }
.mover-list button:hover { background: var(--surface-2); }
.mover-list .muted { padding: 16px; display: block; }
.row { display: flex; gap: 8px; justify-content: flex-end; }

/* Viewer */
.viewer { position: fixed; inset: 0; z-index: 70; background: #0b0d10; display: flex; flex-direction: column; }
.viewer-bar { display: flex; align-items: center; gap: 4px; padding: 8px; padding-top: max(8px, env(safe-area-inset-top)); color: #fff; }
.viewer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 8px; }
.viewer-body { flex: 1; min-height: 0; display: grid; place-items: center; padding: 8px; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.viewer-body audio { width: min(500px, 90vw); }
.viewer-body .nopreview { color: #cfd4dc; text-align: center; display: grid; gap: 14px; justify-items: center; }

@media (max-width: 560px) {
  .brand span { display: none; }
  .topbar { gap: 8px; padding-left: 12px; padding-right: 8px; }
  .crumbs { font-size: 16px; padding-left: 12px; padding-right: 12px; }
  .toolbar, .list { padding-left: 12px; padding-right: 12px; }
  .toolbar .btn { flex: 1; justify-content: center; }
  .toolbar #count { display: none; }
  .list.grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* ===== v2: tabs, vault, links, sharing ===== */
.mx { margin: 0 auto; }
.small-text { font-size: 13.5px; }
.center-screen { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.center-screen.in-app { min-height: calc(100vh - 140px); }
.card {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 22px; display: grid; gap: 12px; text-align: center; box-shadow: var(--shadow);
}
.card.narrow { max-width: 380px; }
.card h1, .card h2 { margin: 0; }
.card h1 { font-size: 24px; }
.card h2 { font-size: 20px; }
.card p { margin: 0; }
.card input[type=password], .card input[type=text] {
  padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); width: 100%;
}
.btn.block { justify-content: center; padding: 12px; width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; text-decoration: none; }
.btn.danger-btn { color: var(--danger); }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px; font-size: 14px; }
.big-icon { font-size: 40px; line-height: 1; }
.check { display: flex; gap: 8px; align-items: flex-start; text-align: left; font-size: 14px; cursor: pointer; }
.check input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--accent); }
.recovery-key {
  font: 600 17px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .5px;
  background: var(--surface-2); border: 1px dashed var(--accent); border-radius: 10px; padding: 14px; word-break: break-all;
}

/* Tabs */
.tabs { display: flex; gap: 4px; }
.tabs a {
  display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.search { margin: 0 0 0 auto; max-width: 340px; }

.vault-banner {
  display: flex; align-items: center; gap: 10px; margin: 12px 16px 0; padding: 10px 12px;
  background: color-mix(in srgb, #12b76a 12%, var(--surface)); border: 1px solid color-mix(in srgb, #12b76a 35%, transparent);
  border-radius: var(--radius); font-size: 13.5px;
}
.vault-banner svg { color: #12b76a; }
.vault-banner span { flex: 1; }

/* Quick Show */
.quick { padding: 4px 16px 6px; }
.quick h2 { font-size: 14px; margin: 6px 0 8px; color: var(--muted); font-weight: 600; }
.quick-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.quick-item {
  flex: none; width: 128px; scroll-snap-align: start; border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius); padding: 0; cursor: pointer; overflow: hidden; text-align: left;
}
.quick-item .thumb { width: 100%; height: 88px; border-radius: 0; }
.quick-item .thumb svg { width: 32px; height: 32px; }
.quick-item span { display: block; padding: 6px 8px; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Select mode */
.checkbox { display: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); flex: none;
  place-items: center; font-size: 13px; font-weight: 700; color: #fff; }
.list.selecting .checkbox { display: grid; }
.list.selecting .more { visibility: hidden; }
.row-item.is-selected { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.row-item.is-selected .checkbox { background: var(--accent); border-color: var(--accent); }
.list.grid .checkbox { position: absolute; top: 8px; left: 8px; z-index: 2; background: rgba(0,0,0,.25); border-color: #fff; }
.list.grid .row-item.is-selected .checkbox { background: var(--accent); }
.select-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 35;
  display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); border-radius: 999px; padding: 8px 8px 8px 18px; white-space: nowrap;
}

/* Dialog fields */
.sheet.padded { padding: 10px 16px max(16px, env(safe-area-inset-bottom)); gap: 12px; }
.sheet .field { display: grid; gap: 6px; font-size: 14px; font-weight: 500; }
.sheet .field input, .sheet .field select, .link-box {
  padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); font-weight: 400; width: 100%;
}
.sheet p { margin: 0; }
.row.wrap { flex-wrap: wrap; }
.sheet .error:empty { display: none; }

/* Links page */
.section-head { padding: 16px 16px 6px; }
.section-head h1 { font-size: 20px; margin: 0 0 4px; }
.section-head p { margin: 0; }
.links-list { padding: 8px 16px 120px; display: grid; gap: 10px; }
.link-card {
  display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
}
.link-card .thumb { width: 56px; height: 56px; }
.link-card.expired, .link-card.revoked { opacity: .65; }
.link-info { min-width: 0; display: grid; gap: 3px; }
.link-info b { font-weight: 600; }
.link-actions { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pill { justify-self: start; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; margin-top: 3px; }
.pill.ok { background: color-mix(in srgb, #12b76a 16%, transparent); color: #0e9f5b; }
.pill.off { background: var(--surface-2); color: var(--muted); }
@media (min-width: 700px) {
  .link-card { grid-template-columns: 56px 1fr auto; align-items: center; }
  .link-actions { grid-column: auto; }
}

@media (max-width: 760px) {
  /* Tabs move to a bottom bar on phones */
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; justify-content: space-around;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 8px max(6px, env(safe-area-inset-bottom));
  }
  .tabs a { flex-direction: column; gap: 2px; font-size: 11.5px; padding: 6px 18px; border-radius: 12px; }
  .search { max-width: none; }
  .list, .links-list { padding-bottom: 150px; }
  .uploads, .select-bar, .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}
@media (max-width: 560px) {
  .vault-banner { margin: 10px 12px 0; }
  .quick, .section-head { padding-left: 12px; padding-right: 12px; }
  .links-list { padding-left: 12px; padding-right: 12px; }
}

#menuBtn { margin-left: auto; }
.search + #menuBtn { margin-left: 0; }
