/* Apple-HIG-informed web adaptation. Opaque content; one floating navigation layer. */
:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: #fff;
  --subtle: #eaeaee;
  --text: #1c1c1e;
  --muted: #626269;
  --accent: #075fd8;
  --accent-fill: #075fd8;
  --accent-text: #fff;
  --selection: #e7effc;
  --line: #dddde2;
  --control-line: #92929b;
  --danger: #b32629;
  --nav: rgb(255 255 255 / 94%);
  --shadow: 0 4px 24px rgb(0 0 0 / 8%);
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px));
  --content-top: var(--tg-content-safe-area-inset-top, 0px);
  --content-bottom: var(--tg-content-safe-area-inset-bottom, 0px);
  font: 100%/1.5 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101012; --surface: #1c1c1f; --subtle: #2b2b30;
  --text: #f5f5f7; --muted: #aaaab3; --accent: #78b4ff;
  --selection: #233249; --line: #36363b; --control-line: #777780;
  --danger: #ff999d; --nav: rgb(35 35 39 / 96%); --shadow: 0 4px 24px rgb(0 0 0 / 24%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #101012; --surface: #1c1c1f; --subtle: #2b2b30;
    --text: #f5f5f7; --muted: #aaaab3; --accent: #78b4ff;
    --selection: #233249; --line: #36363b; --control-line: #777780;
    --danger: #ff999d; --nav: rgb(35 35 39 / 96%); --shadow: 0 4px 24px rgb(0 0 0 / 24%);
  }
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--text); background: var(--bg); }
[hidden] { display: none !important; }
button, input, select { font: inherit; }
button, a { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button, input, select, a.button { min-height: 44px; min-width: 44px; }
button { color: inherit; cursor: pointer; }
button:disabled, input:disabled, select:disabled { opacity: .5; cursor: not-allowed; }
button, input, select { border: 1px solid var(--control-line); border-radius: .625rem; background: var(--surface); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
:focus { scroll-margin-block: 1rem 9rem; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.25rem; font-weight: 650; letter-spacing: -.035em; line-height: 1.25; }
h2 { font-size: 1.125rem; font-weight: 650; line-height: 1.3; }
a { color: inherit; }
.icon { display: block; flex-shrink: 0; width: 1.375rem; height: 1.375rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: -100px; left: 1rem; z-index: 10; min-height: 44px; padding: .75rem; background: var(--accent-fill); color: var(--accent-text); }
.skip-link:focus { top: calc(.75rem + var(--safe-top)); }
main {
  width: 100%; max-width: 70rem; margin: auto;
  padding: calc(1.5rem + var(--safe-top) + var(--content-top))
    calc(max(1rem, var(--safe-right)) + var(--tg-content-safe-area-inset-right, 0px))
    calc(8rem + var(--safe-bottom) + var(--content-bottom))
    calc(max(1rem, var(--safe-left)) + var(--tg-content-safe-area-inset-left, 0px));
}
.header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; }
.brand { min-width: 0; }
.brand > span { display: block; margin-top: .125rem; font-size: .8125rem; color: var(--muted); }
.connection-divider { margin-inline: .125rem; }
.button { display: inline-flex; align-items: center; justify-content: center; padding: .625rem 1rem; gap: .5rem; border-radius: .625rem; text-decoration: none; font-weight: 550; line-height: 1.4; }
.primary { background: var(--accent-fill); color: var(--accent-text); border-color: transparent; }
.quiet { background: transparent; border-color: transparent; color: var(--muted); }
.danger { color: var(--danger); }
#upload { flex-shrink: 0; }
#upload .icon { width: 1.125rem; height: 1.125rem; }
.navigation { margin: 0; }
[role="tablist"] {
  position: fixed; z-index: 4;
  bottom: calc(.75rem + var(--safe-bottom) + var(--content-bottom));
  left: calc(max(.75rem, var(--safe-left)) + var(--tg-content-safe-area-inset-left, 0px));
  right: calc(max(.75rem, var(--safe-right)) + var(--tg-content-safe-area-inset-right, 0px));
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .25rem;
  padding: .375rem; border: 1px solid var(--line); border-radius: 2rem;
  background: var(--surface); box-shadow: var(--shadow);
}
@supports (backdrop-filter: blur(12px)) {
  [role="tablist"] { background: var(--nav); backdrop-filter: blur(12px); }
}
[role="tab"] { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .125rem; min-height: 3.5rem; padding: .375rem .5rem; border: 0; border-radius: 1.625rem; background: transparent; color: var(--muted); font-size: .75rem; font-weight: 550; }
[role="tab"] .icon { width: 1.5rem; height: 1.5rem; }
[role="tab"][aria-selected="true"] { background: var(--selection); color: var(--accent); font-weight: 700; }
.results-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; padding: 1.75rem 0 1.125rem; }
.results-title { display: flex; align-items: baseline; flex-wrap: wrap; column-gap: .75rem; min-width: 0; }
#section-title { font-size: 2.125rem; letter-spacing: -.04em; font-weight: 700; line-height: 1.2; }
#results-count { font-size: .875rem; color: var(--muted); white-space: nowrap; }
#trash { padding-inline: .5rem; font-size: .875rem; flex-shrink: 0; }
#trash .icon { width: 1.125rem; height: 1.125rem; }
#trash[aria-pressed="true"] { color: var(--accent); text-decoration: underline; text-underline-offset: .25rem; }
.toolbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(9.75rem, auto); align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
.search-field { display: flex; align-items: center; position: relative; min-width: 0; }
.search-field .icon { position: absolute; left: .875rem; color: var(--muted); width: 1.125rem; height: 1.125rem; pointer-events: none; }
.toolbar input, .toolbar select { width: 100%; min-width: 0; padding: .625rem .75rem; color: var(--text); }
.toolbar input { padding-left: 2.625rem; background: var(--subtle); border-color: transparent; }
.toolbar select { font-size: .875rem; }
input::placeholder { color: var(--muted); opacity: 1; }
.file-list { padding: 0 .75rem; margin: 0; list-style: none; border-radius: 1rem; background: var(--surface); }
.file-row { display: flex; align-items: center; min-width: 0; position: relative; }
.file-list .file-row:not(:last-child)::after { content: ""; position: absolute; left: 3.25rem; right: 0; bottom: 0; height: 1px; background: var(--line); }
.file-open { display: flex; align-items: center; flex: 1; width: 100%; min-width: 0; gap: .875rem; padding: .875rem .25rem; border: 0; border-radius: .5rem; background: transparent; text-align: left; }
.file-mark { flex-shrink: 0; width: 2.125rem; height: 2.75rem; display: grid; place-items: center; color: var(--muted); }
.file-mark .icon { width: 1.75rem; height: 1.75rem; stroke-width: 1.5; }
.file-text { display: block; min-width: 0; flex: 1; }
.file-name { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 1rem; font-weight: 500; line-height: 1.4; }
.file-meta { display: block; color: var(--muted); font-size: .8125rem; margin-top: .125rem; }
.file-actions { display: grid; place-items: center; flex-shrink: 0; width: 44px; padding: 0; color: var(--muted); }
.file-actions .icon { width: min(1.25rem, 24px); height: min(1.25rem, 24px); stroke-width: 3; }
.gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr)); gap: .875rem; padding: 0; margin: 0; list-style: none; }
.gallery .file-row { display: grid; grid-template-columns: minmax(0, 1fr) 44px; align-items: end; }
.gallery .file-open { grid-column: 1 / -1; grid-row: 1; display: block; padding: 0; border-radius: .875rem; }
.thumbnail { width: 100%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; background: var(--subtle); overflow: hidden; border-radius: .875rem; color: var(--muted); font-size: .8125rem; }
.thumbnail img, .thumbnail video { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.thumbnail .placeholder { display: flex; flex-direction: column; align-items: center; gap: .75rem; padding: 1rem .5rem; text-align: center; }
.thumbnail .placeholder .icon { width: 2rem; height: 2rem; stroke-width: 1.5; }
.gallery .file-text { padding: .625rem 44px .625rem .125rem; min-height: 4.5rem; }
.gallery .file-name { font-size: .875rem; }
.gallery .file-meta { font-size: .75rem; }
.gallery .file-actions { grid-column: 2; grid-row: 1; z-index: 1; align-self: end; margin-bottom: .75rem; }
.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.empty h3 { color: var(--text); font-size: 1.125rem; font-weight: 600; margin: 0 0 .5rem; }
.empty p { max-width: 28rem; margin: 0 auto .75rem; overflow-wrap: anywhere; }
.notice { padding: .875rem; color: var(--danger); border: 1px solid var(--control-line); border-radius: .625rem; margin-bottom: .75rem; overflow-wrap: anywhere; }
.pagination { display: flex; justify-content: space-between; gap: .75rem; align-items: center; padding-top: 1.25rem; font-size: .875rem; color: var(--muted); }
.upload-panel { border-top: 1px solid var(--line); margin-top: 1.75rem; padding-top: .75rem; }
.upload-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem; }
#upload-list { list-style: none; margin: .5rem 0 .75rem; padding: 0; }
.upload-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .25rem .75rem; border-bottom: 1px solid var(--line); padding: .75rem 0; }
.upload-name { overflow-wrap: anywhere; }
.upload-status { grid-column: 1; color: var(--muted); font-size: .8125rem; }
.upload-item progress { grid-column: 1; width: 100%; height: .375rem; accent-color: var(--accent-fill); }
.upload-item button { grid-column: 2; grid-row: 1 / 4; }
.upload-item.failed .upload-status { color: var(--danger); }
.muted, footer { font-size: .8125rem; color: var(--muted); }
footer { margin-top: 2rem; padding-inline: .25rem; }
footer p { margin-top: .375rem; }
.storage { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem .875rem; }
.storage meter { width: 6rem; height: .5rem; accent-color: var(--muted); }
meter::-webkit-meter-bar { background: var(--subtle); border: 0; border-radius: .25rem; }
meter::-webkit-meter-optimum-value { background: var(--muted); }
dialog { width: calc(100% - 2rem); max-width: 28rem; max-height: calc(100dvh - 2rem - var(--safe-top) - var(--safe-bottom) - var(--content-top) - var(--content-bottom)); padding: 1.25rem; border: 1px solid var(--line); border-radius: 1.25rem; background: var(--surface); color: var(--text); overflow: auto; overscroll-behavior: contain; }
dialog::backdrop { background: rgb(0 0 0 / 50%); }
body:has(dialog[open]) { overflow: hidden; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.dialog-header h2 { overflow-wrap: anywhere; min-width: 0; }
#close-dialog { display: grid; place-items: center; flex-shrink: 0; width: 44px; padding: 0; border-radius: 50%; background: var(--subtle); color: var(--text); }
.action-list { display: grid; gap: .5rem; }
.action-list .button { width: 100%; justify-content: flex-start; text-align: left; }
.dialog-actions, .preview-meta, .pdf-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; margin-top: 1rem; }
.dialog-description { overflow-wrap: anywhere; color: var(--muted); }
.preview-dialog[open] { display: flex; flex-direction: column; width: calc(100% - 3rem); max-width: 68rem; height: min(54rem, calc(100dvh - 3rem - var(--safe-top) - var(--safe-bottom) - var(--content-top) - var(--content-bottom))); padding: 0; overflow: hidden; }
.preview-dialog .dialog-header { flex-shrink: 0; margin: 0; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.preview-dialog .dialog-header h2 { font-size: 1rem; max-height: 4.5rem; overflow: auto; }
.preview-dialog #dialog-content { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; overflow: auto; }
.preview-stage { flex: 1; min-height: 10rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem; background: var(--bg); padding: 1rem; overflow: auto; }
.preview-stage img, .preview-stage video { display: block; max-width: 100%; max-height: 100%; min-height: 0; object-fit: contain; }
.preview-stage audio { width: 100%; max-width: 34rem; }
.preview-stage pre { align-self: stretch; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; padding: .25rem; font: .875rem/1.6 ui-monospace, monospace; max-height: 100%; overflow: auto; }
.preview-stage .empty { padding: 1.5rem .25rem; }
.preview-meta { margin: 0; padding: .75rem 1.25rem; border-top: 1px solid var(--line); flex-shrink: 0; }
.preview-meta > span, .pdf-controls > span { font-size: .8125rem; color: var(--muted); }
.pdf-controls { margin: 0; padding: .5rem 1.25rem; justify-content: center; flex-shrink: 0; }
.pdf-controls .button { font-size: .875rem; }
.toast { position: fixed; bottom: calc(6rem + var(--safe-bottom) + var(--content-bottom)); left: 50%; transform: translateX(-50%); max-width: calc(100% - 2rem); padding: .75rem 1rem; border-radius: .75rem; border: 1px solid var(--line); background: var(--surface); color: var(--text); z-index: 5; box-shadow: var(--shadow); }
@media (hover: hover) {
  .file-open:hover, .quiet:hover:not(:disabled) { background: var(--subtle); }
  .primary:hover:not(:disabled) { filter: brightness(1.1); }
  [role="tab"]:hover:not(:disabled) { color: var(--accent); }
}
@media (max-width: 440px) {
  .toolbar { grid-template-columns: minmax(0, 1fr); gap: .5rem; }
  .toolbar select { width: auto; max-width: 100%; justify-self: end; }
  .results-title { display: block; }
  #results-count { display: block; margin-top: .25rem; }
  .file-meta { overflow-wrap: anywhere; }
  .gallery { gap: .75rem; }
  .gallery .file-text { min-height: 5rem; }
  .gallery .file-meta { max-width: 100%; }
}
@media (max-width: 767px) {
  .preview-dialog[open] { width: calc(100% - var(--safe-left) - var(--safe-right)); max-width: none; height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - var(--content-top) - var(--content-bottom)); max-height: none; margin: calc(var(--safe-top) + var(--content-top)) auto calc(var(--safe-bottom) + var(--content-bottom)); border-radius: 0; border: 0; }
  .preview-dialog .dialog-header { padding: .75rem 1rem; }
  .preview-meta { padding: .75rem 1rem; }
  .preview-stage { padding: .75rem; }
  .pdf-controls { padding: .5rem .75rem; gap: .5rem; }
}
@media (min-width: 768px) {
  main { padding-top: calc(2.5rem + var(--safe-top) + var(--content-top)); padding-inline: calc(2rem + var(--safe-left) + var(--tg-content-safe-area-inset-left, 0px)) calc(2rem + var(--safe-right) + var(--tg-content-safe-area-inset-right, 0px)); padding-bottom: calc(2.5rem + var(--safe-bottom) + var(--content-bottom)); }
  .navigation { margin-top: 1.75rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
  [role="tablist"] { position: static; display: inline-flex; gap: .25rem; padding: .25rem; border-radius: 1rem; box-shadow: none; background: var(--surface); backdrop-filter: none; }
  [role="tab"] { flex-direction: row; gap: .5rem; min-height: 44px; padding: .625rem 1.25rem; border-radius: .75rem; font-size: .875rem; }
  [role="tab"] .icon { width: 1.25rem; height: 1.25rem; }
  .results-heading { padding-top: 1.75rem; }
  #section-title { font-size: 2.375rem; }
  .toolbar { grid-template-columns: minmax(0, 28rem) 11rem; justify-content: space-between; margin-bottom: 1.5rem; }
  .file-list { padding-inline: 1rem; }
  .file-open { padding-block: 1rem; }
  .gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; }
  .gallery .file-text { padding-block: .75rem; }
  .toast { bottom: calc(1.5rem + var(--safe-bottom) + var(--content-bottom)); }
}
@media (min-width: 1024px) { .gallery { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  [role="tablist"] { background: var(--surface); backdrop-filter: none; box-shadow: none; }
}
@media (prefers-contrast: more) {
  :root { --muted: #414147; --line: #73737c; --control-line: #626269; }
  :root[data-theme="dark"] { --muted: #d0d0d7; --line: #888892; --control-line: #aaaab3; }
  .toolbar input { border-color: var(--control-line); }
}
@media (prefers-color-scheme: dark) and (prefers-contrast: more) {
  :root:not([data-theme="light"]) { --muted: #d0d0d7; --line: #888892; --control-line: #aaaab3; }
}
@media (forced-colors: active) {
  [role="tablist"], .file-list, .thumbnail { border: 1px solid CanvasText; }
  [role="tab"][aria-selected="true"] { outline: 2px solid Highlight; outline-offset: -4px; }
  .primary { border: 1px solid ButtonText; }
}
