/* Telegram Web App Styles */
:root {
	--tg-theme-bg-color: #ffffff;
	--tg-theme-text-color: #000000;
	--tg-theme-hint-color: #999999;
	--tg-theme-link-color: #2481cc;
	--tg-theme-button-color: #2481cc;
	--tg-theme-button-text-color: #ffffff;
	--tg-theme-secondary-bg-color: #f1f1f1;
	--tg-theme-accent-color: #2481cc;
	--tg-theme-destructive-text-color: #ff3b30;
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

/* Pull-to-refresh effect to prevent WebApp closing */
.pull-to-refresh-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 0;
    background: linear-gradient(135deg, #FF6B35 0%, #F7931E 100%);
    z-index: 9999;
    transition: height 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    overflow: hidden;
}

.pull-to-refresh-container.active {
    height: 60px;
}

.pull-to-refresh-indicator {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.pull-to-refresh-container.active .pull-to-refresh-indicator {
    opacity: 1;
}

/* Main content with pull-to-refresh support */
.main-content {
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom) + 20px);
    max-width: 600px;
    margin: 0 auto;
    /* Allow horizontal scroll if needed */
    overflow-x: hidden;
    /* Enable pull-to-refresh */
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    /* Smooth transition for pull-to-refresh */
    transition: transform 0.3s ease;
}

/* Container for pull-to-refresh animation */
.container-fluid {
    transition: transform 0.3s ease;
}

/* Body styles for pull-to-refresh */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--tg-theme-bg-color, #ffffff);
    color: var(--tg-theme-text-color, #000000);
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Prevent zoom and ensure proper viewport */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    /* Enable pull-to-refresh behavior */
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}

/* Site Header */
.site-header {
	background: linear-gradient(135deg, #FF6B35 0%, #F7931E 100%);
	padding: 16px 20px;
	padding-top: max(16px, env(safe-area-inset-top) + 16px);
	text-align: center;
	box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
	position: sticky;
	top: 0;
	z-index: 100;
}

.site-title {
	font-size: 24px;
	font-weight: 700;
	color: white;
	margin: 0;
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Blockchain Tabs */
.blockchain-tabs {
	display: flex;
	background: var(--tg-theme-secondary-bg-color, #f8f9fa);
	border-radius: 12px;
	padding: 4px;
	margin-bottom: 16px;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.blockchain-tab {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	padding: 12px 8px;
	background: transparent;
	border: none;
	border-radius: 8px;
	color: var(--tg-theme-hint-color);
	font-size: 12px;
	font-weight: 500;
	cursor: pointer;
	transition: all 0.2s ease;
	/* Prevent text selection */
	-webkit-user-select: none;
	user-select: none;
}

.blockchain-tab.active {
	background: linear-gradient(135deg, #FF6B35 0%, #F7931E 100%);
	color: white;
	box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
}

.blockchain-tab i {
	font-size: 16px;
}

.blockchain-tab span {
	font-size: 11px;
	font-weight: 600;
}

/* Sub-tabs (for Tron) */
.sub-tabs {
	display: flex;
	background: var(--tg-theme-secondary-bg-color, #f8f9fa);
	border-radius: 12px;
	padding: 4px;
	margin-bottom: 16px;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.sub-tab {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 10px 8px;
	background: transparent;
	border: none;
	border-radius: 8px;
	color: var(--tg-theme-hint-color);
	font-size: 13px;
	font-weight: 500;
	cursor: pointer;
	transition: all 0.2s ease;
	-webkit-user-select: none;
	user-select: none;
}

.sub-tab.active {
	background: linear-gradient(135deg, #2481cc 0%, #1a5f9e 100%);
	color: white;
	box-shadow: 0 2px 8px rgba(36, 129, 204, 0.3);
}

.sub-tab i {
	font-size: 14px;
}

/* Service Content */
.service-content {
	position: relative;
}

.service-panel {
	display: none;
	animation: fadeIn 0.3s ease;
}

.service-panel.active {
	display: block;
}

@keyframes fadeIn {
	from { opacity: 0; transform: translateY(10px); }
	to { opacity: 1; transform: translateY(0); }
}

/* Title Section */
.title-section {
	text-align: center;
	margin-bottom: 24px;
}

.main-title {
	font-size: 24px;
	font-weight: 700;
	margin-bottom: 8px;
	color: var(--tg-theme-text-color);
}

.subtitle {
	font-size: 16px;
	color: var(--tg-theme-hint-color);
	margin: 0;
}

/* Form Card */
.form-card {
	background: var(--tg-theme-secondary-bg-color, #f8f9fa);
	border-radius: 16px;
	overflow: hidden;
	margin-bottom: 24px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card-header {
	background: linear-gradient(135deg, #FF6B35 0%, #F7931E 100%);
	padding: 20px;
	text-align: center;
}

.card-title {
	font-size: 18px;
	font-weight: 600;
	color: white;
	margin: 0;
}

.card-body {
	padding: 24px;
}

/* Input with action buttons */
.input-with-action {
	display: flex;
	align-items: center;
	position: relative;
}

.input-with-action .form-control {
	flex-grow: 1;
	padding-right: 50px; /* Space for QR button */
}

.input-with-action .actions {
	position: absolute;
	right: 8px;
	display: flex;
	gap: 4px;
}

.action-btn {
	background: var(--tg-theme-secondary-bg-color, #e9ecef);
	border: 1px solid var(--tg-theme-secondary-bg-color, #e9ecef);
	border-radius: 6px;
	padding: 8px;
	font-size: 14px;
	color: var(--tg-theme-text-color);
	cursor: pointer;
	transition: background-color 0.2s ease;
	-webkit-user-select: none;
	user-select: none;
}

.action-btn:hover {
	background: var(--tg-theme-hint-color);
}

.qr-scan-btn {
	color: #FF6B35;
}

.qr-scan-btn:hover {
	background: rgba(255, 107, 53, 0.1);
}

/* Price/Stars */
.total-cost {
	background: rgba(36, 129, 204, 0.1);
	padding: 16px;
	border-radius: 8px;
	margin: 20px 0;
	border: 1px solid rgba(36, 129, 204, 0.2);
}

.total-cost-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 8px;
}

.total-cost-item:last-child { margin-bottom: 0; }

.total-cost-label {
	font-size: 14px;
	color: var(--tg-theme-text-color);
	font-weight: 500;
}

.total-cost-value {
	font-size: 16px;
	color: #2481cc;
	font-weight: 600;
}

/* Form basics */
.form-group { margin-bottom: 20px; }

.form-label {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 14px;
	font-weight: 600;
	color: var(--tg-theme-text-color);
	margin-bottom: 8px;
}

.form-label i { color: #FF6B35; font-size: 16px; }

.form-control {
	width: 100%;
	padding: 12px 16px;
	border: 2px solid var(--tg-theme-secondary-bg-color, #e9ecef);
	border-radius: 8px;
	font-size: 16px;
	background: white;
	color: var(--tg-theme-text-color);
	transition: border-color 0.2s ease;
	/* Prevent zoom on iOS */
	font-size: 16px;
	/* Ensure consistent font rendering */
	font-family: inherit;
	line-height: 1.4;
}

.form-control:focus {
	outline: none;
	border-color: #FF6B35;
	box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.form-hint { font-size: 12px; color: var(--tg-theme-hint-color); margin-top: 4px; }

/* Quick Buttons */
.quick-buttons { display: flex; gap: 8px; margin-bottom: 12px; }

.quick-btn {
	flex: 1;
	padding: 12px 8px;
	background: var(--tg-theme-secondary-bg-color, #f8f9fa);
	border: 2px solid var(--tg-theme-secondary-bg-color, #e9ecef);
	border-radius: 8px;
	color: var(--tg-theme-text-color);
	font-size: 14px;
	font-weight: 500;
	cursor: pointer;
	transition: all 0.2s ease;
	-webkit-user-select: none;
	user-select: none;
}

.quick-btn.active {
	background: linear-gradient(135deg, #FF6B35 0%, #F7931E 100%);
	border-color: #FF6B35;
	color: white;
	box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
}

.quick-btn .amount { font-weight: 600; }

/* Custom Amount */
.custom-amount { margin-top: 12px; }

.input-group { 
	display: flex; 
	align-items: center;
	/* Ensure consistent width */
	width: 100%;
}

.input-group .form-control {
	border-top-right-radius: 0;
	border-bottom-right-radius: 0;
	border-right: none;
	flex: 1;
	/* Fixed width for consistent sizing */
	min-width: 0;
	/* Set fixed width to match input-group-text */
	width: calc(100% - 100px);
}

.input-group-text {
	padding: 12px 16px;
	background: var(--tg-theme-secondary-bg-color, #f8f9fa);
	border: 2px solid var(--tg-theme-secondary-bg-color, #e9ecef);
	border-left: none;
	border-top-right-radius: 8px;
	border-bottom-right-radius: 8px;
	color: var(--tg-theme-hint-color);
	font-size: 16px;
	font-weight: 500;
	/* Fixed width for consistency - all currency labels same width */
	width: 100px;
	text-align: center;
	white-space: nowrap;
	flex-shrink: 0;
}

/* Submit Section */
.submit-section { margin-top: 24px; }

.submit-btn {
	width: 100%;
	padding: 16px;
	background: linear-gradient(135deg, #FF6B35 0%, #F7931E 100%);
	border: none;
	border-radius: 12px;
	color: white;
	font-size: 16px;
	font-weight: 600;
	cursor: pointer;
	transition: all 0.2s ease;
	box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
	-webkit-user-select: none;
	user-select: none;
}

.submit-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(255, 107, 53, 0.4); }
.submit-btn:active { transform: translateY(0); }

/* Loading Overlay */
.loading-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.7);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1000;
}

.loading-content {
	background: white;
	padding: 32px;
	border-radius: 16px;
	text-align: center;
	max-width: 300px;
	margin: 20px;
}

.spinner {
	width: 40px;
	height: 40px;
	border: 4px solid var(--tg-theme-secondary-bg-color, #f8f9fa);
	border-top: 4px solid #FF6B35;
	border-radius: 50%;
	animation: spin 1s linear infinite;
	margin: 0 auto 16px;
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.loading-content h5 { font-size: 18px; font-weight: 600; margin-bottom: 8px; color: var(--tg-theme-text-color); }
.loading-content p { font-size: 14px; color: var(--tg-theme-hint-color); margin: 0; }

/* Toasts */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 1001; max-width: 300px; }
.toast { background: white; border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); margin-bottom: 8px; overflow: hidden; animation: slideIn 0.3s ease; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast-header { display: flex; align-items: center; gap: 8px; padding: 12px 16px; background: #ff3b30; color: white; font-size: 14px; font-weight: 600; }
.toast-close { background: none; border: none; color: white; font-size: 18px; cursor: pointer; margin-left: auto; padding: 0; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; }
.toast-body { padding: 12px 16px; font-size: 14px; color: var(--tg-theme-text-color); }

/* Responsive */
@media (max-width: 480px) {
	.site-header {
		padding: 12px 16px;
		padding-top: max(12px, env(safe-area-inset-top) + 12px);
	}
	.site-title { font-size: 20px; }
	.main-content { 
		padding: 16px;
		padding-bottom: max(16px, env(safe-area-inset-bottom) + 16px);
	}
	.blockchain-tab { padding: 10px 6px; font-size: 11px; }
	.blockchain-tab i { font-size: 14px; }
	.sub-tab { padding: 8px 6px; font-size: 12px; }
	.sub-tab i { font-size: 12px; }
	.card-body { padding: 20px; }
	.quick-buttons { flex-direction: column; gap: 6px; }
	.quick-btn { padding: 10px; }
	.input-group-text { 
		width: 80px; 
		padding: 12px 12px; 
		font-size: 16px;
	}
	.input-group .form-control { 
		width: calc(100% - 80px); 
		font-size: 16px;
	}
	.action-btn { padding: 6px; font-size: 12px; }
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
	:root { --tg-theme-bg-color: #1a1a1a; --tg-theme-text-color: #ffffff; --tg-theme-hint-color: #888888; --tg-theme-secondary-bg-color: #2a2a2a; }
	.form-control { background: #2a2a2a; color: white; }
	.input-group-text { background: #2a2a2a; color: #888888; }
	.quick-btn { background: #2a2a2a; color: white; }
	.loading-content { background: #2a2a2a; color: white; }
	.toast { background: #2a2a2a; color: white; }
	.action-btn { background: #2a2a2a; color: white; border-color: #3a3a3a; }
}

/* Allow pull-to-refresh and overscroll for Telegram Web App */
html, body {
	overscroll-behavior: auto;
	-webkit-overflow-scrolling: touch;
}

/* Ensure proper touch targets */
button, input, select, textarea {
	touch-action: manipulation;
}
