:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #1a1d23;
  --muted: #646b78;
  --accent: #1f62d6;
  --accent-hover: #174ea9;
  --on-accent: #ffffff;
  --accent-soft: #e7effc;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --ok: #1f8a4c;
  --row-hover: #f3f6fc;
  --row-selected: #e7effc;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 8px 24px rgb(0 0 0 / .08);
  --radius: 10px;
  --folder: #f2b33d;
  --file: #8a93a3;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #22262e;
    --border: #2d323b;
    --text: #e7e9ee;
    --muted: #9aa2b1;
    --accent: #5b9bf5;
    --accent-hover: #86b6f8;
    --on-accent: #071a36;
    --accent-soft: #16263f;
    --danger: #ef5350;
    --danger-soft: #3a1d1f;
    --ok: #4cc27f;
    --row-hover: #20242b;
    --row-selected: #172a46;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .4);
    --folder: #e0a63a;
    --file: #7d8696;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111317; --surface: #1a1d23; --surface-2: #22262e; --border: #2d323b; --text: #e7e9ee; --muted: #9aa2b1;
  --accent: #5b9bf5; --accent-hover: #86b6f8; --on-accent: #071a36; --accent-soft: #16263f; --danger: #ef5350; --danger-soft: #3a1d1f;
  --ok: #4cc27f; --row-hover: #20242b; --row-selected: #172a46; --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .4);
  --folder: #e0a63a; --file: #7d8696; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
/* An iPhone home-screen app's window is black behind the page: paint the page colour all the way out,
   so any moment iOS doesn't repaint shows the page colour, not black. */
html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.error { color: var(--danger); margin: 0; }
.pad { padding: 16px; }

/* ---- Brand ---- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
a.brand { color: inherit; text-decoration: none; border-radius: 8px; }
a.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.brand-lg { font-size: 20px; justify-content: center; margin-bottom: 4px; }
.logo { width: 28px; height: 28px; background: url(favicon.svg?v=2) center / contain no-repeat; flex: none; }
.brand-lg .logo { width: 36px; height: 36px; }
/* "IT" in the accent colour */
.brand-it { color: var(--accent); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer; white-space: nowrap; text-decoration: none;
  color: var(--text); /* also for links styled as buttons, which would otherwise be link-blue */
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .sort:focus-visible, .name-link:focus-visible, .icon-btn:focus-visible, .crumb:focus-visible, .menu-item:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.block { width: 100%; height: 40px; }
.btn:disabled { opacity: .6; cursor: default; }

.icon-btn {
  width: 30px; height: 30px; border: 0; border-radius: 6px; background: transparent; cursor: pointer;
  display: inline-grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---- Fields ---- */
.field { display: grid; gap: 6px; font-weight: 550; font-size: 13px; min-width: 0; }
.field input {
  width: 100%; min-width: 0;
  height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); font-weight: 400; font-size: 14px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; }

/* ---- Auth ---- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.auth-card { width: 100%; max-width: 380px; padding: 32px 28px; display: grid; gap: 16px; }
.auth-card p { margin: 0; text-align: center; }

/* ---- Layout ---- */
.files { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 16px 20px 12px; max-width: 1200px; width: 100%; margin: 0 auto;
}

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); z-index: 10;
}
.menu-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); }

/* ---- Breadcrumbs ---- */
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 16px; font-weight: 600; min-width: 0; }
.crumb { border: 0; background: none; padding: 4px 6px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 600; }
.crumb:hover { background: var(--surface-2); color: var(--text); }
.crumb.current { color: var(--text); cursor: default; }
.crumb.current:hover { background: none; }
.crumb-sep { color: var(--muted); opacity: .6; }

/* ---- File list ---- */
.content {
  position: relative; flex: 1; width: 100%; max-width: 1200px; margin: 0 auto 24px;
  padding: 0 20px;
}
.panel { display: flex; flex-direction: column; flex: 1; }
.page-title { font-size: 18px; margin: 0; font-weight: 650; }
.list { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list th, .list td { padding: 0 12px; height: 46px; text-align: left; border-bottom: 1px solid var(--border); }
.list tbody tr:last-child td { border-bottom: 0; }
.list th { height: 38px; font-weight: 550; color: var(--muted); font-size: 12.5px; background: var(--surface-2); }
.list tbody tr:hover { background: var(--row-hover); }
.list tbody tr.selected { background: var(--row-selected); }
.col-chk { width: 44px; }
.col-size { width: 110px; text-align: right !important; font-variant-numeric: tabular-nums; }
.col-date { width: 190px; font-variant-numeric: tabular-nums; }
.col-act { width: 110px; text-align: right !important; white-space: nowrap; }
td.col-size, td.col-date { color: var(--muted); white-space: nowrap; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.sort { border: 0; background: none; padding: 0; color: inherit; font-weight: inherit; cursor: pointer; }
.sort[data-dir="asc"]::after { content: " ↑"; }
.sort[data-dir="desc"]::after { content: " ↓"; }

.name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.name-link {
  border: 0; background: none; padding: 0; text-align: left; cursor: pointer; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; min-width: 0;
}
.name-link:hover { color: var(--accent); text-decoration: underline; }
.col-name { max-width: 0; width: 100%; }

.ficon { display: inline-block; width: 22px; height: 22px; flex: none; border-radius: 4px; position: relative; }
.ficon.folder {
  background: var(--folder);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 6.5A2.5 2.5 0 0 1 5.5 4h4l2 2.5h7A2.5 2.5 0 0 1 21 9v8.5a2.5 2.5 0 0 1-2.5 2.5h-13A2.5 2.5 0 0 1 3 17.5z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 6.5A2.5 2.5 0 0 1 5.5 4h4l2 2.5h7A2.5 2.5 0 0 1 21 9v8.5a2.5 2.5 0 0 1-2.5 2.5h-13A2.5 2.5 0 0 1 3 17.5z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.ficon.file {
  background: var(--file);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 2h7L19 7.5v12a2.5 2.5 0 0 1-2.5 2.5h-10A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2zm6.5 1.5V8h4.5'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 2h7L19 7.5v12a2.5 2.5 0 0 1-2.5 2.5h-10A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2zm6.5 1.5V8h4.5'/%3E%3C/svg%3E") center / contain no-repeat;
}
.ficon.file[data-kind="image"] { background: #3fa66b; }
.ficon.file[data-kind="video"] { background: #8b5cf6; }
.ficon.file[data-kind="audio"] { background: #e0699a; }
.ficon.file[data-kind="pdf"] { background: #e05252; }
.ficon.file[data-kind="doc"] { background: #3b82f6; }
.ficon.file[data-kind="sheet"] { background: #22a06b; }
.ficon.file[data-kind="archive"] { background: #b08550; }

.empty { text-align: center; padding: 56px 16px; }
.empty p { margin: 4px 0; }
.empty-icon {
  width: 56px; height: 56px; margin: 0 auto 12px; background: var(--border);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 6.5A2.5 2.5 0 0 1 5.5 4h4l2 2.5h7A2.5 2.5 0 0 1 21 9v8.5a2.5 2.5 0 0 1-2.5 2.5h-13A2.5 2.5 0 0 1 3 17.5z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 6.5A2.5 2.5 0 0 1 5.5 4h4l2 2.5h7A2.5 2.5 0 0 1 21 9v8.5a2.5 2.5 0 0 1-2.5 2.5h-13A2.5 2.5 0 0 1 3 17.5z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.drop-hint {
  position: absolute; inset: 0 20px; border: 2px dashed var(--accent); border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent-soft) 85%, transparent);
  display: grid; place-items: center; pointer-events: none; z-index: 3;
}
.drop-hint span { background: var(--accent); color: var(--on-accent); padding: 8px 16px; border-radius: 999px; font-weight: 600; }

/* ---- Uploads panel ---- */
.uploads {
  position: fixed; right: 20px; bottom: 20px; width: 380px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); z-index: 20;
  overflow: hidden;
}
.uploads-head { display: flex; align-items: center; gap: 4px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--border); }
.uploads.collapsed .upload-list { display: none; }
.uploads.collapsed .uploads-head { border-bottom: 0; }
.upload-list { list-style: none; margin: 0; padding: 4px 0; max-height: 300px; overflow: auto; }
.upload-item { padding: 8px 16px; display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-status { font-size: 12px; color: var(--muted); grid-column: 1; }
.upload-status.err { color: var(--danger); }
.upload-status.done { color: var(--ok); }
.upload-item .icon-btn { grid-row: 1 / span 3; grid-column: 2; }
.bar { grid-column: 1; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upload-item.done .bar > i { background: var(--ok); }
.upload-item.error .bar > i { background: var(--danger); }

/* ---- Dialogs ---- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); width: min(440px, calc(100vw - 32px));
  /* Long content scrolls inside the window instead of running off the screen */
  max-height: calc(100dvh - 32px); overflow-y: auto; overflow-x: hidden;
}
/* Long file names, links and paths wrap instead of making the window wider */
.dlg h2, .dlg p, .dlg li, .dlg code { overflow-wrap: anywhere; }
.dlg > *, #dlg-body > * { min-width: 0; }
dialog#users-dlg { width: min(640px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(10 12 16 / .45); }
.dlg { padding: 22px 24px; display: grid; gap: 14px; }
.dlg h2 { margin: 0; font-size: 17px; }
.dlg h3 { margin: 6px 0 0; font-size: 14px; }
.dlg p { margin: 0; }
#dlg-body { display: grid; gap: 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.users-table td, .users-table th { height: 42px; }
.user-add { display: grid; gap: 12px; border-top: 1px solid var(--border); padding-top: 14px; }
.user-add .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--muted); }
.tag.admin { background: var(--accent-soft); color: var(--accent); }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 2px; margin-left: 16px; }
.tab {
  padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 550;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Small bits ---- */
.ico { display: inline-flex; width: 14px; height: 14px; }
.ico svg { width: 100%; height: 100%; }
.shared-badge { display: inline-flex; color: var(--accent); flex: none; }
.name-stack { display: grid; min-width: 0; }
.name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Text found inside a document, under its name in search results */
.sub.snippet { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; margin-top: 2px; }
.snippet mark { background: var(--accent-soft); color: var(--accent); font-weight: 600; border-radius: 3px; padding: 0 1px; }
.tag { display: inline-flex; align-items: center; gap: 4px; flex: none; }
.tag.warn { background: var(--danger-soft); color: var(--danger); }
tr.dim td { opacity: .65; }
.col-act.wide { width: 210px; }
.col-expires { width: 140px; white-space: nowrap; }
.col-count { width: 120px; text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.col-from { width: 240px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-from .name-link { max-width: 100%; display: block; color: var(--muted); }
.hint { font-weight: 400; font-size: 12px; color: var(--muted); }
/* A dropdown is as wide as its longest choice unless told otherwise; keep it inside its field */
.field select {
  width: 100%; min-width: 0;
  height: 40px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); font-weight: 400; font-size: 14px;
}
.field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.link-row { display: flex; gap: 8px; }
.link-input {
  flex: 1; min-width: 0; height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); font-family: ui-monospace, Consolas, monospace; font-size: 13px;
}
.offscreen { position: fixed; left: -9999px; top: 0; }
.empty-icon.trash, .empty-icon.link { background: var(--border); }
.empty-icon.trash {
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6'/%3E%3C/svg%3E") center / contain no-repeat;
}
.empty-icon.link {
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---- Public share page ---- */
.share-main { width: 100%; max-width: 900px; margin: 0 auto; padding: 32px 20px; display: grid; gap: 16px; }
.share-card { padding: 32px 28px; display: grid; gap: 14px; justify-items: center; text-align: center; max-width: 440px; width: 100%; margin: 24px auto 0; }
.share-card h1 { margin: 0; font-size: 20px; word-break: break-word; }
.share-card p { margin: 0; }
.share-card .ficon { width: 56px; height: 56px; }
.share-card .btn.primary { min-width: 180px; height: 40px; }
.share-card form, .share-card .field { width: 100%; text-align: left; }
.share-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.share-head p { margin: 0 0 2px 6px; }
.share-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.share-card .share-buttons .btn { min-width: 140px; height: 40px; }
#unlock-form { display: grid; gap: 12px; }
.share-head h1 { margin: 0; font-size: 20px; }
.share-lock { width: 44px; height: 44px; color: var(--muted); }
.share-lock svg { width: 100%; height: 100%; }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 30;
  max-width: calc(100vw - 32px);
}
.toast.err { background: var(--danger); color: #fff; }
.toast { display: flex; align-items: center; gap: 14px; }
.toast-action {
  border: 0; background: none; color: inherit; font-weight: 650; cursor: pointer; padding: 2px 6px; border-radius: 6px;
  text-decoration: underline; text-underline-offset: 3px;
}
.toast-action:hover { background: rgb(127 127 127 / .2); }

/* ---- Windows drive dialog ---- */
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.drive-manual summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.drive-manual[open] { display: grid; gap: 8px; }
.copy-row { display: flex; align-items: center; gap: 8px; }
.copy-row code { flex: 1; min-width: 0; overflow-wrap: anywhere; padding: 6px 10px; border-radius: 6px; background: var(--surface-2); font: 13px ui-monospace, Consolas, monospace; }

/* ---- Text editor ---- */
dialog.editor {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; border-radius: 0; box-shadow: none; background: var(--bg);
  display: none; grid-template-rows: auto 1fr; overflow: hidden;
}
dialog.editor[open] { display: grid; }
.editor-bar {
  display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px 8px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.editor-title { flex: 1; min-width: 0; display: grid; }
.editor-title > span:first-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-title .dirty { color: var(--accent); font-weight: 600; }
.editor-wrap { font-size: 13px; color: var(--muted); white-space: nowrap; }
.editor-text {
  width: min(1100px, 100%); justify-self: center; height: 100%; resize: none; margin: 0;
  border: 0; border-left: 1px solid var(--border); border-right: 1px solid var(--border); outline: none;
  padding: 18px 22px calc(18px + env(safe-area-inset-bottom)); background: var(--surface); color: var(--text);
  font: 14px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace; tab-size: 4;
}
.editor-text.nowrap { white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.editor-text[readonly] { color: var(--muted); }
@media (max-width: 720px) { .editor-text { border: 0; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); font-size: 14px; } }

/* ---- Viewer ---- */
dialog.viewer {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; border-radius: 0; background: #0b0c0f; color: #f1f3f6; box-shadow: none;
  display: none; grid-template-rows: auto 1fr; overflow: hidden;
}
dialog.viewer[open] { display: grid; animation: none; }
dialog.viewer::backdrop { background: #0b0c0f; }
.viewer-bar {
  display: flex; align-items: center; gap: 6px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  background: rgb(0 0 0 / .35); z-index: 2;
}
.viewer-bar .icon-btn { width: 40px; height: 40px; color: #e7e9ee; }
.viewer-bar .icon-btn:hover { background: rgb(255 255 255 / .1); color: #fff; }
.viewer-bar .icon-btn svg { width: 20px; height: 20px; }
.viewer-title { flex: 1; min-width: 0; display: grid; }
.viewer-title > span:first-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-title .muted, .viewer-bar .muted { color: #9aa2b1; }
.viewer-stage {
  position: relative; display: grid; place-items: center; min-height: 0; overflow: auto;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
}
.viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.viewer-media { max-width: 100%; max-height: 100%; background: #000; border-radius: 6px; }
.viewer-pdf { width: min(1100px, 100%); height: 100%; border: 0; border-radius: 6px; background: #fff; }
.viewer-text {
  align-self: start; width: min(1000px, 100%); margin: 0; padding: 18px 20px; border-radius: 8px;
  background: #16181d; color: #e7e9ee; font: 13px/1.55 ui-monospace, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word; overflow: auto; max-height: 100%;
}
.viewer-audio { display: grid; justify-items: center; gap: 24px; width: min(480px, 100%); }
.viewer-audio .ficon { width: 96px; height: 96px; }
.viewer-audio audio { width: 100%; }
.viewer-none { display: grid; justify-items: center; gap: 14px; text-align: center; color: #c5cad3; }
.viewer-none .ficon { width: 72px; height: 72px; }
.viewer-none p { margin: 0; }
.viewer-nav {
  position: absolute; top: 50%; width: 48px; height: 48px; margin-top: -24px; border: 0; border-radius: 50%;
  background: rgb(0 0 0 / .45); color: #fff; cursor: pointer; display: grid; place-items: center; z-index: 3;
}
.viewer-nav:hover { background: rgb(0 0 0 / .7); }
.viewer-nav svg { width: 26px; height: 26px; }
.viewer-nav.prev { left: 14px; }
.viewer-nav.next { right: 14px; }
.viewer-nav.next svg { transform: scaleX(-1); }
.viewer-nav[hidden] { display: none; }

/* ---- Search ---- */
.search { position: relative; display: flex; align-items: center; flex: 0 1 340px; margin-left: 16px; }
.search-ico { position: absolute; left: 11px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search-ico svg { width: 100%; height: 100%; }
.search input {
  width: 100%; height: 36px; padding: 0 12px 0 34px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); font-size: 14px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
.search-summary { margin: 0 2px 10px; }
.empty-icon.search {
  background: var(--border);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---- Move / copy picker ---- */
.picker-crumbs { font-size: 14px; }
.picker-list {
  display: grid; max-height: 320px; min-height: 120px; overflow: auto;
  border: 1px solid var(--border); border-radius: 10px; padding: 4px; align-content: start;
}
.picker-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 10px;
  border: 0; background: none; border-radius: 8px; text-align: left; cursor: pointer;
}
.picker-item:hover:not(:disabled) { background: var(--surface-2); }
.picker-item:disabled { opacity: .45; cursor: not-allowed; }
.picker-item > span:not(.ficon):not(.ico) { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-item .ico { color: var(--muted); transform: scaleX(-1); }

/* ---- Drag rows onto folders ---- */
.drop-target, .list tbody tr.drop-target { background: var(--accent-soft) !important; outline: 2px solid var(--accent); outline-offset: -2px; }
.drag-ghost {
  position: fixed; top: -100px; left: 0; padding: 6px 12px; border-radius: 8px;
  background: var(--accent); color: var(--on-accent); font-weight: 600; white-space: nowrap;
}

/* ---- Storage ---- */
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.meter.warn > i { background: #e0a020; }
.meter.full > i { background: var(--danger); }
.menu-storage { margin-top: 6px; font-weight: 400; }
.storage-big { font-size: 15px; }
.storage-big strong { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.storage-rows { display: grid; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.storage-row { display: flex; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.storage-row:last-child { border-bottom: 0; }
.storage-row span { color: var(--muted); }
.storage-sub { margin: 10px 0 0; font-size: 14px; }
.col-usage { min-width: 150px; }
.col-usage .meter { margin-top: 4px; }
.banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 12px auto 0; width: calc(100% - 40px); max-width: 1160px; padding: 10px 10px 10px 16px;
  border-radius: 10px; background: #fff4dc; color: #6b4a00; border: 1px solid #f3d38a;
}
.banner.danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.banner .icon-btn { color: inherit; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .banner:not(.danger) { background: #3a2f12; color: #f3d38a; border-color: #6b5520; }
}
:root[data-theme="dark"] .banner:not(.danger) { background: #3a2f12; color: #f3d38a; border-color: #6b5520; }
.user-add .row { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* ---- Account button, menu, phone-only / desktop-only ---- */
.me-btn { gap: 8px; padding: 0 8px 0 4px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font-weight: 650; font-size: 13px; text-transform: uppercase;
}
.menu-head { padding: 8px 10px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border); font-weight: 600; }
.tab-ico { display: none; }
.select-bar { display: contents; }
.phone { display: none !important; }
.page-note { margin: 0 16px 10px; }

/* View-only shared folders hide everything that changes files (beats the phone/desktop rules) */
body .ro-hidden.ro-hidden.ro-hidden { display: none !important; }

/* ---- Sharing with people, versions ---- */
.space-tag { margin-left: 10px; font-weight: 500; }
.section-title { font-size: 15px; margin: 28px 2px 10px; }
/* Side by side when there's room for both choices to be read in full, otherwise one under the other */
.people-add { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.people-list, .versions-list { display: grid; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.people-list { max-height: 40vh; overflow: auto; }
.people-list > p, .versions-list > p { padding: 12px 14px; }
.people-row, .version-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; border-bottom: 1px solid var(--border); }
.people-row:last-child, .version-row:last-child { border-bottom: 0; }
.people-name { flex: 1; font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.versions-list { max-height: 50vh; overflow: auto; }
.tag.upload { background: var(--accent-soft); color: var(--accent); }

/* ---- Upload links (public page) ---- */
.upload-card { max-width: 520px; }
.upload-drop {
  width: 100%; display: grid; justify-items: center; gap: 10px; padding: 26px 16px;
  border: 2px dashed var(--border); border-radius: 12px; background: var(--surface-2);
}
.upload-drop.over { border-color: var(--accent); background: var(--accent-soft); }
.upload-drop p { margin: 0; }
.pub-uploads { width: 100%; text-align: left; max-height: 340px; padding: 0; }
.pub-uploads:empty { display: none; }
.pub-uploads .upload-item { padding: 8px 4px; border-bottom: 1px solid var(--border); }
.share-head #folder-zip { align-self: flex-end; }

/* ---- Document previews (Word, Excel, PowerPoint, zip) ---- */
.viewer-stage > .viewer-doc { align-self: start; width: 100%; display: grid; justify-items: center; }
.doc-page {
  width: min(860px, 100%); padding: 40px 48px; border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 15px; line-height: 1.6; overflow-wrap: anywhere;
}
.doc-page.wide { width: min(1400px, 100%); padding: 20px; }
.doc-page h1 { font-size: 26px; margin: 0 0 14px; line-height: 1.25; }
.doc-page h2 { font-size: 20px; margin: 22px 0 8px; line-height: 1.3; }
.doc-page h3 { font-size: 16.5px; margin: 18px 0 6px; }
.doc-page p { margin: 0 0 10px; white-space: pre-wrap; }
.doc-page ul { margin: 0 0 10px; padding-left: 24px; }
.doc-page li { white-space: pre-wrap; }
.doc-note { color: var(--muted); font-size: 13px; font-style: italic; }
.doc-table-wrap { max-width: 100%; overflow: auto; margin: 6px 0 14px; }
.doc-table { border-collapse: collapse; font-size: 13.5px; }
.doc-table td, .doc-table th { border: 1px solid var(--border); padding: 4px 8px; vertical-align: top; white-space: pre-wrap; text-align: left; }
.doc-table td.num { text-align: right; white-space: nowrap; color: var(--muted); }
.doc-table.sheet td { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc-table.sheet th { background: var(--surface-2); color: var(--muted); font-weight: 550; position: sticky; top: 0; }
.doc-table.sheet tbody th { position: sticky; left: 0; text-align: right; }
.sheet-holder .doc-table-wrap { max-height: calc(100dvh - 190px); }
.sheet-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.sheet-tab {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 8px;
  padding: 4px 12px; cursor: pointer; font: inherit; font-size: 13px;
}
.sheet-tab.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.doc-slide { border: 1px solid var(--border); border-radius: 10px; padding: 16px 20px; margin-bottom: 14px; }
.doc-slide h2 { margin-top: 0; }
.doc-slide-no { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* ---- Action sheet ---- */
dialog.sheet { width: min(400px, calc(100vw - 32px)); }
.sheet-inner { padding: 8px 8px 10px; display: grid; }
.sheet-grip { display: none; }
.sheet-title {
  margin: 6px 12px 8px; font-size: 14px; font-weight: 600; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sheet-list { display: grid; }
.sheet-item {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 48px; padding: 0 14px;
  border: 0; background: none; border-radius: 10px; text-align: left; font-size: 15px; cursor: pointer;
  color: var(--text); text-decoration: none;
}
.sheet-item .ico { width: 20px; height: 20px; color: var(--muted); }
.sheet-item:hover { background: var(--surface-2); }
.sheet-item.danger, .sheet-item.danger .ico { color: var(--danger); }
.sheet-cancel { justify-content: center; margin-top: 4px; border-top: 1px solid var(--border); border-radius: 0 0 10px 10px; font-weight: 600; }

/* ---- Floating add button (phones) ---- */
.fab {
  position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 15;
  width: 58px; height: 58px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--on-accent); box-shadow: 0 6px 20px rgb(31 98 214 / .4);
  place-items: center;
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(.95); }

button, a, .sheet-item, .tab { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: pop-in .16s ease-out; }
  @keyframes pop-in { from { opacity: 0; transform: scale(.97); } }
}

/* ---- Small screens ---- */
@media (max-width: 900px) {
  .col-date { width: 150px; }
}

@media (max-width: 720px) {
  .desk { display: none !important; }
  .phone:not([hidden]) { display: revert !important; }
  .fab.phone:not([hidden]), .icon-btn.phone:not([hidden]) { display: inline-grid !important; }

  /* In a subfolder: back arrow + folder name, like a phone file manager */
  .crumbs .crumb:not(.current), .crumbs .crumb-sep { display: none; }
  .crumbs .crumb.current { padding-left: 0; font-size: 20px; overflow: hidden; text-overflow: ellipsis; }
  .up-btn { margin-left: -8px; color: var(--text); }
  .up-btn svg { width: 24px !important; height: 24px !important; }
  body.selecting .up-btn { display: none !important; }

  body { font-size: 15px; }
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 12px 8px 16px; }
  .brand-text { font-size: 16px; }
  .me-name { display: none; }
  .me-btn { padding: 0; width: 40px; height: 40px; justify-content: center; }
  .avatar { width: 32px; height: 32px; font-size: 14px; }

  /* Bottom tab bar */
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 14; margin: 0;
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    /* Solid, not frosted glass: iPhones flicker a blurred fixed bar black while the page under it changes */
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .tab {
    display: grid; justify-items: center; gap: 2px; padding: 6px 0 4px; border-radius: 12px;
    font-size: 11.5px; font-weight: 600;
  }
  .tab:hover { background: none; color: var(--muted); }
  .tab.active, .tab.active:hover { background: none; color: var(--accent); }
  .tab-ico { display: block; width: 24px; height: 24px; }
  .tab-ico svg { width: 24px; height: 24px; }
  .tab.active .tab-ico {
    background: var(--accent-soft); border-radius: 999px; width: 52px; display: grid; place-items: center;
  }

  /* Room for the tab bar and + button */
  .files { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .content { padding: 0 12px; margin-bottom: 88px; }

  .toolbar { padding: 12px 16px 10px; gap: 6px; min-height: 56px; }
  .page-title { font-size: 22px; }
  .crumbs { font-size: 18px; min-width: 0; flex: 1; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .crumbs::-webkit-scrollbar { display: none; }
  .crumb { white-space: nowrap; }

  /* Selecting (after a long-press) replaces the path with a selection bar */
  .select-bar { display: none; }
  body.selecting #files-panel .crumbs { display: none; }
  body.selecting .select-bar { display: flex; align-items: center; gap: 6px; flex: 1; }
  body.selecting #selection-info { font-size: 16px; color: var(--text); font-weight: 600; white-space: nowrap; }
  body.selecting #files-panel .toolbar > .spacer, body.selecting .fab { display: none !important; }
  body.selecting #files-table .col-act { visibility: hidden; }

  /* Lists become roomy, tappable rows */
  .list { border-radius: 14px; }
  .list thead { display: none; }
  .list th, .list td { padding: 0 6px; height: 62px; }
  .list td:first-child, .list td.col-name { padding-left: 14px; }
  body.selecting #files-table td.col-name { padding-left: 4px; }
  .list td:last-child { padding-right: 6px; }
  .has-sub .col-size, .has-sub .col-date, .col-from, .col-expires, .col-count { display: none; }
  .col-chk { display: none; width: 40px; }
  body.selecting #files-table .col-chk { display: table-cell; }
  #files-table .col-chk input { width: 20px; height: 20px; }
  .col-act, .col-act.wide { width: 48px; }
  .icon-btn.phone { width: 40px; height: 40px; }
  .icon-btn.phone svg { width: 20px; height: 20px; }
  .ficon { width: 30px; height: 30px; }
  .name-cell { gap: 14px; }
  .name-link { font-size: 15.5px; color: var(--text); }
  .name-link:hover { text-decoration: none; color: var(--text); }
  .sub { font-size: 12.5px; margin-top: 1px; }
  .list tbody tr { cursor: pointer; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
  .list tbody tr:hover { background: none; }
  .list tbody tr:active { background: var(--row-hover); }
  .list tbody tr.selected { background: var(--row-selected); }

  .empty { padding: 72px 16px; }

  /* Inputs at 16px so iPhones don't zoom in */
  .field input, .field select, .link-input { font-size: 16px; height: 46px; }
  .btn { height: 40px; }

  /* Dialogs slide up from the bottom */
  dialog, dialog#users-dlg, dialog.sheet {
    width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0;
    border-bottom: 0; max-height: 90vh; overflow: auto;
  }
  .dlg { padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
  .dlg-actions .btn { flex: 1; height: 46px; }
  .sheet-inner { padding: 6px 10px calc(10px + env(safe-area-inset-bottom)); }
  .sheet-grip { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 4px auto 6px; }
  .sheet-item { min-height: 54px; font-size: 16px; }
  .user-add .row { grid-template-columns: 1fr; }

  /* Uploads panel and toast sit above the tab bar */
  .uploads { left: 12px; right: 88px; bottom: calc(76px + env(safe-area-inset-bottom)); width: auto; max-width: none; }
  .toast { bottom: calc(150px + env(safe-area-inset-bottom)); width: max-content; }
  .menu-list { min-width: 220px; }
  .menu-item { padding: 12px 12px; font-size: 15px; }

  /* Search on phones: a big box at the top of the search page */
  .search-page { margin: 0; flex: 1; }
  .search-page input { height: 46px; font-size: 16px; border-radius: 12px; }
  .search-page .search-ico { left: 14px; width: 18px; height: 18px; }
  .search-page input { padding-left: 42px; }
  .header-btn { width: 40px; height: 40px; color: var(--text); }
  .header-btn svg { width: 22px; height: 22px; }

  /* Viewer: hide the arrows (swipe instead) and give the picker more room */
  .viewer-nav { display: none !important; }
  .viewer-stage { padding: 0 0 env(safe-area-inset-bottom); }
  .viewer-img, .viewer-media { border-radius: 0; }
  .viewer-text { border-radius: 0; padding: 14px; width: 100%; }
  dialog.viewer { border-radius: 0; max-height: none; }
  .picker-list { max-height: 45vh; }
  .picker-item { min-height: 52px; font-size: 15px; }

  /* Previews of documents fill the screen */
  .doc-page { border-radius: 0; padding: 18px 16px; }
  .tab { font-size: 10.5px; }

  /* Users (admins): each user is a small card. Name on top, role and storage below, buttons on the right. */
  .list.users-table, .list.users-table tbody { display: block; }
  .list.users-table tr {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "name name act" "role usage act";
    align-items: center; column-gap: 8px; row-gap: 4px; padding: 10px 4px 10px 14px; border-bottom: 1px solid var(--border);
  }
  .list.users-table tr:last-child { border-bottom: 0; }
  .list.users-table td { display: block; height: auto; padding: 0; border: 0; }
  .list.users-table td:nth-child(1) { grid-area: name; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .list.users-table td:nth-child(2) { grid-area: role; }
  .list.users-table td:nth-child(3) { grid-area: usage; min-width: 0; }
  .list.users-table td:nth-child(4) { grid-area: act; width: auto; display: flex; }
  .list.users-table td[colspan] { grid-column: 1 / -1; }

  /* Public share page */
  .share-main { padding: 16px 12px; }
  .share-head #folder-zip { width: 100%; }
  #folder-table .col-date { display: none; }
  #folder-table .col-size { width: 80px; }
}

@media (max-width: 720px) and (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: sheet-up .22s cubic-bezier(.2, .8, .2, 1); }
  @keyframes sheet-up { from { transform: translateY(100%); } }
}

/* No hover effects on touch screens (they "stick" after a tap) */
@media (hover: none) {
  .btn:hover { background: var(--surface); }
  .btn.ghost:hover { background: transparent; }
  .btn.primary:hover { background: var(--accent); }
  .icon-btn:hover { background: transparent; color: var(--muted); }
}
