@layer reset, base, theme, components, utilities;

@layer reset {
  *, *::before, *::after {
    box-sizing: border-box;
  }
  body {
    margin: 0;
  }
  h1, h2, h3, p {
    margin-block: 0;
  }
}

@layer theme {
  :root {
    color-scheme: light dark;
    --bg: #faf6f0;
    --surface: #ffffff;
    --surface-alt: #f3ece1;
    --border: #dfd4c4;
    --text: #221d18;
    --muted: #665d53;
    --accent: #d95d39;
    --accent-hover: #bf4a28;
    --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
    --ok: #2a7b4f;
    --warn: #b4690e;
    --err: #b82d2d;
    --radius: 12px;
    --shadow: 0 2px 10px rgba(34, 29, 24, 0.06);
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #171411;
      --surface: #221e1a;
      --surface-alt: #2b2520;
      --border: #3d352e;
      --text: #f3ede5;
      --muted: #b0a599;
      --accent: #ee7551;
      --accent-hover: #f58a6a;
      --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    }
  }
}

@layer base {
  body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    text-align: start;
  }

  input, textarea, select, button {
    font: inherit;
    color: inherit;
  }

  input[type="text"],
  input[type="password"],
  input[type="search"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  textarea,
  select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
  }

  a.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
  }

  textarea {
    resize: vertical;
  }

  :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
}

@layer components {
  .topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  .brand-badge {
    font-size: 1.75rem;
    background: var(--accent-soft);
    padding: 0.35rem 0.55rem;
    border-radius: 10px;
  }

  .brand h1 {
    font-size: 1.15rem;
    line-height: 1.2;
  }

  .subtitle {
    font-size: 0.8rem;
    color: var(--muted);
  }

  .show-controls, .topbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem;
  }

  .inline-field {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.85rem;
    font-weight: 600;
  }

  .inline-field input {
    width: auto;
  }

  .duration-pill {
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    font-size: 0.85rem;
  }

  .status-dot {
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
  }

  .status-dot.ok {
    border-color: var(--ok);
    color: var(--ok);
  }

  .status-dot.warn {
    border-color: var(--warn);
    color: var(--warn);
  }

  .btn {
    padding: 0.55rem 0.95rem;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    min-height: 38px;
    transition: background-color 140ms ease, opacity 140ms ease;
  }

  .btn:disabled {
    opacity: 0.55;
    cursor: wait;
  }

  .btn-primary {
    background: var(--accent);
    color: #ffffff;
  }

  .btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
  }

  .btn-secondary {
    background: var(--surface-alt);
    border-color: var(--border);
  }

  .btn-secondary:hover:not(:disabled) {
    background: color-mix(in srgb, var(--surface-alt) 75%, var(--border));
  }

  .btn-danger {
    background: transparent;
    border-color: var(--err);
    color: var(--err);
  }

  .studio-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.25rem;
    padding: 1.25rem 1.5rem;
    max-width: 1440px;
    margin-inline: auto;
  }

  @media (max-width: 920px) {
    .studio-layout {
      grid-template-columns: 1fr;
    }
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .panel h2 {
    font-size: 1rem;
  }

  .shows-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 220px;
    overflow-y: auto;
  }

  .show-date-btn {
    text-align: start;
    padding: 0.45rem 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-alt);
    cursor: pointer;
    font-size: 0.88rem;
  }

  .show-date-btn.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    font-weight: 700;
  }

  .timeline-mini {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.82rem;
  }

  .timeline-item {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    background: var(--surface-alt);
  }

  .step-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-block-end: 1rem;
  }

  .step-tab {
    padding: 0.55rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
  }

  .step-tab.active {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
  }

  .step-panel {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    flex-direction: column;
    gap: 1rem;
  }

  .step-panel.active {
    display: flex;
  }

  .panel-header, .sub-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
  }

  .field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.85rem;
    font-weight: 600;
  }

  .checkbox-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
    font-weight: 600;
  }

  .two-col {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 0.9rem;
  }

  .cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 0.9rem;
  }

  .card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.85rem;
    background: var(--surface-alt);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
  }

  .card video, .card img {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: 8px;
    background: #000000;
  }

  .stack {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
  }

  .segment-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    background: var(--surface-alt);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .segment-top {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
  }

  .badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--surface);
    border: 1px solid var(--border);
  }

  .badge.ready { border-color: var(--ok); color: var(--ok); }
  .badge.error { border-color: var(--err); color: var(--err); }
  .badge.generating { border-color: var(--warn); color: var(--warn); }

  .generating-banner {
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px dashed var(--warn);
    background: color-mix(in srgb, var(--warn) 10%, transparent);
    color: var(--warn);
    font-weight: 600;
    font-size: 0.88rem;
  }

  .footage-tools {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }

  @media (max-width: 800px) {
    .footage-tools {
      grid-template-columns: 1fr;
    }
  }

  .search-bar, .upload-box {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-alt);
  }

  .render-settings {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.9rem;
    align-items: end;
  }

  .preview-box {
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    background: var(--surface-alt);
  }

  .preview-box video {
    max-width: 100%;
    max-height: 520px;
    border-radius: 10px;
    background: #000000;
  }

  .toast-region {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 50;
  }

  .toast {
    padding: 0.7rem 1rem;
    border-radius: 8px;
    background: var(--text);
    color: var(--bg);
    font-size: 0.88rem;
    box-shadow: var(--shadow);
    max-width: 360px;
  }

  .toast.error {
    background: var(--err);
    color: #ffffff;
  }

  dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    max-width: 560px;
    width: calc(100% - 2rem);
    padding: 0;
  }

  dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
  }

  .dialog-body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .dialog-header, .dialog-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
  }

  .panel-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding-block-start: 0.5rem;
    border-top: 1px solid var(--border);
  }

  .script-drawer {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    background: var(--surface-alt);
  }

  .script-drawer summary {
    cursor: pointer;
    user-select: none;
  }

  .drawer-content {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    margin-block-start: 0.85rem;
  }

  .segment-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 1rem;
    align-items: start;
  }

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

  .segment-media-box {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
  }

  .segment-media-box video {
    width: 100%;
    max-height: 240px;
    border-radius: 8px;
    background: #000000;
  }

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

  .kpi-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.85rem 1rem;
    background: var(--surface-alt);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  .kpi-card strong {
    font-size: 1.35rem;
    color: var(--accent);
  }

  .table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
  }

  .stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
  }

  .stats-table th, .stats-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: start;
    white-space: nowrap;
  }

  .stats-table th {
    background: var(--surface-alt);
    font-weight: 700;
  }

  .stats-table tbody tr:last-child td {
    border-bottom: none;
  }

  /* Landing Page */
  .landing-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.75rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  .brand-title {
    font-size: 1.2rem;
    display: block;
    line-height: 1.2;
  }

  .landing-main {
    max-width: 1120px;
    margin-inline: auto;
    padding: 3rem 1.5rem 4rem;
    display: flex;
    flex-direction: column;
    gap: 3rem;
  }

  .landing-hero {
    text-align: center;
    max-width: 780px;
    margin-inline: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.15rem;
  }

  .hero-pill {
    display: inline-block;
    padding: 0.3rem 0.85rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
    font-size: 0.85rem;
  }

  .landing-hero h1 {
    font-size: clamp(1.9rem, 4vw, 2.75rem);
    line-height: 1.15;
    letter-spacing: -0.02em;
  }

  .hero-lead {
    font-size: 1.05rem;
    color: var(--muted);
    line-height: 1.65;
  }

  .hero-actions {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
  }

  .btn-lg {
    padding: 0.75rem 1.4rem;
    font-size: 1rem;
    min-height: 46px;
  }

  .btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.82rem;
    min-height: 30px;
  }

  .landing-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 1.15rem;
  }

  .feature-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.35rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .feature-icon {
    font-size: 1.85rem;
    line-height: 1;
  }

  .feature-card h2 {
    font-size: 1.05rem;
  }

  .feature-card p {
    font-size: 0.92rem;
    color: var(--muted);
  }

  /* Channel switcher, user pill, banners */
  .channel-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
  }

  .channel-bar select {
    width: auto;
    min-width: 170px;
  }

  .status-btn {
    cursor: pointer;
    font: inherit;
    font-size: 0.8rem;
  }

  .user-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.35rem 0.25rem 0.75rem;
    border-radius: 999px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    font-size: 0.85rem;
    font-weight: 600;
  }

  .callout-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    max-width: 1440px;
    margin: 1rem auto 0;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--warn);
    background: color-mix(in srgb, var(--warn) 12%, var(--surface));
    font-size: 0.92rem;
  }

  .empty-channels-state {
    max-width: 640px;
    margin: 3.5rem auto;
    padding-inline: 1.25rem;
  }

  .empty-card {
    padding: 2rem;
    align-items: center;
    text-align: center;
    gap: 1rem;
  }

  .preset-editor-row {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem;
    background: var(--surface-alt);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .dialog-footer-split {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
  }

  dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
  }
}

@layer utilities {
  .flex-1 {
    flex: 1;
  }
  .muted {
    color: var(--muted);
    font-size: 0.88rem;
  }
  .full-width {
    width: 100%;
  }
  .row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
