:root {
  color-scheme: dark;
  --bg: #0d0e12;
  --panel: rgba(20, 24, 34, 0.72);
  --line: rgba(181, 192, 255, 0.16);
  --text: rgb(248 250 252);
  --soft: rgb(203 213 225);
  --muted: rgb(148 163 184);
  --signal: #8ea3ff;
  --mint: #5ee6b5;
  --field: rgba(9, 12, 20, 0.62);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(94, 230, 181, 0.08), transparent 32%),
    linear-gradient(225deg, rgba(142, 163, 255, 0.1), transparent 38%),
    linear-gradient(140deg, #0d0e12 0%, #111827 46%, #0d0e12 100%);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

code {
  color: rgb(226 232 240);
}

.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto auto;
  gap: 1rem;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 14, 18, 0.78);
  padding: 0.9rem clamp(1rem, 3vw, 2rem);
  backdrop-filter: blur(18px);
}

.brand-block,
.topnav,
.section-heading,
.segmented-control,
.settings-actions,
.import-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-block {
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 2.5rem;
  height: 2.5rem;
  place-items: center;
  border: 1px solid rgba(94, 230, 181, 0.38);
  border-radius: 0.5rem;
  background: rgba(94, 230, 181, 0.12);
  color: rgb(209 250 229);
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  line-height: 1.1;
}

h2 {
  margin-top: 0.45rem;
  font-size: clamp(1.8rem, 4vw, 3.5rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--signal);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.topnav {
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(15, 23, 42, 0.44);
  padding: 0.3rem;
}

.nav-tab,
.segment-button,
.button-primary,
.button-ghost {
  min-height: 2.5rem;
  border-radius: 0.5rem;
  padding: 0.65rem 0.95rem;
  border: 1px solid transparent;
  font-size: 0.875rem;
  font-weight: 800;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.nav-tab {
  background: transparent;
  color: var(--soft);
}

.nav-tab.active,
.segment-button.active {
  border-color: rgba(94, 230, 181, 0.48);
  background: rgba(94, 230, 181, 0.13);
  color: rgb(209 250 229);
}

.segment-button {
  border-color: var(--line);
  background: rgba(15, 23, 42, 0.42);
  color: var(--soft);
}

.button-primary {
  border-color: rgba(142, 163, 255, 0.7);
  background: linear-gradient(135deg, rgba(142, 163, 255, 0.92), rgba(94, 230, 181, 0.84));
  color: #081018;
}

.button-primary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button-ghost {
  border-color: var(--line);
  background: rgba(15, 23, 42, 0.42);
  color: var(--soft);
}

.button-primary:hover,
.button-ghost:hover,
.nav-tab:hover,
.segment-button:hover {
  transform: translateY(-1px);
}

.page-shell {
  width: min(1280px, calc(100% - 2rem));
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2rem) 0 4rem;
}

.glass-panel {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
}

.auth-panel,
.p-section,
.stat-card {
  padding: clamp(1rem, 2.5vw, 1.5rem);
}

.auth-panel {
  display: grid;
  max-width: 560px;
  margin: 8vh auto 0;
  gap: 1.25rem;
}

.app-shell,
.view-panel,
.auth-form,
.settings-grid,
.import-preview,
.history-table,
.db-status {
  display: grid;
  gap: 1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.stat-card {
  display: grid;
  min-height: 140px;
  align-content: space-between;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 800;
}

.stat-card b {
  color: var(--text);
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1;
}

.section-heading {
  flex-wrap: wrap;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.section-heading p {
  color: var(--text);
  font-size: 1.125rem;
  font-weight: 900;
}

.section-heading span,
.muted-copy,
.endpoint-box p,
.db-status p {
  color: var(--muted);
  line-height: 1.6;
}

.field-label,
.search-box {
  display: grid;
  gap: 0.5rem;
  color: rgb(226 232 240);
  font-size: 0.875rem;
  font-weight: 700;
}

.search-box {
  min-width: min(420px, 100%);
}

.field {
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--field);
  padding: 0.75rem 0.875rem;
  color: var(--text);
  outline: none;
}

.field:focus {
  border-color: rgba(142, 163, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(142, 163, 255, 0.16);
}

.message {
  min-height: 1.25rem;
  color: var(--muted);
}

.message[data-tone="success"] {
  color: rgb(134 239 172);
}

.message[data-tone="error"] {
  color: rgb(252 165 165);
}

.status-pill,
.source-badge,
.target-pill {
  display: inline-flex;
  align-items: center;
  width: max-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.56);
  padding: 0.35rem 0.65rem;
  color: var(--soft);
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.status-ready,
.target-pill[data-status="success"] {
  border-color: rgba(94, 230, 181, 0.48);
  background: rgba(94, 230, 181, 0.13);
  color: rgb(187 247 208);
}

.target-pill[data-status="error"] {
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.12);
  color: rgb(254 202 202);
}

.table-row,
.endpoint-box,
.empty-log,
.drop-zone {
  display: grid;
  gap: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(15, 23, 42, 0.46);
  padding: 1rem;
}

.table-row {
  grid-template-columns: minmax(260px, 1.7fr) 0.5fr 0.65fr 0.9fr;
  align-items: center;
}

.row-button {
  width: 100%;
  color: inherit;
  text-align: left;
}

.row-button:hover,
.movie-card:hover,
.folder-trigger:hover,
.season-trigger:hover,
.episode-row:hover {
  border-color: rgba(142, 163, 255, 0.42);
  background: rgba(30, 41, 59, 0.58);
}

.table-row b {
  display: block;
  color: var(--text);
}

.table-row small {
  display: block;
  margin-top: 0.3rem;
  color: var(--muted);
}

.table-head {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.drop-zone {
  min-height: 220px;
  place-items: center;
  text-align: center;
}

.drop-zone input {
  max-width: 280px;
}

.drop-zone b {
  font-size: 1.15rem;
}

.movie-grid,
.explorer-panel,
.folder-children,
.episode-list {
  display: grid;
  gap: 0.75rem;
}

.movie-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.movie-card,
.folder-card,
.season-card,
.episode-row,
.folder-trigger,
.season-trigger {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(15, 23, 42, 0.46);
  color: var(--text);
}

.movie-card,
.folder-trigger,
.season-trigger,
.episode-row {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem;
  text-align: left;
}

.movie-card {
  display: grid;
  justify-items: start;
}

.movie-card span,
.movie-card small,
.folder-trigger span,
.season-trigger span,
.episode-row time {
  color: var(--muted);
}

.folder-card,
.season-card {
  display: grid;
  gap: 0.75rem;
  padding: 0.75rem;
}

.folder-children,
.episode-list {
  padding-left: clamp(0rem, 2vw, 1rem);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(2, 6, 23, 0.72);
  padding: 1rem;
}

.modal-panel {
  display: grid;
  width: min(860px, 100%);
  max-height: min(760px, calc(100vh - 2rem));
  overflow: auto;
  gap: 1rem;
  padding: clamp(1rem, 3vw, 1.5rem);
}

.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.diagnostic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}

.diagnostic-grid div,
.telemetry-block {
  display: grid;
  gap: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(15, 23, 42, 0.48);
  padding: 0.85rem;
}

.diagnostic-grid span,
.telemetry-block p {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.telemetry-block {
  margin-top: 1rem;
}

.telemetry-block pre {
  margin: 0;
  overflow: auto;
  color: rgb(226 232 240);
  font-size: 0.875rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.import-actions,
.settings-actions {
  justify-content: flex-end;
}

.settings-grid {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.help-layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.help-sidebar {
  position: sticky;
  top: 6.25rem;
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.help-sidebar-head h2 {
  font-size: 1.35rem;
}

.help-menu,
.help-menu-group {
  display: grid;
  gap: 0.5rem;
}

.help-menu-group {
  gap: 0.35rem;
}

.help-menu-group p {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.help-menu-item {
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--soft);
  padding: 0.65rem 0.75rem;
  text-align: left;
}

.help-menu-item.active,
.help-menu-item:hover {
  border-color: rgba(142, 163, 255, 0.35);
  background: rgba(15, 23, 42, 0.58);
  color: var(--text);
}

.help-canvas {
  display: grid;
  gap: 1.25rem;
  padding: clamp(1rem, 3vw, 2rem);
}

.help-hero {
  display: grid;
  gap: 0.8rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
}

.help-hero h2 {
  font-size: clamp(2rem, 4vw, 3.6rem);
}

.token-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.token-badge {
  border: 1px solid rgba(251, 191, 36, 0.38);
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.12);
  color: rgb(254 240 138);
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 900;
}

.help-doc-body {
  display: grid;
  gap: 1rem;
  color: var(--soft);
  line-height: 1.7;
}

.help-doc-body ol {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding-left: 1.25rem;
}

.help-doc-body code {
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  background: rgba(2, 6, 23, 0.48);
  padding: 0.1rem 0.3rem;
}

.guide-callout {
  display: grid;
  gap: 0.65rem;
  border: 1px solid rgba(142, 163, 255, 0.24);
  border-radius: 0.5rem;
  background: rgba(15, 23, 42, 0.52);
  padding: 1rem;
}

.credential-guide {
  background: rgba(15, 23, 42, 0.58);
}

.credential-guide h3 {
  margin: 0.35rem 0 0;
  color: var(--text);
  font-size: 0.98rem;
}

.credential-guide ul {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding-left: 1.25rem;
  line-height: 1.7;
}

.copy-block {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(2, 6, 23, 0.75);
}

.copy-block pre {
  margin: 0;
  overflow: auto;
  padding: 1rem;
  padding-right: 5rem;
  color: rgb(226 232 240);
  font-size: 0.875rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.copy-button {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: rgba(15, 23, 42, 0.9);
  color: var(--soft);
  padding: 0.35rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 900;
}

.copy-button:hover {
  border-color: rgba(94, 230, 181, 0.48);
  color: rgb(187 247 208);
}

.copy-toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 80;
  border: 1px solid rgba(94, 230, 181, 0.48);
  border-radius: 999px;
  background: rgba(20, 24, 34, 0.94);
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.35);
  color: rgb(187 247 208);
  padding: 0.65rem 0.9rem;
  font-weight: 900;
}

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

  .topnav {
    justify-content: stretch;
  }

  .nav-tab {
    flex: 1;
  }

  .table-row {
    grid-template-columns: 1fr;
  }

  .table-head {
    display: none;
  }

  .help-layout {
    grid-template-columns: 1fr;
  }

  .help-sidebar {
    position: static;
  }
}

@media (max-width: 620px) {
  .brand-block,
  .import-actions,
  .settings-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
