:root {
  color-scheme: light;
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-soft: #f7f9fa;
  --text: #142126;
  --muted: #5f6d73;
  --line: #cfd9dd;
  --primary: #176d73;
  --primary-dark: #0d5156;
  --accent: #9b5d1b;
  --danger: #a2382f;
  --ok: #1f7a4d;
  --shadow: 0 12px 30px rgba(20, 33, 38, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  padding: 0 12px;
}

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

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

button.secondary {
  background: var(--surface);
  color: var(--primary);
}

button.secondary:hover {
  background: #e4f0f1;
}

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

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions,
.form-actions,
.remote-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.auth-box {
  display: none;
  grid-template-columns: minmax(190px, 260px) auto;
  gap: 8px;
}

.auth-box.visible {
  display: grid;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(420px, 1fr) minmax(360px, 440px);
  gap: 14px;
  padding: 14px;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-heading {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading.inline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.panel h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
}

.nested-heading {
  padding-left: 0;
  padding-right: 0;
  border-bottom: 0;
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 32px;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid #bdd4d8;
  border-radius: 999px;
  color: var(--primary);
  background: #eef8f9;
  font-size: 12px;
  font-weight: 600;
}

.badge.muted {
  border-color: var(--line);
  background: var(--surface-soft);
  color: var(--muted);
}

.filters {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 12px;
}

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

.agent-list,
.point-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.agent-item,
.point-item {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  padding: 9px 10px;
  text-align: left;
}

.agent-item.active,
.point-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(23, 109, 115, 0.14);
}

.tv-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.tv-address {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.agent-state {
  min-width: 70px;
  color: var(--danger);
  font-size: 12px;
  text-align: right;
}

.agent-state.online {
  color: var(--ok);
  font-weight: 700;
}

.selected-agent,
.preview-block {
  padding: 14px;
}

.details-grid {
  display: grid;
  grid-template-columns: minmax(110px, 160px) minmax(0, 1fr);
  gap: 8px 14px;
  margin: 0;
}

.details-grid dt {
  color: var(--muted);
  font-size: 13px;
}

.details-grid dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.remote-actions {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(180px, 1fr) minmax(140px, 0.7fr);
  padding: 0 14px 14px;
}

.remote-actions.compact {
  grid-template-columns: repeat(2, minmax(140px, 220px));
  padding: 10px 14px 14px;
}

.advanced-actions {
  margin: 0 14px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.advanced-actions summary {
  cursor: pointer;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 700;
}

.form-grid {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.point-form {
  border-top: 0;
}

.screens-editor {
  display: grid;
  gap: 8px;
}

.screen-row {
  display: grid;
  grid-template-columns: 54px minmax(120px, 1fr) minmax(84px, 110px);
  align-items: end;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.screen-row strong {
  align-self: center;
  color: var(--accent);
}

.menu-preview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.slide-card {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.slide-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111;
}

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

.empty-state {
  min-height: 58px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
  text-align: center;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid #bdd4d8;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-color: #d8b6b1;
  color: var(--danger);
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: minmax(280px, 360px) minmax(420px, 1fr);
  }

  .points-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .remote-actions {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 560px) {
  .screen-row,
  .details-grid {
    grid-template-columns: 1fr;
  }

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