/* ---------- Design tokens ---------- */
:root {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #121d30;
  --raised: #19263b;
  --raised-hover: #22324b;
  --text: #e8edf5;
  --muted: #a0acc0;
  --faint: #8794aa;
  --accent: #38bdf8;
  --accent-strong: #7dd3fc;
  --accent-soft: rgba(56, 189, 248, .14);
  --accent-line: rgba(56, 189, 248, .42);
  --on-accent: #04121f;
  --line: rgba(148, 163, 184, .14);
  --line-strong: rgba(148, 163, 184, .24);
  --hover: rgba(148, 163, 184, .10);
  --danger: #f68b8b;
  --danger-solid: #c93a49;
  --danger-soft: rgba(246, 139, 139, .12);
  --success: #4ade80;
  --warn: #f5b84c;
  --warn-soft: rgba(245, 184, 76, .09);
  --r-panel: 16px;
  --r-control: 10px;
  --shadow-menu: 0 12px 32px rgba(0, 0, 0, .38);
  --tab-bg: #141e2d;
  --tab-bg-hover: #1a2637;
  --tab-line: rgba(148, 163, 184, .10);
  --tab-text: #d5deea;
  --tab-active-top: #245a88;
  --tab-active-bottom: #1c4a73;
  --tab-active-line: rgba(125, 190, 255, .45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: max(16px, env(safe-area-inset-left));
  --gutter-r: max(16px, env(safe-area-inset-right));
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.45; }
body { min-height: 100dvh; -webkit-font-smoothing: antialiased; }
body.modal-open { overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
h1, h2, p { margin: 0; }
h2 { font-size: 1.125rem; font-weight: 600; letter-spacing: -.01em; }
svg { flex: 0 0 auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Stroke icons used across the app */
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Buttons ---------- */
.btn { appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border: 1px solid transparent; border-radius: var(--r-control); background: var(--accent); color: var(--on-accent); font-size: .9375rem; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background-color .15s ease, border-color .15s ease, color .15s ease; }
.btn:hover { background: var(--accent-strong); }
.btn .i { width: 18px; height: 18px; stroke-width: 2.1; }
.btn.secondary { background: var(--raised); color: var(--text); border-color: var(--line); }
.btn.secondary:hover { background: var(--raised-hover); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line-strong); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.danger-solid { background: var(--danger-solid); color: #fff; }
.btn.danger-solid:hover { background: #b3303e; }
.btn.compact { min-height: 36px; padding: 0 12px; font-size: .875rem; }
.btn:disabled { opacity: .45; cursor: default; }

.icon-btn { appearance: none; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: var(--r-control); background: transparent; color: var(--muted); cursor: pointer; transition: background-color .15s ease, color .15s ease; }
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: var(--hover); color: var(--text); }
.icon-btn:disabled { opacity: .45; cursor: default; }

.ghost-btn { appearance: none; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px; border: 0; border-radius: var(--r-control); background: transparent; color: var(--muted); font-size: .9375rem; font-weight: 500; cursor: pointer; }
.ghost-btn:hover { background: var(--hover); color: var(--text); }
.ghost-btn .i { width: 18px; height: 18px; }

.link-btn { appearance: none; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 2px; border: 0; background: none; color: var(--accent); font-size: .9375rem; font-weight: 500; cursor: pointer; }
.link-btn:hover { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- App shell ---------- */
.app-shell { width: 100%; max-width: 760px; margin: 0 auto; padding: max(8px, calc(env(safe-area-inset-top) + 16px)) var(--gutter-r) max(32px, env(safe-area-inset-bottom)) var(--gutter); }
body.signed-out .app-shell { display: none; }

/* Header */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 6px 0 10px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { width: 30px; height: 30px; flex: 0 0 auto; }
.brand h1 { font-size: 1.375rem; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 6px; }

/* Connection indicator: a quiet dot while connected, words only when not */
.conn { display: inline-flex; align-items: center; gap: 7px; padding: 0 6px; color: var(--muted); font-size: .8125rem; white-space: nowrap; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.conn[data-state="live"] .conn-dot { background: var(--success); opacity: .85; }
.conn[data-state="live"] .conn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.conn[data-state="offline"] { color: var(--warn); }
.conn[data-state="offline"] .conn-dot { background: var(--warn); }

.account-btn { appearance: none; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: transparent; cursor: pointer; }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--raised); border: 1px solid var(--line-strong); color: var(--text); font-size: .9375rem; font-weight: 600; text-transform: uppercase; }
.account-btn:hover .avatar, .account-btn[aria-expanded="true"] .avatar { background: var(--raised-hover); }

/* ---------- Sheet tabs ---------- */
.sheet-bar { display: flex; align-items: center; gap: 4px; margin: 0 0 14px; }
.tabs-scroller { position: relative; flex: 1 1 auto; min-width: 0; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; scroll-padding-inline: 24px; }
.tabs-scroller::-webkit-scrollbar { display: none; }
.tabs-scroller.fade-end { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); }
.tabs-scroller.fade-start { -webkit-mask-image: linear-gradient(to right, transparent, #000 32px); mask-image: linear-gradient(to right, transparent, #000 32px); }
.tabs-scroller.fade-start.fade-end { -webkit-mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent); }
.sheet-tabs { display: flex; gap: 10px; width: max-content; padding: 2px; }
.sheet-tab { appearance: none; position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 44px; min-width: 84px; max-width: 200px; padding: 2px 20px; border: 1px solid var(--tab-line); border-radius: 12px; background: var(--tab-bg); color: var(--tab-text); font-size: 1rem; font-weight: 600; letter-spacing: -.005em; cursor: pointer; white-space: nowrap; transition: background-color .15s ease, color .15s ease, border-color .15s ease; }
.sheet-tab::after { content: ''; position: absolute; inset: -2px 0; }
.sheet-tab:hover { background: var(--tab-bg-hover); color: var(--text); }
.sheet-tab.active { background: linear-gradient(180deg, var(--tab-active-top), var(--tab-active-bottom)); border-color: var(--tab-active-line); color: #fff; box-shadow: 0 4px 14px rgba(20, 90, 160, .22); }
.sheet-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; line-height: 1.15; }
.sheet-status { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 15px; color: var(--muted); opacity: .8; font-size: .8125rem; font-weight: 400; line-height: 1; letter-spacing: 0; }
.sheet-status:empty { display: none; }
.sheet-status .i { width: 15px; height: 15px; stroke-width: 1.9; }
.tab-files { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.sheet-tab.active .sheet-status { color: #fff; opacity: .9; }
.add-sheet-btn { flex: 0 0 auto; }

/* ---------- Writing area ---------- */
.pad-card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); }
.pad-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; padding: 4px 6px 4px 20px; border-bottom: 1px solid var(--line); }
.save-status { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); font-size: .8125rem; }
.save-status span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-status[data-state="failed"] { color: var(--danger); }
.save-status[data-state="unsaved"], .save-status[data-state="saving"], .save-status[data-state="loading"] { color: var(--faint); }
.save-status .link-btn { min-height: 36px; font-size: .8125rem; }
.pad-actions { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }

.editor { position: relative; min-height: clamp(200px, 32vh, 340px); padding: 22px 24px 28px; outline: 0; color: var(--text); font-size: 1.0625rem; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.editor:focus-visible { outline: none; }
.pad-card:focus-within { border-color: var(--line-strong); }
.editor.is-empty::before { content: attr(data-placeholder); position: absolute; top: 22px; left: 24px; right: 24px; color: var(--faint); pointer-events: none; }
.editor.is-empty.is-loading::before { content: none; }
.editor[contenteditable="false"] { opacity: .6; }

.pad-image { display: block; max-width: 100%; max-height: min(480px, 60vh); height: auto; margin: 12px 0; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, .03); cursor: zoom-in; }
.pad-image.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.pad-image.pending { opacity: .45; outline: 2px dashed var(--accent-line); outline-offset: 3px; cursor: progress; }
.image-frame { position: absolute; z-index: 5; pointer-events: none; }
.image-handle { position: absolute; right: -13px; bottom: -13px; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); pointer-events: auto; cursor: nwse-resize; touch-action: none; }
.image-handle::before { content: ''; position: absolute; inset: -10px; }
.image-tools { position: absolute; z-index: 6; display: flex; align-items: stretch; gap: 2px; padding: 4px; border-radius: 12px; background: var(--raised); border: 1px solid var(--line-strong); box-shadow: var(--shadow-menu); }
.image-tools button { appearance: none; min-width: 40px; min-height: 40px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font-size: .875rem; font-weight: 600; cursor: pointer; }
.image-tools button:hover { background: var(--hover); }
.image-tools button.active { background: var(--accent-soft); color: var(--accent-strong); box-shadow: inset 0 0 0 1px var(--accent-line); }
.image-tools button.danger { color: var(--danger); }
.image-tools-sep { width: 1px; margin: 6px 2px; background: var(--line-strong); }

.pad-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding: 0 8px 4px 16px; }
.attach-link { font-size: .875rem; }
.attach-link .i { width: 17px; height: 17px; }
.tips { position: relative; margin-left: auto; }
.tips summary { list-style: none; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 10px; border-radius: var(--r-control); color: var(--faint); font-size: .8125rem; cursor: pointer; }
.tips summary::-webkit-details-marker { display: none; }
.tips summary:hover, .tips[open] summary { background: var(--hover); color: var(--text); }
.tips summary .i { width: 17px; height: 17px; }
.tips-panel { position: absolute; z-index: 20; right: 0; bottom: calc(100% + 6px); width: min(300px, calc(100vw - 40px)); padding: 12px 14px; border-radius: 12px; background: var(--raised); border: 1px solid var(--line-strong); box-shadow: var(--shadow-menu); color: var(--muted); font-size: .875rem; line-height: 1.45; }
.tips-panel ul { margin: 0; padding: 0 0 0 16px; display: grid; gap: 6px; }
.tips-panel strong { color: var(--text); font-weight: 600; }

/* ---------- Files ---------- */
.files { --files-bg: var(--bg); position: relative; margin-top: 32px; scroll-margin-top: 16px; }
.files-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.files-titles { min-width: 0; }
.files-title { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.files-title:focus { outline: none; }
.files-sub { margin-top: 3px; color: var(--muted); font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-row { display: flex; justify-content: flex-end; min-height: 12px; margin-top: 2px; }
.select-files-btn { appearance: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; margin: -2px -8px -6px 0; padding: 0 8px; border: 0; border-radius: 10px; background: transparent; color: var(--accent); font: inherit; font-size: .9375rem; font-weight: 600; cursor: pointer; }
.select-files-btn .i { width: 19px; height: 19px; stroke-width: 2; }
.select-files-btn:hover { background: var(--hover); }
.select-cancel { appearance: none; flex: 0 0 auto; min-height: 44px; margin: 0 -8px 0 auto; padding: 0 8px; border: 0; border-radius: 10px; background: transparent; color: var(--accent); font: inherit; font-size: 1.0625rem; font-weight: 600; cursor: pointer; }
.select-cancel:hover { background: var(--hover); }
body:not(.selecting) .file-list { border-top: 1px solid var(--line); }
body.selecting .select-row { display: none; }

/* Upload zone: tap to pick files; on a computer, also the drop target */
.drop-zone { appearance: none; display: grid; justify-items: center; gap: 4px; width: 100%; margin-top: 18px; padding: 18px 16px 16px; border: 1.5px dashed rgba(56, 189, 248, .75); border-radius: 14px; background: rgba(56, 189, 248, .06); color: var(--text); font: inherit; text-align: center; cursor: pointer; transition: background-color .15s ease, border-color .15s ease; }
.drop-zone:hover { background: rgba(56, 189, 248, .1); border-color: rgba(56, 189, 248, .75); }
.drop-zone .i { width: 28px; height: 28px; margin-bottom: 4px; color: var(--text); stroke-width: 2; }
.dz-title { font-size: 1.0625rem; font-weight: 600; }
.dz-pointer { display: none; }
.dz-touch { color: var(--accent); }
.dz-link { color: var(--accent); }
.dz-sub { color: var(--muted); font-size: .875rem; }
@media (hover: hover) and (pointer: fine) {
  .dz-pointer { display: inline; }
  .dz-touch { display: none; }
}
body.dragging-files .drop-zone { border-color: var(--accent); background: rgba(56, 189, 248, .1); }
.files.drag-active .drop-zone { border-style: solid; border-color: var(--accent); background: rgba(56, 189, 248, .16); }

.file-list { margin-top: 6px; }
body:not(.selecting) .select-row:has(#selectBtn:not([hidden])) + .transfer-list:empty ~ .file-list { margin-top: 0; }
.file-list:empty { display: none; }
.file-row { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.file-row-inner { position: relative; z-index: 1; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto auto; align-items: center; gap: 14px; min-height: 72px; padding: 10px 0; background: var(--files-bg); touch-action: pan-y; transition: transform .22s ease; }
.file-row.swiping .file-row-inner { transition: none; }
.swipe-delete { position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-end; padding: 0 22px; border: 0; background: var(--danger-solid); color: #fff; font: inherit; font-size: .9375rem; font-weight: 600; cursor: pointer; }
.file-row:not(.swiping):not(.open):not(.removing) .swipe-delete { visibility: hidden; }
.file-main { min-width: 0; }
.file-name { appearance: none; display: block; max-width: 100%; padding: 2px 0; border: 0; background: none; color: var(--text); font-size: 1.0625rem; font-weight: 600; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.file-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.file-title { display: block; color: var(--text); font-size: 1.0625rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { margin-top: 2px; color: var(--muted); font-size: .9375rem; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row.is-old .age { color: var(--warn); }
.file-row .icon-btn { color: var(--text); }
.file-row .icon-btn .i { width: 22px; height: 22px; stroke-width: 2; }

/* File-type marks */
.file-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; background: rgba(148, 163, 184, .14); color: #cbd5e1; font-size: .75rem; font-weight: 700; letter-spacing: .04em; }
.file-icon .i { width: 22px; height: 22px; }
.file-icon.has-thumb { overflow: hidden; background: var(--raised); }
.file-icon img { display: block; width: 100%; height: 100%; object-fit: cover; }
.file-row-inner .file-icon[data-view] { cursor: pointer; }
.file-icon.kind-img { background: #b9bec7; color: #eef1f5; }
.file-icon.kind-img .i { width: 26px; height: 26px; }
.file-icon.kind-pdf { background: rgba(246, 113, 113, .16); color: #fca5a5; }
.file-icon.kind-sheet { background: rgba(74, 222, 128, .15); color: #86efac; }
.file-icon.kind-doc { background: rgba(96, 165, 250, .16); color: #93c5fd; }
.file-icon.kind-slides { background: rgba(251, 146, 60, .16); color: #fdba74; }
.file-icon.kind-video, .file-icon.kind-audio { background: rgba(167, 139, 250, .16); color: #c4b5fd; }
.file-icon.kind-zip { background: rgba(250, 204, 21, .13); color: #fde047; }

/* Selecting several files */

/* Selecting files: checkboxes, a Select all row, and Download / Delete */
.check { appearance: none; flex: 0 0 auto; width: 22px; height: 22px; margin: 0; border: 2px solid rgba(160, 172, 192, .65); border-radius: 6px; background: transparent; cursor: pointer; transition: background-color .12s ease, border-color .12s ease; }
.check:checked, .check:indeterminate { border-color: var(--accent); background: var(--accent) center / 16px no-repeat; }
.check:checked { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2304121f' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E"); }
.check:indeterminate { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2304121f' stroke-width='3.2' stroke-linecap='round'%3E%3Cpath d='M6 12h12'/%3E%3C/svg%3E"); }

.select-bar { display: flex; align-items: center; margin-top: 6px; }
.select-all { display: inline-flex; align-items: center; gap: 14px; white-space: nowrap; min-height: 44px; color: var(--text); font-size: 1rem; font-weight: 600; cursor: pointer; }
.bulk-bar { display: flex; align-items: center; flex: 1 1 auto; min-width: 0; }
.sb-sep { flex: 0 0 auto; width: 1px; height: 26px; background: var(--line-strong); }
.bulk-count { color: var(--muted); font-size: 1rem; white-space: nowrap; }
.bulk-btn { appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; font: inherit; font-size: 1rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.bulk-btn .i { width: 22px; height: 22px; stroke-width: 2; }
.bulk-btn:hover:not(:disabled) { background: var(--hover); }
.bulk-btn:disabled { opacity: .4; cursor: default; }
.bulk-save, .bulk-share { color: var(--accent); }
.bulk-delete { color: var(--danger); }

/* Rows while selecting: checkbox, mark, name; picked rows tinted as one block */
.file-row.selectable { --sel-line: rgba(56, 189, 248, .3); display: grid; grid-template-columns: 22px 44px minmax(0, 1fr); align-items: center; gap: 16px; min-height: 72px; margin: 0 -12px; padding: 10px 12px; border: 1px solid transparent; border-bottom-color: var(--line); cursor: pointer; }
.file-row.selectable.selected { background: rgba(34, 170, 200, .13); border-left-color: var(--sel-line); border-right-color: var(--sel-line); border-bottom-color: rgba(56, 189, 248, .16); }
.file-row.selectable.selected:first-child, .file-row.selectable:not(.selected) + .file-row.selectable.selected { border-top-color: var(--sel-line); border-top-left-radius: 12px; border-top-right-radius: 12px; }
.file-row.selectable.selected:not(:has(+ .file-row.selected)) { border-bottom-color: var(--sel-line); border-bottom-left-radius: 12px; border-bottom-right-radius: 12px; }
.file-row.selectable:not(.selected):has(+ .file-row.selected) { border-bottom-color: transparent; }

/* Phones: Select all above the list, actions in a floating bar */
@media (max-width: 699px) {
  body.selecting .app-shell { padding-bottom: 110px; }
  body.selecting .toast { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 76px); }
  /* "3 selected" | Share · Download · Delete, each an icon over its label */
  .bulk-bar { position: fixed; z-index: 800; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); gap: 0; height: 58px; padding: 0 2px 0 20px; border: 1px solid var(--line-strong); border-radius: 18px; background: var(--raised); box-shadow: 0 10px 30px rgba(0, 0, 0, .45); }
  .sb-sep-lead, .sb-sep-cancel, .bulk-bar .sb-sep:not(.sb-sep-count) { display: none; }
  .bulk-bar .sb-sep-count { height: 26px; margin: 0 4px 0 16px; }
  .bulk-count { flex: 0 0 auto; color: var(--text); font-weight: 600; font-size: 1rem; }
  .bulk-bar .bulk-btn { flex: 1 1 0; flex-direction: column; gap: 2px; min-width: 0; height: 52px; padding: 0 2px; border-radius: 12px; font-size: .71875rem; font-weight: 600; }
  .bulk-bar .bulk-btn .i { width: 27px; height: 27px; stroke-width: 1.9; }
}

.empty-state { padding: 16px 0 4px; color: var(--muted); font-size: .9375rem; }
.empty-state span { display: block; margin-top: 2px; color: var(--faint); font-size: .8125rem; }
.files-foot-row { display: flex; flex-direction: column; gap: 22px; margin-top: 16px; }
.files-foot { color: var(--muted); font-size: .9375rem; font-variant-numeric: tabular-nums; }
.files-foot.near { color: var(--warn); }
.files-foot.full { color: var(--danger); }

/* Drop target, shown only while files are dragged over the page */
body.dragging-files .files.drag-active 
/* Uploads and downloads in progress */
.transfer-list { display: grid; margin-top: 12px; }
.transfer-list:empty { display: none; }
.transfer-row { padding: 10px 0 12px; border-bottom: 1px solid var(--line); }
.transfer-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 36px; }
.transfer-name { min-width: 0; font-size: .9375rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transfer-buttons { display: flex; gap: 4px; flex: 0 0 auto; }
.transfer-cancel { appearance: none; min-height: 36px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: .8125rem; cursor: pointer; }
.transfer-cancel:hover { background: var(--hover); color: var(--text); }
.transfer-retry { color: var(--accent-strong); font-weight: 600; }
.transfer-bar { height: 4px; margin-top: 6px; border-radius: 999px; background: rgba(148, 163, 184, .16); overflow: hidden; }
.transfer-fill { width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .2s ease; }
.transfer-row.done .transfer-fill { background: var(--success); }
.transfer-row.failed .transfer-fill { background: var(--danger); }
.transfer-meta { margin-top: 6px; color: var(--muted); font-size: .8125rem; font-variant-numeric: tabular-nums; }
.transfer-row.failed .transfer-meta { color: var(--danger); }
.transfer-items { display: grid; gap: 4px; margin-top: 8px; font-size: .8125rem; }
.transfer-item { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); }
.transfer-item span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.transfer-item.done span:last-child { color: var(--success); }

/* Forgotten-files reminder */
.old-files-note { margin-top: 14px; padding: 14px 16px; border-radius: 12px; background: var(--warn-soft); border: 1px solid rgba(245, 184, 76, .22); }
.old-files-title { display: block; font-size: .9375rem; font-weight: 600; color: var(--text); }
.old-files-note p { margin: 3px 0 10px; color: var(--muted); font-size: .875rem; line-height: 1.45; }
.old-files-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.privacy { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: .9375rem; }
.privacy .i { width: 17px; height: 17px; }

/* Bulk actions while selecting */

/* ---------- Menus ---------- */
.menu { position: fixed; z-index: 950; min-width: 210px; max-width: calc(100vw - 16px); padding: 6px; border-radius: 12px; background: var(--raised); border: 1px solid var(--line-strong); box-shadow: var(--shadow-menu); }
.menu-heading { padding: 8px 12px 6px; color: var(--muted); font-size: .8125rem; overflow-wrap: anywhere; }
.menu-item { appearance: none; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font-size: .9375rem; text-align: left; cursor: pointer; }
.menu-item .i { width: 18px; height: 18px; color: var(--muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); outline: none; }
.menu-item.danger, .menu-item.danger .i { color: var(--danger); }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--line-strong); }

/* ---------- Toast ---------- */
.toast { position: fixed; z-index: 1000; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px; background: var(--raised); border: 1px solid var(--line-strong); box-shadow: var(--shadow-menu); color: var(--text); font-size: .9375rem; transform: translate(-50%, 12px); opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.has-action { display: flex; align-items: center; gap: 12px; padding: 4px 6px 4px 16px; }
.toast.show.has-action { pointer-events: auto; }
.toast span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-action { appearance: none; flex: 0 0 auto; min-height: 40px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--accent-strong); font: inherit; font-weight: 600; cursor: pointer; }
.toast-action:hover { background: var(--hover); }

/* ---------- Dialogs ---------- */
.modal-backdrop { position: fixed; z-index: 900; inset: 0; display: flex; align-items: center; justify-content: center; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); background: rgba(3, 7, 15, .72); }
.modal-card { width: min(460px, 100%); border-radius: var(--r-panel); background: var(--surface); border: 1px solid var(--line-strong); box-shadow: 0 24px 60px rgba(0, 0, 0, .45); overflow: hidden; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 12px 14px 20px; border-bottom: 1px solid var(--line); }
.modal-header h2 { font-size: 1.0625rem; }
.modal-kicker { margin-bottom: 2px; color: var(--muted); font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.modal-close { appearance: none; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: var(--r-control); background: transparent; color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer; flex: 0 0 auto; }
.modal-close:hover { background: var(--hover); color: var(--text); }
.rename-modal form { padding: 18px 20px 20px; }
.field-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .8125rem; }
.rename-input, .auth-input { width: 100%; min-height: 48px; padding: 12px 13px; border: 1px solid var(--line-strong); border-radius: var(--r-control); background: #0e1727; color: var(--text); font-size: 1rem; }
.rename-input:focus, .auth-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 189, 248, .16); outline: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Bottom sheet for confirmations and choices */
.modal-backdrop.sheet-backdrop { align-items: flex-end; padding: 0; }
.sheet-card { width: min(520px, 100%); padding: 20px 18px max(22px, env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0; background: var(--surface); border: 1px solid var(--line-strong); border-bottom: 0; }
.sheet-grabber { width: 36px; height: 4px; margin: -6px auto 16px; border-radius: 2px; background: var(--line-strong); }
.sheet-card h2 { font-size: 1.1875rem; overflow-wrap: anywhere; }
.sheet-text { margin: 6px 0 14px; color: var(--muted); font-size: .9375rem; line-height: 1.45; }
.sheet-items { display: grid; gap: 6px; max-height: 32vh; overflow: auto; padding: 10px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); font-size: .875rem; }
.sheet-item { display: flex; justify-content: space-between; gap: 10px; }
.sheet-item span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-item span:last-child { flex: 0 0 auto; color: var(--muted); }
.sheet-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.sheet-actions .btn { min-height: 48px; }
.sheet-actions .btn.full { grid-column: 1 / -1; }

/* File preview */
.preview-backdrop { padding: 0; align-items: stretch; justify-content: stretch; }
.preview-modal { width: 100%; height: 100%; border-radius: 0; border: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.preview-header { min-height: 64px; padding: max(10px, calc(env(safe-area-inset-top) + 16px)) 10px 10px 18px; background: var(--surface); }
.preview-title-wrap { min-width: 0; }
.preview-title-wrap h2 { max-width: min(620px, 55vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-toolbar { display: flex; align-items: center; gap: 6px; }
.preview-body { position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; overflow: auto; background: #070c16; }
.preview-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.preview-image, .preview-media { display: block; max-width: 100%; max-height: 100%; margin: auto; object-fit: contain; }
.preview-fallback { width: min(520px, calc(100% - 32px)); padding: 26px; color: var(--muted); text-align: center; }
.preview-fallback strong { display: block; margin-bottom: 8px; color: var(--text); }
.preview-loading { width: min(420px, calc(100% - 40px)); color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.preview-loading .transfer-bar { margin-top: 10px; }

/* Admin */
/* Search: a panel at the top of the screen */
.modal-backdrop.search-backdrop { align-items: flex-start; padding-top: max(16px, calc(env(safe-area-inset-top) + 12px)); }
.search-card { display: flex; flex-direction: column; width: min(640px, 100%); max-height: min(78dvh, 720px); border-radius: var(--r-panel); background: var(--surface); border: 1px solid var(--line-strong); box-shadow: 0 24px 60px rgba(0, 0, 0, .5); overflow: hidden; }
.search-field { display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 16px; border-bottom: 1px solid var(--line); }
.search-field > .i { flex: 0 0 auto; color: var(--muted); }
.search-field input { flex: 1 1 auto; min-width: 0; min-height: 48px; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 1.0625rem; }
.search-field input::placeholder { color: var(--faint); }
.search-field input::-webkit-search-cancel-button { display: none; }
.search-cancel { flex: 0 0 auto; padding: 0 10px; font-weight: 600; }
.search-results { overflow-y: auto; overscroll-behavior: contain; padding: 6px 0 10px; }
.search-group { padding: 12px 18px 4px; color: var(--faint); font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.search-item { display: grid; grid-template-columns: 36px minmax(0, 1fr); align-items: center; gap: 12px; margin: 0 8px; padding: 10px; border-radius: 10px; color: var(--text); cursor: pointer; }
.search-item.active, .search-item:hover { background: var(--hover); }
.search-item.active { box-shadow: inset 0 0 0 1px var(--accent-line); }
.search-item .file-icon { width: 36px; height: 36px; border-radius: 9px; }
.search-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; background: var(--raised); color: var(--muted); }
.search-mark .i { width: 18px; height: 18px; }
.search-main { min-width: 0; }
.search-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-meta { margin-top: 2px; color: var(--muted); font-size: .8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-snippet { margin-top: 2px; color: var(--muted); font-size: .9375rem; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.search-results mark { padding: 0 1px; border-radius: 3px; background: rgba(250, 204, 21, .32); color: var(--text); }
.search-empty { padding: 22px 20px; color: var(--muted); font-size: .9375rem; }
.search-empty kbd { padding: 1px 6px; border: 1px solid var(--line-strong); border-radius: 5px; font: inherit; font-size: .8125rem; }
::highlight(search-hit) { background-color: rgba(250, 204, 21, .45); color: inherit; }
@keyframes row-flash { from { background-color: rgba(56, 189, 248, .22); } to { background-color: var(--files-bg); } }
.file-row.flash .file-row-inner { animation: row-flash 2.2s ease-out; }

/* Share links */
.share-modal { width: min(500px, 100%); }
.share-head { min-width: 0; }
.share-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-body { display: grid; gap: 16px; padding: 18px 20px 20px; }
.share-body > * { min-width: 0; }
.share-explain { color: var(--muted); font-size: .9375rem; line-height: 1.5; }
.seg-label { color: var(--muted); font-size: .8125rem; margin-bottom: -8px; }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.seg button { appearance: none; min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: inherit; font-size: .9375rem; font-weight: 600; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--raised); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
.share-url-row { display: flex; gap: 8px; }
.share-url-row input { flex: 1 1 0; width: 0; min-width: 0; min-height: 48px; padding: 0 13px; border: 1px solid var(--line-strong); border-radius: var(--r-control); background: #0e1727; color: var(--text); font: inherit; font-size: .9375rem; text-overflow: ellipsis; }
.share-url-row input:focus { border-color: var(--accent); outline: none; }
.share-url-row .btn { flex: 0 0 auto; min-height: 48px; padding: 0 16px; }
.share-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.share-status { color: var(--muted); font-size: .875rem; }
.share-status b { color: var(--text); font-weight: 600; }
.share-off { color: var(--danger); }
.btn.full { width: 100%; }
.shared-tag { display: inline-flex; align-items: center; margin-right: 6px; color: var(--accent); vertical-align: -2px; }
.shared-tag .i { width: 15px; height: 15px; stroke-width: 2.2; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.link-row-state.off { color: var(--faint); }

/* Recently Deleted */
.trash-modal { width: min(620px, 100%); max-height: min(86dvh, 860px); display: flex; flex-direction: column; }
.trash-sub { margin-top: 3px; color: var(--muted); font-size: .8125rem; }
.trash-body { overflow-y: auto; padding: 4px 20px 16px; }
.trash-group { padding: 16px 0 6px; color: var(--faint); font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.trash-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; align-items: center; gap: 12px; min-height: 72px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.trash-row .file-icon, .trash-row .search-mark { width: 40px; height: 40px; }
.trash-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-meta { margin-top: 2px; color: var(--muted); font-size: .8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-meta .soon { color: var(--warn); }
.trash-row .link-btn { padding: 0 10px; font-weight: 600; }
.trash-row .icon-btn { color: var(--danger); }
.trash-empty { padding: 28px 0 16px; color: var(--muted); }
.trash-empty strong { display: block; margin-bottom: 4px; color: var(--text); font-weight: 600; }
.trash-foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; border-top: 1px solid var(--line); }

.admin-modal { width: min(720px, 100%); max-height: min(88dvh, 900px); display: flex; flex-direction: column; }
.admin-body { overflow: auto; padding: 16px 20px 20px; }
.admin-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.admin-stat { padding: 12px 14px; border-radius: 12px; background: var(--raised); border: 1px solid var(--line); }
.admin-stat strong { display: block; font-size: 1.375rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.admin-stat span { color: var(--muted); font-size: .8125rem; }
.admin-list { display: grid; }
.admin-row { padding: 14px 0; border-bottom: 1px solid var(--line); }
.admin-email { display: flex; align-items: center; gap: 8px; font-weight: 600; overflow-wrap: anywhere; }
.admin-badge { flex: 0 0 auto; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: .75rem; font-weight: 600; }
.admin-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 4px 14px; margin-top: 8px; color: var(--muted); font-size: .8125rem; }
.admin-facts b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.admin-limit { min-height: 36px; margin-top: 4px; font-size: .8125rem; }
.admin-note { margin-top: 14px; color: var(--faint); font-size: .8125rem; }

/* ---------- Sign-in ---------- */
.auth-screen { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
.auth-card { width: min(420px, 100%); padding: 26px 22px 22px; border-radius: var(--r-panel); background: var(--surface); border: 1px solid var(--line); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand .brand-icon { width: 34px; height: 34px; }
.auth-brand h1 { font-size: 1.375rem; font-weight: 700; letter-spacing: -.02em; }
.auth-step { display: flex; flex-direction: column; }
.auth-step h2 { margin-bottom: 12px; font-size: 1.25rem; }
.auth-text { margin: 0 0 14px; color: var(--muted); font-size: .9375rem; line-height: 1.5; }
.auth-text strong { color: var(--text); }
.auth-input { margin-bottom: 14px; }
.code-input { font-size: 1.25rem; font-weight: 600; letter-spacing: .05em; }
.password-field { position: relative; }
.password-field .auth-input { padding-right: 52px; }
.reveal-btn { position: absolute; top: 2px; right: 2px; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.reveal-btn:hover, .reveal-btn[aria-pressed="true"] { color: var(--text); }
.reveal-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.reveal-btn .eye-closed, .reveal-btn[aria-pressed="true"] .eye-open { display: none; }
.reveal-btn[aria-pressed="true"] .eye-closed { display: block; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.small-link { min-height: auto; padding: 0 0 7px; font-size: .8125rem; }
.auth-error { min-height: 1.2em; margin: 0 0 10px; color: var(--danger); font-size: .875rem; }
.auth-submit, .auth-create { min-height: 48px; font-size: 1rem; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0 12px; color: var(--muted); font-size: .8125rem; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.auth-alt { margin: 16px 0 0; color: var(--muted); font-size: .875rem; line-height: 1.4; text-align: center; }
.auth-alt .link-btn { min-height: 36px; font-size: .875rem; }
.recovery-input { font-size: 1rem; letter-spacing: .04em; text-transform: uppercase; }
.recovery-box { display: grid; gap: 10px; margin-bottom: 16px; padding: 14px; border: 1px solid var(--line-strong); border-radius: var(--r-control); background: var(--bg); }
.recovery-key { display: block; color: var(--text); font: 600 1.0625rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .04em; text-align: center; overflow-wrap: anywhere; user-select: all; }
.recovery-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.recovery-actions .btn { min-height: 40px; }
.recovery-check { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: .9375rem; cursor: pointer; }
.recovery-check input { width: 20px; height: 20px; accent-color: var(--accent); }
/* An image in the text that is still being unlocked. */
.editor img[src^="data:image/gif"] { min-width: 64px; min-height: 64px; border-radius: 8px; background: var(--raised); }

/* ---------- Larger screens ---------- */
@media (min-width: 700px) {
  .app-shell { padding-top: max(20px, calc(env(safe-area-inset-top) + 16px)); --gutter: 24px; --gutter-r: 24px; }
  .topbar { padding-bottom: 14px; }
  .editor { padding: 26px 32px 32px; }
  .editor.is-empty::before { top: 26px; left: 32px; right: 32px; }
  .pad-toolbar { padding-left: 24px; }
  .pad-footer { padding-left: 20px; }
  .files { --files-bg: var(--surface); margin-top: 32px; padding: 28px 30px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); }
  .drop-zone { margin-top: 20px; padding: 22px 16px 20px; }
  .dz-title { font-size: 1.1875rem; }
  .dz-sub { font-size: .9375rem; }
  .files-foot-row { flex-direction: row; align-items: center; justify-content: space-between; margin-top: 18px; }
  .select-bar { gap: 0; min-height: 58px; padding: 0 12px 0 22px; border: 1px solid var(--line-strong); border-radius: 12px; background: rgba(25, 38, 59, .7); }
  .select-all { padding-right: 18px; }
  .sb-sep-lead { margin-right: 18px; }
  .sb-sep-count { flex: 1 1 auto; height: 0; background: none; }
  .bulk-btn { padding: 0 12px; }
  /* Delete is the trash icon here; its name is read out and shown on hover */
  .bulk-delete { width: 44px; padding: 0; }
  .bulk-delete-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .select-bar .sb-sep:not(.sb-sep-lead):not(.sb-sep-count) { margin: 0 8px; }
  .select-cancel { margin: 0; padding: 0 14px; font-size: 1rem; }
}

/* ---------- Narrow phones ---------- */
@media (max-width: 380px) {
  .editor { padding: 18px 18px 24px; font-size: 1rem; }
  .editor.is-empty::before { top: 18px; left: 18px; right: 18px; }
  .pad-toolbar { padding-left: 16px; }
  .ghost-btn span { display: none; }
  .ghost-btn { width: 44px; justify-content: center; padding: 0; }
  .sheet-tab { min-width: 0; max-width: 150px; padding: 0 14px; }
}

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