/* Variables */
:root {
	color-scheme: light dark;
	--bg-primary: light-dark(#f5f7fa, #141618);
	--bg-secondary: light-dark(#fafbfd, #1e2124);
	--text-primary: light-dark(#0f1115, #dde1e7);
	--text-secondary: light-dark(#566070, #8ea0b5);
	--text-on-color: #f8fafc;
	--border-color: light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.1));
	--accent: light-dark(#0b74b5, #71c9f8);
	--accent-hover: light-dark(#0a6399, #4db8f5);
	--text-on-accent: light-dark(#f8fafc, #00243c);
	--success: light-dark(#077a5d, #34d399);
	--success-hover: light-dark(#065e48, #2ab886);
	--success-bg: light-dark(#077a5d, #065e48);
	--error: light-dark(#c01746, #f87171);
	--error-hover: light-dark(#9e1239, #7f1d3e);
	--error-bg: light-dark(#c01746, #9e1239);
	--channel-signal-bg: light-dark(#e0f0fa, #1a3044);
	--channel-signal-hover: light-dark(#cce4f3, #243d55);
	--channel-webpush-bg: light-dark(#e0f5ef, #1a3329);
	--channel-webpush-hover: light-dark(#cceade, #243d33);
	--spinner-track: light-dark(#d9dde5, #2e3440);
	--shadow-tooltip: light-dark(rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.5));
}

:root[data-theme="light"] {
	color-scheme: light;
}
:root[data-theme="dark"] {
	color-scheme: dark;
}

/* Reset */
*,
*::before,
*::after {
	box-sizing: border-box;
}

* {
	margin: 0;
	padding: 0;
}

body {
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

img,
picture,
video,
canvas,
svg {
	display: block;
	max-width: 100%;
}

input,
button,
textarea,
select {
	font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
	overflow-wrap: break-word;
}

/* Base */
body {
	font-family:
		ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
	max-width: 50rem;
	margin: 1rem auto;
	padding: 0 1.25rem 1.25rem;
	background: var(--bg-primary);
	color: var(--text-primary);
}

h2 {
	margin-bottom: 1.25rem;
}

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

a:hover {
	color: var(--accent-hover);
}

/* Components */

/* Cards */
.card,
.integration-card {
	background: var(--bg-secondary);
	border-radius: 0.5rem;
	padding: 0;
	margin-bottom: 1.25rem;
	box-shadow: 0 0.125rem 0.25rem var(--border-color);
}

.card-header,
.integration-header {
	font-weight: 600;
	font-size: 1.1em;
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 1.25rem;
	cursor: pointer;
	list-style: none;
	user-select: none;
}

.card-header::-webkit-details-marker,
.integration-header::-webkit-details-marker {
	display: none;
}

.card-header::before,
.integration-header::before {
	content: "▶";
	font-size: 0.7em;
	margin-right: 0.5rem;
	transition: transform 0.2s;
	display: inline-block;
}

details[open] > .card-header::before,
details[open] > .integration-header::before {
	transform: rotate(90deg);
}

.card-content,
.integration-content {
	padding: 0 1.25rem 1.25rem 1.25rem;
}

/* Page identity */
.site-header {
	padding-bottom: 1.25rem;
	display: flex;
	align-items: baseline;
	gap: 0.5rem;
}

.site-wordmark {
	font-size: 0.9rem;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--accent);
}

.card-header h2,
.integration-header h3 {
	margin-bottom: 0;
	font-size: 1.2em;
	font-weight: 600;
}

/* Tooltips */
.integration-status:has(.tooltip) {
	cursor: help;
}

.tooltip {
	visibility: hidden;
	opacity: 0;
	position: absolute;
	bottom: 100%;
	left: 50%;
	transform: translateX(-50%);
	margin-bottom: 0.5rem;
	background: #1e2124;
	color: #fafbfd;
	padding: 0.375rem 0.625rem;
	border-radius: 0.25rem;
	border: none;
	font-size: 0.875rem;
	font-weight: 400;
	white-space: nowrap;
	transition: opacity 0.2s;
	pointer-events: none;
	z-index: 10;
	box-shadow: 0 0.25rem 0.5rem var(--shadow-tooltip);
}

.tooltip::after {
	content: "";
	position: absolute;
	top: 100%;
	left: 50%;
	transform: translateX(-50%);
	border: 0.3125rem solid transparent;
	border-top-color: #1e2124;
}

:hover > .tooltip,
:focus-within > .tooltip {
	visibility: visible;
	opacity: 1;
}

/* Theme Toggle */
.theme-toggle {
	position: fixed;
	bottom: 1.5rem;
	right: 1.5rem;
	background: transparent;
	border: none;
	cursor: pointer;
	font-size: 1.5rem;
	padding: 0;
	line-height: 1;
	opacity: 0.6;
	transition: opacity 0.2s;
	min-width: 2.75rem;
	min-height: 2.75rem;
	display: grid;
	place-items: center;
}

.theme-toggle:hover {
	opacity: 1;
}

/* App List */
.app-list {
	list-style: none;
	padding: 0;
}

.app-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.75rem;
	background: var(--bg-primary);
	border-radius: 0.25rem;
	margin-bottom: 0.5rem;
	gap: 1rem;
}

.app-info {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.app-name {
	font-size: 1.2em;
}

.app-subscriptions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.375rem;
}

.channel-badge {
	padding: 0.375rem 0.75rem;
	border-radius: 1rem;
	font-size: 0.875em;
	font-weight: 500;
	position: relative;
	border: none;
	background: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.25rem;
}

.badge-active {
	cursor: pointer;
	transition: background-color 0.2s ease;
	min-height: 2.75rem;
}

.badge-active:hover {
	background-color: var(--channel-signal-hover);
}

.channel-webpush.badge-active:hover {
	background-color: var(--channel-webpush-hover);
}

.badge-active.htmx-request {
	opacity: 0.6;
	cursor: wait;
	pointer-events: none;
}

.badge-inactive {
	cursor: pointer;
	border: 0.0625rem dashed currentColor;
	transition: filter 0.2s ease;
	min-height: 2.75rem;
}

.badge-inactive:hover {
	filter: brightness(1.15);
}

.badge-inactive.htmx-request {
	opacity: 0.6;
	cursor: wait;
	pointer-events: none;
}

.badge-subscribed {
	cursor: default;
}

.channel-signal.badge-active {
	background: var(--channel-signal-bg);
	color: var(--accent);
}

.channel-signal.badge-inactive {
	color: var(--accent);
	background: transparent;
}

.channel-signal.badge-subscribed {
	background: var(--channel-signal-bg);
	color: var(--accent);
}

.channel-webpush.badge-active {
	background: var(--channel-webpush-bg);
	color: var(--success);
}

.channel-webpush.badge-subscribed {
	background: var(--channel-signal-bg);
	color: var(--accent);
}

.channel-telegram.badge-active {
	background: var(--channel-signal-bg);
	color: var(--accent);
}

.channel-telegram.badge-inactive {
	color: var(--accent);
	background: transparent;
}

.channel-telegram.badge-subscribed {
	background: var(--channel-signal-bg);
	color: var(--accent);
}

.app-actions {
	display: flex;
	gap: 0.5rem;
	align-items: center;
}

.btn-delete-sub {
	background: none;
	border: none;
	color: inherit;
	font-size: 1em;
	font-weight: bold;
	cursor: pointer;
	padding: 0.125rem 0.25rem;
	margin-left: 0.125rem;
	opacity: 0.7;
	transition: opacity 0.2s ease;
	line-height: 1;
	min-width: 1rem;
	min-height: 1.5rem;
	display: inline-grid;
	place-items: center;
}

.btn-delete-sub:hover {
	opacity: 1;
}

/* Loading Spinner */
.loading {
	color: var(--text-secondary);
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.spinner {
	width: 1.25rem;
	height: 1.25rem;
	border: 0.125rem solid var(--spinner-track);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* Integrations */
.integration-container {
	margin-bottom: 1.25rem;
}

.integration-status {
	font-size: 0.875em;
	font-weight: 500;
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
}

.integration-status::before {
	content: "";
	width: 0.5rem;
	height: 0.5rem;
	border-radius: 50%;
	flex-shrink: 0;
}

.integration-status.connected::before,
.integration-status.available::before {
	background: var(--success);
}

.integration-status.connected,
.integration-status.available {
	color: var(--success);
}

.integration-status.disconnected::before {
	background: var(--error);
}

.integration-status.disconnected {
	color: var(--error);
}

.integration-status.unlinked::before {
	background: var(--text-secondary);
}

.integration-status.unlinked {
	color: var(--text-secondary);
}

.link-instructions {
	margin: 0.25rem 0;
	padding-left: 1.25rem;
	line-height: 1.8;
}

.channel-not-configured {
	background: var(--error-bg);
	color: var(--text-on-color);
	padding: 0.25rem 0.625rem;
	border-radius: 0.25rem;
}

.integration-content code {
	background: var(--bg-primary);
	padding: 0.125rem 0.375rem;
	border-radius: 0.25rem;
	font-size: 0.875em;
}

/* Forms */
.auth-form {
	margin-top: 1rem;
	max-width: 25rem;
}

.form-group {
	margin-bottom: 1rem;
}

.form-group label {
	display: block;
	margin-bottom: 0.5rem;
	font-weight: 500;
	color: var(--text-primary);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"] {
	width: 100%;
	padding: 0.5rem;
	border: 0.0625rem solid var(--border-color);
	border-radius: 0.25rem;
	background: var(--bg-secondary);
	color: var(--text-primary);
	font-size: 1rem;
}

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

/* Password Toggle */
.password-wrapper {
	position: relative;
	display: flex;
	align-items: center;
}

.password-wrapper input {
	width: 100%;
}

.form-group .password-wrapper input[type="text"],
.form-group .password-wrapper input[type="email"],
.form-group .password-wrapper input[type="password"] {
	padding-right: 2.5rem;
}

.password-toggle {
	position: absolute;
	right: 0.5rem;
	background: none;
	border: none;
	cursor: pointer;
	padding: 0.25rem;
	color: var(--text-secondary);
	display: grid;
	place-items: center;
	transition: color 0.2s;
}

.password-toggle:hover {
	color: var(--text-primary);
}

.eye-icon {
	width: 1.25rem;
	height: 1.25rem;
}

.eye-hide {
	display: none; /* overridden by inline style after first toggle */
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-danger {
	padding: 0.5rem 1rem;
	border: none;
	border-radius: 0.25rem;
	cursor: pointer;
	font-size: 1rem;
	font-weight: 500;
	transition: background-color 0.2s ease;
}

.btn-primary:hover {
	background-color: var(--accent-hover);
}

.btn-secondary:hover {
	opacity: 0.8;
}

.btn-danger:hover {
	background-color: var(--error-hover);
}

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-danger:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.btn-primary {
	background: var(--accent);
	color: var(--text-on-accent);
}

.btn-secondary {
	background: var(--bg-secondary);
	color: var(--text-primary);
	border: 0.0625rem solid var(--border-color);
}

.btn-danger {
	background: var(--error-bg);
	color: var(--text-on-color);
}

.auth-status {
	margin-top: 1rem;
	padding: 0.75rem;
	border-radius: 0.25rem;
	display: none;
}

.auth-status.success {
	display: block;
	background: var(--success-bg);
	color: var(--text-on-color);
}

.auth-status.error {
	display: block;
	background: var(--error-bg);
	color: var(--text-on-color);
}

.auth-status.info {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	background: var(--accent);
	color: var(--text-on-accent);
}

/* QR Code */
.qr-container {
	margin-top: 1rem;
}

.qr-code-wrapper {
	background: var(--text-on-color);
	padding: 1rem;
	text-align: center;
	display: inline-block;
	max-width: 100%;
	border-radius: 0.5rem;
}

.qr-code-wrapper img {
	width: 100%;
	max-width: 25rem;
	height: auto;
	display: block;
	aspect-ratio: 1;
}

/* Toast Notifications */
#toast-container {
	position: fixed;
	bottom: 4rem;
	right: 1.5rem;
	z-index: 9999;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	pointer-events: none;
}

.toast {
	background: var(--bg-secondary);
	color: var(--text-primary);
	padding: 0.875rem 1.25rem;
	border-radius: 0.375rem;
	box-shadow:
		0 0.25rem 0.5rem var(--shadow-tooltip),
		0 0 0 0.0625rem var(--border-color);
	min-width: 15rem;
	max-width: 25rem;
	pointer-events: auto;
	animation: toastSlideIn 0.3s ease;
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.toast.success {
	background: var(--success-bg);
	color: var(--text-on-color);
}

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

.toast.info {
	background: var(--accent);
	color: var(--text-on-accent);
}

.toast.hiding {
	animation: toastSlideOut 0.3s ease forwards;
}

@keyframes toastSlideIn {
	from {
		transform: translateX(calc(100% + 1.5rem));
		opacity: 0;
	}
	to {
		transform: translateX(0);
		opacity: 1;
	}
}

@keyframes toastSlideOut {
	from {
		transform: translateX(0);
		opacity: 1;
	}
	to {
		transform: translateX(calc(100% + 1.5rem));
		opacity: 0;
	}
}

/* Inline confirm widget */
.confirm-inline {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
	flex-wrap: wrap;
	min-width: 0;
}

.confirm-message {
	font-size: 0.875rem;
	color: var(--text-secondary);
}

.confirm-inline .confirm-message {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	max-width: 12rem;
}

.btn-sm {
	padding: 0.25rem 0.625rem;
	font-size: 0.875rem;
	min-height: 2.75rem;
	min-width: 2.75rem;
}

:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
	border-radius: 2px;
}

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.noscript-msg {
	padding: 1rem;
	text-align: center;
}

.skip-nav {
	position: absolute;
	top: -100%;
	left: 1rem;
	background: var(--bg-secondary);
	color: var(--accent);
	padding: 0.5rem 1rem;
	border-radius: 0.25rem;
	font-weight: 600;
	z-index: 10000;
	transition: top 0.1s;
}

.skip-nav:focus {
	top: 1rem;
}

#signal-qr-code:not([src]),
#signal-qr-code[src=""] {
	display: none;
}

@media (max-width: 48rem) {
	.app-item {
		flex-direction: column;
		align-items: flex-start;
	}

	.app-actions {
		align-self: flex-end;
	}

	.auth-form {
		max-width: none;
	}
}

@media (max-width: 30rem) {
	.theme-toggle {
		bottom: 0.75rem;
		right: 0.75rem;
		font-size: 1.25rem;
	}

	#toast-container {
		right: 1rem;
		left: 1rem;
		bottom: 3rem;
	}

	.toast {
		min-width: 0;
		max-width: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms;
		animation-iteration-count: 1;
		transition-duration: 0.01ms;
	}
}
