@use "../constants" as *;
@use "../components/pro-feature-notice";

.alerts {

	// ── Layout ────────────────────────────────────────────────────
	.alerts-layout {
		display: grid;
		grid-template-columns: 1fr 1.1fr;
		gap: 1rem;
		align-items: start;
		margin-top: 2rem;
	}

	.alerts-col-left {
		display: flex;
		flex-direction: column;
		gap: 1rem;
	}

	// ── Card ──────────────────────────────────────────────────────
	.alerts-card {
		background: $surface-color;
		border-radius: 5px;
		box-shadow: $card-box-shadow;
		overflow: hidden;
	}

	.alerts-card-header {
		display: flex;
		align-items: center;
		gap: 1rem;
		padding: 1.25rem;
		border-bottom: 1px solid $surface-subtle;
	}

	.alerts-card-icon-wrap {
		width: 44px;
		height: 44px;
		min-width: 44px;
		background: $surface-blue-tint;
		border-radius: 5px;
		display: flex;
		align-items: center;
		justify-content: center;
		align-self: flex-start;

		i {
			font-size: 18px;
			color: $main-theme-color;
		}
	}

    .upgrade-notice {
        border-radius: 0;
    }

	.alerts-card-info {
		flex: 1;

		.alerts-card-title {
			font-weight: 600;
			color: $text-heading;
			margin-bottom: 2px;
		}

		.alerts-card-desc {
			font-size: 13px;
			color: $text-secondary;
		}
	}

	.alerts-card-body {
		padding: 1.25rem;
	}

	// ── Email recipients ──────────────────────────────────────────
	#email-recipients-container {
		display: flex;
		flex-direction: column;
		gap: 0.6rem;
		margin-bottom: 0.75rem;

		.email-input-row {
			display: flex;
			align-items: center;
			gap: 0.5rem;

			input[type="email"] {
				flex: 1;
				height: 36px;
				padding: 0 0.75rem;
				border: 1px solid $border-input;
				border-radius: 6px;
				color: $text-body;
				outline: none;

				&:focus {
					border-color: $main-theme-color;
					box-shadow: 0 0 0 3px rgba($main-theme-color, 0.1);
				}

				&:disabled {
					background: $surface-light;
					cursor: not-allowed;
				}
			}
		}
	}

	.alerts-remove-email-btn {
		width: 34px;
		height: 34px;
		min-width: 34px;
		padding: 0;
		display: flex;
		align-items: center;
		justify-content: center;
		border: 1px solid $danger-bg;
		background: $surface-color;
		border-radius: 6px;
		color: $danger-color;
		cursor: pointer;
		transition: background 0.15s;

		i { font-size: 13px; }

		&:hover { background: $danger-bg; }

		&:disabled {
			opacity: 0.4;
			cursor: not-allowed;
		}
	}

	.alerts-email-actions {
		display: flex;
		align-items: center;
		gap: 1rem;
		flex-wrap: wrap;
        justify-content: space-between;
	}

	.alerts-add-btn {
		display: inline-flex;
		align-items: center;
		gap: 0.4rem;
		padding: 6px 14px;
		border: 1px solid $main-theme-color;
		background: $surface-color;
		border-radius: 6px;
		color: $main-theme-color;
		font-size: 13px;
		font-weight: 500;
		cursor: pointer;
		transition: background 0.15s;

		&:hover { background: $surface-primary-hover; }

		&:disabled {
			opacity: 0.4;
			cursor: not-allowed;
		}
	}

	// ── Alert frequency ───────────────────────────────────────────
	.alerts-select {
		width: 100%;
		height: 36px;
		padding: 0 0.75rem;
		border: 1px solid $border-input;
		border-radius: 6px;
		font-size: 13px;
		background: $surface-color;
		color: $text-body;
		cursor: pointer;
		outline: none;

		&:focus {
			border-color: $main-theme-color;
			box-shadow: 0 0 0 3px rgba($main-theme-color, 0.1);
		}

		&:disabled {
			background: $surface-light;
			cursor: not-allowed;
		}
	}

	// ── Test notifications ────────────────────────────────────────
	.alert-test-card {
		display: none;
	}

	.alerts-test-email-btn {
		display: inline-flex;
		align-items: center;
		gap: 0.5rem;
		padding: 7px 16px;
		border: 1px solid $main-theme-color;
		border-radius: 6px;
		background: transparent;
		color: $main-theme-color;
		font-size: 13px;
		font-weight: 500;
		cursor: pointer;
		transition: background 0.15s, opacity 0.15s;

		&:hover:not(:disabled) { background: $surface-primary-hover; }

		&:disabled {
			opacity: 0.5;
			cursor: not-allowed;
		}

		&.loading { opacity: 0.7; }
	}

	// ── Error levels (right card) ─────────────────────────────────
	.alerts-notify-card {
		height: 100%;
	}

	.alerts-error-levels {
		padding: 0.25rem 0;
	}

	.alerts-level-row {
		display: flex;
		align-items: center;
		gap: 1rem;
		padding: 0.65rem 1.25rem;
		border-bottom: 1px solid $surface-subtle;

		&:last-child { border-bottom: none; }

		&.pro-preview {
			border-top: 1px dashed $border-muted;
			border-bottom: none;
			padding: 0.75rem 1.25rem;

            .pro-badge {
                position: relative !important;
            }

			.preview-text {
				font-size: 13px;
				font-style: italic;
				color: $text-secondary;
				display: flex;
				align-items: center;
				gap: 6px;
			}
		}
	}

	.alerts-level-icon-wrap {
		width: 36px;
		height: 36px;
		min-width: 36px;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 8px;

		i { font-size: 16px; }
	}

	.alerts-level-info {
		flex: 1;

		.alerts-level-name {
			font-weight: 600;
			color: $text-heading;
			margin-bottom: 1px;
		}

		.alerts-level-desc {
			color: $text-secondary;
		}
	}

	// iOS-style toggle switch (mirrors settings page)
	.toggle-switch {
		display: flex;
		align-items: center;
		cursor: pointer;
		margin: 0;

		input[type="checkbox"] {
			position: absolute;
			opacity: 0;
			width: 0;
			height: 0;
			pointer-events: none;
		}

		.toggle-slider {
			position: relative;
			width: 44px;
			height: 24px;
			min-width: 44px;
			background: $toggle-off-bg;
			border-radius: 999px;
			transition: background 0.2s ease;
			flex-shrink: 0;

			&::after {
				content: '';
				position: absolute;
				top: 3px;
				left: 3px;
				width: 18px;
				height: 18px;
				background: $white;
				border-radius: 50%;
				transition: transform 0.2s ease;
				box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
			}
		}

		input[type="checkbox"]:checked ~ .toggle-slider {
			background: $main-theme-color;

			&::after { transform: translateX(20px); }
		}

		input[type="checkbox"]:disabled ~ .toggle-slider {
			opacity: 0.45;
			cursor: not-allowed;
		}
	}

	// Pro feature dimming
	.pro-feature-section {
		.togglers-group.pro-disabled {
			.alerts-level-row:not(.pro-preview) {
				opacity: 0.6;
				pointer-events: none;
			}
		}
	}

	// ── Footer ────────────────────────────────────────────────────
	.alerts-footer {
		display: flex;
		align-items: center;
		padding-top: 1.25rem;
		margin-top: 0.25rem;
		border-top: 1px solid $surface-subtle;
	}

	// Disable button: neutral until hover
	.btn.disable {
		color: $text-secondary;
		border-color: $border-input;
		background: transparent;

		&:hover {
			color: $danger-color-dark;
			border-color: $danger-color-dark;
			background: $danger-bg-light;
		}
	}

	// Form loading state
	.alerts-form.loading {
		pointer-events: none;
		opacity: 0.7;
	}

	// ── Responsive ───────────────────────────────────────────────
	@media (max-width: 900px) {
		.alerts-layout {
			grid-template-columns: 1fr;
		}
	}
}
