/* Variables */
:root {
	color-scheme: light dark;
	--bg-primary: light-dark(#f4f7f8, #141a1d);
	--bg-secondary: light-dark(#fafcfd, #1e262a);
	--text-primary: light-dark(#0f1517, #dce9ed);
	--text-secondary: light-dark(#566870, #8eacb5);
	--text-on-color: #fff;
	--border-color: light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.1));
	--accent: light-dark(#0b7589, #7dd4e8);
	--accent-hover: light-dark(#086b7c, #5ec8e0);
	--text-on-accent: light-dark(#fff, #0a2a33);
	--success: #077a5d;
	--success-hover: #065e48;
	--error: #c01746;
	--error-hover: #9e1239;
	--spinner-track: light-dark(#dae5e9, #2e3e44);
	--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 h2 {
	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: var(--bg-secondary);
	color: var(--text-primary);
	padding: 0.375rem 0.625rem;
	border-radius: 0.25rem;
	border: 0.0625rem solid var(--border-color);
	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: var(--bg-secondary);
}

: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.5rem;
}

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

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

.channel-badge {
	padding: 0.2rem 0.5rem;
	border-radius: 0.25rem;
	font-size: 0.8em;
	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;
}

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

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

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

.badge-inactive {
	cursor: pointer;
	border: 0.0625rem dashed currentColor;
	transition: opacity 0.2s ease;
}

.badge-inactive:hover {
	opacity: 0.75;
}

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

.badge-subscribed {
	cursor: default;
}

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

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

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

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

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

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

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

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

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

.btn-delete {
	padding: 0.375rem 0.75rem;
	background: var(--error);
	color: var(--text-on-color);
	border: none;
	border-radius: 0.25rem;
	cursor: pointer;
	transition: background-color 0.2s ease;
	white-space: nowrap;
}

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

.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;
}

.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 {
	padding: 0.25rem 0.625rem;
	border-radius: 0.25rem;
	font-size: 0.875em;
	font-weight: 500;
	position: relative;
}

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

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

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

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

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

/* 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;
}

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

.password-wrapper input {
	width: 100%;
	padding-right: 2.5rem;
}

.password-toggle {
	position: absolute;
	right: 0.5rem;
	background: none;
	border: none;
	cursor: pointer;
	padding: 0;
	color: var(--text-secondary);
	display: grid;
	place-items: center;
	min-width: 2.75rem;
	min-height: 2.75rem;
	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);
	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);
	color: var(--text-on-color);
}

.auth-status.error {
	display: block;
	background: var(--error);
	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;
}

/* 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);
	color: var(--text-on-color);
}

.toast.error {
	background: var(--error);
	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;
}

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

.btn-sm {
	padding: 0.25rem 0.625rem;
	font-size: 0.875rem;
	min-height: 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;
}

.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: 30rem) {
	.theme-toggle {
		bottom: 0.75rem;
		right: 0.75rem;
		font-size: 1.25rem;
	}

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

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