:root {
	--bg: #f5f6fa;
	--surface: #ffffff;
	--border: #e2e5ec;
	--text: #1c1f2b;
	--text-muted: #6b7280;
	--accent: #4f46e5;
	--accent-hover: #4338ca;
	--danger: #dc2626;
	--danger-hover: #b91c1c;
	--success-bg: #ecfdf5;
	--success-text: #047857;
	--success-border: #a7f3d0;
	--error-bg: #fef2f2;
	--error-text: #b91c1c;
	--error-border: #fecaca;
	--live-bg: #ecfdf5;
	--live-text: #047857;
	--offline-bg: #f3f4f6;
	--offline-text: #6b7280;
	--warn: #d97706;
	--radius: 10px;
	--shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

* {
	box-sizing: border-box;
}

html {
	height: 100%;
}

body {
	margin: 0;
	min-height: 100%;
	/* column-flex body + flex:1 на .container ниже — футер прижат к низу
	   вьюпорта даже на страницах с мало контента (например пустой список
	   точек приёма), а не сразу под контентом посередине экрана. */
	display: flex;
	flex-direction: column;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	background: var(--bg);
	color: var(--text);
	line-height: 1.5;
}

a {
	color: var(--accent);
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}

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

.topbar .brand {
	font-weight: 700;
	font-size: 1.1rem;
	color: var(--text);
	text-decoration: none;
}

.topbar .brand:hover {
	text-decoration: none;
}

.topbar .user-info {
	display: flex;
	align-items: center;
	gap: 14px;
	font-size: 0.9rem;
	color: var(--text-muted);
}

.topbar form {
	display: inline;
}

.topbar button.link-button {
	background: none;
	border: none;
	padding: 0;
	color: var(--text-muted);
	font-size: 0.9rem;
	cursor: pointer;
	text-decoration: underline;
}

/* Тот же трюк — <button> внутри inline-формы, оформленная как обычная
   текстовая ссылка, чтобы вписаться в список действий рядом с <a>-шками
   (лог/изменить/удалить), которым для POST-запроса нужна форма, а не href. */
.destination-list .actions button.link-button {
	background: none;
	border: none;
	padding: 0;
	font: inherit;
	color: var(--accent);
	cursor: pointer;
	text-decoration: none;
}

.destination-list .actions button.link-button:hover {
	text-decoration: underline;
}

.destination-list .actions form {
	display: inline;
}

.container {
	max-width: 840px;
	width: 100%;
	margin: 0 auto;
	padding: 32px 24px 64px;
	flex: 1 0 auto;
	box-sizing: border-box;
}

.site-footer {
	flex-shrink: 0;
	max-width: 840px;
	margin: 0 auto;
	padding: 0 24px 24px;
	font-size: 0.78rem;
	color: var(--text-muted);
	text-align: center;
}

h1 {
	font-size: 1.6rem;
	margin: 0 0 20px;
}

h2 {
	font-size: 1.1rem;
	margin: 32px 0 12px;
	color: var(--text);
}

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 20px 24px;
	margin-bottom: 20px;
}

.messages {
	list-style: none;
	padding: 0;
	margin: 0 0 20px;
}

.messages li {
	padding: 10px 14px;
	border-radius: var(--radius);
	margin-bottom: 8px;
	font-size: 0.92rem;
	border: 1px solid var(--border);
	background: var(--surface);
}

.messages li.success {
	background: var(--success-bg);
	color: var(--success-text);
	border-color: var(--success-border);
}

.messages li.error {
	background: var(--error-bg);
	color: var(--error-text);
	border-color: var(--error-border);
}

.stream-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.stream-list li {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 14px 18px;
	box-shadow: var(--shadow);
}

.stream-list a {
	font-weight: 600;
	font-size: 1rem;
	color: var(--text);
}

.stream-list a:hover {
	color: var(--accent);
	text-decoration: none;
}

.empty-state {
	color: var(--text-muted);
	font-style: italic;
}

.load-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
	gap: 16px;
}

.load-grid .metric {
	text-align: center;
}

.gauge {
	--pct: 0;
	--color: var(--accent);
	position: relative;
	width: 64px;
	height: 64px;
	margin: 0 auto 8px;
	border-radius: 50%;
	background: conic-gradient(var(--color) calc(var(--pct) * 1%), var(--border) 0);
}

.gauge::after {
	content: "";
	position: absolute;
	inset: 7px;
	border-radius: 50%;
	background: var(--surface);
	z-index: 0;
}

.gauge-text {
	position: absolute;
	inset: 0;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.78rem;
	font-weight: 700;
	color: var(--text);
}

.gauge.ok {
	--color: var(--live-text);
}

.gauge.warn {
	--color: var(--warn);
}

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

.gauge.unknown {
	--color: var(--offline-text);
	background: var(--offline-bg);
}

.gauge.unknown .gauge-text {
	color: var(--offline-text);
	font-size: 0.7rem;
}

.load-grid .metric .value {
	font-size: 1.4rem;
	font-weight: 700;
}

.load-grid .metric .label {
	font-size: 0.8rem;
	color: var(--text-muted);
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

.publish-urls {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.publish-urls .row {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
}

.publish-urls .row form {
	margin: 0;
	flex: 0 0 auto;
}

.copy-field {
	display: flex;
	align-items: stretch;
	flex: 1 1 auto;
	min-width: 0;
	background: #f1f2f6;
	border-radius: 8px;
	overflow: hidden;
}

.copy-field code {
	background: none;
	border-radius: 0;
	padding: 7px 10px;
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	align-items: center;
}

.copy-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 34px;
	background: transparent;
	border: none;
	border-left: 1px solid rgba(15, 23, 42, 0.08);
	color: var(--text-muted);
	cursor: pointer;
	transition: background-color 0.15s ease, color 0.15s ease;
}

.copy-btn:hover {
	background: rgba(15, 23, 42, 0.06);
	color: var(--text);
}

.copy-btn:active {
	transform: scale(0.94);
}

.copy-btn svg {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
}

.copy-btn .icon-check {
	display: none;
}

.copy-btn.copied {
	background: var(--live-bg);
	color: var(--live-text);
}

.copy-btn.copied .icon-copy {
	display: none;
}

.copy-btn.copied .icon-check {
	display: block;
}

.publish-urls .proto {
	font-weight: 600;
	font-size: 0.85rem;
	color: var(--text-muted);
	min-width: 44px;
}

.publish-urls .unavailable {
	color: var(--text-muted);
	font-style: italic;
	font-size: 0.9rem;
}

code {
	background: #f1f2f6;
	border-radius: 6px;
	padding: 2px 6px;
	font-size: 0.88rem;
	word-break: break-all;
}

.log-view {
	background: #1c1f2b;
	color: #e5e7eb;
	border-radius: 8px;
	padding: 14px 16px;
	font-size: 0.82rem;
	line-height: 1.5;
	overflow-x: auto;
	white-space: pre-wrap;
	word-break: break-word;
	max-height: 60vh;
	overflow-y: auto;
}

.chat-source-form label {
	font-weight: 600;
	font-size: 0.88rem;
	display: block;
	margin-bottom: 6px;
}

.chat-source-form .row {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
}

.chat-source-form input[type="text"] {
	flex: 1 1 260px;
	min-width: 0;
	padding: 9px 12px;
	border: 1px solid var(--border);
	border-radius: 8px;
	font-size: 0.92rem;
	background: var(--surface);
	color: var(--text);
}

.chat-messages {
	margin-top: 14px;
	max-height: 320px;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.chat-message {
	font-size: 0.88rem;
	line-height: 1.4;
	padding: 6px 10px;
	border-radius: 8px;
	background: var(--bg);
	word-break: break-word;
}

.chat-message strong {
	color: var(--accent);
	margin-right: 6px;
}

.chat-time {
	color: var(--text-muted);
	font-size: 0.76rem;
	margin-right: 6px;
}

.badge {
	display: inline-block;
	padding: 3px 10px;
	border-radius: 999px;
	font-size: 0.78rem;
	font-weight: 600;
}

.badge.live {
	background: var(--live-bg);
	color: var(--live-text);
}

.badge.offline {
	background: var(--offline-bg);
	color: var(--offline-text);
}

.badge.error {
	background: var(--error-bg);
	color: var(--error-text);
}

.stats-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
	gap: 14px;
	margin-top: 12px;
}

.stats-grid.media-info {
	padding-top: 12px;
	border-top: 1px solid var(--border);
}

.stats-grid .metric .value {
	font-size: 1.1rem;
	font-weight: 600;
}

.stats-grid .metric .label {
	font-size: 0.78rem;
	color: var(--text-muted);
}

.destination-list {
	list-style: none;
	margin: 12px 0 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.destination-list li {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	justify-content: space-between;
	gap: 4px 16px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 10px 14px;
	background: var(--bg);
}

.destination-list li.disabled {
	opacity: 0.6;
}

.destination-list .name-group {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
	min-width: 0;
}

.destination-list .name-group form {
	display: flex;
	align-items: center;
	margin: 0;
}

.platform-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 26px;
	height: 26px;
	border-radius: 50%;
	color: #fff;
	font-size: 0.68rem;
	font-weight: 700;
	letter-spacing: -0.02em;
}

.toggle-switch {
	position: relative;
	display: inline-block;
	flex: 0 0 auto;
	width: 36px;
	height: 20px;
	cursor: pointer;
}

.toggle-switch input {
	position: absolute;
	opacity: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	cursor: pointer;
}

.toggle-slider {
	position: absolute;
	inset: 0;
	background: var(--border);
	border-radius: 999px;
	transition: background-color 0.15s ease;
}

.toggle-slider::before {
	content: "";
	position: absolute;
	top: 2px;
	left: 2px;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: var(--surface);
	box-shadow: 0 1px 2px rgba(16, 24, 40, 0.2);
	transition: transform 0.15s ease;
}

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

.toggle-switch input:checked + .toggle-slider::before {
	transform: translateX(16px);
}

.toggle-switch input:focus-visible + .toggle-slider {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.destination-list .name {
	font-weight: 600;
	min-width: 0;
	word-break: break-word;
}

.destination-list .actions {
	display: flex;
	flex: 0 0 auto;
	gap: 12px;
	font-size: 0.88rem;
	white-space: nowrap;
}

.actions-row {
	display: flex;
	align-items: center;
	gap: 16px;
	flex-wrap: wrap;
	margin-top: 8px;
	margin-bottom: 20px;
}

form p {
	margin: 0 0 14px;
}

form label {
	display: block;
	font-weight: 600;
	font-size: 0.88rem;
	margin-bottom: 6px;
}

form input[type="text"],
form input[type="url"],
form input[type="email"],
form input[type="password"],
form input[type="number"] {
	width: 100%;
	padding: 9px 12px;
	border: 1px solid var(--border);
	border-radius: 8px;
	font-size: 0.95rem;
	background: var(--surface);
	color: var(--text);
}

form input:focus {
	outline: 2px solid var(--accent);
	outline-offset: 1px;
	border-color: var(--accent);
}

.errorlist {
	list-style: none;
	margin: 4px 0 0;
	padding: 0;
	color: var(--danger);
	font-size: 0.85rem;
}

button,
.button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 9px 18px;
	border-radius: 8px;
	border: none;
	background: var(--accent);
	color: #fff;
	font-size: 0.92rem;
	font-weight: 600;
	cursor: pointer;
}

button:hover,
.button:hover {
	background: var(--accent-hover);
	text-decoration: none;
}

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

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

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

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

.hint {
	color: var(--text-muted);
	font-size: 0.85rem;
	margin-top: 8px;
}

/* Django's ModelForm as_p renders a field's help_text as <span class="helptext">
   right after the widget — style it like .hint so it reads the same as the
   other explanatory notes on this form. */
.helptext {
	display: block;
	color: var(--text-muted);
	font-size: 0.85rem;
	margin-top: 4px;
}
