:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d8dee8;
  --primary: #1268b3;
  --primary-hover: #0f5796;
  --danger: #b42318;
  --ok: #117a48;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
}

h2 {
  font-size: 16px;
  font-weight: 700;
}

.app-header p,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.header-actions,
.toolbar,
.panel-head,
.panel-controls,
.bulk-actions,
.filters {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.button.primary {
  border-color: var(--primary);
  color: #fff;
  background: var(--primary);
}

.button.primary:hover {
  background: var(--primary-hover);
}

.button.secondary:hover {
  border-color: #aeb8c8;
  background: #f8fafc;
}

.button.danger-button {
  color: var(--danger);
}

.button.danger-button:hover {
  border-color: var(--danger);
}

.output-button {
  min-width: 116px;
  white-space: nowrap;
}

.output-button.copied {
  border-color: var(--ok);
  color: var(--ok);
}

.output-button.copy-error {
  border-color: var(--danger);
  color: var(--danger);
}

.button.compact {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

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

.layout {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px 24px 32px;
}

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

.metric,
.status-panel,
.source-panel,
.panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric {
  padding: 14px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.status-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 1fr);
  gap: 16px;
  margin-top: 14px;
  padding: 16px;
}

.status-panel p {
  margin-top: 8px;
  color: var(--muted);
}

.source-panel {
  margin-top: 14px;
  padding: 14px 16px;
}

.playlist-tools {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(220px, 1fr) auto minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.playlist-tools select {
  width: 100%;
}

.playlist-actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.countries-panel {
  min-height: 0;
  margin-top: 14px;
}

.countries-panel .panel-head > div {
  min-width: 0;
}

.country-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-height: 360px;
}

.country-row {
  min-height: 72px;
}

.source-form {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-top: 10px;
}

.source-fields {
  display: grid;
  grid-template-columns: minmax(220px, 1.3fr) minmax(140px, 0.7fr) minmax(140px, 0.7fr) 140px;
  gap: 10px;
}

.field {
  min-width: 0;
}

.field-wide {
  min-width: 240px;
  grid-column: 1 / -1;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.source-actions {
  display: flex;
  align-items: end;
}

.hidden {
  display: none;
}

.form-message {
  min-height: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

dl {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

dd {
  margin: 4px 0 0;
  font-weight: 650;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  min-height: 520px;
  overflow: hidden;
}

.panel-head {
  justify-content: space-between;
  min-height: 56px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-controls {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.bulk-actions {
  flex-wrap: wrap;
}

.toolbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

input {
  padding: 0 12px;
}

select {
  width: 128px;
  padding: 0 10px;
}

#contentTypeFilter {
  width: 138px;
}

#streamStateFilter {
  width: 128px;
}

.list {
  max-height: 620px;
  overflow: auto;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid #edf1f6;
}

.row:hover {
  background: #f8fafc;
}

.row.active {
  background: #eaf4ff;
}

.row-title {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 650;
}

.row-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.switch input {
  width: 18px;
  height: 18px;
  min-height: 18px;
}

.empty,
.error {
  padding: 24px 16px;
  color: var(--muted);
}

.error {
  color: var(--danger);
}

.ok {
  color: var(--ok);
}

@media (max-width: 900px) {
  .app-header,
  .status-panel,
  .workspace {
    grid-template-columns: 1fr;
  }

  .source-form {
    grid-template-columns: 1fr;
  }

  .playlist-tools {
    grid-template-columns: 1fr;
  }

  .source-fields {
    grid-template-columns: 1fr;
  }

  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    flex-wrap: wrap;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .country-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .layout,
  .app-header {
    padding-left: 14px;
    padding-right: 14px;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .header-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-controls,
  .filters {
    flex-wrap: wrap;
  }

  .country-list {
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }
}
