﻿*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ============================================
   Ambient background — depth without kitsch
   ============================================ */
.ambient { display: none; }

/* ============================================
   Shell layout modes: gate | content | cinema
   ============================================ */
.shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* -- Top bar -- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  height: var(--topbar-h);
  transition: background 0.35s var(--ease-out), border-color 0.35s;
  border-bottom: 1px solid transparent;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: 100%;
  padding: 0 clamp(16px, 3.4vw, 48px);
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.topbar-brand:hover { opacity: 0.9; }

.brand-glyph {
  font-size: 1.2rem;
}

.brand-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.03em;
  color: var(--text);
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.nav-item {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s var(--ease-out);
  white-space: nowrap;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
  color: var(--accent);
  background: rgba(94, 234, 212, 0.1);
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
  flex-shrink: 0;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 var(--space-2);
  cursor: default;
}

.status-dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.3s;
}

.status-dot.online {
  background: var(--success);
}

.topbar-status .status-label {
  font-size: 0.72rem;
  color: var(--text-faint);
}

.topbar-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--stroke-strong);
  border-radius: 50%;
  background: var(--bg-glass-light);
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

.topbar-avatar:hover {
  border-color: var(--accent);
}

.topbar-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.topbar-logout:hover {
  color: var(--danger);
  background: rgba(251, 113, 133, 0.08);
}

/* Cinema: overlay topbar on hero */
.shell[data-layout="cinema"] .topbar {
  background: rgba(5, 6, 8, 0.55);
}

.shell[data-layout="cinema"].topbar-solid .topbar {
  background: #0a0c10;
  border-bottom-color: var(--stroke);
}

/* Content pages */
.shell[data-layout="content"] .topbar {
  position: sticky;
  background: #0a0c10;
  border-bottom-color: var(--stroke);
}

/* Login gate: minimal chrome */
.shell[data-layout="gate"] .topbar {
  position: relative;
  background: transparent;
  border-bottom-color: transparent;
}

.shell[data-layout="gate"] .topbar-nav,
.shell[data-layout="gate"] .topbar-end {
  display: none;
}

.shell[data-layout="gate"] .topbar-inner {
  justify-content: center;
}

/* ============================================
   Main area
   ============================================ */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.view-host {
  width: 100%;
}

/* Content layout: centered readable width */
.shell[data-layout="content"] .stage {
  padding: var(--space-6) clamp(16px, 3.4vw, 48px) var(--space-12);
}

.shell[data-layout="content"] .view-host {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* Cinema layout: full bleed */
.shell[data-layout="cinema"] .stage {
  padding: 0;
}

.shell[data-layout="cinema"] .view-host {
  max-width: none;
}

/* Login gate: full viewport center */
.shell[data-layout="gate"] .main-area {
  min-height: calc(100dvh - var(--topbar-h));
}

.shell[data-layout="gate"] .stage {
  padding: var(--space-6) clamp(16px, 3.4vw, 48px);
  align-items: center;
  justify-content: center;
}

.shell[data-layout="gate"] .view-host {
  max-width: 420px;
}

/* ============================================
   Primitives (preserved & refined)
   ============================================ */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.page-head h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.page-head p {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.glass {
  background: var(--bg-glass);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
}

.panel {
  padding: 1.35rem 1.5rem 1.25rem;
  margin-bottom: 0.75rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.field label {
  font-size: 0.76rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 0.8rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  transition: border-color 0.2s;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.72rem 1.2rem;
  border: 0;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  background: var(--accent);
  color: #042f2e;
  transition: background 0.2s;
}

.btn:hover { background: #14b8a6; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.6rem 0.95rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--stroke);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.84rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-ghost:hover { color: var(--text); border-color: var(--stroke-strong); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-sm { padding: 0.42rem 0.8rem; font-size: 0.78rem; }

.chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }

.chip {
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 600;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
}

.chip.ok  { color: var(--accent); border-color: rgba(94, 234, 212, 0.35); }
.chip.warn { color: var(--accent-2); border-color: rgba(249, 115, 22, 0.35); }

.hint { color: var(--text-faint); font-size: 0.84rem; line-height: 1.5; }
.err-inline { color: var(--danger); font-size: 0.84rem; margin-top: 0.5rem; }

.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

/* ============================================
   Auth
   ============================================ */
.auth-scene {
  width: 100%;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(100%, 420px);
  padding: 2rem 1.75rem;
  position: relative;
  overflow: hidden;
}

.auth-card > * { position: relative; }

.auth-title {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  text-align: center;
}

.auth-tabs {
  display: flex;
  width: fit-content;
  gap: 0.35rem;
  padding: 0.25rem;
  margin: 1.25rem auto 1.5rem;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--stroke);
}

.auth-tab {
  padding: 0.55rem 1.15rem;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s;
}

.auth-tab.active { background: var(--text); color: var(--bg-deep); }

.auth-panel.hidden { display: none; }

.auth-panel .modal-actions {
  justify-content: flex-end;
}

.auth-error {
  margin: 0.15rem 0 0;
  text-align: left;
}

.modal-actions .btn,
.modal-actions .btn-ghost {
  width: auto;
  flex: 0 0 auto;
}

/* ============================================
   Admin invites
   ============================================ */
.invite-grid {
  display: grid;
  gap: 0.5rem;
  max-height: 280px;
  overflow-y: auto;
  margin-top: 1rem;
}

.invite-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.25);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.invite-row .status {
  font-family: var(--font-body);
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-available { background: rgba(94, 234, 212, 0.15); color: var(--accent); }
.status-claimed   { background: rgba(249, 115, 22, 0.15);  color: var(--accent-2); }
.status-used      { background: rgba(255, 255, 255, 0.08); color: var(--text-faint); }

.hero-lib-grid {
  display: grid;
  gap: 0.45rem;
  max-height: 200px;
  overflow-y: auto;
  padding: 0.5rem;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
}

.hero-lib-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
}

.hero-preview {
  display: grid;
  gap: 0.65rem;
}

.hero-preview-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.hero-preview-row img {
  width: 96px;
  height: 54px;
  object-fit: cover;
  border-radius: var(--radius-xs);
  border: 1px solid var(--stroke);
}

/* ============================================
   Toast
   ============================================ */
.toast-stack {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 500;
  display: grid;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
}

.toast {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  border: 1px solid var(--stroke);
  font-size: 0.9rem;
  animation: toast-in 0.2s ease;
}

.toast.error   { border-color: rgba(251, 113, 133, 0.5); }
.toast.success { border-color: rgba(94, 234, 212, 0.45); }

@keyframes toast-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ============================================
   Modal
   ============================================ */
dialog.modal {
  border: 1px solid var(--stroke-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  color: var(--text);
  padding: 1.5rem;
  max-width: 520px;
  width: calc(100% - 2rem);
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.modal-actions {
  display: flex;
  gap: 0.65rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

/* Hero cache job progress (admin) */
.hero-cache-progress {
  margin: 0.5rem 0 0.85rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
}

.hero-cache-progress.hidden { display: none; }

.hero-cache-progress-head {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 0.65rem;
}

.hero-cache-ring {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  transform: rotate(-90deg);
}

.hero-cache-ring-bg {
  stroke: var(--stroke);
}

.hero-cache-ring-path {
  stroke: var(--accent);
  transition: stroke-dashoffset 0.35s var(--ease-out);
}

.hero-cache-progress-text {
  font-size: 0.88rem;
  font-weight: 600;
}

.hero-cache-progress-sub {
  margin-top: 0.15rem;
  font-size: 0.76rem;
}

.hero-cache-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--stroke);
  overflow: hidden;
}

.hero-cache-bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.35s var(--ease-out);
}

.hero-video-quota {
  margin-top: 0.35rem;
}

.hero-video-quota-head {
  font-size: 0.82rem;
  margin-bottom: 0.35rem;
  line-height: 1.45;
}

.hero-video-quota-head.hero-video-quota-ok strong {
  color: var(--accent-2);
}

.hero-video-quota-head.hero-video-quota-over strong {
  color: var(--danger, #e85d5d);
}

.hero-video-quota-bar {
  margin-bottom: 0.35rem;
}

.hero-video-quota-bar.is-over .hero-cache-bar-fill {
  background: var(--danger, #e85d5d);
}

.hero-video-quota-hint {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
}

.hero-video-cache-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.45rem;
}

.hero-video-cache-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--stroke);
}

.hero-video-cache-row:last-child {
  border-bottom: 0;
}

.hero-video-cache-row-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
}

.hero-video-cache-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 12rem;
}

.hero-video-cache-row-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.hero-video-cache-size {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.hero-cache-bar.is-indeterminate .hero-cache-bar-fill,
.hero-cache-bar-fill.is-indeterminate {
  width: 35% !important;
  animation: hero-bar-slide 1.2s ease-in-out infinite;
}

.hero-cache-ring-path.is-indeterminate {
  animation: hero-ring-spin 1.4s linear infinite;
}

@keyframes hero-bar-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

@keyframes hero-ring-spin {
  to { stroke-dashoffset: 0; }
}

.hero-cache-item-list {
  margin: 0.65rem 0 0;
  padding: 0;
  list-style: none;
  max-height: 140px;
  overflow-y: auto;
  font-size: 0.78rem;
}

.hero-cache-item-list.hidden { display: none; }

.hero-cache-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.28rem 0;
  border-bottom: 1px solid var(--stroke);
}

.hero-cache-item-state {
  flex-shrink: 0;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.hero-cache-item--running .hero-cache-item-state { color: var(--accent); }
.hero-cache-item--done .hero-cache-item-state,
.hero-cache-item--skipped .hero-cache-item-state { color: var(--accent-2); }
.hero-cache-item--error .hero-cache-item-state { color: var(--danger, #f87171); }

/* Settings hub */
.settings-page { display: grid; gap: var(--space-4); }

.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  border-bottom: 1px solid var(--stroke);
  padding-bottom: 0.5rem;
}

.settings-tab {
  border: 1px solid transparent;
  background: none;
  color: var(--text-muted);
  border-radius: var(--radius-pill);
  padding: 0.35rem 0.9rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.settings-tab.active {
  border-color: var(--stroke-strong);
  background: var(--bg-glass);
  color: var(--text);
}

.settings-panel {
  display: grid;
  gap: var(--space-4);
}

.settings-plugin-panel { width: 100%; }

.settings-cards {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

@media (min-width: 720px) {
  .settings-cards.settings-cards--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.settings-card {
  background: var(--bg-glass);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
}

.settings-card--wide {
  grid-column: 1 / -1;
}

.settings-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.settings-card-head h2,
.settings-card-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
}

.settings-card-desc {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--text-faint);
  line-height: 1.4;
}

.settings-card-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--stroke);
}

.settings-field-grid {
  display: grid;
  gap: 0.55rem;
  grid-template-columns: 1fr;
}

@media (min-width: 560px) {
  .settings-field-grid.settings-field-grid--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .settings-field-grid.settings-field-grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.settings-field-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.settings-field-grid label:has(> input[type="checkbox"]) {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
}

.settings-field-grid input:not([type="checkbox"]):not([type="radio"]),
.settings-field-grid select,
.settings-field-grid textarea {
  width: 100%;
}

.settings-inline-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  align-items: center;
}

.settings-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.backup-domain-row {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  font-size: 0.88rem;
}

.backup-archive-list {
  display: grid;
  gap: 0.45rem;
}

.backup-archive-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  background: var(--bg-glass-light);
}

.hero-cache-progress-detail {
  margin: 0.35rem 0 0.55rem;
  font-size: 0.74rem;
  line-height: 1.45;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 640px) {
  .brand-text { display: none; }

  .topbar-status .status-label { display: none; }

  .shell[data-layout="content"] .stage {
    padding: var(--space-4) var(--space-3) var(--space-8);
  }
}
