:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-hover: #1c1c1c;
  --surface-active: #222;
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.14);
  --text: #fff;
  --text-2: rgba(255,255,255,0.55);
  --text-3: rgba(255,255,255,0.35);
  --accent: #3b82f6;
  --danger: #ef4444;
  --radius: 8px;
  --radius-lg: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
*, *::before, *::after {
  /* Kill the gray flash on tap that screams "this is a browser". Buttons get their own
     :active styling for visual feedback. */
  -webkit-tap-highlight-color: transparent;
}
html {
  color-scheme: dark;
  height: 100%;
  /* Stop the iOS rubber-band that exposes the page-behind-the-app. */
  overscroll-behavior: none;
  /* Disable text-size-adjust so iOS in landscape doesn't randomly upscale fonts. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Smooth programmatic scrolls (e.g. scrollIntoView from highlightFileRow). Native apps
     glide; webpages snap. */
  scroll-behavior: smooth;
  /* Crisp text on retina/HiDPI screens - Safari and Firefox without this look fuzzy. */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent the iOS edge-swipe gesture on the WHOLE page from triggering nav back; our
     popstate handler will catch it where it's appropriate. */
  -webkit-user-drag: none;
}

body {
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  overscroll-behavior: none;
  /* Prevent iOS Safari from showing the long-press "Save Image / Open in New Tab" callout
     anywhere in the app. Inputs/textareas re-enable it below. */
  -webkit-touch-callout: none;
  /* App chrome shouldn't be selectable - it's not text, it's controls. Inputs/text content
     re-enable selection where needed. */
  user-select: none;
  -webkit-user-select: none;
  /* Fast taps without the 300ms delay; double-tap-to-zoom is suppressed. */
  touch-action: manipulation;
}
body.viewer-open { overflow: hidden; }

/* Allow text selection and the system callout in places where it actually makes sense. */
input, textarea, [contenteditable], .selectable {
  -webkit-touch-callout: default;
  user-select: text;
  -webkit-user-select: text;
}

button, input, textarea { font: inherit; color: inherit; }
button {
  appearance: none;
  cursor: pointer;
  border: 0;
  /* Kill 300ms tap delay and prevent double-tap zoom on rapid taps. */
  touch-action: manipulation;
}
.hidden { display: none !important; }

/* iOS zooms the page when an input with font-size <16px is focused. Force 16px on real
   inputs via a min, but keep visual sizing the same with line-height. */
input, textarea, select { font-size: 16px; }

/* Show the focus ring only for keyboard navigation, not on every tap/click. */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Prevent the system context menu from popping up when long-pressing images. The app's own
   long-press handlers still fire because we attach them at the JS level. */
img { -webkit-touch-callout: none; -webkit-user-drag: none; }

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: var(--safe-top) max(24px, var(--safe-right)) var(--safe-bottom) max(24px, var(--safe-left));
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 56px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  background: rgba(10,10,10,0.82);
}
.brand-block { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px; display: grid; place-items: center;
  border-radius: 6px; background: #fff; color: #000;
  font-size: 14px; font-weight: 700;
}
.brand-name { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
#authActions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.auth-panel {
  display: flex; align-items: center; justify-content: center; min-height: 70vh;
}
.auth-card {
  width: 100%; max-width: 360px; padding: 32px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.auth-title { font-size: 20px; font-weight: 600; margin-bottom: 24px; }

.field-row { display: grid; gap: 6px; margin-bottom: 16px; }
.field-row label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-2);
}

input, textarea {
  width: 100%; padding: 10px 12px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-3); }
textarea { resize: vertical; min-height: 120px; }

button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  background: #fff; color: #000; font-weight: 500; font-size: 13px;
  transition: opacity 0.12s ease, transform 0.08s ease, background 0.12s ease;
}
button:hover:not(:disabled) { opacity: 0.85; }
button:active:not(:disabled) { transform: scale(0.97); opacity: 0.9; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
button.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: #000;
  animation: btn-spin 0.7s linear infinite;
}
button.secondary.is-loading::after, button.is-loading[class*="secondary"]::after {
  color: var(--text);
}
@keyframes btn-spin { to { transform: rotate(1turn); } }
button.secondary {
  background: transparent; color: var(--text); border: 1px solid var(--border);
}
button.secondary:hover:not(:disabled) { border-color: var(--border-hover); background: var(--surface-hover); }
button.secondary:active:not(:disabled) { background: var(--surface-active); }

.auth-buttons { display: flex; gap: 8px; margin-top: 20px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

.tool-btn {
  padding: 6px 12px; font-size: 13px; font-weight: 500;
  background: transparent; color: var(--text-2); border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: nowrap;
}
.tool-btn:hover:not(:disabled) { color: var(--text); border-color: var(--border-hover); background: var(--surface-hover); }
.tool-btn:active:not(:disabled) { background: var(--surface-active); transform: scale(0.97); }
.tool-btn { transition: color 0.12s, border-color 0.12s, background 0.12s, transform 0.08s; }

.upload-label {
  display: inline-flex; align-items: center; cursor: pointer;
  padding: 6px 12px; font-size: 13px; font-weight: 500;
  background: transparent; color: var(--text-2); border: 1px solid var(--border);
  border-radius: var(--radius); transition: all 0.15s;
  white-space: nowrap;
}
.upload-label:hover { color: var(--text); border-color: var(--border-hover); background: var(--surface-hover); }
.upload-label input[type="file"] { display: none; }

.user-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); font-size: 13px;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.drive-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 0;
  min-height: 0;
}
.drive-toolbar {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.drive-path {
  font-size: 13px;
  color: var(--text-2);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drive-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.drive-actions::-webkit-scrollbar { display: none; }

.drive-status {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; font-size: 12px; color: var(--text-3);
  border-bottom: 1px solid var(--border);
}
.drive-stats { display: flex; gap: 16px; font-size: 12px; color: var(--text-3); }

.view-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px; gap: 8px; border-bottom: 1px solid var(--border);
}
.sort-buttons { display: flex; gap: 4px; }
.sort-btn {
  padding: 4px 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  border: 1px solid var(--border); border-radius: var(--radius); background: transparent;
  color: var(--text-3); cursor: pointer; transition: all 0.15s; user-select: none;
}
.sort-btn:hover { border-color: var(--border-hover); color: var(--text-2); }
.sort-btn.active { background: var(--surface-active); color: var(--text); border-color: var(--border-hover); }
.sort-arrow { font-size: 10px; margin-left: 2px; }
.view-modes { display: flex; gap: 4px; }
.view-btn {
  width: 30px; height: 28px; font-size: 14px; border: 1px solid var(--border);
  border-radius: var(--radius); background: transparent; color: var(--text-3);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s; user-select: none; padding: 0;
}
.view-btn:hover { border-color: var(--border-hover); color: var(--text-2); }
.view-btn.active { background: var(--surface-active); color: var(--text); border-color: var(--border-hover); }

.grid-thumb { display: none; }

.thumb-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px; padding: 12px 16px;
}
.thumb-grid .file-row {
  display: flex; flex-direction: column; align-items: stretch;
  padding: 0; border-radius: var(--radius-lg); border: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface); min-height: auto; gap: 0;
  overflow: hidden; transition: border-color 0.15s, background 0.15s;
}
.thumb-grid .file-row:hover { border-color: var(--border-hover); background: var(--surface-hover); }
.thumb-grid .grid-thumb {
  display: grid; place-items: center; width: 100%; aspect-ratio: 4/3;
  background: var(--surface-active); overflow: hidden;
  font-size: 28px; color: var(--text-3); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.thumb-grid .grid-thumb img {
  width: 100%; height: 100%; object-fit: cover;
}
.thumb-grid .grid-thumb-folder {
  font-size: 42px; background: rgba(59,130,246,0.08);
}
.thumb-grid .file-row-name {
  padding: 8px 10px; gap: 6px;
}
.thumb-grid .file-row-name span { font-size: 12px; }
.thumb-grid .file-row-icon { display: none; }
.thumb-grid .col-type,
.thumb-grid .col-size,
.thumb-grid .col-date { display: none; }
.thumb-grid .file-row-dots {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px;
  background: rgba(0,0,0,0.5); border-radius: 6px; opacity: 0;
  transition: opacity 0.15s; color: #fff; font-size: 14px;
}
.thumb-grid .file-row:hover .file-row-dots { opacity: 1; }
.thumb-grid .file-row { position: relative; }
.thumb-grid .file-row-parent {
  aspect-ratio: auto; flex-direction: row; border: none;
  background: transparent; padding: 6px 10px;
}
.thumb-grid .file-row-parent .grid-thumb { display: none; }
.thumb-grid .file-row-parent .file-row-icon { display: grid; }

.file-table-wrap {
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.file-table-header {
  display: grid; grid-template-columns: 1fr 100px 100px 140px 40px; gap: 8px;
  padding: 10px 16px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3);
  border-bottom: 1px solid var(--border); user-select: none;
}

.file-row {
  display: grid; grid-template-columns: 1fr 100px 100px 140px 40px; gap: 8px;
  align-items: center; padding: 6px 16px; min-height: 44px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  cursor: default; user-select: none; transition: background 0.1s;
}
.file-row:hover { background: var(--surface-hover); }
.file-row.drag-over {
  background: rgba(59,130,246,0.1);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.file-row.dragging { opacity: 0.4; }
.file-table-wrap.drop-active {
  outline: 2px dashed var(--accent); outline-offset: -2px;
  background: rgba(59,130,246,0.06); border-radius: var(--radius);
}

.file-row-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-row-name span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px;
}
.file-row-badge {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(96,165,250,0.14);
  border: 1px solid rgba(96,165,250,0.32);
  color: #93c5fd;
  font-size: 10px !important;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  overflow: visible !important;
  text-overflow: clip !important;
}
.file-row-badge-danger {
  background: rgba(239,68,68,0.14);
  border-color: rgba(239,68,68,0.32);
  color: #fca5a5;
}
.file-row-pending-delete { opacity: 0.5; }
.file-row-busy .col-type { color: #93c5fd; }
.file-row-icon {
  width: 32px; height: 32px; border-radius: 6px; display: grid; place-items: center;
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  flex-shrink: 0; background: var(--surface-active); color: var(--text-2); overflow: hidden;
}
.file-row-icon.is-folder { background: rgba(59,130,246,0.15); color: #60a5fa; }
.file-row-icon img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.file-row .col-type,
.file-row .col-size,
.file-row .col-date { font-size: 13px; color: var(--text-2); }

.file-row-dots {
  width: 32px; height: 32px; border-radius: 6px;
  border: 0; background: transparent; color: var(--text-3);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0; font-size: 18px; line-height: 1;
  transition: background 0.1s, color 0.1s;
}
.file-row-dots:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.file-row-dots:active { background: rgba(255,255,255,0.12); }

.empty-state {
  padding: 64px 20px; text-align: center; color: var(--text-3); font-size: 14px;
  display: grid; gap: 14px; justify-items: center;
}
.empty-state::before {
  content: '';
  display: block;
  width: 64px; height: 64px;
  border-radius: 16px;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2360606a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='M3 7h6l2 2h10v10a2 2 0 0 1-2 2H3z'/></svg>") center / 32px no-repeat,
    linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.015));
  border: 1px solid var(--border);
}

.ctx-menu {
  position: fixed; z-index: 9999; min-width: 180px; padding: 4px;
  background: #1a1a1a; border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,0.6);
}
.ctx-item {
  display: flex; align-items: center; width: 100%; padding: 8px 12px;
  border: 0; border-radius: 4px; background: transparent; color: var(--text);
  font-size: 13px; text-align: left; cursor: pointer;
}
.ctx-item:hover { background: rgba(255,255,255,0.08); }
.ctx-item:disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}
.ctx-danger { color: var(--danger); }
.ctx-danger:hover { background: rgba(239,68,68,0.12); }
.ctx-sep { height: 1px; margin: 4px 0; background: rgba(255,255,255,0.08); }

.viewer-modal {
  width: min(1100px, calc(100vw - 32px)); max-width: 1100px;
  margin: auto;
  border: 0; padding: 0; border-radius: var(--radius-lg); background: transparent;
}
.viewer-modal::backdrop { background: rgba(0,0,0,0.82); backdrop-filter: blur(8px); }
.viewer-modal.viewer-modal-fallback {
  position: fixed;
  inset: 0;
  margin: 0;
  width: 100vw;
  max-width: none;
  height: 100vh;
  padding: 16px;
  border: 0;
  background: rgba(0,0,0,0.82);
  backdrop-filter: blur(8px);
  overflow: auto;
  z-index: 10000;
}
.viewer-modal.viewer-modal-fallback .viewer-shell {
  width: min(1100px, calc(100vw - 32px));
  margin: 0 auto;
}
.viewer-shell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; color: var(--text);
}
.viewer-shell button.secondary {
  background: rgba(255,255,255,0.06); color: var(--text); border-color: var(--border);
}
.viewer-close { margin-top: 12px; }
.viewer-stage { display: grid; gap: 12px; }
.viewer-meta { display: flex; align-items: center; justify-content: space-between; }
.viewer-meta h3 { font-size: 16px; font-weight: 600; margin: 0; }
.viewer-subtle { color: var(--text-2); font-size: 13px; }

.image-viewer img {
  width: 100%; max-height: 75vh; object-fit: contain;
  border-radius: var(--radius); background: #000;
}

.dd-player-shell {
  position: relative; width: 100%;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; background: #000; border-radius: var(--radius);
}
.dd-player-shell video {
  width: 100%; display: block;
  object-fit: contain; background: #000; max-height: 72vh;
}
.dd-player-controls {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  display: grid; grid-template-columns: auto auto 1fr auto auto auto;
  gap: 8px; align-items: center; padding: 8px 12px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.14);
  background: linear-gradient(180deg, rgba(6,8,14,0.64), rgba(4,5,10,0.86));
  backdrop-filter: blur(7px);
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.dd-player-shell:hover .dd-player-controls,
.dd-player-shell:focus-within .dd-player-controls {
  opacity: 1; transform: translateY(0);
}
.dd-player-shell:fullscreen,
.dd-player-shell:-webkit-full-screen {
  width: 100vw !important; max-width: none !important;
  height: 100vh !important; border-radius: 0 !important;
}
.dd-player-shell:fullscreen video,
.dd-player-shell:-webkit-full-screen video { max-height: 100vh; }
.dd-player-shell:fullscreen .dd-player-controls,
.dd-player-shell:-webkit-full-screen .dd-player-controls {
  left: 20px; right: 20px; bottom: 20px; opacity: 1; transform: none;
}
.dd-player-btn {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2); background: rgba(15,17,24,0.74);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0;
}
.dd-player-btn:hover { border-color: rgba(255,255,255,0.38); background: rgba(31,35,46,0.84); }
.dd-player-btn svg {
  width: 16px; height: 16px; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.dd-player-time {
  min-width: 78px; font-size: 11px; color: rgba(255,255,255,0.9);
  font-variant-numeric: tabular-nums; text-align: center;
}
.dd-player-seek, .dd-player-volume {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 999px; outline: none;
  background: rgba(255,255,255,0.24); border: 0; padding: 0; margin: 0;
  box-shadow: none;
}
.dd-player-seek {
  background:
    linear-gradient(
      to right,
      #fff 0 var(--seek, 0%),
      rgba(255,255,255,0.56) var(--seek, 0%) var(--buffered, var(--seek, 0%)),
      rgba(255,255,255,0.24) var(--buffered, var(--seek, 0%)) 100%
    );
}
.dd-player-volume {
  width: 68px;
  background: linear-gradient(to right, #60a5fa var(--vol, 100%), rgba(255,255,255,0.24) var(--vol, 100%));
}
.dd-player-seek::-webkit-slider-thumb,
.dd-player-volume::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 12px; height: 12px; border-radius: 50%; border: 0;
  background: #fff; box-shadow: 0 0 4px rgba(0,0,0,0.4); cursor: pointer;
}
.dd-player-seek::-moz-range-thumb,
.dd-player-volume::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%; border: 0;
  background: #fff; box-shadow: 0 0 4px rgba(0,0,0,0.4); cursor: pointer;
}
.dd-seek-wrap {
  position: relative; flex: 1; display: flex; align-items: center;
}
.dd-seek-tip {
  position: absolute; bottom: 18px;
  transform: translateX(-50%);
  padding: 3px 7px; border-radius: 5px;
  background: rgba(0,0,0,0.82); color: #fff; font-size: 11px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity 0.12s ease;
}
.dd-seek-wrap:hover .dd-seek-tip { opacity: 1; }
@media (hover: none), (pointer: coarse) {
  .dd-player-controls { opacity: 1; transform: none; }
  .dd-seek-tip { display: none; }
  .thumb-grid .file-row-dots { opacity: 1; }
  .file-row { cursor: pointer; }
}

.player-status-bar {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: var(--radius);
  background: rgba(255,255,255,0.06); color: var(--text-2); font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-editor { display: grid; gap: 12px; }
.text-editor-header h3 { font-size: 16px; font-weight: 600; margin: 0 0 4px; }
.text-editor-header p { margin: 0; color: var(--text-2); font-size: 13px; }
.device-link-auth { display: grid; gap: 14px; }
.device-link-hero {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(59,130,246,0.42);
  background:
    radial-gradient(120% 120% at 0% 0%, rgba(59,130,246,0.28), transparent 65%),
    radial-gradient(100% 100% at 100% 100%, rgba(16,185,129,0.15), transparent 70%),
    linear-gradient(160deg, rgba(23,37,84,0.7), rgba(15,23,42,0.85));
}
.device-link-tag {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #bfdbfe;
  background: rgba(30,64,175,0.35);
  border: 1px solid rgba(147,197,253,0.38);
}
.device-link-hero h3 { font-size: 18px; font-weight: 600; }
.device-link-hero p {
  margin: 0;
  color: rgba(255,255,255,0.82);
  font-size: 13px;
  line-height: 1.45;
}
button.device-link-button {
  justify-self: start;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid rgba(147,197,253,0.45);
  background: linear-gradient(135deg, rgba(37,99,235,0.95), rgba(29,78,216,0.95));
  color: #eff6ff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
button.device-link-button:hover { opacity: 1; filter: brightness(1.08); }
.device-link-fingerprint {
  margin: 0;
  color: rgba(191,219,254,0.9);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
}
.device-link-field { display: grid; gap: 6px; }
.device-link-field span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
}
.share-dialog { display: grid; gap: 16px; }
.share-dialog-header h3 { font-size: 17px; font-weight: 600; margin: 0 0 4px; }
.share-dialog-header p { margin: 0; color: var(--text-2); font-size: 13px; }
.share-meta-line { display: flex; align-items: center; gap: 8px; min-height: 24px; }
.share-status-badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
  background: rgba(255,255,255,0.06); color: var(--text-3);
  border: 1px solid var(--border);
}
.share-status-badge.is-active {
  border-color: rgba(34,197,94,0.45); color: #86efac;
  background: rgba(34,197,94,0.08);
}
.share-status-badge.is-revoked {
  border-color: rgba(239,68,68,0.4); color: #fca5a5;
  background: rgba(239,68,68,0.08);
}
.share-status-badge.is-expired {
  border-color: rgba(251,191,36,0.4); color: #fcd34d;
  background: rgba(251,191,36,0.08);
}
.share-empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px 16px; text-align: center;
  border: 1px dashed rgba(255,255,255,0.1); border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.02);
}
.share-empty-icon {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255,255,255,0.06); color: var(--text-3);
  font-size: 18px; font-weight: 600; margin-bottom: 10px;
}
.share-empty-state p {
  margin: 0; font-size: 14px; font-weight: 500; color: var(--text-2);
}
.share-empty-state span {
  margin-top: 4px; font-size: 12px; color: var(--text-3);
}
.share-link-section { display: grid; gap: 12px; }
.share-field-group { display: grid; gap: 5px; }
.share-field-group label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-2);
}
.share-field-with-copy {
  display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center;
}
.share-input {
  width: 100%; padding: 9px 12px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); outline: none;
  font-size: 13px; transition: border-color 0.15s;
}
.share-input:focus { border-color: var(--accent); }
.share-link-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}
.share-key-field {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}
.share-copy-btn {
  padding: 9px 14px; font-size: 12px; font-weight: 500;
  background: rgba(255,255,255,0.08); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  white-space: nowrap; min-width: 60px;
  transition: background 0.15s, border-color 0.15s;
}
.share-copy-btn:hover { background: rgba(255,255,255,0.12); border-color: var(--border-hover); }
.share-separate-fields { display: grid; gap: 10px; }
.share-toggle-row { display: flex; }
.share-toggle-btn {
  padding: 0; background: none; border: none;
  color: var(--accent); font-size: 12px; font-weight: 500;
  cursor: pointer; opacity: 0.85;
}
.share-toggle-btn:hover { opacity: 1; text-decoration: underline; }
.share-actions {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding-top: 4px; border-top: 1px solid var(--border);
}

.share-manage-list {
  display: grid;
  gap: 10px;
  max-height: 55vh;
  overflow: auto;
}
.share-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
}
.share-row-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-2);
}
.share-row-status {
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 11px;
}
.share-row-status.is-revoked {
  border-color: rgba(239,68,68,0.4);
  color: #fca5a5;
}
.share-row-status.is-expired {
  border-color: rgba(251,191,36,0.4);
  color: #fcd34d;
}
.share-row-status.is-active {
  border-color: rgba(34,197,94,0.45);
  color: #86efac;
}
.share-url {
  font-size: 12px;
  color: var(--text-3);
  word-break: break-all;
}
.share-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.share-empty {
  font-size: 13px;
  color: var(--text-3);
}
.share-note {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.4;
}

.audit-view { display: grid; gap: 12px; }
.audit-view h3 { font-size: 16px; font-weight: 600; margin: 0; }
.audit-list { display: grid; gap: 8px; max-height: 60vh; overflow: auto; }
.audit-item {
  padding: 12px; border-radius: var(--radius);
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
}
.audit-item strong, .audit-item p, .audit-item pre { margin: 0; }
.audit-item p { color: var(--text-2); font-size: 13px; }
.audit-item pre {
  margin-top: 8px; white-space: pre-wrap; word-break: break-word;
  color: var(--text-2); font-size: 12px;
}
.admin-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.admin-user-info {
  display: grid;
  gap: 6px;
  min-width: 0;
}
.admin-user-title {
  font-size: 14px;
  line-height: 1.2;
}
.admin-danger-btn {
  border-color: rgba(239,68,68,0.45) !important;
  color: #fecaca !important;
}
.admin-danger-btn:hover {
  border-color: rgba(239,68,68,0.8) !important;
  background: rgba(239,68,68,0.14) !important;
}

.upload-panel {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 320px;
  max-height: 400px;
  background: rgba(20, 20, 20, 0.94);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  z-index: 9998;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: panel-slide-up 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes panel-slide-up {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.upload-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}
.upload-panel-header .upload-count {
  font-weight: 400;
  color: var(--text-3);
  font-size: 12px;
}
.upload-panel-list {
  overflow-y: auto;
  max-height: 320px;
  padding: 6px;
  display: grid;
  gap: 4px;
}
.upload-item {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.03);
}
.upload-item-name {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upload-item-progress {
  height: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  overflow: hidden;
}
.upload-item-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.15s ease;
}
.upload-item-status {
  font-size: 11px;
  color: var(--text-3);
}
.upload-item.upload-done .upload-item-bar { background: #22c55e; }
.upload-item.upload-done .upload-item-status { color: #22c55e; }
.upload-item.upload-failed .upload-item-bar { background: var(--danger); }
.upload-item.upload-failed .upload-item-status { color: var(--danger); }

.upload-item-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.upload-item-actions .tool-btn {
  padding: 3px 8px;
  font-size: 11px;
}

@keyframes row-flash {
  0%   { background: rgba(250, 204, 21, 0.35); }
  100% { background: transparent; }
}
.row-highlight { animation: row-flash 2.5s ease-out; }

.completed-group {
  display: grid;
  gap: 4px;
}
.completed-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.18);
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  color: #86efac;
}
.completed-group-header:hover { background: rgba(34, 197, 94, 0.14); }
.completed-group-header .chevron {
  display: inline-block;
  transition: transform 0.15s ease;
  font-size: 11px;
  opacity: 0.7;
  margin-right: 6px;
}
.completed-group.is-expanded .completed-group-header .chevron { transform: rotate(90deg); }
.completed-group-list {
  display: none;
  gap: 4px;
  padding-left: 8px;
}
.completed-group.is-expanded .completed-group-list { display: grid; }
.completed-group-list .upload-item { opacity: 0.7; }

.file-row-parent { cursor: pointer; }
.file-row-parent .file-row-icon {
  background: transparent; color: var(--text-3);
  font-size: 14px; font-weight: 400;
}
.file-row-parent:hover { background: var(--surface-hover); }

@media (max-width: 768px) {
  .app-shell { padding: var(--safe-top) max(10px, var(--safe-right)) var(--safe-bottom) max(10px, var(--safe-left)); }
  .topbar { min-height: 50px; }
  .brand-name { font-size: 14px; }
  .top-actions { max-width: 62vw; overflow-x: auto; scrollbar-width: none; }
  .top-actions::-webkit-scrollbar { display: none; }
  #authActions { min-width: max-content; }
  .drive-toolbar { grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 10px 0; }
  .drive-actions { gap: 6px; padding-bottom: 2px; }
  /* Native-app tap target minimum (~44px). Was 8x12px / 13px font - feels like a webpage. */
  .tool-btn, .upload-label { padding: 10px 14px; font-size: 14px; min-height: 40px; }
  .view-toolbar { padding: 6px 10px; }
  .sort-btn { padding: 6px 10px; font-size: 12px; min-height: 32px; }
  .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; padding: 8px 10px; }
  .file-table-header, .file-row { grid-template-columns: 1fr 70px 40px; }
  .col-type, .col-date { display: none; }
  .file-table-header { padding: 8px 10px; }
  .file-row { padding: 10px; min-height: 52px; }
  .drive-status { flex-direction: column; gap: 4px; padding: 6px 0; }
  /* Mobile viewer behaves like an iOS bottom sheet - full width, slides up from below.
     Keep generous breathing room at top so the system status bar isn't crowded. */
  .viewer-modal {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    padding: 0;
    border-radius: 0;
    margin: 0;
    animation: viewer-sheet-up 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  }
  .viewer-modal.viewer-modal-fallback {
    padding: 0;
    height: 100dvh;
  }
  @keyframes viewer-sheet-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }
  .viewer-shell {
    padding: max(20px, var(--safe-top)) 16px max(16px, var(--safe-bottom));
    border-radius: 0;
    min-height: 100dvh;
    border: 0;
  }
  /* Big tap target for the close button when the viewer is full-screen. */
  .viewer-close { min-height: 44px; }
  .viewer-meta h3, .viewer-subtle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 78vw; }
  .auth-card { padding: 24px 20px; }
  .dd-player-controls {
    grid-template-columns: auto 1fr auto auto;
    gap: 6px; padding: 6px 8px;
  }
  .dd-player-time, .dd-player-volume { display: none; }
  .ctx-menu { min-width: 180px; }
  .ctx-item { padding: 14px 16px; font-size: 15px; }
  .admin-user-row { flex-direction: column; align-items: stretch; }
  .upload-panel {
    left: 10px;
    right: 10px;
    width: auto;
    bottom: calc(10px + var(--safe-bottom));
    max-height: 45vh;
  }
  .share-row-actions button { flex: 1 1 140px; }

  /* Hide scrollbars entirely on phones - they look webby. Scroll still works fine. */
  ::-webkit-scrollbar { display: none; width: 0; height: 0; }
  * { scrollbar-width: none; }
  /* Native-feeling momentum on any scrolling container. */
  .file-table-body, .upload-list, .ctx-menu, .viewer-shell {
    -webkit-overflow-scrolling: touch;
  }
  /* Tap feedback - the user sees the row dim briefly when they touch it. iOS-style. */
  .file-row:active, .tool-btn:active, .ctx-item:active, .sort-btn:active, .view-btn:active,
  button:not(:disabled):active, .upload-label:active, .file-row-parent:active {
    background: var(--surface-active);
    transform: scale(0.97);
    transition: transform 0.06s ease, background 0.06s ease;
  }
  .file-row:active { transform: none; }
  /* Disable the 0.97 scale on full-width rows (file rows) - the side bounce reads as glitchy
     on a list item but feels right on a discrete button. */

  /* Smooth, native-feeling page transitions when navigating into a folder. */
  .file-table-body { will-change: transform; }
}

/* In standalone (PWA) mode, drop the install button styling and tighten chrome. */
@media (display-mode: standalone) {
  .topbar { background: var(--bg); backdrop-filter: none; }
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
.app-toast {
  position: fixed;
  left: 50%;
  top: calc(12px + var(--safe-top));
  transform: translate(-50%, -160%);
  max-width: min(420px, calc(100vw - 24px));
  padding: 11px 18px;
  background: rgba(28, 28, 30, 0.96);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  z-index: 10001;
  pointer-events: none;
  opacity: 0;
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.app-toast[data-kind="error"] {
  background: rgba(60, 18, 18, 0.96);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fecaca;
}
.app-toast[data-kind="success"] {
  background: rgba(15, 36, 22, 0.96);
  border-color: rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
}

/* ── Skeleton loading ────────────────────────────────────────────────────── */
.items-skeleton { display: grid; gap: 4px; padding: 4px 0; }
.skeleton-row {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius);
}
.skeleton-thumb {
  width: 40px; height: 40px;
  border-radius: 6px;
  background: var(--surface);
}
.skeleton-lines { display: grid; gap: 6px; }
.skeleton-line {
  height: 12px;
  width: 60%;
  background: var(--surface);
  border-radius: 4px;
}
.skeleton-line-short { width: 35%; height: 10px; }
.shimmer {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.shimmer::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.06) 50%,
    transparent 100%
  );
  transform: translateX(-100%);
  animation: shimmer-slide 1.4s linear infinite;
}
@keyframes shimmer-slide { to { transform: translateX(100%); } }

/* ── Slide-in when a folder finishes loading ─────────────────────────────── */
@keyframes items-fade-in {
  0%   { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}
.items-enter > * {
  animation: items-fade-in 0.28s cubic-bezier(0.32, 0.72, 0, 1) both;
}
/* Stagger the first ~12 rows so the folder cascades in instead of popping all at once. */
.items-enter > *:nth-child(1)  { animation-delay: 0ms;   }
.items-enter > *:nth-child(2)  { animation-delay: 18ms;  }
.items-enter > *:nth-child(3)  { animation-delay: 32ms;  }
.items-enter > *:nth-child(4)  { animation-delay: 46ms;  }
.items-enter > *:nth-child(5)  { animation-delay: 60ms;  }
.items-enter > *:nth-child(6)  { animation-delay: 72ms;  }
.items-enter > *:nth-child(7)  { animation-delay: 84ms;  }
.items-enter > *:nth-child(8)  { animation-delay: 92ms;  }
.items-enter > *:nth-child(9)  { animation-delay: 100ms; }
.items-enter > *:nth-child(10) { animation-delay: 108ms; }
.items-enter > *:nth-child(11) { animation-delay: 114ms; }
.items-enter > *:nth-child(12) { animation-delay: 120ms; }
@media (prefers-reduced-motion: reduce) {
  .items-enter > * { animation: none; }
  .app-toast { transition: opacity 0.15s ease; transform: translate(-50%, 0); }
  .shimmer::after { animation: none; }
}

/* Native share button - a touch wider than the Copy button so the ellipsis fits. */
.share-native-btn { padding-left: 12px; padding-right: 12px; }

/* ── In-app confirm / prompt dialog ─────────────────────────────────────── */
.app-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10002;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.app-confirm-overlay.is-visible { opacity: 1; }
.app-confirm-sheet {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: grid;
  gap: 16px;
  color: var(--text);
  transform: translateY(4px);
  opacity: 0;
  transition: transform 0.18s ease, opacity 0.15s ease;
}
.app-confirm-overlay.is-visible .app-confirm-sheet {
  transform: translateY(0);
  opacity: 1;
}
.app-confirm-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.app-confirm-message {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  white-space: pre-wrap;
  margin-top: -8px;
}
.app-prompt-input {
  width: 100%;
  padding: 10px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s;
}
.app-prompt-input:focus { border-color: var(--accent); outline: none; }
.app-prompt-input.is-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.app-prompt-input.is-uppercase {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.app-confirm-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.app-confirm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.12s ease, transform 0.08s ease, background 0.12s ease, border-color 0.12s ease;
}
.app-confirm-cancel {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.app-confirm-cancel:hover { border-color: var(--border-hover); background: var(--surface-hover); }
.app-confirm-cancel:active { background: var(--surface-active); transform: scale(0.97); }
.app-confirm-ok {
  background: #fff;
  color: #000;
  border: 1px solid #fff;
}
.app-confirm-ok:hover { opacity: 0.85; }
.app-confirm-ok:active { transform: scale(0.97); opacity: 0.9; }
.app-confirm-ok.is-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.app-confirm-ok.is-danger:hover { opacity: 0.88; }

/* ── Admin panel: tabs + invite-key cards ────────────────────────────────── */
.admin-panel { display: grid; gap: 12px; }
.admin-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.admin-tab {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.is-active {
  background: var(--surface-active);
  color: var(--text);
}
.admin-pane { display: grid; gap: 12px; }
.admin-footer { justify-content: flex-end; }

.invite-create-box {
  display: grid;
  gap: 8px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.invite-create-box input {
  font-size: 14px;
}
.invite-list { display: grid; gap: 8px; }
.invite-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.invite-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.invite-card-code-block {
  display: flex;
  align-items: center;
  gap: 8px;
}
.invite-card-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0.04em;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 6px;
}
.invite-copy-btn { padding: 5px 10px; font-size: 12px; }
.invite-status {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 999px;
}
.invite-status.is-active { background: rgba(34, 197, 94, 0.12); color: #4ade80; }
.invite-status.is-revoked { background: rgba(239, 68, 68, 0.12); color: #fca5a5; }
.invite-meta { font-size: 12px; color: var(--text-3); }
.invite-users {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}
.invite-users-label { font-size: 11px; color: var(--text-3); width: 100%; }
.invite-user-chip {
  font-size: 11px;
  background: var(--surface-active);
  color: var(--text);
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.invite-revoke-btn { justify-self: end; padding: 6px 12px; font-size: 12px; }

/* ── Admin stats strip ───────────────────────────────────────────────────── */
.admin-stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 4px;
}
.admin-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 2px;
  min-height: 78px;
}
.admin-stat-value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}
.admin-stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}
.admin-stat-sub { font-size: 11px; color: var(--text-2); }
.admin-stat-skel .skeleton-line { width: 60%; height: 18px; }
.admin-stat-skel .skeleton-line-short { width: 40%; height: 10px; }

/* ── Admin tabs danger styling ───────────────────────────────────────────── */
.admin-tab-danger {
  color: rgba(239, 68, 68, 0.7);
}
.admin-tab-danger.is-active {
  background: rgba(239, 68, 68, 0.1);
  color: #fca5a5;
}

/* ── Admin toolbar (search + refresh) ────────────────────────────────────── */
.admin-toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.admin-search {
  font-size: 14px;
  padding: 9px 12px;
}

/* ── Admin user cards ────────────────────────────────────────────────────── */
.admin-list { display: grid; gap: 8px; }
.admin-user-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 8px;
}
.admin-user-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.admin-user-title { font-size: 14px; }
.admin-user-card-meta { font-size: 12px; color: var(--text-3); }
.admin-user-you-tag {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-2);
}
.admin-user-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.admin-user-browse,
.admin-user-delete {
  padding: 6px 12px;
  font-size: 12px;
}

/* ── Browse-as-user banner ───────────────────────────────────────────────── */
.impersonation-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.4);
  border-radius: var(--radius);
}
.impersonation-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.impersonation-text strong { font-size: 13px; color: #bfdbfe; }
.impersonation-user {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 600;
}
.impersonation-sub { font-size: 11px; color: var(--text-3); }
.impersonation-exit {
  padding: 6px 12px;
  font-size: 12px;
  white-space: nowrap;
}

/* ── Danger zone card ────────────────────────────────────────────────────── */
.admin-danger-card {
  background: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius);
  padding: 18px;
  display: grid;
  gap: 10px;
}
.admin-danger-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #fca5a5;
}
.admin-danger-card .admin-danger-btn {
  justify-self: start;
  padding: 8px 14px;
}

/* ── Devices panel ───────────────────────────────────────────────────────── */
.devices-panel { display: grid; gap: 12px; }
.devices-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.devices-header .viewer-subtle { margin: 0; max-width: 60%; }
.devices-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.devices-toggle input { width: auto; font-size: 14px; padding: 0; }

.devices-list { display: grid; gap: 8px; }
.devices-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 8px;
}
.devices-card.is-revoked { opacity: 0.55; }
.devices-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.devices-card-label { font-size: 14px; }
.devices-card-meta { font-size: 12px; color: var(--text-3); }
.devices-card-id-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  flex-wrap: wrap;
}
.devices-card-id-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.devices-card-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-2);
  flex: 1;
  min-width: 120px;
  overflow-x: auto;
  white-space: nowrap;
}
.devices-id-copy { padding: 4px 10px; font-size: 11px; }
.devices-revoke-btn { justify-self: end; padding: 6px 12px; font-size: 12px; }
.devices-skeleton { display: grid; gap: 8px; }
.devices-skeleton-card { padding: 14px; min-height: 80px; }
.devices-error {
  padding: 12px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius);
  color: #fecaca;
  font-size: 13px;
}
.empty-line {
  padding: 24px 12px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── API docs pane ───────────────────────────────────────────────────────── */
.api-docs-pane {
  font-size: 13px;
  line-height: 1.6;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}
.api-docs-title { margin: 0 0 8px; font-size: 16px; }
.api-docs-section {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.api-docs-section > summary {
  cursor: pointer;
  font-weight: 600;
  padding: 10px 14px;
  list-style: none;
}
.api-docs-section > summary::marker, .api-docs-section > summary::-webkit-details-marker { display: none; }
.api-docs-section > summary::before {
  content: '›';
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.15s;
}
.api-docs-section[open] > summary::before { transform: rotate(90deg); }
.api-docs-body {
  padding: 0 14px 14px 30px;
  color: var(--text-2);
}
.api-docs-body p { margin: 0 0 6px; }
.api-docs-body p strong { color: var(--text); }
.api-docs-body code {
  background: var(--surface-active);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text);
}
.api-docs-list { margin: 4px 0 8px; padding-left: 20px; font-size: 12px; }
.api-docs-list li { margin-bottom: 2px; }
.api-docs-table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
  margin-bottom: 8px;
}
.api-docs-table tr { border-bottom: 1px solid var(--border); }
.api-docs-table td { padding: 5px 8px; vertical-align: top; }
.api-docs-table td:first-child { color: var(--text-2); white-space: nowrap; }
.api-docs-pre {
  background: var(--surface-active);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
  margin: 6px 0 10px;
  white-space: pre;
  color: var(--text);
}
.api-docs-pre code { background: transparent; padding: 0; font-size: 12px; }


/* ── Escrow admin pane ───────────────────────────────────────────────────── */
.escrow-status-card {
  display: grid;
  gap: 6px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.escrow-status-row { color: var(--text-2); }
.escrow-status-row:first-child { color: var(--text); font-weight: 600; }
.escrow-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.escrow-decrypt-box, .escrow-decrypt-box.hidden { transition: opacity 0.15s; }
.escrow-decrypt-box {
  display: grid;
  gap: 8px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.escrow-decrypt-title { margin: 0; font-size: 14px; }
.escrow-decrypt-result { display: grid; gap: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.escrow-decrypt-meta { margin: 0; font-size: 12px; color: var(--text-2); }
.escrow-decrypt-preview { max-width: 100%; max-height: 320px; border-radius: var(--radius); }
.escrow-decrypt-download {
  display: inline-block;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 13px;
  text-decoration: none;
  justify-self: start;
}

.authorize-device-label { margin-bottom: 8px; }
.authorize-device-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

@media (max-width: 768px) {
  .admin-stats-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .devices-header .viewer-subtle { max-width: 100%; }
  .devices-header { gap: 8px; }
  .admin-toolbar { grid-template-columns: 1fr; }
  .api-docs-pane { max-height: none; }
}
@media (prefers-reduced-motion: reduce) {
  .app-confirm-overlay, .app-confirm-sheet { transition: opacity 0.1s ease; transform: none; }
}

.settings-body { display: flex; flex-direction: column; gap: 12px; padding: 4px 0; }
.settings-row {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 10px 12px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); font-size: 14px; user-select: none;
}
.settings-row input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0;
}
.settings-warning {
  font-size: 12px; line-height: 1.5; color: var(--text-3);
  padding: 10px 12px; border-radius: var(--radius);
  background: rgba(239,68,68,0.06); border: 1px solid rgba(239,68,68,0.12);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.settings-warning-active {
  color: #fca5a5; background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3);
}

/* ── Advanced text/code editor ──────────────────────────────────────────── */
/* When the editor is mounted, we flatten the surrounding viewer-shell so the
   editor itself becomes the card. Otherwise we'd have card-in-a-card with
   double borders and double padding. */
.viewer-shell:has(.editor-stage) {
  padding: 0;
  overflow: hidden;
}
.viewer-shell:has(.editor-stage) #closeViewer { display: none; }

.editor-stage {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  height: min(78vh, 800px);
  width: 100%;
  --gutter-w: 52px;
  --line-h: 22px;
}
.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.editor-title { display: grid; gap: 4px; min-width: 0; flex: 1; }
.editor-filename {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.editor-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
  flex-wrap: wrap;
}
.editor-dot {
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--text-3);
  display: inline-block;
}
.editor-mod-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}
.editor-mod-badge.is-modified { color: #fbbf24; }
.editor-mod-badge.is-saved { color: var(--text-2); }
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.editor-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s, transform 0.08s;
  white-space: nowrap;
}
.editor-tool:hover:not(:disabled) { color: var(--text); border-color: var(--border-hover); background: var(--surface-hover); }
.editor-tool:active:not(:disabled) { background: var(--surface-active); transform: scale(0.97); }
.editor-tool:disabled { opacity: 0.4; cursor: default; }
.editor-tool svg { width: 14px; height: 14px; flex-shrink: 0; }
.editor-tool.is-primary {
  background: #fff;
  color: #000;
  border-color: #fff;
  font-weight: 600;
}
.editor-tool.is-primary:hover:not(:disabled) {
  background: #fff;
  color: #000;
  opacity: 0.85;
}
.editor-tool.is-active { color: var(--text); border-color: var(--border-hover); background: var(--surface-active); }
.editor-tool-spacer { flex: 1; }

.editor-find {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.editor-find-input {
  flex: 1;
  max-width: 320px;
  padding: 6px 10px;
  font-size: 13px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  width: auto;
}
.editor-find-input:focus { border-color: var(--accent); outline: none; }
.editor-find-count {
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  padding: 0 6px;
  min-width: 38px;
  text-align: center;
}
.editor-find-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.editor-find-btn:hover { color: var(--text); border-color: var(--border-hover); background: var(--surface-hover); }
.editor-find-btn svg { width: 12px; height: 12px; }

.editor-body {
  position: relative;
  display: grid;
  grid-template-columns: var(--gutter-w) 1fr;
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: var(--line-h);
  background: var(--bg);
}
.editor-gutter {
  border-right: 1px solid var(--border);
  padding: 14px 0;
  text-align: right;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  user-select: none;
  overflow: hidden;
}
.editor-gutter > div {
  height: var(--line-h);
  padding-right: 12px;
  font-size: 12px;
  line-height: var(--line-h);
}
.editor-code-wrap {
  position: relative;
  overflow: hidden;
}
.editor-highlight, .editor-textarea {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 14px 14px;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  white-space: pre;
  tab-size: 2;
  -moz-tab-size: 2;
  border: 0;
  background: transparent;
  resize: none;
  width: 100%;
  min-height: 0;
}
.editor-highlight {
  pointer-events: none;
  overflow: auto;
  scrollbar-width: none;
  color: var(--text);
}
.editor-highlight::-webkit-scrollbar { display: none; }
.editor-highlight code { font: inherit; background: transparent; padding: 0; color: inherit; border: 0; }
.editor-textarea {
  color: transparent;
  caret-color: var(--text);
  overflow: auto;
  outline: none;
  z-index: 2;
  -webkit-text-fill-color: transparent;
  border-radius: 0;
}
.editor-textarea:focus { border: 0; }
.editor-textarea::selection {
  background: rgba(59,130,246,0.30);
  color: transparent;
  -webkit-text-fill-color: transparent;
}
.editor-textarea[readonly] { caret-color: transparent; }
.editor-stage.is-wrap .editor-highlight,
.editor-stage.is-wrap .editor-textarea {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Highlighted-token colors. Subdued so the page reads as monochrome at a glance. */
.tk-cmt   { color: var(--text-3); font-style: italic; }
.tk-str   { color: #9bbf8a; }
.tk-num   { color: #d4a574; }
.tk-bool  { color: #c585c5; }
.tk-kw    { color: #7aa2c8; }
.tk-key   { color: #c585c5; }
.tk-tag   { color: #7aa2c8; }
.tk-attr  { color: #d4a574; }
.tk-prop  { color: #d4a574; }
.tk-sel   { color: #7aa2c8; }
.tk-col   { color: #d4a574; }
.tk-find  { background: rgba(251,191,36,0.25); }
.tk-find-active { background: rgba(251,191,36,0.5); }

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-3);
}
.editor-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  font-variant-numeric: tabular-nums;
}
.editor-lang {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
}

@media (max-width: 720px) {
  .editor-stage {
    height: calc(100dvh - 80px);
    --gutter-w: 40px;
  }
  .editor-toolbar { padding: 6px 10px; gap: 4px; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .editor-toolbar::-webkit-scrollbar { display: none; }
  .editor-tool { padding: 6px 10px; font-size: 12px; }
  .editor-tool .editor-tool-label { display: none; }
  .editor-head { padding: 12px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .editor-tool, .editor-find-btn { transition: none; }
}
