/* Variables */
:root {
	--bg-primary: #f5f5f5;
	--bg-secondary: #fdfdfd;
	--text-primary: #000;
	--text-secondary: #666;
	--text-on-color: #fff;
	--border-color: rgba(0, 0, 0, 0.1);
	--accent: #00b4d8;
	--success: #06d6a0;
	--error: #ef476f;
	--spinner-track: #e0e0e0;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg-primary: #1a1a1a;
		--bg-secondary: #2d2d2d;
		--text-primary: #e0e0e0;
		--text-secondary: #a0a0a0;
		--text-on-color: #fff;
		--border-color: rgba(255, 255, 255, 0.1);
		--accent: #60c5ff;
		--spinner-track: #4a4a4a;
	}
}

:root[data-theme="dark"] {
	--bg-primary: #1a1a1a;
	--bg-secondary: #2d2d2d;
	--text-primary: #e0e0e0;
	--text-secondary: #a0a0a0;
	--text-on-color: #fff;
	--border-color: rgba(255, 255, 255, 0.1);
	--accent: #60c5ff;
	--spinner-track: #4a4a4a;
}

/* 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: system-ui;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
	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 {
	opacity: 0.8;
}

/* Components */

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

.card-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 {
	display: none;
}

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

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

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

/* 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 rgba(0, 0, 0, 0.3);
}

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

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

/* App List */
.app-list {
	list-style: none;
	padding: 0;
	max-height: 18.75rem;
	overflow: visible;
}

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

.channel-badge {
	padding: 0.15rem 0.5rem;
	border-radius: 0.25rem;
	font-size: 0.85em;
	font-weight: 500;
	position: relative;
	border: none;
	background: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.25rem;
	min-width: 5rem;
}

.badge-active {
	cursor: pointer;
	transition: filter 0.2s ease;
}

.badge-active:hover {
	filter: brightness(0.9);
}

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

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

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

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

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

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

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

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

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

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

.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: filter 0.2s ease;
	white-space: nowrap;
}

.btn-delete:hover {
	filter: brightness(0.85);
}

.btn-delete-sub {
	background: none;
	border: none;
	color: inherit;
	font-size: 1em;
	font-weight: bold;
	cursor: pointer;
	padding: 0 0.25rem;
	margin-left: 0.25rem;
	opacity: 0.7;
	transition: opacity 0.2s ease;
}

.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-card {
	background: var(--bg-secondary);
	border-radius: 0.5rem;
	margin-bottom: 1.25rem;
	box-shadow: 0 0.125rem 0.25rem var(--border-color);
	padding: 0;
}

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

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

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

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

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

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

.integration-content {
	padding: 0 1.25rem 1.25rem 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);
}

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

.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: 1px solid var(--border-color);
	border-radius: 0.25rem;
	background: var(--bg-secondary);
	color: var(--text-primary);
	font-size: 1rem;
}

/* 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: filter 0.2s ease;
}

.btn-primary:hover,
.btn-secondary:hover,
.btn-danger:hover {
	filter: brightness(0.85);
}

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

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

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

/* 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: 1.5rem;
	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 rgba(0, 0, 0, 0.1),
		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-color);
}

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