:root {
  /* Forest Canopy: forest green, sage, olive, ivory */
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-2: #efeee6;
  --text: #1f2a1e;
  --muted: #5f6656;
  --border: #dcdccf;
  --accent: #2d4a2b;
  --accent-text: #faf9f6;
  --link: #3b6b37;
  --danger: #a8322a;
  --ok: #2f6b3a;
  --ok-bg: #e6ede7;
  --warn: #85560f;
  --warn-bg: #f0ebe2;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(31 42 30 / 6%), 0 4px 16px rgb(31 42 30 / 6%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121a12;
    --surface: #1a241a;
    --surface-2: #243024;
    --text: #ecebe4;
    --muted: #a4ac86;
    --border: #2f3b2e;
    --accent: #a4ac86;
    --accent-text: #131a12;
    --link: #b5c98f;
    --danger: #e8806f;
    --ok: #8fcf8f;
    --ok-bg: #2d3f2d;
    --warn: #e6b45c;
    --warn-bg: #3b3b25;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.35rem; margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 1.6rem 0 0.6rem; font-weight: 650; }

main { max-width: 960px; margin: 0 auto; padding: 16px; }

.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }

/* --- header --- */

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.top nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.top nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.top nav a:hover { background: var(--surface-2); text-decoration: none; }
.top nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 600; }
.logout { margin: 0; }
button.plain { background: none; border: 0; color: var(--muted); padding: 6px; font: inherit; cursor: pointer; }

@media (max-width: 560px) {
  .brand span { display: none; }
  .top { gap: 6px; padding: 6px 8px; }
}

/* --- buttons and forms --- */

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: 0.6; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.primary:hover { background: var(--accent); filter: brightness(1.08); }
.danger { color: var(--danger); }
.small { padding: 5px 10px; font-size: 0.9rem; }
.big { padding: 12px 22px; font-size: 1.05rem; }
.wide { width: 100%; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
label[hidden] { display: none; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, .button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.inline { display: flex; gap: 6px; }
.inline select { width: auto; }

.error { color: var(--danger); margin: 0; }
.error[hidden] { display: none; }
.empty { color: var(--muted); padding: 24px 0; }
.note { color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.meta { color: var(--muted); font-size: 0.85rem; }
.mono { font-family: ui-monospace, monospace; font-size: 0.85rem; color: var(--muted); word-break: break-all; }

/* --- page structure --- */

.pagehead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.tools { display: flex; gap: 6px; flex-wrap: wrap; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 1.05rem; min-width: 0; }
.crumbs a:last-child { color: var(--text); font-weight: 600; }
.crumbs span { color: var(--muted); }

.center { display: flex; justify-content: center; padding-top: 6vh; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow);
}
.panel.narrow { max-width: 400px; }
.panel h1 { display: flex; align-items: center; gap: 8px; }
.panel p { margin: 0; }
main > .panel { margin-top: 24px; }

/* --- file lists --- */

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.entries li { display: flex; align-items: center; gap: 8px; padding-right: 10px; border-top: 1px solid var(--border); }
.entries li:first-child { border-top: 0; }
.entry {
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  align-items: center;
  padding: 8px 12px;
  flex: 1;
  min-width: 0;
  color: var(--text);
}
.entry:hover { text-decoration: none; background: var(--surface-2); }
.entry .thumb { grid-row: 1 / 3; }
.entry .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.entry .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--muted);
}
.thumb .icon { width: 22px; height: 22px; }
.thumb-video { position: relative; overflow: hidden; }
.thumb-video img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb-video:has(img)::after { /* play marker over the frame */
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  border-style: solid;
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent #fff;
  filter: drop-shadow(0 0 2px rgb(0 0 0 / 70%));
}
.thumb .icon-dir { color: var(--link); }
.shared { color: var(--link); }

@media (max-width: 560px) {
  .entries li button span, .entries li .button span { display: none; }
}

/* --- previews --- */

.preview { margin: 12px 0; display: flex; justify-content: center; }
.preview img, .preview video {
  max-width: 100%;
  max-height: 72vh;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.preview video {
  /* 16:9 frame, shrunk to fit the viewport height; other ratios letterbox */
  width: min(100%, calc(72vh * 16 / 9));
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #000;
}
.preview audio { width: 100%; }

/* Share pages: a big play button over the poster until the video starts. */
.player { position: relative; width: min(100%, calc(72vh * 16 / 9)); }
.player video { display: block; width: 100%; }
.player video::-webkit-media-controls-overlay-play-button { display: none; } /* Chrome's own, on Android */
.play-overlay {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 76px;
  height: 76px;
  padding: 0;
  border: 2px solid rgb(255 255 255 / 85%);
  border-radius: 50%;
  background: rgb(0 0 0 / 55%);
  color: #fff;
  box-shadow: 0 2px 12px rgb(0 0 0 / 35%);
  transition: background 0.15s, transform 0.15s;
}
.play-overlay[hidden] { display: none; }
.play-overlay:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-text); transform: scale(1.06); }
.play-overlay .icon { width: 36px; height: 36px; margin-left: 4px; /* optical centre of the triangle */ }
.nopreview {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 48px; color: var(--muted); background: var(--surface); border-radius: var(--radius); width: 100%;
}
.nopreview .icon { width: 48px; height: 48px; }
.info { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }

/* --- share and upload link cards --- */

.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card.inactive { background: var(--bg); border-style: dashed; }
.cardhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.subject { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 0; margin: 0; color: var(--text); }
.subject span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cardnote { margin: 0; color: var(--muted); font-style: italic; }
.cardactions { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
.cardactions form { margin: 0; }

.copyrow { display: flex; gap: 6px; }
.copyrow input { font-family: ui-monospace, monospace; font-size: 0.85rem; }

.facts { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 0.85rem; }

.badge { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge-active { color: var(--ok); background: var(--ok-bg); }
.badge-missing { color: var(--warn); background: var(--warn-bg); }
.badge-revoked, .badge-expired, .badge-full { color: var(--muted); }

/* --- activity log --- */

.log { list-style: none; padding: 0; margin: 0; }
.log li { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.log .action { font-weight: 600; }
.log .action[data-action="bad password"], .log .action[data-action="rejected"] { color: var(--danger); }
.log .detail { word-break: break-all; }
.log .meta { flex-basis: 100%; }

/* --- dialog --- */

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.dialog h2 { margin: 0; }
.center .dialog { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 480px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* --- public pages --- */

body.public main { max-width: 760px; }
.sharepage { display: flex; flex-direction: column; gap: 8px; align-items: stretch; padding-top: 12px; }
.sharepage > .button.big { align-self: center; }
.sharepage > .meta { text-align: center; margin: 0; }
.sharepage > .filename { display: block; text-align: center; word-break: normal; overflow-wrap: anywhere; }
.sharepage > .filename .icon { margin-right: 6px; }
@media (max-width: 560px) { .sharepage > .filename { font-size: 1.1rem; } }
.filename { display: flex; align-items: center; gap: 8px; word-break: break-word; }
.sharepage .pagehead { margin: 0; }

.drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  position: relative;
}
.drop.over { border-color: var(--link); color: var(--link); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.progress { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.progress:empty { display: none; }
.progress li { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; }
.progress .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress progress { flex-basis: 100%; width: 100%; height: 6px; }
.progress .ok .meta { color: var(--ok); }
.progress .failed .meta { color: var(--danger); }
