:root {
	--bg: #f3f5f8;
	--card: #ffffff;
	--text: #1d2430;
	--muted: #6b7686;
	--line: #dde2ea;
	--primary: #1f6feb;
	--primary-text: #ffffff;
	--danger: #c93c37;
	--ok: #1a7f37;
	--warn: #b7791f;
	--ring: #f0b429;
	--radius: 10px;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #12161c;
		--card: #1b212a;
		--text: #e6eaf0;
		--muted: #94a0b2;
		--line: #2c3542;
		--primary: #3b82f6;
		--danger: #e5534b;
		--ok: #3fb950;
		--warn: #d29922;
		color-scheme: dark;
	}
}

* {
	box-sizing: border-box;
}

html, body {
	margin: 0;
	height: 100%;
}

body {
	font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	background: var(--bg);
	color: var(--text);
}

[hidden] {
	display: none !important;
}

h1 {
	font-size: 22px;
	margin: 0 0 16px;
}

h2 {
	font-size: 13px;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: var(--muted);
	margin: 0 0 10px;
}

.card {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 14px;
}

.muted {
	color: var(--muted);
}

.error {
	color: var(--danger);
	margin: 0;
}

button, input, select, textarea {
	font: inherit;
	color: inherit;
}

input, select, textarea {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid var(--line);
	border-radius: 8px;
	background: var(--bg);
}

button {
	padding: 8px 14px;
	border: 1px solid var(--line);
	border-radius: 8px;
	background: var(--card);
	cursor: pointer;
	white-space: nowrap;
}

button:hover:not(:disabled) {
	border-color: var(--muted);
}

button:disabled {
	opacity: .5;
	cursor: default;
}

button.primary {
	background: var(--primary);
	border-color: var(--primary);
	color: var(--primary-text);
}

button.danger {
	background: var(--danger);
	border-color: var(--danger);
	color: #fff;
}

button.small {
	padding: 4px 10px;
	font-size: 12px;
}

button.off {
	text-decoration: line-through;
	opacity: .7;
}

.row {
	display: flex;
	gap: 8px;
	align-items: center;
	margin-top: 8px;
	flex-wrap: wrap;
}

.row > select, .row > button {
	flex: 1;
}

label {
	display: block;
	margin-bottom: 12px;
	color: var(--muted);
}

label > input {
	margin-top: 4px;
	color: var(--text);
}

label.check {
	display: inline-flex;
	gap: 6px;
	align-items: center;
	margin: 0;
	color: var(--text);
}

label.check input {
	width: auto;
}

.pill {
	display: inline-block;
	padding: 2px 9px;
	border-radius: 999px;
	font-size: 12px;
	background: var(--bg);
	border: 1px solid var(--line);
}

.pill.ok {
	color: var(--ok);
	border-color: var(--ok);
}

.pill.warn {
	color: var(--warn);
	border-color: var(--warn);
}

.pill.bad {
	color: var(--danger);
	border-color: var(--danger);
}

/* ------------------------------------------------------------ login */

.login {
	display: grid;
	place-items: center;
	min-height: 100%;
	padding: 16px;
}

.login-card {
	width: min(380px, 100%);
	padding: 28px;
}

.login-card button {
	width: 100%;
	margin-top: 8px;
}

/* ------------------------------------------------------------ console */

.console {
	display: flex;
	flex-direction: column;
	min-height: 100%;
}

.topbar {
	display: flex;
	align-items: center;
	gap: 16px;
	padding: 10px 16px;
	background: var(--card);
	border-bottom: 1px solid var(--line);
	flex-wrap: wrap;
}

.brand {
	font-weight: 600;
}

.who {
	flex: 1 1 140px;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.status, .actions {
	display: flex;
	gap: 8px;
	align-items: center;
}

.toggle.available {
	background: var(--ok);
	border-color: var(--ok);
	color: #fff;
}

.toggle.blocked {
	background: var(--warn);
	border-color: var(--warn);
	color: #fff;
}

.layout {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 340px;
	gap: 16px;
	padding: 16px;
	flex: 1;
}

.center {
	display: flex;
	flex-direction: column;
	gap: 16px;
	min-width: 0;
}

.right {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

/* ------------------------------------------------------------ video */

/* The box follows the incoming picture's aspect ratio (--video-ar, set from the stream's real size in app.js)
   and scales with the window: as wide as the column allows, but never taller than --video-max-h. */
.video-area {
	--video-ar: 16 / 9;
	--video-max-h: 70vh;
	position: relative;
	padding: 0;
	overflow: hidden;
	background: #000;
	aspect-ratio: var(--video-ar);
	width: min(100%, calc(var(--video-max-h) * (var(--video-ar))));
	min-height: 180px;
	margin-inline: auto;
	flex: none;
}

#remoteVideo {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
	background: #000;
}

#localVideo {
	position: absolute;
	right: 10px;
	bottom: 44px;
	width: 22%;
	min-width: 120px;
	border-radius: 8px;
	border: 1px solid #ffffff55;
	background: #111;
	transform: scaleX(-1);
}

/* double-click a video during a call for full screen (app.js toggleFullscreen); the own picture stays mirrored */
#remoteVideo:fullscreen, #localVideo:fullscreen {
	width: 100%;
	height: 100%;
	min-width: 0;
	border: 0;
	border-radius: 0;
	object-fit: contain;
	background: #000;
}

.video-bar {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	gap: 6px;
	padding: 6px 10px;
	background: linear-gradient(transparent, #000c);
}

.video-bar button {
	background: #ffffff22;
	border-color: #ffffff44;
	color: #fff;
}

/* ------------------------------------------------------------ sides */

.sides {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 16px;
}

.side header {
	display: flex;
	gap: 8px;
	align-items: center;
	margin-bottom: 8px;
}

.side-name {
	font-weight: 600;
	font-size: 16px;
}

.side-media {
	margin-left: auto;
	font-size: 12px;
}

.side[data-state="IDLE"] .chat {
	display: none;
}

.side[data-state="IDLE"] .side-number {
	color: var(--muted);
}

.video-hint {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	color: #ffffff99;
	font-size: 15px;
	pointer-events: none;
}

.side[data-state="RINGING"] {
	border-color: var(--ring);
	box-shadow: 0 0 0 2px var(--ring);
}

.side[data-state="ESTABLISHED"] .side-state {
	color: var(--ok);
	border-color: var(--ok);
}

.side-party {
	min-height: 40px;
}

.side-number {
	font-size: 15px;
	overflow-wrap: anywhere;
}

.side-actions {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
	margin: 8px 0;
}

.side.vco {
	padding: 10px;
}

.side.vco .chat, .side.vco .keypad {
	display: none !important;
}

.keypad {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 6px;
	margin-bottom: 8px;
}

.chat {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.chat-remote {
	min-height: 64px;
	max-height: 160px;
	overflow-y: auto;
	padding: 8px 10px;
	border: 1px solid var(--line);
	border-radius: 8px;
	background: var(--bg);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

/* ------------------------------------------------------------ incoming */

.incoming {
	position: sticky;
	top: 0;
	z-index: 10;
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 16px;
	padding: 12px 16px;
	background: var(--ring);
	color: #1d1500;
	animation: pulse 1.2s ease-in-out infinite alternate;
}

.incoming-title {
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: .05em;
}

.incoming-from {
	font-size: 18px;
	font-weight: 600;
}

.incoming .muted {
	color: #3b2f05;
}

.incoming-actions {
	display: flex;
	gap: 8px;
}

@keyframes pulse {
	from {
		filter: brightness(1);
	}

	to {
		filter: brightness(1.12);
	}
}

/* ------------------------------------------------------------ right column */

.queues {
	width: 100%;
	border-collapse: collapse;
	font-size: 13px;
}

.queues th, .queues td {
	text-align: left;
	padding: 4px 6px;
	border-bottom: 1px solid var(--line);
}

.queues td:not(:first-child), .queues th:not(:first-child) {
	text-align: right;
	width: 52px;
}

.queues tr.waiting td {
	color: var(--warn);
	font-weight: 600;
}

.log-card {
	flex: 1;
	min-height: 160px;
	display: flex;
	flex-direction: column;
}

.log {
	list-style: none;
	margin: 0;
	padding: 0;
	overflow-y: auto;
	max-height: 260px;
	font-size: 12px;
}

.log li {
	padding: 3px 0;
	border-bottom: 1px dashed var(--line);
}

.log time {
	color: var(--muted);
	margin-right: 6px;
}

/* ------------------------------------------------------------ tabs */

.tabs {
	display: flex;
	gap: 2px;
	margin: -4px -4px 12px;
	border-bottom: 1px solid var(--line);
}

.tabs button {
	flex: 1;
	padding: 6px 4px;
	border: none;
	border-bottom: 2px solid transparent;
	border-radius: 0;
	background: none;
	color: var(--muted);
	font-size: 13px;
}

.tabs button[aria-selected="true"] {
	color: var(--text);
	border-bottom-color: var(--primary);
}

.badge {
	display: inline-block;
	min-width: 18px;
	padding: 0 5px;
	border-radius: 9px;
	background: var(--danger);
	color: #fff;
	font-size: 11px;
	line-height: 18px;
}

.tab-pane .pick-list {
	max-height: 340px;
	margin-top: 8px;
}

.pick-list .item-main {
	min-width: 0;
	overflow-wrap: anywhere;
}

.pick-list .item-actions {
	display: flex;
	gap: 4px;
	flex-shrink: 0;
}

.pick-list .item-text {
	font-size: 12px;
	color: var(--muted);
	white-space: pre-wrap;
}

/* ------------------------------------------------------------ dialogs */

dialog {
	width: min(420px, calc(100% - 32px));
	color: var(--text);
}

dialog::backdrop {
	background: #0008;
}

.pick-list {
	list-style: none;
	margin: 0 0 12px;
	padding: 0;
	max-height: 240px;
	overflow-y: auto;
}

.pick-list li {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
	padding: 6px 0;
	border-bottom: 1px solid var(--line);
}

.pick-list .kind {
	font-size: 11px;
	color: var(--muted);
}

.video-bar button.on {
	background: var(--ok);
	border-color: var(--ok);
}

@media (max-width: 960px) {
	.layout {
		grid-template-columns: 1fr;
	}

	.sides {
		grid-template-columns: 1fr;
	}
}
