/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

:root {
  --bg: #14161a;
  --surface: #1c1f26;
  --surface-2: #23262f;
  --border: #2e323c;
  --text: #e8eaee;
  --muted: #98a0ae;
  --accent: #ff4b4b;
  --success: #3ecf8e;
  --danger: #ff6b6b;
  --radius: 10px;

  /* One spacing scale for the whole app — no ad-hoc pixel values in views. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
}

* { box-sizing: border-box; }

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

a { color: var(--text); }

.site-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand { font-weight: 600; text-decoration: none; white-space: nowrap; }
.header-user { margin-left: auto; color: var(--muted); font-size: 13px; }

/* Wide screens lay the actions out as if this wrapper were not there, so the
   header stays one flex row and the toggle never appears. */
.header-menu { display: contents; }
.menu-toggle { display: none; }

.menu-icon,
.menu-icon::before,
.menu-icon::after {
  background: currentColor;
  border-radius: 1px;
  height: 2px;
  width: 18px;
}

.menu-icon { display: block; position: relative; }

.menu-icon::before,
.menu-icon::after {
  content: "";
  left: 0;
  position: absolute;
  transition: transform 0.15s ease, top 0.15s ease;
}

.menu-icon::before { top: -6px; }
.menu-icon::after { top: 6px; }

.menu-toggle[aria-expanded="true"] .menu-icon { background: transparent; }
.menu-toggle[aria-expanded="true"] .menu-icon::before { top: 0; transform: rotate(45deg); }
.menu-toggle[aria-expanded="true"] .menu-icon::after { top: 0; transform: rotate(-45deg); }

.container {
  max-width: 820px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-7);
}

/* A phone cannot fit the brand and three actions on one line, so the actions
   collapse behind the toggle and drop below the brand when opened. */
@media (max-width: 560px) {
  .site-header {
    flex-wrap: wrap;
    padding: var(--space-3) var(--space-4);
  }

  .brand { margin-right: auto; }

  .menu-toggle {
    align-items: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    height: 40px;
    justify-content: center;
    padding: 0;
    width: 40px;
  }

  .header-menu {
    display: none;
    flex: 1 0 100%;
    flex-direction: column;
    gap: var(--space-2);
    padding-top: var(--space-3);
  }

  .header-menu.is-open { display: flex; }

  .header-user {
    margin-left: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header-menu form { width: 100%; }

  .header-menu .btn {
    display: block;
    text-align: center;
    width: 100%;
  }
}

h1 { font-size: 22px; line-height: 1.3; margin: 0 0 var(--space-5); }

h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
  margin: var(--space-6) 0 var(--space-3);
}

.flash {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  margin: 0 0 var(--space-4);
}

.flash-alert { background: rgba(255, 107, 107, 0.12); color: var(--danger); }
.flash-notice { background: rgba(62, 207, 142, 0.12); color: var(--success); }

/* Layout helpers */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.page-head h1 { margin: 0; }

@media (max-width: 560px) {
  .page-head { flex-wrap: wrap; }
}

.back-link {
  display: inline-block;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: var(--space-5);
}

/* Forms */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
}

.card-flush { padding: 0; overflow: hidden; }

.new-download { display: grid; gap: var(--space-3); }

.field-row { display: flex; gap: var(--space-3); flex-wrap: wrap; }

.field { display: grid; gap: var(--space-2); }

.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--muted);
  font-size: 14px;
}

input[type="text"], input[type="email"], input[type="password"], select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: var(--space-3);
  font-size: 14px;
  width: 100%;
}

input::placeholder { color: var(--muted); opacity: 0.7; }

input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

select { width: auto; }

.btn, input[type="submit"] {
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: var(--space-3) var(--space-4);
}

.btn:hover, input[type="submit"]:hover { filter: brightness(1.1); }

.btn-block { width: 100%; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
}

.btn-row { display: flex; gap: var(--space-2); align-items: center; }
.btn-row form { margin: 0; }

.errors {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
  padding-left: var(--space-5);
}

/* Auth screens — split cover + form, see layouts/auth.html.erb */

.auth-body { min-height: 100vh; }

.auth-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
}

.auth-cover {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
}

.auth-cover-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Keeps the caption readable no matter how bright the photo is. */
.auth-cover-content {
  position: absolute;
  inset: auto 0 0 0;
  display: grid;
  gap: var(--space-2);
  padding: var(--space-7);
  background: linear-gradient(to top, rgba(10, 11, 14, 0.92), rgba(10, 11, 14, 0));
}

.auth-cover-brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-cover-tagline {
  margin: 0;
  max-width: 34ch;
  color: rgba(232, 234, 238, 0.75);
  font-size: 14px;
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-7) var(--space-5);
}

.auth-card { width: 100%; max-width: 360px; }

.auth-title { margin: 0 0 var(--space-2); font-size: 26px; }

.auth-subtitle {
  margin: 0 0 var(--space-6);
  color: var(--muted);
  font-size: 14px;
}

.auth-form { display: grid; gap: var(--space-4); }
.auth-form input[type="submit"] { margin-top: var(--space-2); }

.auth-foot {
  margin: var(--space-5) 0 0;
  font-size: 13px;
}

.auth-foot a { color: var(--muted); }

@media (max-width: 860px) {
  .auth-split { grid-template-columns: 1fr; }
  .auth-cover { display: none; }
  .auth-panel { padding: var(--space-6) var(--space-5); }
}

/* Download list */

.downloads { display: grid; gap: var(--space-3); margin-top: var(--space-3); }

.download {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.download-thumb {
  width: 120px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
}

.download-body { min-width: 0; display: grid; gap: var(--space-2); align-content: start; }

.download-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-meta {
  color: var(--muted);
  font-size: 13px;
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* Quiet download date, pushed to the end of the meta row. */
.download-date { margin-left: auto; opacity: 0.75; font-variant-numeric: tabular-nums; }

.download-progress { display: grid; gap: var(--space-2); margin-top: var(--space-1); }
.download-progress .download-meta { font-size: 12px; }

.download-actions { margin-top: var(--space-2); }

.download-detail { display: grid; gap: var(--space-4); justify-items: start; }
.download-detail h1 { margin: 0; }

.detail-thumb {
  width: 100%;
  max-width: 320px;
  border-radius: 8px;
}

.thumbnail-fallback {
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: linear-gradient(135deg, #ff6a5c, #e11d2e);
}

.badge {
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  text-transform: uppercase;
}

.badge-pending, .badge-fetching_info { background: var(--surface-2); color: var(--muted); }
.badge-downloading { background: rgba(255, 75, 75, 0.16); color: var(--accent); }
.badge-completed { background: rgba(62, 207, 142, 0.16); color: var(--success); }
.badge-failed { background: rgba(255, 107, 107, 0.16); color: var(--danger); }

progress {
  appearance: none;
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-2);
}

progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
  word-break: break-word;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: var(--space-6);
}

@media (max-width: 560px) {
  .download { grid-template-columns: 1fr; }

  /* Stacked, the thumbnail should stay a thumbnail — full width turns the
     placeholder for a download without one into a large empty block. */
  .download-thumb { width: 160px; }
}

/* Admin */

.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }

.admin-table th, .admin-table td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.admin-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-table tbody tr:last-child td { border-bottom: 0; }

/* Cells stay on one line; the wrapper scrolls instead of the table reflowing. */
.admin-table td, .admin-table th { white-space: nowrap; }

.table-scroll { overflow-x: auto; }

.admin-nav {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.admin-nav-link {
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
}

.admin-nav-link.is-active {
  background: var(--surface-2);
  color: var(--text);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.stat {
  display: grid;
  gap: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.stat-value { font-size: 22px; font-weight: 700; }

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.note {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 var(--space-4);
}

/* Long video titles must not stretch the table past the container. */
.title-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A table cell that opens the video, styled as text rather than a control. */
.link-button {
  background: none;
  border: 0;
  color: var(--text);
  cursor: pointer;
  display: block;
  font: inherit;
  max-width: 100%;
  overflow: hidden;
  padding: 0;
  text-align: left;
  text-decoration: underline;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-button:hover { color: var(--accent); }

.video-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  max-width: 880px;
  padding: var(--space-4);
  width: calc(100% - 2 * var(--space-5));
}

.video-dialog::backdrop { background: rgba(10, 11, 14, 0.72); }

.video-dialog-head {
  align-items: center;
  display: flex;
  gap: var(--space-4);
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.video-dialog-title {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


/* Local player (streamed from the server), reusing .video-dialog. */
.player-video {
  background: #000;
  border-radius: 8px;
  display: block;
  max-height: 70vh;
  width: 100%;
}

.player-audio {
  display: block;
  width: 100%;
}

/* The app has no [hidden] reset, so these rules would otherwise show a hidden
   element; the higher-specificity selector keeps hidden winning. */
.player-video[hidden],
.player-audio[hidden] {
  display: none;
}

.field-hint {
  color: var(--muted);
  font-size: 13px;
  margin: calc(var(--space-1) * -1) 0 0;
}

/* The platform tag doubles as a link back to the original post. */
.source-link { color: inherit; text-decoration: none; }
.source-link:hover { color: var(--text); text-decoration: underline; }

.day-picker { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.day-option {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  font-size: 13px;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
}

.day-option:has(input:checked) {
  background: var(--surface-2);
  color: var(--text);
}

/* iOS Safari zooms the whole page in when a field under 16px takes focus, and
   never zooms back out — the page is left wider than the screen until the
   reader pinches it back. Only touch devices need the larger text, so the
   desktop sizing is untouched. */
@media (pointer: coarse) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px;
  }
}

/* Guide pages: running text rather than the app's dense rows. */
.prose { display: grid; gap: var(--space-4); }
.prose p { margin: 0; line-height: 1.65; }
.prose h2 { margin: var(--space-3) 0 0; color: var(--text); font-size: 15px; }
.prose h2:first-of-type { margin-top: 0; }

.steps {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding-left: var(--space-5);
}

.steps li { line-height: 1.6; padding-left: var(--space-1); }
.code-line { margin-top: var(--space-2); }
.code-line code, .prose p > code, .steps code {
  background: var(--surface-2);
  border-radius: 4px;
  font-size: 13px;
  padding: 2px 6px;
  word-break: break-all;
}
.code-line code { display: block; padding: var(--space-2) var(--space-3); }

/* Floating PWA install button, bottom-right. Hidden until the controller
   decides the app can be installed. */
.install-prompt {
  bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-2);
  position: fixed;
  right: var(--space-4);
  z-index: 50;
}

.install-button {
  align-items: center;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  font-weight: 600;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
}

.install-button:hover { filter: brightness(1.1); }

/* Down-arrow-into-tray glyph, drawn in CSS so no image is needed. */
.install-icon {
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 3px 3px;
  height: 7px;
  position: relative;
  width: 14px;
}

.install-icon::before {
  border-left: 2px solid currentColor;
  content: "";
  height: 8px;
  left: 50%;
  position: absolute;
  top: -9px;
  transform: translateX(-50%);
}

.install-icon::after {
  border-bottom: 2px solid currentColor;
  border-right: 2px solid currentColor;
  content: "";
  height: 5px;
  left: 50%;
  position: absolute;
  top: -5px;
  transform: translate(-50%, -50%) rotate(45deg);
  width: 5px;
}

.install-ios-help {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 13px;
  max-width: 220px;
  padding: var(--space-3);
}

.install-bar {
  align-items: center;
  display: flex;
  gap: var(--space-2);
}

.install-dismiss {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  font-size: 18px;
  height: 28px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 28px;
}

.install-dismiss:hover { color: var(--text); }

/* Settings variant: sits in the page instead of floating over it. */
.install-prompt-inline {
  align-items: flex-start;
  bottom: auto;
  margin-top: var(--space-3);
  position: static;
  right: auto;
  z-index: auto;
}
