:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --surface: #121821;
  --surface-strong: #17202b;
  --border: #263241;
  --text: #eef3f8;
  --muted: #91a0af;
  --accent: #14b8a6;
  --accent-soft: rgba(20, 184, 166, 0.15);
  --warning-soft: rgba(245, 158, 11, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.13);
}

* {
  box-sizing: border-box;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: #0e141b;
  padding: 24px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.brand-name {
  font-size: 16px;
  font-weight: 750;
}

.brand-subtitle,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--text);
}

.nav-item:hover {
  color: var(--text);
}

.content {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 16px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(20, 184, 166, 0.45);
  border-radius: 999px;
  background: var(--accent-soft);
  color: #8df5e7;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.muted-badge {
  border-color: rgba(245, 158, 11, 0.34);
  background: var(--warning-soft);
  color: #f8ce7b;
}

.ok-badge {
  border-color: rgba(20, 184, 166, 0.45);
  background: var(--accent-soft);
  color: #8df5e7;
}

.error-badge {
  border-color: rgba(248, 113, 113, 0.4);
  background: var(--danger-soft);
  color: #fecaca;
}

.unknown-badge {
  border-color: rgba(245, 158, 11, 0.34);
  background: var(--warning-soft);
  color: #f8ce7b;
}

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

.metric-card,
.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.metric-card {
  min-height: 128px;
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 24px;
  font-size: 34px;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.55fr);
  gap: 18px;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

.table-wrap {
  overflow-x: auto;
}

thead th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

th,
td {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 14px;
}

tr:last-child th,
tr:last-child td {
  border-bottom: 0;
}

th {
  color: var(--text);
  font-weight: 700;
}

td {
  color: var(--muted);
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover,
.clickable-row:focus-visible {
  background: var(--surface-strong);
  outline: none;
}
.disabled-row { opacity: 0.62; }
.detail-actions { display:flex;flex-wrap:wrap;gap:10px;padding:0 18px 18px; }

.detail-dialog {
  width: min(1180px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.detail-dialog::backdrop {
  background: rgba(3, 7, 12, 0.78);
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.channel-identity > div,
.channel-identity > div > div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.channel-identity > div > div {
  align-items: flex-start;
  flex-direction: column;
  gap: 4px;
}

.channel-logo {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--surface-strong);
  object-fit: contain;
}

.metadata-logo {
  width: 96px;
  height: 54px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-strong);
  object-fit: contain;
}

.metadata-tabs { display:flex; gap:.55rem; margin-bottom:1rem; flex-wrap:wrap; }
.metadata-tab { border:1px solid var(--border); background:var(--surface); color:var(--muted); border-radius:.6rem; padding:.65rem 1rem; cursor:pointer; }
.metadata-tab.active { color:var(--text); border-color:var(--primary); background:rgba(99,102,241,.14); }
.logo-library-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(210px,1fr)); gap:1rem; }
.logo-library-card { display:flex; flex-direction:column; gap:.55rem; border:1px solid var(--border); background:var(--surface-soft); border-radius:.8rem; padding:.8rem; min-width:0; }
.logo-library-card img { width:100%; aspect-ratio:16/9; object-fit:contain; border-radius:.5rem; background:#090d18; }
.logo-library-card strong,.logo-library-card span { overflow-wrap:anywhere; }
.metadata-drop-zone { display:flex; min-height:150px; margin:1rem 0; padding:1.5rem; border:2px dashed var(--border); border-radius:.8rem; flex-direction:column; align-items:center; justify-content:center; gap:.45rem; text-align:center; cursor:pointer; }
.metadata-drop-zone.drag-active { border-color:var(--primary); background:rgba(99,102,241,.12); }
.metadata-drop-zone input,.file-button input { position:absolute; width:1px; height:1px; opacity:0; pointer-events:none; }
.file-button { position:relative; cursor:pointer; }
.metadata-upload-preview { display:block; max-width:100%; width:320px; aspect-ratio:16/9; object-fit:contain; margin:0 auto 1rem; background:#090d18; border-radius:.6rem; }
.metadata-upload-dialog progress { width:100%; }
.pack-preview { display:grid; gap:.75rem; padding:1rem; margin-bottom:1rem; border:1px solid var(--primary); border-radius:.75rem; background:rgba(99,102,241,.08); }
.card-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(250px,1fr)); gap:1rem; }
.summary-card { display:flex; flex-direction:column; align-items:flex-start; gap:.65rem; border:1px solid var(--border); border-radius:.75rem; padding:1rem; }
.result-block { white-space:pre-wrap; overflow:auto; padding:1rem; border-radius:.65rem; background:#090d18; color:var(--muted); }

.metadata-help {
  margin-top: 18px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  cursor: pointer;
  font-size: 24px;
}

.detail-content {
  overflow: auto;
}

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

.detail-summary > div {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
}

.detail-summary span {
  color: var(--muted);
  font-size: 12px;
}

.primary-button {
  min-height: 38px;
  border: 1px solid rgba(20, 184, 166, 0.55);
  border-radius: 8px;
  background: var(--accent);
  color: #06201d;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  padding: 0 14px;
}

.primary-button:hover {
  filter: brightness(1.08);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.secondary-button {
  border-color: var(--border);
  background: var(--surface-strong);
  color: var(--text);
}

.number-input {
  width: 96px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 0 10px;
}

.search-input {
  width: min(320px, 100%);
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  font: inherit;
  padding: 0 12px;
}

.audit-panel {
  margin-top: 18px;
}

.epg-icon {
  width: 44px;
  height: 32px;
  border-radius: 5px;
  background: var(--surface-strong);
  object-fit: contain;
}

.danger-button {
  border-color: rgba(248, 113, 113, 0.4);
  color: #fecaca;
}

.mapping-dialog {
  width: min(680px, calc(100vw - 40px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.mapping-dialog::backdrop { background: rgba(3, 7, 12, 0.78); }
.mapping-form { display: grid; gap: 12px; padding: 18px; }
.mapping-form p { margin: 0; }
.warning-list { display: grid; gap: 8px; margin: 0; padding-left: 22px; color: var(--text); }
#maintenance-page .metrics-grid { padding: 18px; margin-bottom: 0; grid-template-columns: repeat(4, minmax(0, 1fr)); }
#maintenance-page .metric-card { min-height: 104px; }
#maintenance-page .metric-card strong { margin-top: 16px; }
.mapping-form .search-input { width: 100%; }
.nested-form { display: contents; }
.nested-form[hidden] { display: none; }
.search-results { display: grid; max-height: 280px; overflow-y: auto; border-radius: 8px; }
.search-result { border: 0; border-bottom: 1px solid var(--border); background: var(--surface-strong); color: var(--text); cursor: pointer; padding: 12px; text-align: left; }
.search-result:hover, .search-result:focus-visible { background: var(--accent-soft); }
.selected-mapping { border: 1px solid var(--border); border-radius: 8px; color: var(--muted); padding: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 18px; border-top: 1px solid var(--border); }
.action-row { display: flex; flex-wrap: wrap; gap: 7px; min-width: 360px; }
.action-row .primary-button { min-height: 32px; padding: 0 10px; font-size: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 9px; color: var(--text); }

.number-input:focus {
  border-color: rgba(20, 184, 166, 0.7);
  outline: 2px solid rgba(20, 184, 166, 0.16);
}

.notice {
  margin: -8px 0 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  padding: 12px 14px;
  font-size: 14px;
}

.notice.success {
  border-color: rgba(20, 184, 166, 0.35);
  background: var(--accent-soft);
  color: #b8fff5;
}

.notice.error {
  border-color: rgba(248, 113, 113, 0.4);
  background: var(--danger-soft);
  color: #fecaca;
}

.cell-stack {
  display: grid;
  gap: 4px;
  min-width: 150px;
}

.cell-stack span,
.cell-stack small {
  overflow-wrap: anywhere;
}

.cell-stack span {
  color: var(--text);
  white-space: pre-line;
}

.cell-stack small {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  padding: 28px 18px;
  color: var(--muted);
  font-size: 14px;
}

.activity-list {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
}

.activity-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 12px;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

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

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

@media (max-width: 640px) {
  .content {
    padding: 20px;
  }

  .topbar,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .nav-list,
  .metrics-grid,
  .panel-grid,
  .detail-summary {
    grid-template-columns: 1fr;
  }
}
