/* The file pages: /f/<link> (one file) and /files/ (their files). On top of /style.css. */

:root {
  --file-bg: #f2f5f5;
  --file-sheet: #ffffff;
  --file-shadow: 0 1px 2px rgba(14, 26, 27, 0.05), 0 16px 40px rgba(14, 26, 27, 0.07);
  --file-bar-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --file-bg: #050809;
    --file-sheet: #0f1718;
    --file-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --file-bg: #050809;
  --file-sheet: #0f1718;
  --file-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px rgba(0, 0, 0, 0.35);
}

/* ---- /f/<link> ------------------------------------------------------------ */

body[data-page="file"] { background: var(--file-bg); }

/* The header: the brand, who it was made for, and Share. It scrolls away with
   the page, and the compact bar takes its place at the top. */
.file-head { padding: 28px 16px 24px; text-align: center; }
.file-head .brand { display: inline-flex; font-size: 22px; gap: 10px; }
.file-head .brand img { width: 40px; height: 40px; border-radius: 11px; }
.file-made { margin: 6px 0 0; font-size: 15px; color: var(--muted); overflow-wrap: anywhere; }
.file-actions { display: flex; justify-content: center; gap: 8px; }
.file-head .file-actions:not(:empty) { margin-top: 16px; }
.share-button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 7px 22px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--file-sheet); color: var(--ink);
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
}
.share-button:hover { border-color: color-mix(in srgb, var(--ink) 30%, var(--line)); }
.share-button:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.file-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: var(--file-bar-h); padding: 0 12px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--file-bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  backdrop-filter: saturate(1.4) blur(16px);
  border-bottom: 1px solid var(--line);
  opacity: 0; transform: translateY(-100%); pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.file-bar.shown { opacity: 1; transform: none; pointer-events: auto; }
.file-bar-mid { grid-column: 2; min-width: 0; text-align: center; line-height: 1.2; }
.file-bar .brand { display: inline-flex; font-size: 15px; gap: 7px; }
.file-bar .brand img { width: 22px; height: 22px; border-radius: 6px; }
.file-bar .file-made {
  margin: 1px 0 0; font-size: 12px;
  max-width: 58vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-bar .file-actions { grid-column: 3; justify-self: end; }
.file-bar .share-button { min-height: 34px; padding: 4px 16px; font-size: 14px; }

/* The sheet: the file itself, under the header. */
main.file-main { flex: 1; width: 100%; max-width: none; margin: 0; padding: 0; }
.sheet {
  background: var(--file-sheet);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--file-shadow);
  overflow: hidden;
  min-height: 60vh;
}
.sheet[data-show="note"], .sheet[data-show="card"], .sheet[data-show="image"] { padding: 32px 20px 40px; }
/* A page is a document of its own: white under it, whatever the theme. */
.sheet[data-show="frame"] { background: #fff; }
@media (min-width: 760px) {
  .sheet { width: min(1040px, calc(100% - 48px)); margin: 0 auto; border-radius: 24px; min-height: 0; }
  .sheet[data-show="note"], .sheet[data-show="card"], .sheet[data-show="image"] { padding: 48px 40px 56px; }
}

/* Words (loading, unavailable, the sign-in) sit in a column; a file takes the sheet's whole width. */
.sheet[data-show="note"] .file-view { max-width: 560px; margin: 0 auto; }
.file-title { font-size: clamp(24px, 4.5vw, 32px); margin: 0 0 8px; overflow-wrap: anywhere; }
.sheet .center { margin-top: 24px; }

/* A page or a text file: a sandboxed frame. A page tells us its height and
   scrolls with this page; until it does (or if it keeps growing with its
   frame), the frame fills the window and scrolls inside. */
.file-frame {
  display: block; width: 100%; border: 0; background: #fff;
  height: calc(100vh - var(--file-bar-h));
  height: calc(100dvh - var(--file-bar-h));
}
.file-frame.fixed { height: calc(100dvh - var(--file-bar-h)) !important; }
.sheet[data-show="text"] .file-frame { padding: 8px; }

.file-image { text-align: center; }
.file-image img { max-width: 100%; max-height: 80vh; height: auto; border-radius: 12px; }

/* A deck, a document, a sheet or a PDF: a card to open it from. */
.file-card { max-width: 440px; margin: 0 auto; text-align: center; }
.file-card .file-icon { display: block; width: 88px; height: 88px; margin: 0 auto 18px; border-radius: 18px; }
.file-card h1 { font-size: clamp(24px, 5vw, 30px); line-height: 1.2; margin: 0 0 8px; overflow-wrap: anywhere; }
.file-card .file-desc { color: var(--muted); margin: 0 0 4px; overflow-wrap: anywhere; }
.file-card .meta { margin: 6px 0 24px; }
.file-open { display: grid; gap: 10px; }
.file-card .hint { margin-top: 12px; }

/* Under the sheet: Your files, Download and Delete for the owner; Report for anyone else. */
.file-end {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px 20px;
  padding: 20px 16px 4px; font-size: 14px; color: var(--muted);
}
.file-end:empty { display: none; }
.file-end a, .file-end .link { color: var(--muted); font-size: 14px; padding: 10px 2px; }
.file-end .confirm { flex-basis: 100%; max-width: 440px; margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--file-sheet); text-align: start; }
body[data-page="file"] .session { margin-top: 4px; }

/* The Share sheet: from the bottom on a phone, in the middle on a wider screen. */
dialog.share-sheet {
  width: 100%; max-width: none; max-height: 92vh; max-height: 92dvh;
  margin: auto 0 0; padding: 0; border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--file-sheet); color: var(--ink);
  box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.22);
  overflow: auto;
}
dialog.share-sheet[open] { animation: sheet-up 0.22s ease-out; }
dialog.share-sheet::backdrop { background: rgba(6, 12, 13, 0.5); }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 760px) {
  dialog.share-sheet { margin: auto; width: min(480px, calc(100vw - 32px)); border-radius: 20px; border: 1px solid var(--line); }
  dialog.share-sheet[open] { animation: none; }
}
.share-in { padding: 14px 20px 28px; }
.share-top { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; }
.share-top h2 { grid-column: 2; margin: 0; text-align: center; font-size: 22px; }
.share-close {
  grid-column: 3; justify-self: end;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; color: var(--ink);
  font: inherit; font-size: 28px; line-height: 1; cursor: pointer;
}
.share-close:hover, .share-close:focus-visible { background: color-mix(in srgb, var(--line) 60%, transparent); }
.share-file { margin: 2px 0 22px; text-align: center; color: var(--muted); font-size: 15px; overflow-wrap: anywhere; }

/* Who can open it: Only you, or Anyone with the link. */
.share-panel { margin-top: 12px; }
.share-sheet .share-panel { margin-top: 0; }
fieldset.share { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.share[disabled] { opacity: 0.6; }
fieldset.share legend { padding: 0; margin: 0 0 8px; }
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  border-radius: 12px; background: color-mix(in srgb, var(--line) 60%, transparent);
}
.segmented label { position: relative; margin: 0; font-size: 15px; font-weight: 500; }
.segmented input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.segmented span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 44px; padding: 6px; border-radius: 9px; line-height: 1.25; color: var(--muted);
}
.segmented input:checked + span { background: var(--file-sheet); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); }
.segmented input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: 1px; }
.share .meta.access { margin-top: 12px; font-size: 15px; color: var(--ink); }
.meta.access.public { color: var(--teal); font-weight: 500; }
.share .hint { margin-top: 4px; }
.days { display: flex; align-items: center; gap: 12px; margin: 12px 0 0; }
.days label { margin: 0; font-size: 15px; color: var(--muted); }
.days .select { flex: 1; max-width: 220px; }
.days select { min-height: 42px; padding-top: 6px; padding-bottom: 6px; font-size: 15px; }
.share .notice { margin: 14px 0 0; }
.share .notice .button { margin: 8px 0 4px; }

/* The link, and Copy: crossed out while only they can open it. */
.share-link {
  display: flex; align-items: center; gap: 8px; margin-top: 20px;
  padding: 6px; padding-inline-start: 14px;
  border: 1px solid var(--line); border-radius: 12px;
}
.share-link .url { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.share-link.off .url { color: var(--muted); text-decoration: line-through; }
.share-link .button { min-height: 40px; padding: 6px 18px; border-radius: 9px; font-size: 15px; }
.share-panel .status, .share-panel .error { margin-top: 10px; }

/* ---- /files/ ------------------------------------------------------------------ */

/* A grid item grows to fit a long unbroken line (the link) unless told it may shrink. */
.items > .item, .share-panel, .share-link { min-width: 0; }
.item h3 a { text-decoration: none; }
.item h3 a:hover { text-decoration: underline; }
.muted-item { opacity: 0.85; }
.item .share-panel { padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--line); }

@media (max-width: 560px) {
  .days { flex-wrap: wrap; }
}
@media (max-width: 400px) {
  .segmented label { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .file-bar, dialog.share-sheet[open] { transition: none; animation: none; }
}
