/* Shared dashboard shell for /app, /app/history, /app/contact.
   Owns the sidebar grid layout, sidebar nav styles, topbar, and the
   contact-form styles ported from the marketing site's stylesheet. */

:root {
  /* Light theme defaults (matches marketing site). */
  color-scheme: light;
  --shell-bg: #ffffff;
  --shell-ink: #0A1E4D;
  --shell-ink-strong: #061338;
  --shell-muted: #4a5673;
  --shell-muted-strong: #2f3a55;
  --shell-line: #d6dbe5;
  --shell-line-strong: #a8b2c4;
  --shell-accent: #2563eb;
  --shell-accent-soft: rgba(37, 99, 235, 0.18);
  --shell-on-accent: #ffffff;
  --shell-accent-warn: #f59e0b;
  --shell-accent-warn-bg: #fdf2dc;
  --shell-on-accent-warn: #1a1a1a;
  --shell-danger: #c53030;
  --shell-danger-soft: rgba(197, 48, 48, 0.18);
  --shell-success: #15803d;
  --shell-surface: #f5f7fb;
  --shell-surface-strong: #ffffff;
  --shell-surface-deeper: #eef1f7;
  --shell-input-bg: #ffffff;
  --shell-sidebar-bg: #f5f7fb;
  --shell-topbar-bg: #ffffff;
  --shell-hover: #e8edf6;
  --shell-button-secondary-bg: #e8edf6;
  --shell-button-secondary-ink: #0A1E4D;
  --shell-step-active-bg: rgba(37, 99, 235, 0.10);
  --shell-step-done-bg: #2563eb;
  --shell-step-error-bg: rgba(197, 48, 48, 0.18);
  --shell-status-success-bg: #e6f5ec;
  --shell-status-success-border: #b3d8c1;
  --shell-status-success-ink: #157a39;
  --shell-status-warn-bg: #fdf3e0;
  --shell-status-warn-border: #e7d29c;
  --shell-status-warn-ink: #8a5d00;
  --shell-status-error-bg: #fdecec;
  --shell-status-error-border: #f5c2c2;
  --shell-status-error-ink: #8b2020;
  --shell-advisory-bg: #eef4ff;
  --shell-shadow: 0 8px 24px rgba(10, 30, 77, 0.08);
  --shell-radius: 8px;
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --font-scale: 1;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --shell-bg: #0f1115;
  --shell-ink: #e6e8ec;
  --shell-ink-strong: #ffffff;
  --shell-muted: #b1b8c5;
  --shell-muted-strong: #d1d6e0;
  --shell-line: #1c2030;
  --shell-line-strong: #3a3f4b;
  --shell-accent: #6aa1ff;
  --shell-accent-soft: rgba(106, 161, 255, 0.27);
  --shell-on-accent: #0f1115;
  --shell-accent-warn: #ffd166;
  --shell-accent-warn-bg: #2a230f;
  --shell-danger: #ff6a6a;
  --shell-danger-soft: rgba(255, 106, 106, 0.27);
  --shell-success: #c8eed7;
  --shell-surface: #161a22;
  --shell-surface-strong: #1b2130;
  --shell-surface-deeper: #0f1218;
  --shell-input-bg: #0f1218;
  --shell-sidebar-bg: #0a0d14;
  --shell-topbar-bg: #0f1115;
  --shell-hover: #141828;
  --shell-button-secondary-bg: #242a36;
  --shell-button-secondary-ink: #e6e8ec;
  --shell-step-active-bg: rgba(106, 161, 255, 0.27);
  --shell-step-done-bg: #6aa1ff;
  --shell-step-error-bg: rgba(255, 106, 106, 0.27);
  --shell-status-success-bg: #16321f;
  --shell-status-success-border: #1f5230;
  --shell-status-success-ink: #b8f0c8;
  --shell-status-warn-bg: #322716;
  --shell-status-warn-border: #523f1f;
  --shell-status-warn-ink: #f0d8b8;
  --shell-status-error-bg: #2a1818;
  --shell-status-error-border: #5c2a2a;
  --shell-status-error-ink: #ffd1d1;
  --shell-advisory-bg: #1a2330;
  --shell-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* Text-size buttons set a font-scale variable AND html font-size so that:
   - pages that style with rem/em scale via html font-size
   - pages that style with raw px scale via zoom on .app-main         */
:root[data-font-level="-3"] { font-size: 13px; --font-scale: 0.82; }
:root[data-font-level="-2"] { font-size: 14px; --font-scale: 0.88; }
:root[data-font-level="-1"] { font-size: 15px; --font-scale: 0.94; }
:root[data-font-level="1"]  { font-size: 17px; --font-scale: 1.08; }
:root[data-font-level="2"]  { font-size: 18px; --font-scale: 1.18; }
:root[data-font-level="3"]  { font-size: 19px; --font-scale: 1.30; }

.app-main { zoom: var(--font-scale, 1); }

body.app-shell {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--shell-bg);
  color: var(--shell-ink);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.55;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: auto 1fr;
}

/* ─── Marketing-style site header (no page nav links) ───────────────────── */
.app-shell .site-header {
  grid-column: 1 / -1;
  grid-row: 1;
  background: var(--shell-topbar-bg);
  border-bottom: 1px solid var(--shell-line);
  /* Sticky so the sidebar (which sits below it) stays anchored to a fixed
     point. Without this, the header scrolls away and the sidebar's top
     visually slides up with the page, defeating "fixed" feel. */
  position: sticky;
  top: 0;
  z-index: 30;
}
.app-shell .site-header .header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  flex-wrap: wrap;
}
.app-shell .site-header .brand {
  display: inline-flex;
  align-items: center;
}
.app-shell .site-header .brand img {
  height: 40px;
  width: auto;
  display: block;
}
.app-shell .site-header .brand:focus-visible {
  outline: 3px solid var(--shell-accent);
  outline-offset: 4px;
  border-radius: 4px;
}
.app-shell .header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.app-shell .text-controls {
  display: inline-flex;
  gap: 4px;
}
.app-shell .control-button {
  background: transparent;
  color: var(--shell-ink);
  border: 1px solid var(--shell-line-strong);
  padding: 6px 12px;
  border-radius: var(--shell-radius);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  min-width: 36px;
}
.app-shell .control-button:hover { background: var(--shell-hover); }
.app-shell .control-button:focus-visible {
  outline: 3px solid var(--shell-accent);
  outline-offset: 2px;
}
.app-shell .control-button[aria-pressed="true"] {
  background: var(--shell-accent);
  color: var(--shell-on-accent);
  border-color: var(--shell-accent);
}
.app-shell .control-button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Skip link reused across pages. */
.app-shell .skip-link {
  position: absolute;
  top: -100px;
  left: 12px;
  background: var(--shell-accent);
  color: var(--shell-bg);
  padding: 10px 16px;
  border-radius: var(--shell-radius);
  font-weight: 600;
  z-index: 100;
  transition: top .15s ease;
  text-decoration: none;
}
.app-shell .skip-link:focus { top: 12px; outline: 3px solid var(--shell-accent-warn); outline-offset: 2px; }

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
.app-sidebar {
  grid-column: 1;
  grid-row: 2;
  background: var(--shell-sidebar-bg);
  border-right: 1px solid var(--shell-line);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 6px;
  /* Pinned below the sticky site-header. The grid row would normally stretch
     the sidebar to match main-column height; align-self:start keeps it the
     height of the viewport remainder. overflow-y:auto so that when the nav
     items exceed the viewport height, the sidebar scrolls internally instead
     of clipping the items below the fold. */
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
}
.app-sidebar .brand {
  color: var(--shell-ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 18px;
  padding: 8px 10px 18px;
  display: block;
}
.app-sidebar .brand:focus-visible {
  outline: 3px solid var(--shell-accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.app-sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.app-sidebar nav a {
  color: var(--shell-ink);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: var(--shell-radius);
  font-size: 15px;
  border: 1px solid transparent;
}
.app-sidebar nav a:hover { background: var(--shell-hover); }
.app-sidebar nav a:focus-visible {
  outline: 3px solid var(--shell-accent);
  outline-offset: 2px;
}
.app-sidebar nav a[aria-current="page"] {
  background: var(--shell-accent-soft);
  border-color: var(--shell-accent);
  color: var(--shell-ink);
  font-weight: 600;
}
.app-sidebar .sidebar-close {
  display: none;
  background: transparent;
  color: var(--shell-ink);
  border: 1px solid var(--shell-line-strong);
  padding: 10px 12px;
  border-radius: var(--shell-radius);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.app-sidebar .sidebar-close:focus-visible {
  outline: 3px solid var(--shell-accent);
  outline-offset: 2px;
}
.app-sidebar .logout-btn {
  margin-top: auto;
  background: transparent;
  color: var(--shell-ink);
  border: 1px solid var(--shell-line-strong);
  padding: 10px 12px;
  border-radius: var(--shell-radius);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.app-sidebar .logout-btn:hover { background: var(--shell-hover); }
.app-sidebar .logout-btn:focus-visible {
  outline: 3px solid var(--shell-accent);
  outline-offset: 2px;
}
.app-sidebar .logout-btn:disabled { opacity: 0.6; cursor: progress; }

.app-sidebar .sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--shell-line);
}

.app-sidebar .user-email {
  display: block;
  color: var(--shell-muted);
  font-size: 13px;
  padding: 6px 12px;
  word-break: break-word;
}

.app-sidebar .admin-link {
  color: var(--shell-accent-warn);
  border: 1px solid var(--shell-accent-warn);
  padding: 8px 12px;
  border-radius: var(--shell-radius);
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 8px;
  display: inline-block;
}
.app-sidebar .admin-link:hover { background: var(--shell-accent-warn-bg); }
.app-sidebar .admin-link[hidden] { display: none !important; }

/* ─── Topbar (mobile only) ──────────────────────────────────────────────── */
.app-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--shell-line);
  background: var(--shell-bg);
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-topbar .brand {
  color: var(--shell-ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
}
.app-topbar .sidebar-toggle {
  background: transparent;
  border: 1px solid var(--shell-line-strong);
  color: var(--shell-ink);
  border-radius: var(--shell-radius);
  width: 40px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
  font-family: inherit;
}
.app-topbar .sidebar-toggle:focus-visible {
  outline: 3px solid var(--shell-accent);
  outline-offset: 2px;
}

/* ─── Main column ───────────────────────────────────────────────────────── */
.app-main {
  grid-column: 2;
  grid-row: 2;
  padding: 32px 24px 48px;
  min-width: 0; /* prevent grid blow-out for wide tables */
}
.app-main .container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}
.app-main h1 {
  margin: 0 0 8px;
  font-size: 26px;
}
.app-main .page-intro {
  color: var(--shell-muted);
  margin: 0 0 24px;
}

.app-userbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 18px;
  color: var(--shell-muted);
  font-size: 14px;
}

/* ─── Generic surfaces / status rows for History + Contact ──────────────── */
.shell-card {
  background: var(--shell-surface);
  border: 1px solid var(--shell-line);
  border-radius: var(--shell-radius);
  padding: 18px;
}
.shell-empty {
  color: var(--shell-muted);
  text-align: center;
  padding: 36px 18px;
}
.shell-error {
  color: var(--shell-status-error-ink);
  background: var(--shell-status-error-bg);
  border: 1px solid var(--shell-status-error-border);
  border-radius: var(--shell-radius);
  padding: 14px 16px;
}

/* ─── History table ─────────────────────────────────────────────────────── */
.history-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--shell-line);
  border-radius: var(--shell-radius);
  background: var(--shell-surface);
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}
.history-table th,
.history-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--shell-line);
  vertical-align: top;
  font-size: 14px;
}
.history-table th {
  background: var(--shell-surface-deeper);
  color: var(--shell-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.history-table tr:last-child td { border-bottom: none; }
.history-table .col-video,
.history-table .col-original-video {
  max-width: 360px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.history-table .original-video-link,
.history-table .original-video-name {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.history-table a {
  color: var(--shell-accent);
  text-decoration: none;
}
.history-table a:hover { text-decoration: underline; }
.history-output-links {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
}
.history-comparison-outputs,
.history-version-output {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.history-comparison-outputs { gap: 16px; }
.history-version-output strong { font-size: 0.9rem; }
.history-table .history-output-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--shell-line-strong);
  border-radius: 6px;
  background: var(--shell-surface-strong);
  line-height: 1.2;
}
.history-table .history-output-link:hover {
  background: var(--shell-hover);
  text-decoration: none;
}
.history-table a:focus-visible {
  outline: 2px solid var(--shell-accent);
  outline-offset: 2px;
  border-radius: 2px;
}
.history-table .cell-dash { color: var(--shell-muted); }

/* ─── Contact form (ported from website/assets/styles.css, remapped to the
       analyzer's dark palette) ───────────────────────────────────────────── */
.contact-form-public {
  background: var(--shell-surface);
  border: 1px solid var(--shell-line);
  border-radius: var(--shell-radius);
  display: grid;
  gap: 0.85rem;
  margin: 0 auto;
  max-width: 720px;
  padding: clamp(0.9rem, 2vw, 1.2rem);
}
.form-grid {
  display: grid;
  align-items: start;
  gap: 0.85rem;
  grid-template-columns: 1fr;
}
/* Dashboard contact form intentionally stays single-column at every width. */
.form-field {
  display: grid;
  gap: 0.35rem;
}
.form-field label {
  font-weight: 600;
  font-size: 14px;
  color: var(--shell-ink);
}
.form-field .optional,
.character-count {
  color: var(--shell-muted);
  font-size: 0.85rem;
  font-weight: 400;
}
.textarea-wrap { position: relative; }
.textarea-wrap .character-count {
  bottom: 0.45rem;
  margin: 0;
  pointer-events: none;
  position: absolute;
  right: 0.7rem;
}
.contact-form-public .textarea-wrap textarea {
  padding-bottom: 1.7rem;
}
.contact-form-public input,
.contact-form-public select,
.contact-form-public textarea {
  background: var(--shell-input-bg);
  border: 1px solid var(--shell-line-strong);
  border-radius: var(--shell-radius);
  color: var(--shell-ink);
  min-height: 2.45rem;
  padding: 0.5rem 0.65rem;
  width: 100%;
  font-family: inherit;
  font-size: 14px;
}
.contact-form-public textarea {
  min-height: 7.5rem;
  resize: vertical;
}
.contact-form-public input:focus,
.contact-form-public select:focus,
.contact-form-public textarea:focus {
  border-color: var(--shell-accent);
  outline: 3px solid var(--shell-accent);
  outline-offset: 1px;
}
.contact-form-public textarea:disabled,
.contact-form-public input[readonly] {
  cursor: not-allowed;
  opacity: 0.7;
  background: var(--shell-surface-deeper);
}
.contact-form-public input[readonly]:focus {
  outline-color: var(--shell-line-strong);
}
.field-error {
  color: var(--shell-danger);
  font-weight: 600;
  margin: 0;
  min-height: 1rem;
  font-size: 13px;
}
.section-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}
.button {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: var(--shell-radius);
  border: 1px solid transparent;
  cursor: pointer;
}
.button-primary {
  background: var(--shell-accent);
  color: var(--shell-on-accent);
  font-weight: 700;
}
.button-primary:hover { filter: brightness(1.08); }
.button-primary:focus-visible {
  outline: 3px solid var(--shell-accent-warn);
  outline-offset: 2px;
}
.button-primary:disabled { opacity: 0.6; cursor: progress; }
.form-status {
  border-radius: var(--shell-radius);
  font-weight: 600;
  margin: 0;
  min-height: 1.5rem;
  padding: 0.2rem 0;
  font-size: 14px;
}
.form-status[data-state="success"] { color: var(--shell-success); }
.form-status[data-state="error"]   { color: var(--shell-danger); }
.form-status[data-state="pending"] { color: var(--shell-muted); }
.honeypot { display: none !important; }

/* ─── Responsive: collapse sidebar into a slide-in panel ────────────────── */
@media (max-width: 860px) {
  body.app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto var(--topbar-height) 1fr;
  }
  .app-shell .site-header {
    grid-column: 1;
    grid-row: 1;
  }
  .app-shell .site-header .header-inner {
    padding: 10px 16px;
  }
  .app-topbar {
    display: flex;
    grid-column: 1;
    grid-row: 2;
  }
  .app-sidebar {
    grid-column: 1;
    grid-row: 3;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform .18s ease;
    z-index: 30;
    height: 100vh;
  }
  .app-sidebar[aria-hidden="true"] { pointer-events: none; }
  .app-sidebar.is-open { transform: translateX(0); }
  .app-sidebar .sidebar-close { display: block; }
  .app-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 25;
  }
  .app-sidebar-backdrop.is-open { display: block; }
  .app-main {
    grid-column: 1;
    grid-row: 3;
    padding: 20px 16px 36px;
  }
}
