/* One stylesheet for every page: the CSP allows no inline style. */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* The `hidden` attribute must win over the display rules below (admin.js toggles it). */
[hidden] { display: none !important; }

:root {
  --bg: #1e1e1e;
  --card: #2a2a2a;
  --card-active: #323232;
  --line: #333;
  --line-hover: #555;
  --text: #ddd;
  --muted: #9a9a9a;
  --accent: #6fa3f7;
  --danger: #f07a6f;
  --ok: #5ec476;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.spacer { flex: 1; }

.btn {
  font: inherit; font-size: 13px; font-weight: 500;
  color: #eee; background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14); border-radius: 5px;
  padding: 6px 14px; cursor: pointer;
}
.btn:hover { background: rgba(255,255,255,0.18); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: #1f4f99; border-color: #2c63b8; }
.btn-primary:hover { background: #2a5fb0; }

/* -- Gallery ------------------------------------------------------------------------------ */

body.dashboard { min-height: 100vh; padding: 24px 16px 72px; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (min-width: 640px)  { .grid { grid-template-columns: repeat(3, 1fr); gap: 18px; } }
@media (min-width: 1024px) { .grid { grid-template-columns: repeat(4, 1fr); gap: 22px; } }

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.card:hover { border-color: var(--line-hover); }
.card:active { background: var(--card-active); }

.card-link {
  display: block; color: inherit; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.thumb { width: 100%; aspect-ratio: 4 / 3; background: #111; overflow: hidden; }
.thumb img {
  width: 100%; height: 100%; display: block;
  object-fit: cover; object-position: top center;
}
.thumb-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center; color: #3a3a3a;
}
.thumb-placeholder svg { width: 44px; height: 44px; }

.card-body { padding: 9px 11px 11px; }

.badge {
  display: inline-block;
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 3px; margin-bottom: 5px;
}
.badge-pdf   { background: #162d56; color: var(--accent); }
.badge-video { background: #162d1a; color: var(--ok); }

.card-title {
  font-size: 13px; font-weight: 500; color: var(--text); line-height: 1.35;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
}

.empty { color: #666; font-size: 14px; text-align: center; margin-top: 80px; grid-column: 1 / -1; }

/* The admin widget: a discreet lock in the corner. */
.admin-widget {
  position: fixed; right: 14px; bottom: 14px;
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #555; background: rgba(255,255,255,0.03); border: 1px solid #2c2c2c;
  transition: color 0.15s, border-color 0.15s;
}
.admin-widget:hover, .admin-widget:focus-visible { color: #bbb; border-color: #555; }
.admin-widget svg { width: 15px; height: 15px; }

/* -- Admin mode --------------------------------------------------------------------------- */

.admin-bar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px; padding: 8px 12px;
  background: #24282f; border: 1px solid #34404f; border-radius: 8px;
  font-size: 13px;
}
.admin-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: #ffd27a; background: #3d3218; padding: 3px 7px; border-radius: 3px;
}
.admin-user, .admin-usage { color: var(--muted); }
@media (max-width: 560px) { .admin-usage { display: none; } }

.dropzone {
  margin-bottom: 20px;
  border: 2px dashed #3e4a5a; border-radius: 10px;
  background: #20242a;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.is-over { border-color: var(--accent); background: #1f2836; }
.dz-idle {
  display: block; width: 100%; padding: 22px 16px;
  font: inherit; font-size: 14px; color: var(--text); text-align: center;
  background: none; border: 0; cursor: pointer;
}
.dz-hint { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
.dz-form { display: grid; gap: 10px; padding: 16px; }
.dz-file { font-size: 13px; color: var(--muted); word-break: break-all; }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.field input, .card-title-input {
  font: inherit; font-size: 14px; color: var(--text);
  background: #15181c; border: 1px solid #3a3f46; border-radius: 5px; padding: 7px 9px;
  width: 100%;
}
.field input:focus, .card-title-input:focus { outline: 2px solid #2c63b8; outline-offset: -1px; }
.dz-link { display: flex; align-items: center; gap: 4px; }
.dz-prefix { color: var(--muted); font-size: 14px; }
.dz-actions { display: flex; gap: 8px; }
.dz-form progress { width: 100%; height: 6px; }
.dz-status { font-size: 13px; padding: 0 16px; }
.dz-status:empty { display: none; }
.dz-status { padding-bottom: 14px; }
.dz-status.is-error { color: var(--danger); }
.dz-status.is-ok { color: var(--ok); }

.card-tools {
  position: absolute; top: 6px; right: 6px;
  display: flex; gap: 6px;
}
.tool {
  width: 30px; height: 30px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #eee; background: rgba(20,20,20,0.82); border: 1px solid rgba(255,255,255,0.18);
  cursor: pointer;
}
.tool svg { width: 15px; height: 15px; }
.tool:hover { background: rgba(50,50,50,0.95); }
.tool-delete:hover { color: var(--danger); border-color: var(--danger); }
.card.is-busy { opacity: 0.5; pointer-events: none; }
.card-rename { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px; background: var(--card); }
.card-title-input { font-size: 13px; padding: 5px 7px; }

/* -- Viewers ------------------------------------------------------------------------------ */

body.viewer { background: #525659; }
body.viewer-video { background: #000; min-height: 100vh; display: flex; flex-direction: column; }

.toolbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; gap: 10px; align-items: center;
  background: #3d3d3d; border-bottom: 1px solid #222; padding: 8px 16px;
}
.toolbar a {
  display: inline-flex; align-items: center; gap: 6px;
  color: #eee; text-decoration: none; white-space: nowrap;
  padding: 6px 14px; border-radius: 5px; font-size: 13px; font-weight: 500;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12);
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.toolbar a:hover, .toolbar a:active { background: rgba(255,255,255,0.22); }
.toolbar a.btn-back { padding: 6px 10px; }

.pages {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 16px 0 32px;
}
.pages img {
  display: block; width: 100%; max-width: 900px; height: auto;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

.video-wrap { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.video-wrap video { max-width: 100%; max-height: calc(100vh - 52px); outline: none; }
.video-wrap a { color: var(--accent); }

/* -- Messages (errors, sign-in refused) --------------------------------------------------- */

body.message-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.message { max-width: 460px; text-align: center; }
.message h1 { font-size: 20px; margin-bottom: 10px; }
.message p { color: var(--muted); font-size: 14px; line-height: 1.5; margin-bottom: 10px; }
.message a { color: var(--accent); }
