:root {
  color-scheme: light;
  --bg: #f5f6f7;
  --ink: #1f2328;
  --muted: #68707a;
  --line: #d8dee4;
  --panel: #ffffff;
  --field: #f9fafb;
  --accent: #e53935;
  --accent-dark: #c62828;
  --green: #1b7f5f;
  --focus: rgb(229 57 53 / 16%);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  width: min(1880px, calc(100% - 24px));
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: 10px 0;
  overflow: hidden;
}

.toolbar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(250px, 0.58fr) minmax(680px, 1.42fr);
  gap: 20px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgb(31 35 40 / 6%);
}

.headingBlock {
  min-width: 0;
}

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

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2.4vw, 2.25rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.summary {
  max-width: 460px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.settings {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 118px;
  gap: 8px 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 5px;
  color: #4d5560;
  font-size: 0.76rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--field);
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid var(--focus);
}

.fieldWithButton {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 8px;
}

.fieldWithButton .iconButton {
  width: 38px;
  min-height: 38px;
  background: #fff;
}

button,
.actions a {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

button:disabled {
  cursor: progress;
  opacity: 0.72;
}

.formActions {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 132px 1fr;
  gap: 10px;
}

.advancedSettings {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.advancedSettings summary {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
}

.advancedGrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 8px;
}

.channelSettings {
  display: grid;
  gap: 8px;
}

.advancedLabel {
  margin: 0;
  color: #4d5560;
  font-size: 0.82rem;
  font-weight: 800;
}

.channelConfigGrid {
  display: grid;
  grid-template-columns: minmax(140px, 0.7fr) minmax(240px, 1.3fr);
  gap: 8px 10px;
}

#loadButton {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

button:hover,
.actions a:hover {
  border-color: var(--accent);
}

#loadButton:hover {
  background: var(--accent-dark);
}

.statusRow {
  z-index: 4;
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.statusRow strong,
.statusRow span {
  display: block;
}

.statusRow span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.84rem;
}

.filters {
  z-index: 4;
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.aiPanel {
  z-index: 3;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.aiPanel summary {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
  cursor: pointer;
  list-style: none;
}

.aiPanel summary::-webkit-details-marker {
  display: none;
}

.aiPanel summary strong,
.aiPanel summary small {
  display: block;
}

.aiPanel summary strong {
  font-size: 0.9rem;
  line-height: 1.25;
}

.aiPanel summary small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.aiPanel summary svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
  transition: transform 160ms ease;
}

.aiPanel[open] summary {
  border-bottom: 1px solid var(--line);
}

.aiPanel[open] summary svg {
  transform: rotate(180deg);
}

.aiPanelBody {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr)) 156px;
  gap: 14px;
  align-items: end;
  padding: 14px;
}

#copyPromptButton {
  min-height: 38px;
  align-self: end;
}

.listEditor {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.listEditor header,
.ruleItem,
.newRuleRow {
  display: flex;
  align-items: center;
  gap: 8px;
}

.listEditor header {
  justify-content: space-between;
}

.listEditor h3 {
  margin: 0;
  color: #4d5560;
  font-size: 0.82rem;
  line-height: 1.3;
}

.ruleList {
  display: grid;
  gap: 8px;
  max-height: 170px;
  overflow: auto;
  padding-right: 2px;
}

.ruleItem {
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 9px 9px 11px;
  background: var(--field);
}

.ruleItem p {
  flex: 1;
  margin: 0;
  color: #343941;
  font-size: 0.88rem;
  line-height: 1.45;
}

.ruleItem.editing {
  align-items: center;
  padding: 8px;
}

.editRuleInput,
.newRuleInput {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
}

.editRuleInput:focus,
.newRuleInput:focus {
  border-color: var(--accent);
  outline: 3px solid var(--focus);
}

.newRuleRow {
  align-items: center;
}

.iconActions {
  display: flex;
  flex: 0 0 auto;
  gap: 4px;
}

.iconButton {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

.iconButton svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.2;
}

.filterButton {
  min-height: 34px;
  padding: 0 14px;
}

.filterButton.active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.results {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
  min-height: 0;
  margin-top: 8px;
  overflow: hidden;
}

.channelColumn {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 36px rgb(31 35 40 / 5%);
  overflow: hidden;
}

.channelColumnHeader {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
  backdrop-filter: blur(10px);
}

.channelTitleBlock {
  min-width: 0;
}

.channelColumnHeader h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
}

.channelColumnHeader p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.channelActions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.channelAction {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  color: var(--ink);
  background: #fff;
  font-size: 0.76rem;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.channelAction:hover {
  border-color: var(--accent);
}

.channelAction svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.3;
}

.channelAction img {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.channelColumnBody {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 10px;
  overflow-y: scroll;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.channelEmpty {
  margin: 0;
  padding: 24px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.videoGroup {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.videoGroupHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--field);
}

.videoGroupMedia {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
  align-items: center;
}

.videoThumb {
  width: 84px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  object-fit: cover;
  background: #eef1f4;
}

.videoGroupTitle {
  min-width: 0;
}

.videoGroupHeader h2 {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.35;
}

.videoGroupHeader p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.videoGroupHeader a {
  display: inline-flex;
  min-height: 30px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  font-size: 0.86rem;
  font-weight: 800;
  text-decoration: none;
}

.videoGroupHeader a:hover {
  border-color: var(--accent);
}

.videoComments {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 10px;
}

.commentCard {
  display: grid;
  gap: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.commentCard header,
.commentCard footer {
  display: flex;
  gap: 12px;
  align-items: center;
}

.commentCard footer {
  align-self: end;
  justify-content: space-between;
}

.avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 50%;
  background: #eef1f4;
}

.author {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.25;
}

.meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.commentText {
  margin: 0;
  color: #343941;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.48;
}

.replyForm {
  display: grid;
  gap: 8px;
}

.existingReplies {
  display: grid;
  gap: 8px;
  border-left: 3px solid #e8edf2;
  padding-left: 10px;
}

.replyListTitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.replyItem {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
}

.replyAvatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eef1f4;
}

.replyMeta,
.replyBody {
  margin: 0;
}

.replyMeta {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.replyBody {
  margin-top: 3px;
  color: #343941;
  font-size: 0.88rem;
  line-height: 1.45;
}

.replyText {
  width: 100%;
  min-height: 42px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--field);
  font: inherit;
  line-height: 1.45;
}

.replyText:focus {
  border-color: var(--accent);
  outline: 3px solid var(--focus);
}

.replyButton {
  justify-self: end;
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.86rem;
}

.likeBadge {
  color: var(--green);
  font-size: 0.84rem;
  font-weight: 800;
}

.actions {
  display: flex;
  gap: 8px;
}

.actions a {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.86rem;
}

.empty {
  grid-column: 1 / -1;
  padding: 34px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgb(255 255 255 / 64%);
  text-align: center;
}

@media (max-width: 960px) {
  html {
    height: auto;
    overflow: auto;
  }

  body {
    height: auto;
    max-height: none;
    overflow: auto;
  }

  .shell {
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .toolbar,
  .settings,
  .formActions,
  .advancedGrid,
  .channelConfigGrid,
  .aiPanelBody,
  .results,
  .videoComments {
    grid-template-columns: 1fr;
  }

  .results {
    height: auto;
    overflow: visible;
  }

  .channelColumn {
    height: auto;
    max-height: none;
  }

  .channelColumnBody {
    height: auto;
    overflow: visible;
  }

  .statusRow {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 20px, 1280px);
    padding-top: 10px;
  }

  .toolbar {
    padding: 18px;
  }

  h1 {
    font-size: 2rem;
  }

  .filters {
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .commentCard footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .videoGroupHeader {
    align-items: flex-start;
    flex-direction: column;
  }

  .videoGroupMedia {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .videoThumb {
    width: 88px;
  }
}
