:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --border: #e3e8f1;
  --text: #172033;
  --text-muted: #667085;
  --accent: #2f6fed;
  --accent-dark: #2459c6;
  --green: #16a34a;
  --red: #dc2626;
  --header-bg: #111c35;
  --header-bg-2: #263653;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.login-page{min-height:100vh;display:grid;place-items:center;background:#f2f6fc;padding:24px}
.login-card{width:min(430px,100%);background:#fff;border:1px solid #dbe4f0;border-radius:22px;padding:32px;box-shadow:0 24px 70px rgba(15,35,70,.14)}
.login-brand{display:flex;align-items:center;gap:14px;margin-bottom:28px}.login-brand>div{display:grid}.login-brand small{color:#71809a;margin-top:4px}
.login-card h1{margin:0 0 8px}.login-card form{display:grid;gap:18px;margin-top:24px}.login-card label{display:grid;gap:7px;font-weight:700}.login-card input{padding:13px 14px;border:1px solid #cfd9e8;border-radius:10px;font:inherit}.form-error{padding:11px 13px;border-radius:10px;background:#fff0f1;color:#c52e3e;margin-top:16px}
.logout-form{margin-left:auto}.logout-form button{border:0;background:transparent;color:#aebbd0;cursor:pointer;font:inherit}.logout-form button:hover{color:#fff}

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--header-bg);
  padding: 0 20px;
  height: 52px;
}
.topnav-brand { color: #fff; font-weight: 600; margin-right: 24px; }
.topnav a {
  color: #c7cad1;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
}
.topnav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.topnav a.active { background: var(--accent); color: #fff; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }

h1 { font-size: 22px; margin: 0 0 20px; }
h2 { font-size: 17px; margin: 0 0 12px; }

/* --- Dashboard cards --- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card .value { font-size: 26px; font-weight: 700; }
.card .label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.actions-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 24px; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all .12s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--red); border-color: var(--red); background: #fff; }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}

.log-lines { font-family: "Cascadia Code", Consolas, monospace; font-size: 12.5px; max-height: 320px; overflow-y: auto; background: #fbfbfc; border: 1px solid var(--border); border-radius: 6px; padding: 10px; white-space: pre-wrap; }
.log-lines div { padding: 1px 0; }
.log-lines .lvl-ERROR { color: var(--red); font-weight: 600; }
.log-lines .lvl-WARNING { color: #b45309; }

/* --- Channels toolbar --- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input[type=text] {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; min-width: 220px;
}
.toolbar select { padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }

.bulk-bar {
  position: sticky; top: 10px; z-index: 45;
  display: flex; align-items: end; gap: 10px; background: rgba(238,244,255,.97); border: 1px solid #bdd1f5;
  border-radius: 10px; padding: 11px 13px; margin-bottom: 14px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(31,74,145,.18);
  backdrop-filter: blur(8px);
}
.bulk-bar .count { font-weight: 700; }
.bulk-destination {
  display: grid;
  gap: 4px;
  min-width: 250px;
  margin-left: auto;
}
.bulk-destination span {
  color: #52627a;
  font-size: 11px;
  font-weight: 650;
}
.bulk-destination select { width: 100%; }
.channel-group-help {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: -3px 0 14px;
  padding: 10px 13px;
  border: 1px solid #d9e5f8;
  border-radius: 10px;
  color: #52627a;
  background: #f7f9fd;
  font-size: 12.5px;
  line-height: 1.45;
}
.channel-group-help b {
  flex: 0 0 auto;
  color: #294d82;
}
.select-category-channels {
  width: 17px;
  height: 17px;
  margin: 0 1px 0 0;
  accent-color: #2f6fed;
  cursor: pointer;
}

/* --- Category block --- */
.category {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}
.category-header {
  display: flex; align-items: center; gap: 10px;
  background: var(--header-bg-2); color: #fff;
  padding: 10px 14px; cursor: pointer; user-select: none;
}
.category-header .chevron { font-size: 12px; width: 14px; }
.category-header .cat-name { font-weight: 600; flex: 1; }
.category-header .cat-count { font-size: 12.5px; color: #c7cad1; }
.category-header input.cat-rename {
  background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: 4px; padding: 3px 6px;
  font-size: 14px; font-weight: 600;
}
.category-toolbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--border);
  background: #fafafa; flex-wrap: wrap;
}
.category-body { padding: 4px 0; }
.category-body.collapsed { display: none; }

.channel-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  border-bottom: 1px solid #f0f1f4;
  min-width: 0;
}
.channel-row:last-child { border-bottom: none; }
.channel-row.drag-ghost { opacity: .4; }
.channel-row .drag-handle { cursor: grab; color: #b6b9c2; flex: 0 0 auto; }
.channel-row > input[type="checkbox"] { flex: 0 0 auto; }
.channel-logo,
.channel-row img.logo {
  display: block;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  max-width: 44px;
  min-height: 44px;
  max-height: 44px;
  object-fit: contain;
  border-radius: 4px;
  background: #f2f2f4;
}
.channel-logo.empty,
.channel-row img.logo.empty { visibility: hidden; }
.channel-main { flex: 1 1 auto; min-width: 0; font-size: 14px; }
.channel-main b,
.channel-main small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stream-select {
  flex: 0 1 280px;
  width: min(280px, 28vw);
  min-width: 140px;
  max-width: 280px;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.channel-row .info { flex: 0 0 auto; }
.channel-row .name { flex: 1; font-size: 14px; }
.channel-row .source { color: var(--text-muted); font-size: 12px; }
.channel-row .select-box { margin-left: auto; }

@media (max-width: 760px) {
  .container { padding: 16px 10px 40px; }
  .topnav { padding: 0 10px; overflow-x: auto; }
  .topnav-brand { margin-right: 8px; white-space: nowrap; }
  .category-header { flex-wrap: wrap; }
  .channel-row {
    display: grid;
    grid-template-columns: auto auto 44px minmax(0, 1fr) auto auto;
    gap: 8px;
    padding: 8px 10px;
  }
  .stream-select {
    grid-column: 4 / -1;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    max-width: none;
  }
  .channel-row > .switch { grid-column: 5; grid-row: 1; }
  .channel-row > .info { grid-column: 6; grid-row: 1; }
}

/* toggle switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }

label { display:block; margin:10px 0; }
label > input:not([type="checkbox"]), label > select { display:block; width:100%; margin-top:4px; padding:8px; box-sizing:border-box; }
fieldset { border:1px solid #d8dee9; border-radius:8px; margin:12px 0; }
.grow { flex:1; }
.card-head,.status-row,.source-meta,.picker-row { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.source-meta { flex-wrap:wrap; justify-content:flex-start; margin:12px 0; color:#586174; }
.badge { padding:3px 9px; border-radius:999px; background:#e8edf5; font-size:12px; }
.badge.done,.badge.idle { background:#dff6e8; color:#146c37; }
.badge.updating,.badge.running { background:#fff0c7; color:#775600; }
.badge.error { background:#ffe0e0; color:#a40000; }
.badge.unchecked { background:#e8edf5; color:#586174; }
.badge.unsupported { background:#fff0c7; color:#775600; }
.error-box { background:#ffe9e9; color:#8b0000; padding:10px; border-radius:6px; margin:10px 0; }
.source-channels { margin-top:14px; }
.source-target { position:sticky; left:0; }
.source-channel-table {
  width: 100%;
  min-width: 1080px;
  table-layout: fixed;
}
.source-channel-table th:nth-child(1) { width: 13%; }
.source-channel-table th:nth-child(2) { width: 16%; }
.source-channel-table th:nth-child(3) { width: 6%; }
.source-channel-table th:nth-child(4) { width: 16%; }
.source-channel-table th:nth-child(5) { width: 19%; }
.source-channel-table th:last-child { width: 142px; }
.source-channel-table .nowrap { white-space:nowrap; }
.source-channel-table th:nth-child(4),
.source-channel-table td:nth-child(4) { min-width: 175px; }
.source-channel-table td:nth-child(4) .badge { white-space: nowrap; }
.source-channel-table th:last-child,
.source-channel-table td:last-child {
  position: sticky;
  right: 0;
  z-index: 2;
  min-width: 142px;
  background: #fff;
  box-shadow: -8px 0 12px -12px rgba(15, 23, 42, .45);
}
.source-channel-table th:last-child { z-index: 3; }
.source-channel-table .stream-url {
  max-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.source-channel-table .stream-link-exact {
  color: #15803d;
  font-weight: 650;
}
.source-channel-table .stream-link-different {
  color: #c56a0a;
  font-weight: 650;
}
.source-channel-table .stream-link-dead {
  color: #c62828;
  font-weight: 700;
}
.source-channel-table .stream-link-unstable {
  color: #7b4bb7;
  font-weight: 700;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.source-channel-table .stream-link-unconfirmed {
  color: #8a5a00;
  font-weight: 700;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.badge.unstable { color:#6941a5; background:#f1eaff; }
.badge.unconfirmed { color:#7a4d00; background:#fff4d6; }
.color-legend {
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:9px 16px;
  margin:0 0 15px;
  padding:11px 14px;
  border:1px solid #dfe5ee;
  border-radius:10px;
  color:#475467;
  background:#fbfcfe;
  font-size:12px;
}
.color-legend > span { display:inline-flex; align-items:center; gap:6px; }
.legend-dot { width:10px; height:10px; border-radius:50%; background:#98a2b3; }
.legend-dot.exact { background:#1f9d68; }
.legend-dot.different { background:#e39a19; }
.legend-dot.unstable { background:#8754c7; }
.legend-dot.unconfirmed { background:#d89414; }
.legend-dot.dead { background:#d92d20; }
.legend-dot.unchecked { background:#98a2b3; }
.job-return-focus {
  position: relative;
  background: #eef5ff !important;
  box-shadow: inset 4px 0 0 var(--accent), inset 0 0 0 1px #bcd0f7;
  transition: background .25s, box-shadow .25s;
}
.source-category-summary {
  margin: 0 0 10px;
  color: var(--text-muted);
  font-size: 12.5px;
}
.source-category-list {
  display: grid;
  gap: 4px;
}
.source-category {
  min-width: 0;
  border-radius: 7px;
  overflow: hidden;
}
.source-category-header {
  width: 100%;
  min-height: 39px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border: 0;
  border-radius: 7px;
  background: #263142;
  color: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.source-category-header:hover { background: #303d50; }
.source-category-chevron {
  width: 14px;
  color: #a9c2ee;
  font-size: 15px;
  line-height: 1;
}
.source-category-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}
.source-category-count {
  color: #cbd5e1;
  font-size: 12px;
  white-space: nowrap;
}
.source-category-body {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 7px 7px;
}
.playlist-pending {
  display: block;
  max-width: 190px;
  margin-top: 4px;
  color: #5f6f89;
  line-height: 1.25;
}
table { width:100%; border-collapse:collapse; font-size:13px; }
th,td { text-align:left; padding:8px; border-bottom:1px solid #e4e8ef; }
.wide { width:min(900px,90vw); }
.picker-list { max-height:60vh; overflow:auto; margin:12px 0; }
.picker-row { border-bottom:1px solid #e4e8ef; padding:8px; }
.picker-row span small,.channel-main small { display:block; color:#758095; margin-top:3px; }
.add-channels-heading { margin-bottom:12px; }
.add-list-panel {
  margin-bottom:14px;
  padding:0;
  overflow:hidden;
}
.add-list-summary {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:18px;
  padding:17px 19px;
  color:#17233a;
  background:#f5f8fd;
  cursor:pointer;
  list-style:none;
}
.add-list-summary::-webkit-details-marker { display:none; }
.add-list-summary::before {
  content:"▸";
  flex:0 0 auto;
  color:#2f6fed;
  font-size:15px;
}
.add-list-panel[open] > .add-list-summary::before { content:"▾"; }
.add-list-summary > span {
  display:flex;
  flex:1;
  flex-direction:column;
  gap:4px;
}
.add-list-summary b { font-size:17px; }
.add-list-summary small,
.add-list-summary em { color:var(--text-muted); font-style:normal; }
.add-list-content {
  padding:16px;
  border-top:1px solid #e3e9f2;
}
.source-picker-toolbar {
  justify-content:flex-end;
  margin-bottom:14px;
}
.source-picker-toolbar .search-box { min-width:min(360px,100%); }
.target-playlist-categories { display:grid; gap:8px; }
.target-playlist-category {
  overflow:hidden;
  border:1px solid #dfe5ee;
  border-radius:10px;
  background:#fff;
}
.target-playlist-category > summary {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  padding:12px 14px;
  color:#253858;
  background:#f7f9fc;
  cursor:pointer;
  list-style:none;
}
.target-playlist-category > summary::-webkit-details-marker { display:none; }
.target-playlist-category > summary::before {
  content:"▸";
  color:#2f6fed;
}
.target-playlist-category[open] > summary::before { content:"▾"; }
.target-playlist-category > summary > span {
  display:flex;
  flex:1;
  align-items:baseline;
  gap:10px;
  min-width:0;
}
.target-playlist-category > summary small,
.target-playlist-category > summary em {
  color:var(--text-muted);
  font-style:normal;
}
.target-playlist-channel-list {
  display:grid;
  max-height:360px;
  overflow:auto;
  border-top:1px solid #e5eaf1;
}
.target-playlist-channel {
  display:flex;
  justify-content:space-between;
  gap:14px;
  padding:9px 14px;
  border-bottom:1px solid #edf0f4;
}
.target-playlist-channel:last-child { border-bottom:0; }
.target-playlist-channel small { color:var(--text-muted); }
.target-playlist-panel .manual-channel-panel { margin-bottom:14px; }
@media (max-width:700px) {
  .add-list-summary { align-items:flex-start; padding:14px; }
  .add-list-summary b { font-size:15px; }
  .add-list-summary em { flex:0 0 auto; font-size:11px; text-align:right; }
  .add-list-content { padding:11px; }
  .source-picker-toolbar { display:grid; grid-template-columns:1fr; }
  .source-picker-toolbar .compact-field,
  .source-picker-toolbar .search-box { width:100%; min-width:0; }
  .target-playlist-category > summary > span { align-items:flex-start; flex-direction:column; gap:2px; }
  .target-playlist-channel { align-items:flex-start; flex-direction:column; gap:3px; }
}
.picker-category-list { display:grid; gap:7px; }
.picker-category {
  overflow:hidden;
  border:1px solid #dfe5ee;
  border-radius:11px;
  background:#fff;
}
.picker-category-header {
  display:flex;
  align-items:center;
  gap:8px;
  width:100%;
  padding:12px 14px;
  border:0;
  color:#253858;
  background:#f4f7fb;
  text-align:left;
}
.picker-category-header small { color:var(--text-muted); font-style:normal; }
.picker-category-toggle {
  display:grid;
  grid-template-columns:20px minmax(0,1fr) auto;
  align-items:center;
  gap:8px;
  min-width:0;
  flex:1;
  padding:0;
  border:0;
  color:inherit;
  background:transparent;
  text-align:left;
  cursor:pointer;
}
.picker-import-options {
  display:grid;
  grid-template-columns:minmax(240px,320px) minmax(280px,1fr) auto;
  align-items:end;
  gap:18px;
  margin-bottom:12px;
  padding:14px;
  border:1px solid #d7e1f0;
  border-radius:10px;
  background:#fff;
}
.picker-import-options p { margin:0; color:var(--muted); line-height:1.45; }
.picker-category-body { border-top:1px solid #e5eaf1; }
.picker-category-body .picker-row {
  display:grid;
  grid-template-columns:22px minmax(0,1fr) auto;
  align-items:center;
  gap:10px;
  margin:0;
  padding:10px 14px;
  border:0;
  border-bottom:1px solid #edf0f4;
  border-radius:0;
  cursor:pointer;
}
.picker-category-body .picker-row:last-child { border-bottom:0; }
.picker-category-body .picker-row em { color:#2f6fed; font-size:12px; font-style:normal; }
.picker-category-body .picker-row.already-added { color:#667085; background:#fafafa; cursor:default; }
.picker-category-body .picker-row.already-added em { color:#1b8658; }
.picker-selection-bar {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  margin-bottom:12px;
  padding:12px 14px;
  border:1px solid #d7e1f0;
  border-radius:10px;
  background:#f7f9fd;
}
.compact-field { min-width:210px; }
.playlist-savebar {
  position:fixed;
  z-index:80;
  right:24px;
  bottom:20px;
  left:100px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:20px;
  padding:14px 18px;
  border:1px solid #f0c36a;
  border-radius:12px;
  background:#fff8e7;
  box-shadow:0 12px 34px rgba(16,24,40,.22);
}
body:not(.sidebar-compact) .playlist-savebar { left:272px; }
.playlist-savebar b,.playlist-savebar span { display:block; }
.playlist-savebar span { margin-top:3px; color:#7a5a16; font-size:12px; }
.leave-warning-box p { color:var(--text-muted); line-height:1.5; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0; background: #d1d5db; border-radius: 999px; transition: .15s;
}
.switch .slider:before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%; transition: .15s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(18px); }

/* --- Modal --- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-box { background: #fff; border-radius: 10px; padding: 20px; width: 520px; max-width: 92vw; max-height: 82vh; overflow-y: auto; }
.modal-box h3 { margin-top: 0; }
.progress-log { list-style: none; padding: 0; margin: 0 0 16px; font-size: 13px; }
.progress-log li { padding: 5px 0; border-bottom: 1px solid #f0f1f4; }
.progress-log li.stage-error { color: var(--red); font-weight: 600; }
.progress-log li.stage-done { color: var(--green); font-weight: 600; }
.progress-box { width: 620px; }
.progress-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.progress-heading > div { display: flex; align-items: center; gap: 11px; }
.progress-heading h3 { margin: 0; }
.job-spinner {
  display: inline-block;
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  border: 2px solid #cbd8f4;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: job-spin .8s linear infinite;
}
.job-spinner.done {
  border: 0;
  background: var(--green);
  animation: none;
  box-shadow: inset 0 0 0 5px #dcfce7;
}
.job-spinner.error {
  border: 0;
  background: var(--red);
  animation: none;
  box-shadow: inset 0 0 0 5px #fee2e2;
}
@keyframes job-spin { to { transform: rotate(360deg); } }
.progress-percent { color: var(--accent); font-size: 20px; font-weight: 750; }
.progress-track {
  height: 9px;
  margin: 20px 0 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf5;
}
.progress-track > div {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2f6fed, #5b8ff5);
  transition: width .25s ease;
}
.progress-summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #344054;
  font-size: 12px;
  font-weight: 650;
}
.progress-current {
  min-height: 38px;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}
.progress-log {
  max-height: 210px;
  overflow-y: auto;
  margin-top: 10px;
  padding: 0 2px;
}
.progress-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 4px; }
.job-pill {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 210;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 8px 14px;
  border: 1px solid #c9d7f3;
  border-radius: 12px;
  color: var(--text);
  background: #fff;
  box-shadow: 0 14px 38px rgba(16,24,40,.2);
  cursor: pointer;
}
.job-pill span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}
.job-pill b { margin-left: auto; color: var(--accent); font-size: 12px; }

.diff-section { margin-bottom: 14px; }
.diff-section h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; color: var(--text-muted); }
.diff-section ul { margin: 0; padding-left: 18px; font-size: 13.5px; }
.diff-empty { color: var(--text-muted); font-size: 13px; }

#toast-container { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1f2430; color: #fff; padding: 10px 16px; border-radius: 6px; font-size: 13.5px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

.muted { color: var(--text-muted); }
.hidden { display: none !important; }

/* --- Application shell and navigation --- */
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 80;
  width: 248px;
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
  color: #dce5f7;
  background:
    radial-gradient(circle at 20% 0, rgba(58, 112, 226, .22), transparent 30%),
    linear-gradient(180deg, #111c35 0%, #0b1428 100%);
  box-shadow: 12px 0 32px rgba(15, 23, 42, .08);
}
.sidebar-width-toggle {
  display: none;
  position: absolute;
  top: 16px;
  right: -13px;
  z-index: 2;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #cfdaee;
  border-radius: 50%;
  color: #315b9e;
  background: #fff;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .18);
  cursor: pointer;
  font-size: 21px;
  line-height: 24px;
  transition: transform .18s, color .18s;
}
.channel-workspace .sidebar-width-toggle { display: block; }
.sidebar-width-toggle:hover { color: var(--accent); }
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 10px 20px;
  color: #fff;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #4f8cff, #2f6fed);
  box-shadow: 0 8px 20px rgba(47, 111, 237, .35);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -.3px;
}
.sidebar-brand b,
.sidebar-brand small,
.sidebar-footer b,
.sidebar-footer small { display: block; }
.sidebar-brand b { font-size: 15px; letter-spacing: -.2px; }
.sidebar-brand small { margin-top: 3px; color: #8fa0be; font-size: 11px; }
.sidebar-nav { flex: 1; overflow-y: auto; }
.nav-group { margin: 12px 0 22px; }
.nav-label {
  padding: 0 12px 8px;
  color: #7184a6;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin: 3px 0;
  padding: 0 12px;
  border-radius: 9px;
  color: #aebbd1;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .16s, color .16s, transform .16s;
}
.nav-item svg { width: 19px; height: 19px; fill: currentColor; opacity: .9; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.07); transform: translateX(2px); }
.nav-item.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(47,111,237,.95), rgba(67,124,240,.82));
  box-shadow: 0 8px 18px rgba(31, 82, 185, .25);
}
.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 11px 2px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-footer b { color: #dce5f7; font-size: 11px; }
.sidebar-footer small { margin-top: 2px; color: #7184a6; font-size: 10px; }
.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 4px rgba(52,211,153,.12);
}
.workspace { min-width: 0; min-height: 100vh; margin-left: 248px; }
.mobile-header { display: none; }
.sidebar-overlay { display: none; }
.container { max-width: 1460px; margin: 0 auto; padding: 34px 34px 64px; }
.channel-workspace .container {
  max-width: none;
  padding-left: 24px;
  padding-right: 24px;
}

@media (min-width: 901px) {
  .sidebar,
  .workspace,
  .sidebar-brand,
  .nav-item { transition: width .18s, margin-left .18s, padding .18s; }
  .sidebar-compact .sidebar {
    width: 76px;
    padding-left: 10px;
    padding-right: 10px;
  }
  .sidebar-compact .workspace { margin-left: 76px; }
  .sidebar-compact .sidebar-brand {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }
  .sidebar-compact .sidebar-brand > span:last-child,
  .sidebar-compact .nav-label,
  .sidebar-compact .nav-item > span,
  .sidebar-compact .sidebar-footer > span:last-child { display: none; }
  .sidebar-compact .nav-item {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }
  .sidebar-compact .nav-item:hover { transform: none; }
  .sidebar-compact .nav-item svg { width: 21px; height: 21px; }
  .sidebar-compact .sidebar-footer { justify-content: center; padding-left: 0; padding-right: 0; }
  .sidebar-compact .sidebar-width-toggle { transform: rotate(180deg); }
}

/* --- Page hierarchy and tabs --- */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.page-header h1 { margin: 3px 0 7px; font-size: 28px; line-height: 1.2; letter-spacing: -.6px; }
.page-header p,
.panel-head p,
.section-toolbar p,
.tool-panel p { margin: 0; color: var(--text-muted); font-size: 13.5px; line-height: 1.5; }
.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .11em;
  text-transform: uppercase;
}
.back-link { color: var(--accent); font-size: 13px; text-decoration: none; }
.tabs { min-width: 0; }
.tab-list {
  display: flex;
  gap: 5px;
  margin-bottom: 22px;
  padding: 4px;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #edf1f7;
  scrollbar-width: none;
}
.tab-list::-webkit-scrollbar { display: none; }
.tab-button {
  min-height: 36px;
  padding: 0 15px;
  border: 0;
  border-radius: 7px;
  color: #667085;
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
}
.tab-button:hover { color: var(--text); }
.tab-button.active {
  color: var(--text);
  background: #fff;
  box-shadow: 0 1px 4px rgba(16,24,40,.1);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- Surfaces, forms and controls --- */
.panel {
  border-color: var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.panel h2 { margin: 0; font-size: 16px; letter-spacing: -.2px; }
.panel-head,
.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.panel-head { margin-bottom: 18px; }
.panel-head h2,
.section-toolbar h2 { margin: 0 0 4px; font-size: 16px; }
.section-toolbar {
  min-height: 58px;
  margin-bottom: 16px;
}
.text-link { color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 600; white-space: nowrap; }
.content-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.cards { grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 14px; }
.card {
  position: relative;
  min-height: 122px;
  padding: 19px;
  border-color: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card .value { margin-top: 18px; font-size: 24px; letter-spacing: -.5px; }
.card .value-small { font-size: 14px; line-height: 1.35; }
.card .label { margin-top: 5px; }
.card-icon {
  position: absolute;
  top: 17px;
  right: 17px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 800;
}
.card-icon.blue { color:#2563eb; background:#e8f0ff; }
.card-icon.violet { color:#7c3aed; background:#f1eafe; }
.card-icon.cyan { color:#0891b2; background:#e3f8fc; }
.card-icon.green { color:#15803d; background:#e6f8ec; }
.card-icon.orange { color:#c2410c; background:#fff0e5; }
.card-icon.slate { color:#475569; background:#edf1f5; }
.status-row {
  min-height: 42px;
  padding: 8px 0;
  border-bottom: 1px solid #eef1f5;
  font-size: 13px;
}
.status-row:last-child { border-bottom: 0; }
.btn {
  min-height: 38px;
  padding: 8px 14px;
  border-color: #d8dee9;
  border-radius: 8px;
  font-weight: 550;
}
.btn:hover { border-color: #9eb8ef; background: #f7f9fd; }
.btn-primary { box-shadow: 0 5px 12px rgba(47,111,237,.18); }
.btn-sm { min-height: 30px; padding: 4px 9px; }
input:not([type="checkbox"]),
select {
  min-height: 39px;
  padding: 8px 10px;
  border: 1px solid #d8dee9;
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  font: inherit;
}
input:focus,
select:focus {
  outline: 3px solid rgba(47,111,237,.12);
  border-color: #78a1f5;
}
.search-box {
  display: flex;
  align-items: center;
  min-width: 260px;
  height: 40px;
  padding: 0 11px;
  border: 1px solid #d8dee9;
  border-radius: 9px;
  background: #fff;
}
.search-box span { color: #98a2b3; font-size: 18px; }
.search-box input { width: 100%; min-height: auto; border: 0; outline: 0; background: transparent; }
.form-panel { max-width: 900px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { display: block; margin: 0; }
.field > span { display: block; margin-bottom: 6px; color: #344054; font-size: 12.5px; font-weight: 650; }
.field input,
.field select { width: 100%; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.source-selector { margin: 20px 0 0; border-color: var(--border); }
.source-selector legend { padding: 0 7px; color: #344054; font-size: 12.5px; font-weight: 650; }
.source-selector label { display: inline-flex; align-items: center; margin: 7px 18px 7px 0; }
.option-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.check-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
}
.check-option input { margin-top: 3px; }
.check-option b,
.check-option small { display: block; }
.check-option b { font-size: 13px; }
.check-option small { margin-top: 3px; color: var(--text-muted); font-size: 11.5px; }
.action-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.action-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: #fff;
  text-align: left;
  cursor: pointer;
}
.action-card b,
.action-card span { display: block; }
.action-card b { margin-bottom: 6px; }
.action-card span { color: var(--text-muted); font-size: 12px; }
.action-card.primary { border-color: #b8cdf8; background: #f2f6ff; }
.action-card.danger-soft { border-color: #f2c6c6; background: #fff7f7; }
.tool-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

.epg-summary { display:flex; justify-content:space-between; gap:16px; margin:16px 0; }
.epg-actions { margin:16px 0; }
.epg-channel-list { border:1px solid var(--border); border-radius:14px; overflow:hidden; background:#fff; }
.epg-channel-row { display:grid; grid-template-columns:minmax(220px, .8fr) minmax(360px, 1.4fr) auto; gap:18px; align-items:center; padding:14px 16px; border-bottom:1px solid var(--border); }
.epg-channel-row:last-child { border-bottom:0; }
.epg-channel-row small, .epg-candidate small { display:block; color:var(--muted); margin-top:4px; }
.epg-channel-row.epg-pending-row { background:#fff9e8; box-shadow:inset 4px 0 #e3a008; }
.epg-channel-row.epg-focus-row { outline:2px solid #e3a008; outline-offset:-2px; }
.epg-pending-label { display:inline-flex; margin-top:7px; padding:3px 8px; border-radius:999px; background:#fff0b8; color:#805b00; font-size:12px; font-weight:700; }
.epg-pending-summary { color:#8a6200; font-weight:700; }
.epg-modal-box { width:min(820px, 94vw); }
.epg-candidate { display:block; padding:14px; margin:10px 0; border:1px solid var(--border); border-radius:12px; background:#fff; }
.epg-candidate.selected { border-color:#4c7ff0; box-shadow:0 0 0 2px rgba(76,127,240,.12); }
.epg-candidate-head { display:flex; justify-content:space-between; align-items:flex-start; gap:12px; }
.epg-quality { color:#41506a; }
.epg-candidate-search { display:grid; grid-template-columns:1fr auto; gap:10px; margin:8px 0 4px; }
.epg-candidate-search input { min-width:0; border:1px solid var(--border); border-radius:10px; padding:10px 12px; }
.epg-candidate-loading { min-height:150px; display:flex; align-items:center; justify-content:center; gap:14px; color:#26364f; text-align:left; }
.epg-candidate-loading .job-spinner { flex:0 0 auto; }
.epg-candidate-loading small { display:block; color:var(--muted); margin-top:5px; }
.tool-panel { margin-bottom: 0; }
.tool-panel p { min-height: 42px; margin: 8px 0 18px; }
.actions-column { display: grid; gap: 9px; }
.actions-column .btn { width: 100%; text-align: center; }

.settings-status {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:20px;
  padding:16px 20px;
}
.settings-status b,
.settings-status span { display:block; }
.settings-status > div:first-child span { margin-top:4px; color:var(--text-muted); font-size:12px; word-break:break-all; }
.settings-grid { max-width:1100px; }
.settings-section { margin-bottom:0; }
.settings-fields { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:18px; }
.settings-field { display:block; min-width:0; }
.settings-field-wide { grid-column:span 2; }
.settings-field-title { display:block; margin-bottom:6px; color:#344054; font-size:13px; font-weight:700; }
.settings-field input:not([type="checkbox"]),
.settings-field textarea { width:100%; }
.settings-field textarea { min-height:92px; resize:vertical; line-height:1.45; }
.settings-field small { display:block; margin-top:6px; color:var(--text-muted); font-size:11.5px; line-height:1.35; }
.settings-toggle { display:flex; align-items:center; gap:9px; min-height:39px; padding:8px 10px; border:1px solid #d8dee9; border-radius:8px; background:#fff; }
.settings-toggle span { font-weight:600; }
.settings-message { margin:0 0 16px; padding:12px 14px; border:1px solid #b8cdf8; border-radius:9px; background:#f2f6ff; color:#244b91; }
.settings-message.success { border-color:#a7e0c5; background:#effaf5; color:#13704a; }
.settings-message.warning { border-color:#f1d191; background:#fff9eb; color:#8a5a00; }
.settings-message.error { border-color:#efb3b3; background:#fff3f3; color:#a12b2b; }
.settings-savebar {
  position:sticky;
  z-index:20;
  bottom:12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:20px;
  margin-top:18px;
  padding:15px 18px;
  border:1px solid var(--border);
  border-radius:12px;
  background:rgba(255,255,255,.96);
  box-shadow:0 10px 30px rgba(16,24,40,.14);
  backdrop-filter:blur(10px);
}
.settings-savebar b,
.settings-savebar span { display:block; }
.settings-savebar span { margin-top:3px; color:var(--text-muted); font-size:11.5px; }

/* --- Domain-specific lists --- */
.source-card,
.playlist-card { margin-bottom: 14px; padding: 20px; }
.source-card .actions-row,
.playlist-card .actions-row { margin: 15px 0 0; }
.category { border-color: var(--border); border-radius: 11px; box-shadow: var(--shadow-sm); }
.category-header { min-height: 54px; padding: 9px 14px; background: var(--header-bg-2); }
.category-header h2 { flex: 1; margin: 0; font-size: 15px; }
.channel-row { min-height: 62px; }
.stream-help {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: -4px 0 16px;
  padding: 11px 13px;
  border: 1px solid #d9e5f8;
  border-radius: 10px;
  color: #52627a;
  background: #f5f8fd;
  font-size: 12.5px;
  line-height: 1.45;
}
.stream-help b { flex: 0 0 auto; color: #294d82; }
.playlist-category {
  border: 1px solid #dbe4f0;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(31, 56, 91, .045);
}
.playlist-category .category-header {
  min-height: 52px;
  color: #26364d;
  background: linear-gradient(180deg, #f2f6fc, #eaf1fa);
  border-bottom: 1px solid #dbe4f0;
}
.playlist-category .category-drag {
  color: #8496ae;
}
.playlist-category .category-toggle {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  gap: 8px;
  padding: 7px 4px;
  border: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.playlist-category .category-toggle h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.playlist-category .category-chevron {
  flex: 0 0 14px;
  color: #5273a5;
}
.playlist-category .category-count {
  color: #60728c;
  font-size: 12.5px;
  font-weight: 650;
}
.playlist-category .category-header .btn {
  border-color: #cad7e8;
  color: #3b5578;
  background: rgba(255,255,255,.75);
}
.playlist-category .category-header .btn:hover {
  border-color: #8ca9d1;
  color: #234f8e;
  background: #fff;
}
.playlist-category.system-category .category-header {
  background: #f6f7f9;
}
.category-spacer { width: 12px; }
.system-category-label {
  color: #7a8798;
  font-size: 11.5px;
}

.system-category-description {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 500;
  margin-left: auto;
}
.playlist-category .category-header { scroll-margin-top: 18px; }
.floating-channel-return {
  position: fixed;
  right: 24px;
  bottom: 88px;
  z-index: 48;
  max-width: min(230px, calc(100vw - 32px));
  color: #315d9b;
  background: rgba(255,255,255,.96);
  border-color: #b9ccec;
  box-shadow: 0 10px 28px rgba(31,74,145,.2);
  backdrop-filter: blur(8px);
}
.floating-channel-return:hover { color: #fff; background: #2f6fed; border-color: #2f6fed; }
.channel-row.group-selected {
  background: #edf4ff;
  box-shadow: inset 3px 0 0 #5b8def;
}
.channel-stream-control {
  flex: 0 1 370px;
  width: min(370px, 31vw);
  min-width: 245px;
}
.stream-field-label {
  display: block;
  margin: 0 0 4px;
  color: #6d7c91;
  font-size: 10.5px;
}
.channel-stream-control .stream-select {
  width: 100%;
  max-width: none;
}
.playlist-stream-check {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  white-space: nowrap;
}
.log-viewer { min-height: 520px; max-height: calc(100vh - 245px); padding: 14px; background: #101827; color: #cbd5e1; }
.log-viewer div { padding: 4px 3px; border-bottom: 1px solid rgba(255,255,255,.04); }
.log-viewer .muted { color: #8290a7; }
.modal-box { box-shadow: 0 24px 70px rgba(16,24,40,.25); }
.settings-block {
  margin: 18px 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfcff;
}
.settings-block .panel-head { margin-bottom: 12px; }
.channel-editor-box { width: min(850px, calc(100vw - 32px)); max-height: 92vh; overflow: auto; }
.global-override-option { margin: 16px 0; border-color: #b9cdf5; background: #f4f7ff; }
.attribute-editor { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.attribute-row {
  display: grid;
  grid-template-columns: 30px minmax(130px, .8fr) minmax(220px, 2fr) 38px;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
}
.attribute-row input { width: 100%; min-width: 0; }
.attribute-row .attribute-enabled { width: 18px; height: 18px; }
.change-journal { display: grid; gap: 14px; }
.change-run { padding: 17px; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.change-run-head { display: flex; justify-content: space-between; gap: 15px; align-items: flex-start; }
.change-run-head > div:first-child { display: flex; align-items: center; gap: 9px; }
.change-run-head h3 { margin: 0; }
.change-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
.change-column { padding: 12px; border-radius: 10px; background: #f7f8fa; }
.change-column.added { background: #edf9f2; color: #12633c; }
.change-column.removed { background: #fff0f0; color: #9f2020; }
.change-column.updated { background: #fff7e6; color: #7a4d00; }
.change-column h4 { margin: 0 0 8px; }
.change-column ul { margin: 0; padding-left: 18px; max-height: 320px; overflow: auto; }
.change-column li { margin: 5px 0; }
.change-column small,.access-table small { display: block; margin-top: 3px; color: inherit; opacity: .75; }
.access-table { min-width: 1050px; }
.access-table th,.access-table td { vertical-align: top; }
.access-table .ua-cell { max-width: 340px; overflow-wrap: anywhere; }
.inline-check { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }

@media (max-width: 1120px) {
  .cards { grid-template-columns: repeat(2, minmax(170px, 1fr)); }
  .tool-grid { grid-template-columns: 1fr; }
  .epg-summary, .epg-channel-row { display:block; }
  .epg-candidate-search { grid-template-columns:1fr; }
  .epg-channel-row > * { margin-bottom:10px; }
  .tool-panel p { min-height: auto; }
}

@media (max-width: 900px) {
  .sidebar-width-toggle { display: none !important; }
  .sidebar { transform: translateX(-105%); transition: transform .2s ease; }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    border: 0;
    background: rgba(15,23,42,.48);
  }
  .sidebar-open .sidebar-overlay { display: block; }
  .workspace { margin-left: 0; }
  .playlist-savebar { left:18px !important; right:18px; }
  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 12px;
    height: 54px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(10px);
    font-size: 14px;
    font-weight: 700;
  }
  .icon-btn { border: 0; background: transparent; font-size: 21px; cursor: pointer; }
  .container { padding: 24px 18px 48px; }
}

@media (max-width: 700px) {
  .page-header { align-items: flex-start; margin-bottom: 18px; }
  .page-header h1 { font-size: 24px; }
  .cards,
  .content-grid,
  .form-grid,
  .option-grid,
  .action-cards { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .section-toolbar { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; min-width: 0; }
  .status-row { align-items: flex-start; flex-direction: column; gap: 4px; }
  .tab-list { width: 100%; }
  .source-card,
  .playlist-card,
  .panel { padding: 16px; }
  .picker-selection-bar,.playlist-savebar { align-items:stretch; flex-direction:column; }
  .picker-import-options { grid-template-columns:1fr; align-items:stretch; }
  .change-grid { grid-template-columns: 1fr; }
  .change-run-head { flex-direction: column; }
  .attribute-row { grid-template-columns: 28px 1fr 38px; }
  .attribute-row .attribute-value { grid-column: 2 / 4; }
}

/* Public-link chooser, manual channels and administrator user cards. */
.copy-link-box { width: min(620px, calc(100vw - 28px)); }
.copy-protocol-list { display: grid; gap: 10px; margin: 18px 0; }
.copy-protocol {
  display: grid; grid-template-columns: 72px minmax(0,1fr); align-items: center;
  gap: 12px; width: 100%; padding: 14px; border: 1px solid var(--border);
  border-radius: 13px; color: var(--text); background: #f8faff; text-align: left;
}
.copy-protocol:hover { border-color: #8eb5ff; background: #f0f5ff; }
.copy-protocol b { color: var(--primary); }
.copy-protocol span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.playlist-update-stat small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; font-weight: 500; }
.manual-channel-panel { margin: 0 0 18px; padding: 0; overflow: hidden; }
.manual-channel-panel > summary { padding: 16px 18px; cursor: pointer; font-weight: 750; }
.manual-channel-form { display: block; padding: 0 18px 18px; }
.manual-channel-form > div:first-child { margin-bottom: 14px; }
.manual-channel-form > div:first-child h3 { margin: 0 0 5px; }
.manual-channel-form > div:first-child p { margin: 0; color: var(--muted); }
.manual-channel-form label { min-width: 0; }
.manual-channel-form input, .manual-channel-form select { width: 100%; }
.manual-channel-form .form-actions { margin-top: 14px; }
.source-subcategory { margin: 8px 10px 12px; border: 1px solid #dfe7f2; border-radius: 12px; overflow: hidden; background: #fff; }
.source-subcategory-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 13px; background: #f5f8fd; }
.source-subcategory-toggle { display: inline-flex; align-items: center; gap: 10px; border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 4px 2px; font: inherit; }
.source-subcategory-toggle:hover { color: var(--primary); }
.source-subcategory-head small { color: var(--muted); }
.source-subcategory-list .channel-row:last-child { border-bottom: 0; }
.users-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(330px,1fr)); gap: 16px; }
.user-card { padding: 18px; }
.user-card-head { display: flex; justify-content: space-between; gap: 12px; }
.user-identity { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-avatar { display: grid; place-items: center; width: 44px; height: 44px; flex: 0 0 44px; border-radius: 13px; color: #fff; background: linear-gradient(145deg,#5868ff,#287cf1); font-weight: 800; }
.user-card h2 { margin: 0 0 3px; font-size: 17px; }
.user-card-head p { margin: 0; color: var(--muted); font-size: 12px; }
.user-stats { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); margin: 16px 0; overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: #f8faff; }
.user-stats div { padding: 11px; min-width: 0; }
.user-stats div + div { border-left: 1px solid var(--border); }
.user-stats span,.user-stats b { display: block; }
.user-stats span { margin-bottom: 4px; color: var(--muted); font-size: 10px; }
.user-stats b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.user-card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.user-create-panel { margin-bottom: 20px; }

@media (max-width: 700px) {
  .copy-protocol { grid-template-columns: 60px minmax(0,1fr); }
  .users-grid { grid-template-columns: 1fr; }
  .user-stats { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .user-stats div:nth-child(3) { border-left: 0; border-top: 1px solid var(--border); }
  .user-stats div:nth-child(4) { border-top: 1px solid var(--border); }
}

@media (max-width: 760px) {
  .bulk-bar,
  .channel-group-help { align-items: stretch; flex-direction: column; }
  .bulk-destination { width: 100%; min-width: 0; margin-left: 0; }
  .settings-fields { grid-template-columns:1fr; }
  .settings-field-wide { grid-column:auto; }
  .settings-savebar { position:static; display:block; }
  .settings-savebar .actions-row { margin-top:12px; }
  .stream-help { display: block; }
  .stream-help b { display: block; margin-bottom: 4px; }
  .playlist-category .category-header { flex-wrap: wrap; }
  .channel-row .channel-stream-control {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    min-width: 0;
  }
  .channel-row .playlist-stream-check {
    grid-column: 1 / -1;
    grid-row: 3;
  }
  .channel-row:has(.delete-channel) {
    grid-template-columns: auto auto 44px minmax(0, 1fr) auto auto auto;
  }
  .channel-row .delete-channel {
    grid-column: 7;
    grid-row: 1;
  }
  .floating-channel-return {
    right: 12px;
    bottom: 76px;
    padding: 8px 11px;
    font-size: 12px;
  }
}
.migration-source-row {
  display:grid;
  grid-template-columns:1fr 2fr 1fr auto;
  gap:14px;
  align-items:end;
  padding:16px 0;
  border-bottom:1px solid var(--border);
}
.form-panel { margin-bottom:18px; }
.prose-panel { max-width:900px; line-height:1.7; }
.source-card-grid {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(290px,1fr));
  gap:14px;
  margin-bottom:26px;
}
.source-mini-card { display:flex; flex-direction:column; gap:10px; min-width:0; }
.source-mini-card h3,.source-mini-card p { margin:0; overflow-wrap:anywhere; }
.epg-global { display:flex; justify-content:space-between; gap:20px; margin-bottom:22px; }
.quality-grid {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(150px,1fr));
  gap:10px;
  margin:14px 0;
}
.quality-grid span { background:var(--surface-soft,#f3f6fb); padding:12px; border-radius:10px; }
.programme-sample { border-top:1px solid var(--border); padding:14px 0; }
.programme-sample small { display:block; color:var(--muted); margin-top:4px; }
.epg-test-card { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:10px; }
.epg-test-card div { display:flex; flex-direction:column; gap:4px; }
.copy-group { padding:0; overflow:hidden; margin-bottom:12px; }
.copy-group-head {
  display:flex; justify-content:space-between; align-items:center;
  padding:14px 16px; background:#edf3fc;
}
.copy-group-head label { display:flex; gap:10px; align-items:center; }
.copy-channel-grid {
  display:grid; grid-template-columns:repeat(auto-fit,minmax(260px,1fr));
  gap:0; padding:8px;
}
.copy-channel { display:flex; gap:10px; align-items:flex-start; padding:10px; border-radius:8px; }
.copy-channel:hover { background:#f4f7fb; }
.copy-channel span { display:flex; flex-direction:column; }
.copy-channel small { color:var(--muted); margin-top:3px; }
@media (max-width:800px) {
  .migration-source-row { grid-template-columns:1fr; }
  .epg-global,.epg-test-card { align-items:flex-start; flex-direction:column; }
}

/* ========================================================================== 
   Card interface v1 — visual layer only, existing behaviour is unchanged
   ========================================================================== */
:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --border: #e2e8f2;
  --text: #152238;
  --text-muted: #69778e;
  --muted: #69778e;
  --accent: #246bfd;
  --accent-dark: #1958dc;
  --green: #159b5b;
  --red: #db3545;
  --header-bg: #0b1730;
  --header-bg-2: #1d2d4a;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 31, 58, .035), 0 5px 18px rgba(15, 31, 58, .035);
  --shadow-md: 0 16px 42px rgba(15, 31, 58, .09);
}

html { color-scheme: light; }
body {
  min-width: 320px;
  background:
    radial-gradient(circle at 75% -15%, rgba(72, 126, 245, .07), transparent 28rem),
    var(--bg);
  font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: #225fcf; }
h1, h2, h3, h4, b, strong { color: #111d32; }

.sidebar {
  width: 252px;
  padding: 24px 16px 18px;
  background:
    radial-gradient(circle at 18% 0, rgba(56, 115, 245, .23), transparent 24%),
    linear-gradient(180deg, #0c1b37 0%, #071226 100%);
  border-right: 1px solid rgba(255,255,255,.035);
  box-shadow: 14px 0 40px rgba(17, 31, 55, .08);
}
.workspace { margin-left: 252px; }
.sidebar-brand {
  min-height: 58px;
  padding: 0 8px 22px;
  gap: 13px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(145deg, #4489ff, #1760ee);
  box-shadow: 0 10px 26px rgba(32, 103, 244, .34);
}
.sidebar-brand b { font-size: 15px; }
.sidebar-brand small { color: #8495b4; }
.nav-group { margin: 13px 0 24px; }
.nav-label { padding: 0 11px 9px; color: #64789d; }
.nav-item {
  min-height: 46px;
  padding: 0 13px;
  border-radius: 11px;
  color: #aebbd1;
}
.nav-item:hover { background: rgba(255,255,255,.065); transform: none; }
.nav-item.active {
  background: linear-gradient(100deg, #2268ef, #377cf5);
  box-shadow: 0 10px 25px rgba(17, 83, 211, .3);
}
.sidebar-footer {
  margin: 0 3px;
  padding: 16px 10px 4px;
  border-top-color: rgba(255,255,255,.075);
}
.sidebar-footer b { color: #f1f5ff; }

.container {
  width: 100%;
  max-width: 1510px;
  padding: 38px 40px 72px;
}
.page-header { margin-bottom: 28px; }
.page-header h1 {
  margin: 4px 0 8px;
  color: #0f1a2d;
  font-size: clamp(28px, 2.35vw, 36px);
  font-weight: 750;
  letter-spacing: -.9px;
}
.page-header p { font-size: 14px; }
.eyebrow { color: #2869ed; font-size: 10.5px; letter-spacing: .14em; }

.tab-list {
  gap: 4px;
  margin-bottom: 26px;
  padding: 5px;
  border-color: #dde5f0;
  border-radius: 12px;
  background: #eaf0f8;
}
.tab-button {
  min-height: 40px;
  padding: 0 17px;
  border-radius: 9px;
  color: #5f6f88;
  font-size: 13px;
}
.tab-button.active {
  color: #17243a;
  box-shadow: 0 2px 8px rgba(29, 52, 84, .1);
}
.section-toolbar { margin-bottom: 18px; }
.section-toolbar h2, .panel-head h2 { font-size: 17px; }

.panel, .card, .source-card, .source-mini-card, .tool-panel, .change-run {
  border-color: var(--border);
  border-radius: var(--radius);
  background: rgba(255,255,255,.98);
  box-shadow: var(--shadow-sm);
}
.panel { padding: 22px; }
.panel-head { margin-bottom: 20px; }
.cards { gap: 16px; }
.card { min-height: 126px; padding: 20px; }
.card-icon { border-radius: 10px; }

.btn {
  min-height: 40px;
  padding: 8px 15px;
  border-color: #d7e0ed;
  border-radius: 10px;
  color: #263650;
  background: #fff;
  box-shadow: 0 1px 1px rgba(15, 31, 58, .02);
  font-size: 13px;
  font-weight: 650;
}
.btn:hover {
  border-color: #9cb8ee;
  color: #175bcf;
  background: #f7faff;
  transform: translateY(-1px);
}
.btn-primary {
  border-color: var(--accent);
  color: #fff;
  background: linear-gradient(180deg, #347cff, #2168f2);
  box-shadow: 0 7px 17px rgba(36, 107, 253, .2);
}
.btn-primary:hover { border-color: var(--accent-dark); color: #fff; background: #195fe7; }
.btn-danger { border-color: #f2cbd0; color: #ca2d3f; background: #fffafa; }
.btn-danger:hover { border-color: #dc3545; color: #fff; background: #dc3545; }
.btn-sm { min-height: 32px; padding: 5px 10px; border-radius: 8px; }

input:not([type="checkbox"]), select, textarea {
  border-color: #d8e1ed;
  border-radius: 10px;
  background: #fff;
}
input:not([type="checkbox"]):hover, select:hover, textarea:hover { border-color: #bdcaDB; }
input:focus, select:focus, textarea:focus {
  border-color: #79a2f8;
  outline: 3px solid rgba(36,107,253,.11);
}
.search-box { border-color: #d8e1ed; border-radius: 11px; box-shadow: 0 1px 2px rgba(15,31,58,.025); }
.check-option, .settings-block, .source-selector {
  border-color: #e0e7f1;
  border-radius: 12px;
  background: #fbfcfe;
}
.check-option:hover { border-color: #c5d5ee; background: #f8faff; }
.settings-block { padding: 20px; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.badge.done, .badge.available { color: #0b7a45; background: #e5f7ed; }
.badge.idle { color: #6b778a; background: #edf1f6; }
.badge.unstable { color: #9b6500; background: #fff3d5; }

/* Playlist cards */
#playlists-root { display: grid; gap: 18px; }
.playlist-card {
  position: relative;
  margin: 0;
  padding: 22px;
  overflow: hidden;
  border-radius: 18px;
  box-shadow: 0 2px 4px rgba(17, 32, 57, .025), 0 12px 34px rgba(17, 32, 57, .055);
}
.playlist-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(180deg, #2d78ff, #7b55f5);
  opacity: .9;
}
.playlist-card-head { margin-bottom: 18px; }
.playlist-identity { display: flex; align-items: center; min-width: 0; gap: 13px; }
.playlist-identity > div { min-width: 0; }
.playlist-card-icon {
  flex: 0 0 44px;
  display: grid;
  align-content: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  padding: 0 12px;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(145deg, #6e62f8, #2c75fa);
  box-shadow: 0 8px 20px rgba(69, 94, 235, .22);
}
.playlist-card-icon i { display: block; width: 100%; height: 2px; border-radius: 2px; background: currentColor; }
.playlist-card h2 { margin: 0 0 5px; font-size: 19px; font-weight: 750; letter-spacing: -.3px; }
.playlist-card h2 a { color: #152238; text-decoration: none; }
.playlist-card h2 a:hover { color: var(--accent); }
.playlist-quick-meta { display: flex; flex-wrap: wrap; gap: 5px 14px; color: #738198; font-size: 11.5px; }
.playlist-quick-meta span { position: relative; }
.playlist-quick-meta span + span::before { content: ""; position: absolute; left: -8px; top: 50%; width: 3px; height: 3px; border-radius: 50%; background: #b7c2d2; }
.playlist-card-content { display: grid; grid-template-columns: minmax(360px, 1.15fr) minmax(390px, 1fr); gap: 14px; }
.playlist-link-grid, .playlist-stat-grid {
  display: grid;
  min-width: 0;
  border: 1px solid #e4eaf3;
  border-radius: 12px;
  background: #f8fafe;
}
.playlist-link-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.playlist-link-tile { min-width: 0; padding: 12px 14px; }
.playlist-link-tile + .playlist-link-tile { border-left: 1px solid #e4eaf3; }
.playlist-link-tile b, .playlist-link-tile a, .playlist-link-tile span { display: block; }
.playlist-link-tile b { margin-bottom: 5px; color: #34435b; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.playlist-link-tile a, .playlist-link-tile span { overflow: hidden; color: #5f6f88; font-size: 11.5px; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.playlist-link-tile a:hover { color: var(--accent); text-decoration: underline; }
.playlist-stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.playlist-stat-grid > div { min-width: 0; padding: 12px 14px; }
.playlist-stat-grid > div + div { border-left: 1px solid #e4eaf3; }
.playlist-stat-grid span, .playlist-stat-grid b { display: block; }
.playlist-stat-grid span { margin-bottom: 5px; color: #8490a3; font-size: 10.5px; }
.playlist-stat-grid b { overflow: hidden; color: #34435b; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.playlist-flags { margin-top: 12px; }
.playlist-actions { margin: 17px 0 0 !important; padding-top: 16px; border-top: 1px solid #edf1f6; }
.playlist-actions .btn-primary { order: -3; }
.playlist-actions .btn[href^="/playlists/"] { order: -2; }
.playlist-actions .btn[href*="tab=updates"] { order: -1; }
.playlist-card .error-box { margin-top: 14px; border-radius: 10px; }

/* Desktop-only IPTV mode. Nothing is persisted: the window owns its player data. */
body.iptv-mode-open { overflow: hidden; }
.premium-current{display:grid;grid-template-columns:2fr repeat(3,1fr);gap:18px;align-items:center}.premium-current>div{display:grid;gap:4px}.premium-current small,.premium-user-row small{color:var(--muted);display:block}.premium-plans{display:grid;grid-template-columns:repeat(3,1fr);gap:18px;margin:18px 0}.premium-plan{background:#fff;border:1px solid var(--border);border-radius:18px;padding:24px;box-shadow:var(--shadow)}.premium-plan.featured{border:2px solid var(--accent);transform:translateY(-4px)}.premium-plan>span{color:var(--accent);font-size:12px;font-weight:800;letter-spacing:.08em}.premium-plan>b{display:block;font-size:20px;margin:12px 0}.premium-feature-list{display:grid;gap:0}.premium-feature-list>div{display:grid;grid-template-columns:minmax(210px,.4fr) 1fr;gap:20px;padding:14px 0;border-bottom:1px solid var(--border)}.premium-feature-list span{color:var(--muted)}.premium-notice{padding:14px 18px;border-radius:12px;margin:14px 0}.premium-notice.warning{background:#fff4d6;color:#855b00}.premium-notice.danger{background:#ffe5e5;color:#a51d1d}.premium-settings-grid{display:grid;grid-template-columns:repeat(3,minmax(180px,1fr));gap:14px}.premium-settings-grid label,.premium-user-row label{display:grid;gap:6px;font-size:12px;color:var(--muted)}.premium-settings-grid input,.premium-user-row input,.premium-user-row select{width:100%}.premium-user-row{display:grid;grid-template-columns:1.4fr repeat(5,1fr) auto;gap:12px;align-items:end;padding:16px 0;border-bottom:1px solid var(--border)}#premium-alerts:not(:empty){margin-bottom:16px}
@media(max-width:900px){.premium-current,.premium-plans,.premium-settings-grid,.premium-user-row{grid-template-columns:1fr}.premium-plan.featured{transform:none}.premium-feature-list>div{grid-template-columns:1fr;gap:5px}}
.iptv-mode {
  position: fixed;
  inset: 0;
  z-index: 140;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 13, 22, .52);
  backdrop-filter: blur(2px);
}
.iptv-mode-window {
  position: relative;
  display: grid;
  grid-template-columns: 112px 208px minmax(500px, 1fr);
  width: min(840px, calc(100vw - 64px));
  height: min(390px, calc(100vh - 80px));
  min-height: 330px;
  overflow: hidden;
  color: #fff;
  background: #080808;
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 30px 90px rgba(0,0,0,.5);
}
.iptv-mode-loading {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  color: #e8edf5;
  background: rgba(9, 11, 15, .96);
}
.iptv-groups {
  min-width: 0;
  overflow-y: auto;
  background: #101010;
  border-right: 1px solid #292929;
  scrollbar-width: thin;
}
.iptv-brand {
  padding: 14px 16px;
  color: #f3f4f6;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
  border-bottom: 1px solid #292929;
}
.iptv-groups button {
  display: flex;
  width: 100%;
  min-height: 50px;
  padding: 10px 12px;
  color: #b8bec8;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #252525;
  cursor: pointer;
}
.iptv-groups button b {
  flex: 1;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
}
.iptv-groups button small { margin-left: 5px; color: #7f8792; font-size: 10px; }
.iptv-groups button:hover { color: #fff; background: #202020; }
.iptv-groups button.active { color: #fff; background: #635b70; }
.iptv-channels {
  min-width: 0;
  overflow-y: auto;
  background: #191919;
  border-right: 1px solid #303030;
  scrollbar-color: #535353 #191919;
  scrollbar-width: thin;
}
.iptv-channel {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  width: 100%;
  min-height: 74px;
  padding: 8px 10px;
  color: #fff;
  text-align: left;
  background: #1d1d1d;
  border: 0;
  border-bottom: 1px solid #3a3a3a;
  cursor: pointer;
}
.iptv-channel:hover { background: #292929; }
.iptv-channel.active { background: #303030; box-shadow: inset 3px 0 #43df7b; }
.iptv-channel-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 38px;
  overflow: hidden;
  color: #9fa7b4;
  background: #111;
}
.iptv-channel-logo img { width: 100%; height: 100%; object-fit: contain; }
.iptv-channel-logo i { font-size: 11px; font-style: normal; font-weight: 800; }
.iptv-channel > span:last-child { min-width: 0; }
.iptv-channel b, .iptv-channel small { display: block; overflow: hidden; text-overflow: ellipsis; }
.iptv-channel b { color: #f7f9fc !important; font-size: 13px; line-height: 1.2; white-space: normal; }
.iptv-channel small { margin-top: 5px; color: #b4b4b4; font-size: 10px; white-space: nowrap; }
.iptv-player { position: relative; min-width: 0; overflow: hidden; background: #000; }
.iptv-player video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.iptv-video-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,.36), transparent 28%, transparent 66%, rgba(0,0,0,.68));
}
.iptv-now { position: absolute; top: 15px; left: 17px; right: 17px; pointer-events: none; }
.iptv-now > div { display: flex; gap: 10px; align-items: center; max-width: 78%; }
.iptv-now img { width: 46px; height: 34px; object-fit: contain; background: rgba(0,0,0,.4); }
.iptv-now b, .iptv-now span, .iptv-now small { display: block; text-shadow: 0 1px 3px #000; }
.iptv-now b { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.iptv-now span { margin-top: 2px; color: #e6e6e6; font-size: 10px; }
.iptv-now small { margin-top: 4px; color: #c8c8c8; font-size: 10px; }
.iptv-play-toggle {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: #111;
  font-size: 18px;
  font-weight: 900;
  background: rgba(255,255,255,.94);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 4px 18px rgba(0,0,0,.3);
  transform: translate(-50%, -50%);
  cursor: pointer;
}
.iptv-play-toggle.playing { opacity: 0; transition: opacity .2s; }
.iptv-player:hover .iptv-play-toggle.playing { opacity: 1; }
.iptv-player-message {
  position: absolute;
  left: 50%;
  bottom: 61px;
  max-width: 80%;
  padding: 7px 11px;
  color: #eee;
  font-size: 11px;
  text-align: center;
  background: rgba(0,0,0,.68);
  border-radius: 5px;
  transform: translateX(-50%);
}
.iptv-controls {
  position: absolute;
  right: 13px;
  bottom: 13px;
  left: 13px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
}
.iptv-controls span { color: #f1f1f1; font-size: 10px; }
.iptv-controls input { width: 100%; height: 3px; accent-color: #fff; cursor: pointer; }
.iptv-controls button { padding: 0; color: #fff; font-size: 16px; background: transparent; border: 0; cursor: pointer; }

/* Sources, categories and data lists */
.source-card { padding: 22px; border-radius: 17px; box-shadow: 0 8px 28px rgba(17,32,57,.045); }
.source-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; color: #66758c; font-size: 13px; }
.source-meta > span { min-width: 0; }
.category, .playlist-category {
  border-color: #dfe7f1;
  border-radius: 14px;
  box-shadow: 0 3px 14px rgba(27, 48, 77, .035);
}
.category-header, .playlist-category .category-header {
  min-height: 56px;
  padding: 10px 16px;
  color: #293a53;
  background: linear-gradient(180deg, #f8faff, #eff4fa);
  border-bottom-color: #e0e7f0;
}
.category-header .cat-count, .playlist-category .category-count { color: #71819a; }
.channel-row { min-height: 66px; padding: 9px 16px; border-bottom-color: #edf1f6; }
.channel-row:hover { background: #fafcff; }
.channel-logo, .channel-row img.logo { border-radius: 9px; background: #f3f5f8; }
.bulk-bar {
  border-color: #bcd1f6;
  border-radius: 13px;
  background: rgba(243,247,255,.97);
}

table { border-collapse: separate; border-spacing: 0; }
table th { color: #66758c; background: #f7f9fc; font-size: 11px; letter-spacing: .02em; }
table td, table th { border-bottom-color: #e8edf4; }
table tbody tr:hover td { background: #fafcff; }
.log-viewer { border-radius: 12px; background: #101a2b; }

.modal { backdrop-filter: blur(3px); }
.modal-box {
  border: 1px solid rgba(218,226,238,.9);
  border-radius: 17px;
  box-shadow: 0 30px 90px rgba(12, 26, 48, .27);
}
.progress-track { border-radius: 999px; overflow: hidden; }
.toast { border-radius: 10px; box-shadow: 0 12px 30px rgba(15,31,58,.2); }
.settings-savebar, .playlist-savebar {
  border-radius: 14px;
  box-shadow: 0 14px 38px rgba(15,31,58,.14);
}

@media (min-width: 901px) {
  .sidebar-compact .workspace { margin-left: 76px; }
}
@media (max-width: 1180px) {
  .playlist-card-content { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .iptv-mode { display: none !important; }
  .workspace { margin-left: 0; }
  .mobile-header { background: rgba(255,255,255,.96); box-shadow: 0 4px 16px rgba(15,31,58,.05); }
  .container { padding: 26px 20px 54px; }
}
@media (max-width: 700px) {
  .playlist-card { padding: 17px; }
  .playlist-card-head { align-items: flex-start; }
  .playlist-card-icon { flex-basis: 40px; width: 40px; height: 40px; }
  .playlist-card-content, .playlist-link-grid, .playlist-stat-grid { grid-template-columns: 1fr; }
  .playlist-link-tile + .playlist-link-tile, .playlist-stat-grid > div + div { border-left: 0; border-top: 1px solid #e4eaf3; }
  .playlist-actions .btn { flex: 1 1 calc(50% - 8px); }
  .page-header h1 { font-size: 27px; }
}

/* Source cards use the same composition as playlist cards. */
.sidebar b, .sidebar strong { color: inherit; }
.sidebar-brand b { color: #f5f8ff; }
.sidebar-footer b { color: #f1f5ff; }
#sources-root { display: grid; gap: 18px; }
.source-card {
  position: relative;
  margin: 0;
  padding: 22px;
  overflow: hidden;
  border-radius: 18px;
  box-shadow: 0 2px 4px rgba(17, 32, 57, .025), 0 12px 34px rgba(17, 32, 57, .055);
}
.source-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(180deg, #13a677, #2f78fa);
}
.source-card-head { margin-bottom: 18px; }
.source-identity { display: flex; align-items: center; min-width: 0; gap: 13px; }
.source-identity > div { min-width: 0; }
.source-card-icon {
  flex: 0 0 44px;
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: linear-gradient(145deg, #19b77f, #158e67);
  box-shadow: 0 8px 20px rgba(21, 158, 112, .22);
}
.source-card-icon i {
  position: absolute;
  width: 22px;
  height: 8px;
  border: 2px solid #fff;
  border-radius: 50%;
}
.source-card-icon i:nth-child(1) { top: 10px; }
.source-card-icon i:nth-child(2) { top: 17px; }
.source-card-icon i:nth-child(3) { top: 24px; }
.source-card h2 { margin: 0 0 5px; font-size: 19px; font-weight: 750; letter-spacing: -.3px; }
.source-quick-meta { display: flex; flex-wrap: wrap; gap: 5px 14px; color: #738198; font-size: 11.5px; }
.source-quick-meta span { position: relative; }
.source-quick-meta span + span::before { content: ""; position: absolute; left: -8px; top: 50%; width: 3px; height: 3px; border-radius: 50%; background: #b7c2d2; }
.source-card-content { display: grid; grid-template-columns: minmax(360px, 1.1fr) minmax(460px, 1fr); gap: 14px; }
.source-link-tile, .source-stat-grid {
  min-width: 0;
  border: 1px solid #e4eaf3;
  border-radius: 12px;
  background: #f8fafe;
}
.source-link-tile { padding: 12px 14px; }
.source-link-tile b, .source-link-tile span { display: block; }
.source-link-tile b { margin-bottom: 5px; color: #34435b; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.source-link-tile span { overflow: hidden; color: #5f6f88; font-size: 11.5px; text-overflow: ellipsis; white-space: nowrap; }
.source-stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.source-stat-grid > div { min-width: 0; padding: 12px 13px; }
.source-stat-grid > div + div { border-left: 1px solid #e4eaf3; }
.source-stat-grid span, .source-stat-grid b { display: block; }
.source-stat-grid span { margin-bottom: 5px; color: #8490a3; font-size: 10.5px; }
.source-stat-grid b { overflow: hidden; color: #34435b; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.source-last-update { display: flex; align-items: center; gap: 8px; margin-top: 11px; color: #8490a3; font-size: 11px; }
.source-last-update b { color: #596980; font-size: 11.5px; }
.source-actions { margin: 17px 0 0 !important; padding-top: 16px; border-top: 1px solid #edf1f6; }
.source-actions .update-source { order: -3; }
.source-actions .show-channels { order: -2; }
.source-actions a[href*="tab=updates"] { order: -1; }
.source-card > .source-channels:not(.hidden) { margin-top: 20px; padding-top: 18px; border-top: 1px solid #e5ebf3; }

@media (max-width: 1180px) {
  .source-card-content { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .source-card { padding: 17px; }
  .source-card-icon { flex-basis: 40px; width: 40px; height: 40px; }
  .source-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .source-stat-grid > div:nth-child(3) { border-left: 0; border-top: 1px solid #e4eaf3; }
  .source-stat-grid > div:nth-child(4) { border-top: 1px solid #e4eaf3; }
  .source-actions .btn { flex: 1 1 calc(50% - 8px); }
}

/* Final v1 composition: compact cards and an overflow menu for secondary actions. */
.sidebar { width: 224px; padding: 22px 14px 16px; }
.workspace { margin-left: 224px; }
.container { max-width: 1360px; padding: 34px 34px 66px; }
.sidebar-footer {
  margin: 0;
  padding: 13px 12px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 11px;
  background: rgba(255,255,255,.025);
}
.page-header { min-height: 72px; margin-bottom: 22px; }
.page-header h1 { font-size: 31px; }
.page-header p { color: #738097; }
.tab-list { margin-bottom: 24px; }
.section-toolbar { margin-bottom: 14px; }

.playlist-card, .source-card { overflow: visible; }
.playlist-card { padding: 20px; }
.playlist-card-head, .source-card-head { margin-bottom: 14px; }
.playlist-card-content, .source-card-content { gap: 10px; }
.playlist-link-grid, .playlist-stat-grid,
.source-link-tile, .source-stat-grid { background: #f9fbfe; }
.playlist-actions, .source-actions {
  align-items: center;
  gap: 9px;
  margin-top: 14px !important;
  padding-top: 14px;
}
.playlist-actions > .btn, .source-actions > .btn { min-width: 118px; }
.playlist-actions > .btn span, .source-actions > .btn span { margin-right: 5px; color: currentColor; font-size: 16px; line-height: 0; }

.action-menu {
  position: relative;
  margin-left: auto;
}
.playlist-actions > .action-menu {
  margin-left: 0;
}
.action-menu > summary {
  display: grid;
  place-items: center;
  min-width: 42px;
  width: 42px;
  padding: 0;
  list-style: none;
  font-size: 21px;
  line-height: 1;
  user-select: none;
}
.action-menu > summary::-webkit-details-marker { display: none; }
.action-menu[open] > summary { color: var(--accent); border-color: #9db9ef; background: #f4f8ff; }
.action-menu-popover {
  position: absolute;
  z-index: 50;
  right: 0;
  top: calc(100% + 8px);
  width: 220px;
  padding: 7px;
  border: 1px solid #dfe6f0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 45px rgba(15,31,58,.18);
}
.action-menu-popover button, .action-menu-popover a {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  color: #263650;
  background: transparent;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
}
.action-menu-popover button:hover, .action-menu-popover a:hover { color: #175bcf; background: #f2f6fd; }
.action-menu-popover span { display: inline-grid; place-items: center; width: 18px; color: #6f8098; }
.action-menu-popover .danger { color: #cf3143; }
.action-menu-popover .danger:hover { color: #b92133; background: #fff1f3; }
.playlist-card:has(.action-menu[open]), .source-card:has(.action-menu[open]) { z-index: 15; }

.source-card { padding: 20px; }
.source-last-update { margin-top: 9px; }

.color-legend, .stream-help, .channel-group-help {
  border-radius: 12px;
  background: #fbfcfe;
  box-shadow: 0 1px 2px rgba(15,31,58,.025);
}
.form-panel, .settings-section, .tool-panel, .prose-panel { box-shadow: 0 8px 28px rgba(17,32,57,.045); }
.source-mini-card, .epg-test-card, .copy-group, .change-run {
  border-radius: 15px;
  box-shadow: 0 7px 22px rgba(17,32,57,.045);
}
.settings-block { background: #f9fbfe; }
.category, .playlist-category { margin-bottom: 10px; }

@media (min-width: 901px) {
  .sidebar-compact .workspace { margin-left: 76px; }
}
@media (max-width: 900px) {
  .workspace { margin-left: 0; }
}
@media (max-width: 700px) {
  .playlist-actions > .btn, .source-actions > .btn { min-width: 0; }
  .action-menu { margin-left: 0; }
  .action-menu-popover { left: 0; right: auto; }
}

/* EPG source cards */
.source-card-grid { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; }
.epg-source-card { gap: 14px; padding: 18px; }
.epg-source-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.epg-source-identity { display: flex; align-items: center; min-width: 0; gap: 11px; }
.epg-source-identity > div { min-width: 0; }
.epg-source-identity h3 { margin: 0 0 3px; font-size: 15px; }
.epg-source-identity small { display: block; overflow: hidden; color: #7b889d; font-size: 10.5px; text-overflow: ellipsis; white-space: nowrap; }
.epg-source-icon {
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  color: #fff;
  background: linear-gradient(145deg, #6e62f8, #3f72f3);
  box-shadow: 0 7px 17px rgba(76, 91, 224, .2);
  font-size: 10px;
  font-weight: 800;
}
.epg-source-card.custom .epg-source-icon { background: linear-gradient(145deg, #19b77f, #158e67); box-shadow: 0 7px 17px rgba(21,158,112,.2); }
.status-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
}
.status-badge.done { color: #0b7a45; background: #e5f7ed; }
.status-badge.idle { color: #6b778a; background: #edf1f6; }
.epg-source-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: hidden; border: 1px solid #e4eaf3; border-radius: 11px; background: #f9fbfe; }
.epg-source-stats.compact { grid-template-columns: 1fr; }
.epg-source-stats > div { min-width: 0; padding: 10px 12px; }
.epg-source-stats > div + div { border-left: 1px solid #e4eaf3; }
.epg-source-stats span, .epg-source-stats b { display: block; }
.epg-source-stats span, .epg-source-url span { margin-bottom: 4px; color: #8793a6; font-size: 10px; }
.epg-source-stats b { overflow: hidden; font-size: 11.5px; text-overflow: ellipsis; white-space: nowrap; }
.epg-source-url { min-width: 0; padding: 10px 12px; border: 1px solid #e4eaf3; border-radius: 11px; background: #f9fbfe; }
.epg-source-url span, .epg-source-url b { display: block; }
.epg-source-url b { overflow: hidden; color: #52637d; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.epg-source-actions { margin: 0 !important; padding-top: 12px; border-top: 1px solid #edf1f6; }
.epg-global { border-radius: 16px; box-shadow: 0 8px 28px rgba(17,32,57,.05); }

.table-scroll { overflow: auto; border: 1px solid var(--border); border-radius: 14px; background: #fff; box-shadow: var(--shadow-sm); }
.access-table { margin: 0; }

@media (max-width: 700px) {
  .source-card-grid { grid-template-columns: 1fr; }
  .epg-source-stats { grid-template-columns: 1fr; }
  .epg-source-stats > div + div { border-left: 0; border-top: 1px solid #e4eaf3; }
}

/* Mobile playlist editor: keep group names and actions readable. */
.category-actions { display: flex; gap: 8px; }

@media (max-width: 700px) {
  .playlist-category .category-header {
    display: grid;
    grid-template-columns: 22px 22px minmax(0, 1fr) auto;
    gap: 8px 9px;
    min-height: 0;
    padding: 12px;
  }
  .playlist-category .category-drag,
  .playlist-category .category-spacer {
    grid-column: 1;
    grid-row: 1;
    width: 22px;
    align-self: center;
  }
  .playlist-category .select-category-channels {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
  }
  .playlist-category .category-toggle {
    grid-column: 3;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    padding: 5px 0;
  }
  .playlist-category .category-toggle h2 {
    overflow: visible;
    white-space: normal;
    text-overflow: clip;
    overflow-wrap: anywhere;
    line-height: 1.25;
  }
  .playlist-category .category-count {
    grid-column: 4;
    grid-row: 1;
    align-self: center;
    white-space: nowrap;
  }
  .playlist-category .category-actions {
    grid-column: 3 / 5;
    grid-row: 2;
    display: flex;
    gap: 8px;
  }
  .playlist-category .category-actions .btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 7px 9px;
    font-size: 12px;
  }
  .playlist-category .system-category-description {
    grid-column: 1 / -1;
    grid-row: 2;
    margin: 2px 0 0;
    line-height: 1.4;
  }
  .playlist-category .system-category-label {
    grid-column: 3 / 5;
    grid-row: 3;
  }
}
.auth-card { width:min(440px,calc(100vw - 32px)); }
.auth-card form { display:grid; gap:14px; }
.auth-links { margin:18px 0; text-align:center; }
.demo-entry { border-top:1px solid var(--border); padding-top:18px; }
.demo-entry small,.password-hint { color:var(--muted); line-height:1.45; }
.captcha-image { width:210px; max-width:100%; border:1px solid var(--border); border-radius:10px; }
.form-success { padding:12px 14px; margin-bottom:14px; color:#087443; background:#e4f8ed; border-radius:10px; }
.sidebar-profile { min-width:0; display:flex; align-items:center; gap:10px; color:inherit; text-decoration:none; flex:1; }
.sidebar-profile img { width:34px; height:34px; border-radius:50%; object-fit:cover; border:2px solid rgba(255,255,255,.18); }
.profile-panel { max-width:760px; }
.profile-form,.demo-profile { display:grid; grid-template-columns:140px 1fr; gap:28px; align-items:start; }
.profile-avatar img,.profile-avatar span,.demo-profile img { width:128px; height:128px; border-radius:50%; object-fit:cover; }
.profile-avatar span { display:grid; place-items:center; background:#2f71ee; color:white; font-size:44px; font-weight:800; }
@media (max-width:640px){.profile-form,.demo-profile{grid-template-columns:1fr}.profile-avatar img,.profile-avatar span,.demo-profile img{width:96px;height:96px}}
.user-avatar-image { object-fit:cover; }
.user-card-head small { display:block; margin-top:3px; color:var(--muted); }

/* Searchable EPG source selector. */
.searchable-source-picker { position:relative; }
.searchable-source-picker > input[type="search"] { width:100%; }
.searchable-source-menu {
  position:absolute;
  z-index:80;
  top:calc(100% + 6px);
  left:0;
  right:0;
  max-height:340px;
  overflow:auto;
  padding:6px;
  border:1px solid var(--border);
  border-radius:12px;
  background:#fff;
  box-shadow:0 18px 42px rgba(17,32,57,.18);
}
.searchable-source-menu button {
  display:flex;
  width:100%;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:9px 10px;
  border:0;
  border-radius:8px;
  color:var(--text);
  background:transparent;
  text-align:left;
  cursor:pointer;
}
.searchable-source-menu button:hover { background:#eef4ff; }
.searchable-source-menu button:disabled { opacity:.5; cursor:not-allowed; }
.searchable-source-menu button small { color:var(--muted); text-align:right; }
.searchable-source-menu p { margin:8px 10px; color:var(--muted); }

/* Playlist channel order: compact name-only tiles. */
.channel-view-switch { display:inline-flex; gap:4px; padding:3px; border:1px solid var(--border); border-radius:10px; background:#f3f6fb; }
.channel-view-switch .btn { border:0; background:transparent; box-shadow:none; }
.channel-view-switch .btn.active { color:#1761dd; background:#fff; box-shadow:0 2px 8px rgba(17,32,57,.09); }
.channel-tile-category .category-header { grid-template-columns:minmax(0,1fr) auto auto; }
.channel-order-grid {
  display:flex;
  flex-wrap:wrap;
  align-items:stretch;
  gap:5px;
  padding:12px;
  border-top:1px solid var(--border);
}
.channel-order-tile {
  display:block;
  max-width:280px;
  padding:6px 10px;
  border:1px solid #d8e0ec;
  border-radius:5px;
  background:#fff;
  box-shadow:0 1px 3px rgba(17,32,57,.04);
  user-select:none;
}
.channel-order-tile:not(.locked) { cursor:grab; }
.channel-order-tile:not(.locked):active { cursor:grabbing; }
.channel-order-tile b { display:block; overflow:hidden; max-width:260px; font-size:13px; font-weight:500; text-overflow:ellipsis; white-space:nowrap; }
.channel-order-tile.selected { border-color:#e53935; background:#fff0ef; color:#a81717; box-shadow:0 0 0 1px rgba(229,57,53,.15); }
.channel-order-tile.locked { background:#f6f8fb; cursor:default; opacity:.75; }
.channel-order-tile.sortable-ghost { border-color:#2f71ee; background:#eaf2ff; }
@media (max-width:700px) {
  .channel-view-switch { width:100%; }
  .channel-view-switch .btn { flex:1; }
  .channel-order-grid { padding:8px; }
  .channel-order-tile { max-width:100%; }
}
