:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dee6;
  --green: #157f58;
  --blue: #2357c6;
  --red: #b42318;
  --amber: #9a6700;
  --shadow: 0 14px 35px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #edf4f1;
}

.login-shell {
  width: min(420px, calc(100vw - 28px));
}

.login-panel {
  display: grid;
  gap: 16px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  font-size: 32px;
}

.login-panel button {
  width: 100%;
}

.login-error {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #f0b8b2;
  border-radius: 7px;
  background: #fff6f5;
  color: var(--red);
  font-size: 14px;
  font-weight: 700;
}

.topbar,
.status-band,
.preview-panel,
.workspace {
  display: grid;
  gap: 16px;
}

.topbar {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  margin-bottom: 18px;
}

.eyebrow,
.label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 40px;
  line-height: 1.05;
}

h2 {
  font-size: 18px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.primary {
  background: var(--green);
  color: white;
}

.secondary {
  background: var(--blue);
  color: white;
}

.danger {
  background: white;
  border-color: #f0b8b2;
  color: var(--red);
}

.ghost {
  background: white;
  border-color: var(--line);
  color: var(--ink);
}

.status-band {
  grid-template-columns: minmax(0, 1fr) 0.25fr;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf4f1;
}

.status-band div {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.status-band strong {
  overflow-wrap: anywhere;
  font-size: 15px;
}

.ingest-sources {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.ingest-source {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.ingest-source code {
  display: block;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
}

.preview-panel {
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.multi-chat {
  display: grid;
  gap: 9px;
  max-height: 520px;
  overflow: auto;
}

.chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.chat-composer input {
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: white;
  color: var(--ink);
}

.chat-composer input:focus {
  outline: 2px solid rgba(35, 87, 198, 0.22);
  border-color: var(--blue);
}

.chat-empty,
.chat-message {
  padding: 10px 12px;
  border-radius: 7px;
  background: #f9fafb;
}

.chat-empty {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.chat-empty strong {
  color: var(--ink);
}

.chat-empty p {
  margin: 0;
}

.chat-message {
  border-left: 4px solid var(--line);
}

.chat-message.source-telegram {
  border-left-color: #2aabee;
}

.chat-message.source-youtube {
  border-left-color: #ff0033;
}

.chat-message.source-vk {
  border-left-color: #2787f5;
}

.chat-message.source-instagram {
  border-left-color: #c13584;
}

.chat-message.source-donationalerts {
  border-left-color: #d97706;
}

.pinned-chat {
  position: sticky;
  top: 0;
  z-index: 2;
  padding-right: 44px;
  border: 1px solid #f4c56f;
  border-left-width: 4px;
  background: #fff8e5;
  box-shadow: 0 10px 24px rgba(154, 103, 0, 0.14);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.pinned-chat.is-dismissed {
  opacity: 0;
  transform: translateX(24px);
}

.dismiss-pinned {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 28px;
  min-height: 28px;
  padding: 0;
  border: 1px solid #f0b8b2;
  border-radius: 7px;
  background: #fff;
  color: var(--red);
  font-size: 20px;
  line-height: 1;
}

.chat-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.chat-text {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.4;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.select-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.select-inline select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: white;
  color: var(--ink);
  font-weight: 700;
}

.preview-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(320px, 0.32fr);
  gap: 14px;
  align-items: stretch;
}

.preview-stage {
  position: relative;
  min-height: 260px;
  aspect-ratio: 16 / 9;
  border: 1px solid #111827;
  border-radius: 8px;
  overflow: hidden;
  background: #0b1017;
}

.preview-video,
.preview-snapshot {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.preview-video {
  opacity: 0;
  transition: opacity 160ms ease;
}

.preview-video.is-playing {
  opacity: 1;
}

.preview-snapshot {
  opacity: 0;
  transition: opacity 160ms ease;
}

.preview-snapshot.is-visible {
  opacity: 1;
}

.preview-side {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
  min-height: 260px;
}

.compact-head {
  margin-bottom: 0;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  color: var(--ink);
  background: white;
  font-weight: 800;
  text-decoration: none;
}

.button-link[aria-disabled="true"] {
  pointer-events: none;
  opacity: 0.55;
}

.workspace {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.destinations,
.log-panel {
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

#saveState.error {
  color: var(--red);
}

.list-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.count-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.count-field input {
  width: 76px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: #fbfcfd;
}

.destination-list {
  display: grid;
  gap: 10px;
}

.destination-row {
  display: grid;
  grid-template-columns: 46px minmax(110px, 0.42fr) minmax(120px, 0.45fr) minmax(140px, 0.58fr) minmax(220px, 1fr) minmax(180px, 0.85fr) 94px 40px;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.switch {
  position: relative;
  width: 46px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #b7c0cc;
  transition: 160ms ease;
}

.slider::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  border-radius: 999px;
  background: white;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.24);
  transition: 160ms ease;
}

.switch input:checked + .slider {
  background: var(--green);
}

.switch input:checked + .slider::after {
  transform: translateX(20px);
}

.field {
  position: relative;
  display: grid;
  gap: 5px;
}

.field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fbfcfd;
}

.field input:focus,
.field select:focus {
  outline: 2px solid rgba(35, 87, 198, 0.22);
  border-color: var(--blue);
}

.icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  border-color: #f0b8b2;
  background: white;
  color: var(--red);
  font-size: 24px;
  line-height: 1;
}

.secret-field input {
  padding-right: 86px;
}

.tiny-button {
  position: absolute;
  right: 5px;
  bottom: 5px;
  min-height: 30px;
  padding: 0 8px;
  border-color: var(--line);
  background: white;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
  background: #eef0f3;
  color: var(--muted);
  white-space: nowrap;
}

.pill.live {
  background: #dff5ea;
  color: var(--green);
}

.pill.missing {
  background: #fff3cd;
  color: var(--amber);
}

.pill.error {
  background: #fff6f5;
  color: var(--red);
}

.log-panel {
  position: sticky;
  top: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  box-shadow: var(--shadow);
}

.tech-panel {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.tech-panel summary {
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 800;
}

.tech-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.35fr) minmax(0, 1fr);
  gap: 14px;
  padding: 0 16px 16px;
}

.tech-card {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.tech-card strong {
  overflow-wrap: anywhere;
  font-size: 12px;
}

.logs {
  display: grid;
  gap: 9px;
  max-height: 680px;
  overflow: auto;
}

.log-entry {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-left: 4px solid var(--line);
  background: #f9fafb;
  border-radius: 6px;
}

.log-entry[data-level="error"] {
  border-left-color: var(--red);
}

.log-entry[data-level="warn"] {
  border-left-color: var(--amber);
}

.log-entry[data-level="info"] {
  border-left-color: var(--green);
}

.log-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.log-message {
  margin: 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 980px) {
  .topbar,
  .status-band,
  .preview-grid,
  .workspace {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: flex-start;
  }

  .log-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 20px, 720px);
    padding-top: 16px;
  }

  h1 {
    font-size: 32px;
  }

  .destination-row {
    grid-template-columns: 46px minmax(0, 1fr);
  }

  .destination-row .field:nth-of-type(3),
  .destination-row .field:nth-of-type(4),
  .destination-row .pill,
  .destination-row .icon-button {
    grid-column: 1 / -1;
  }

  .icon-button {
    width: 100%;
  }
}
