/* CSS Custom Properties */
:root {
	--primary: #007aff;
	--success: #34c759;
	--danger: #ff3b30;
	--opponent: #5000fd;
	--background: #ffffff;
	--text: #000000;
	--border: #e5e5ea;
	--gray-light: #f5f5f7;
	--gray-dark: #555555;

	--padding: 16px;
	--padding-small: 8px;
	--border-radius: 8px;
	--transition: 0.2s ease;
}

/* Global Styles */
* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
	touch-action: manipulation;
}

body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
		Ubuntu, Cantarell, sans-serif;
	background-color: var(--gray-light);
	color: var(--text);
	line-height: 1.5;
	width: 100vw;
	height: 100vh;
	overflow-x: hidden;
	touch-action: manipulation;
}

button {
	touch-action: manipulation;
}

#app {
	height: 100vh;
}

/* Page Container */
.container {
	max-width: 600px;
	margin: 0 auto;
	padding: var(--padding);
}

/* Pages */
.page {
	display: block;
	animation: fadeIn 0.3s ease;
	height: 100%;
	overflow: auto;
}

.page.hidden {
	display: none;
}

@keyframes fadeIn {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

/* Card */
.card {
	background: var(--background);
	border-radius: var(--border-radius);
	padding: var(--padding);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Header */
.header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
}

.header h1 {
	flex: 1;
	font-size: 28px;
	font-weight: 600;
}

/* Slippage Slider */
.slippage-slider-container {
	display: flex;
	align-items: center;
	gap: 8px;
	flex: 1;
	justify-content: center;
}

.slippage-slider-container label {
	font-size: 12px;
	font-weight: 500;
	white-space: nowrap;
	color: var(--gray-dark);
	margin-bottom: 0;
}

.slippage-slider {
	width: 85vw;
	height: 4px;
	border-radius: 2px;
	background: var(--border);
	outline: none;
	-webkit-appearance: none;
	appearance: none;
	cursor: pointer;
}

.slippage-slider::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: var(--primary);
	cursor: pointer;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
	transition: background-color var(--transition);
}

.slippage-slider::-webkit-slider-thumb:active {
	background: #0051d5;
}

.slippage-slider::-moz-range-thumb {
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: var(--primary);
	cursor: pointer;
	border: none;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
	transition: background-color var(--transition);
}

.slippage-slider::-moz-range-thumb:active {
	background: #0051d5;
}

.slippage-slider::-moz-range-track {
	background: transparent;
	border: none;
}

.slippage-value {
	font-size: 12px;
	font-weight: 600;
	color: var(--primary);
	min-width: 32px;
	text-align: right;
}

/* Typography */
h1 {
	font-size: 32px;
	font-weight: 600;
	margin-bottom: 24px;
	text-align: center;
}

h2 {
	font-size: 20px;
	font-weight: 600;
	margin-bottom: 16px;
}

p {
	margin-bottom: 8px;
}

/* Forms */
.form-group {
	margin-bottom: 16px;
}

label {
	display: block;
	font-weight: 500;
	margin-bottom: 8px;
	font-size: 14px;
}

input[type="text"],
input[type="password"],
input[type="number"] {
	width: 100%;
	padding: 12px;
	border: 1px solid var(--border);
	border-radius: var(--border-radius);
	font-size: 16px;
	font-family: inherit;
	transition: border-color var(--transition);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus {
	outline: none;
	border-color: var(--primary);
	box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

/* Buttons */
.btn {
	padding: 12px 16px;
	border: none;
	border-radius: var(--border-radius);
	font-size: 16px;
	font-weight: 500;
	cursor: pointer;
	transition: all var(--transition);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
}

@keyframes pulse-glow {
	0% {
		box-shadow: 0 0 10px rgba(245, 11, 11, 0.4);
	}
	50% {
		box-shadow: 0 0 40px rgba(245, 11, 11, 0.8);
	}
	100% {
		box-shadow: 0 0 10px rgba(245, 11, 11, 0.4);
	}
}

.confirm-pending {
	background-color: var(--danger) !important; /* Amber color */
	color: white;
	animation: pulse-glow 0.75s infinite ease-in-out;
	transform: scale(1.02);
}

.btn:active {
	transform: scale(0.98);
}

.btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
	background-color: #0051d5;
}

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

.btn-danger:hover:not(:disabled) {
	background-color: #d50000;
}

.btn-opponent {
	background-color: var(--opponent);
	color: white;
}

.btn-opponent:hover:not(:disabled) {
	background-color: #6700d5;
}

.btn-enable {
	margin-bottom: 12px;
}

.btn-success {
	background-color: var(--success);
	color: white;
	flex: 1;
	padding: 16px;
	font-size: 18px;
}

.btn-success:hover:not(:disabled) {
	background-color: #30b050;
}

.btn-secondary {
	background-color: var(--border);
	color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
	background-color: #d5d5db;
}

.btn-full {
	width: 100%;
}

.btn-icon {
	width: 44px;
	height: 44px;
	padding: 0;
	border-radius: 50%;
	background-color: var(--gray-light);
	color: var(--text);
	font-size: 20px;
}

.btn-icon:hover {
	background-color: var(--border);
}

/* Search Box */
.search-box {
	margin-bottom: 16px;
}

.search-box input {
	width: 100%;
}

/* Markets List */
.markets-list {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.market-item {
	background: var(--background);
	border: 1px solid var(--border);
	border-radius: var(--border-radius);
	padding: var(--padding);
	cursor: pointer;
	transition: all var(--transition);
}

.market-item:hover {
	border-color: var(--primary);
	box-shadow: 0 4px 12px rgba(0, 122, 255, 0.15);
	transform: translateY(-2px);
}

.market-header {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	margin-bottom: 8px;
}

.market-title {
	font-weight: 600;
	font-size: 16px;
}

.market-status {
	font-size: 12px;
	padding: 4px 8px;
	border-radius: 4px;
	background-color: var(--gray-light);
	color: var(--gray-dark);
}

.market-subtitle {
	font-size: 14px;
	color: var(--gray-dark);
	margin-bottom: 8px;
}

.market-spread {
	display: flex;
	justify-content: space-between;
	font-size: 14px;
}

/* Event Items */
.event-item {
	background: var(--background);
	border: 1px solid var(--border);
	border-radius: var(--border-radius);
	padding: var(--padding);
	cursor: pointer;
	transition: all var(--transition);
	margin-bottom: 12px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.event-item:hover {
	border-color: var(--primary);
	box-shadow: 0 4px 12px rgba(0, 122, 255, 0.15);
	transform: translateY(-2px);
	background: var(--gray-light);
}

.event-item:active {
	transform: translateY(0);
}

.event-header {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	gap: 8px;
}

.event-title {
	font-weight: 600;
	font-size: 16px;
	flex: 1;
	line-height: 1.4;
}

.event-category {
	display: inline-block;
	padding: 4px 8px;
	background: var(--primary);
	color: white;
	border-radius: 4px;
	font-size: 11px;
	font-weight: 600;
	white-space: nowrap;
}

.event-subtitle {
	font-size: 14px;
	color: var(--gray-dark);
}

.event-details {
	display: flex;
	flex-direction: column;
	gap: 8px;
	font-size: 13px;
}

.event-ticker {
	display: flex;
	gap: 8px;
}

.event-ticker .label,
.event-competition .label {
	font-weight: 500;
	color: #8e8e93;
	min-width: 70px;
}

.event-ticker .value,
.event-competition .value {
	font-family: "Courier New", monospace;
	color: var(--text);
}

.event-competition {
	display: flex;
	gap: 8px;
}

.event-metadata {
	display: flex;
	gap: 16px;
	padding-top: 8px;
	border-top: 1px solid var(--border);
	font-size: 12px;
}

.metadata-item {
	display: flex;
	gap: 4px;
}

.metadata-item .label {
	font-weight: 500;
	color: #8e8e93;
}

.metadata-item .value {
	color: var(--text);
}

.event-status-badge {
	display: inline-block;
	padding: 4px 8px;
	background: var(--success);
	color: white;
	border-radius: 4px;
	font-size: 11px;
	font-weight: 600;
	text-transform: capitalize;
	align-self: flex-start;
}

/* Market Info */
.market-info {
	background: var(--background);
	border: 1px solid var(--border);
	border-radius: var(--border-radius);
	padding: var(--padding);
	margin-bottom: 24px;
}

.info-row {
	display: flex;
	justify-content: space-between;
	padding: 8px 0;
	border-bottom: 1px solid var(--border);
}

.info-row:last-child {
	border-bottom: none;
}

/* Orderbook Error */
.orderbook-error {
	background: var(--warning, #fff3cd);
	border: 1px solid var(--warning-border, #ffc107);
	border-radius: var(--border-radius);
	padding: 8px 12px;
	margin-bottom: 16px;
	font-size: 13px;
	color: var(--text);
	display: flex;
	align-items: center;
	gap: 8px;
}

.orderbook-error.hidden {
	display: none;
}

.selected-market-title {
	margin-bottom: 0;
}

/* Position Display */
.market-position {
	background: var(--gray-light);
	border-radius: var(--border-radius);
	margin-bottom: 4px;
}

.position-header {
	font-size: 14px;
	font-weight: 600;
	color: var(--gray-dark);
	margin-bottom: 12px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

.position-row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 12px;
}

.position-item {
	background: var(--background);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 12px;
	font-size: 13px;
	text-align: center;
	transition: all var(--transition);
	min-height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.position-item.empty {
	color: var(--gray-dark);
	background: #fafafa;
}

.position-item.held {
	background: #f0f8ff;
	border-color: var(--primary);
	color: var(--primary);
	font-weight: 500;
}

.position-item.yes-position.held {
	background: #f0fff4;
	border-color: var(--success);
	color: var(--success);
}

.position-item.no-position.held {
	background: #fff5f5;
	border-color: var(--danger);
	color: var(--danger);
}

/* Position Error */
.position-error {
	background: var(--warning, #fff3cd);
	border: 1px solid var(--warning-border, #ffc107);
	border-radius: var(--border-radius);
	padding: 8px 12px;
	margin-bottom: 16px;
	font-size: 13px;
	color: var(--text);
	display: flex;
	align-items: center;
	gap: 8px;
}

.position-error.hidden {
	display: none;
}

/* Settings Summary */
.settings-summary {
	background: var(--gray-light);
	border-radius: var(--border-radius);
	display: flex;
	flex-direction: row;
	justify-content: space-between;
}

.settings-summary p {
	margin-bottom: 8px;
	font-size: 14px;
}

.settings-summary strong {
	color: var(--primary);
}

/* Order Buttons */
.order-buttons {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	grid-template-rows: repeat(2, 1fr);
	gap: 12px;
	margin-bottom: 24px;
	height: 50vh;
}

.order-buttons .btn {
	width: 100%;
	height: 100%;
	padding: 16px;
	font-size: 16px;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	text-align: center;
	font-weight: 600;
}

.order-buttons .btn span {
	display: block;
	word-wrap: break-word;
	overflow-wrap: break-word;
}

/* Order Status */
.order-status {
	background: var(--gray-light);
	border-radius: var(--border-radius);
	padding: var(--padding);
	margin-bottom: 16px;
	text-align: center;
}

.order-status:not(.hidden) {
	display: block;
}

.order-status.success {
	background-color: rgba(52, 199, 89, 0.1);
	color: #30b050;
}

.order-status.error {
	background-color: rgba(255, 59, 48, 0.1);
	color: #e00;
}

.order-status.loading {
	background-color: rgba(0, 122, 255, 0.1);
	color: var(--primary);
}

/* Messages */
.loading,
.error-message {
	padding: 12px;
	border-radius: var(--border-radius);
	text-align: center;
}

.loading {
	background-color: rgba(0, 122, 255, 0.1);
	color: var(--primary);
}

.error-message {
	background-color: rgba(255, 59, 48, 0.1);
	color: #e00;
}

.error-message.hidden,
.loading.hidden {
	display: none;
}

/* Modal */
.modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1000;
}

.modal.hidden {
	display: none;
}

.modal-overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.4);
	z-index: 999;
}

.modal-content {
	position: relative;
	background: var(--background);
	border-radius: var(--border-radius);
	max-width: 500px;
	width: 90%;
	max-height: 90vh;
	overflow-y: auto;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
	z-index: 1000;
}

.modal-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: var(--padding);
	border-bottom: 1px solid var(--border);
}

.modal-header h2 {
	margin-bottom: 0;
}

.modal-body {
	padding: var(--padding);
}

.modal-actions {
	display: flex;
	flex-direction: column;
	gap: 12px;
	margin-top: 24px;
	padding-top: 16px;
	border-top: 1px solid var(--border);
}

.modal-actions > div {
	display: flex;
	gap: 12px;
}

.modal-actions .btn {
	flex: 1;
}

#reset-defaults-btn {
	width: 100%;
}

.market-orderbook {
	/* Uses flexbox to place YES and NO sides next to each other */
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	gap: 20px;
	padding: 10px 0;
	border-top: 1px solid #ddd;
}

.orderbook-side {
	/* Each side takes up half the available space */
	flex: 1;
	border: 1px solid #ccc;
	border-radius: 8px;
	padding: 12px;
}

/* Specific color for the 'Yes' side (often green for positive/buy) */
.yes-side .side-header {
	color: #10b981; /* Tailwind green-500 */
}

/* Specific color for the 'No' side (often red for negative/sell) */
.no-side .side-header {
	color: #ef4444; /* Tailwind red-500 */
}

/* --- Header Styling --- */

.side-header {
	font-size: 1.1rem;
	font-weight: bold;
	margin-bottom: 10px;
	text-align: center;
	text-transform: uppercase;
}

/* --- Grid Structure for Prices/Volumes --- */

.orderbook-grid {
	display: flex;
	flex-direction: column;
	gap: 8px; /* Space between the Bid and Ask levels */
}

.price-level {
	/* Defines a 3-column grid for Label, Value, and Volume */
	display: flex;
	justify-content: space-between;
	align-items: center;
	background-color: #f9fafb; /* Light background for rows */
	border-radius: 4px;
}

/* --- Content Alignment --- */

.price-label {
	/* Aligns "Bid/Ask" label to the left */
	text-align: left;
	font-weight: 500;
	display: flex;
	align-items: center;
}

.price-value {
	/* Centers the price value */
	text-align: center;
	font-weight: bold;
	color: #333;
}

.price-volume {
	/* Aligns volume to the right */
	text-align: right;
	font-size: 0.85rem;
	color: #6b7280; /* Neutral gray */
}

.extra-info {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
}

/* --- Icons --- */

.bid-icon,
.ask-icon {
	margin-right: 6px;
	font-size: 1rem; /* Adjust emoji size */
}

/* Responsive Design */
@media (max-width: 600px) {
	.container {
		padding: var(--padding-small);
	}

	h1 {
		font-size: 24px;
	}

	.header h1 {
		font-size: 20px;
	}

	.modal-content {
		width: 95%;
	}

	.orderbook-side {
		/* Removes padding on mobile if needed to save space */
		padding: 10px;
	}
}

/* Utilities */
.hidden {
	display: none !important;
}

/* Phase 3: API Integration Styles */

/* Market Controls */
.market-controls {
	display: flex;
	gap: 8px;
	margin-bottom: 16px;
	justify-content: space-between;
}

.market-controls button {
	flex: 1;
	font-size: 12px;
	padding: 8px 12px;
}

.btn-small {
	padding: 8px 12px;
	font-size: 12px;
}

/* Category Selector */
.category-selector {
	margin-bottom: 16px;
	display: flex;
	align-items: center;
	gap: 8px;
}

.category-selector label {
	font-weight: 600;
	font-size: 14px;
}

.category-selector select {
	flex: 1;
	padding: 8px 12px;
	border: 1px solid var(--border);
	border-radius: 6px;
	font-size: 14px;
	background-color: var(--background);
	cursor: pointer;
}

/* Credentials Modal */
#credentials-modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 2000;
	pointer-events: none;
}

#credentials-modal .modal-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	z-index: 1999;
	pointer-events: auto;
}

#credentials-modal .modal-content {
	background: white;
	border-radius: 8px;
	padding: 24px;
	max-width: 500px;
	width: 90%;
	max-height: 80vh;
	overflow-y: auto;
	box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
	z-index: 2001;
	pointer-events: auto;
	position: relative;
}

#credentials-modal.hidden {
	display: none;
}

.modal-info {
	background: #e3f2fd;
	border-left: 4px solid var(--primary);
	padding: 12px;
	border-radius: 4px;
	font-size: 13px;
	margin-bottom: 16px;
}

.modal-info a {
	color: var(--primary);
	text-decoration: none;
	font-weight: 600;
}

.modal-info a:hover {
	text-decoration: underline;
}

#credentials-form .form-group textarea {
	font-family: "Courier New", monospace;
	font-size: 12px;
	line-height: 1.4;
	resize: vertical;
}

#credentials-form .form-group small {
	display: block;
	margin-top: 4px;
	font-size: 12px;
	color: #8e8e93;
}

/* Order Details Display */
.order-details-section {
	background: #f5f5f7;
	border-radius: 8px;
	padding: 16px;
	margin: 16px 0;
	display: none;
}

.order-details-section:not(:empty) {
	display: block;
}

.order-detail-row {
	display: flex;
	justify-content: space-between;
	padding: 10px 0;
	border-bottom: 1px solid #e5e5ea;
	font-size: 14px;
}

.order-detail-row:last-child {
	border-bottom: none;
}

.order-detail-row .label {
	font-weight: 600;
	color: #333;
	min-width: 100px;
}

.order-detail-row .value {
	color: #666;
	font-family: "Courier New", monospace;
	text-align: right;
	flex: 1;
}

/* Enhanced Market List */
.market-item {
	background: var(--background);
	border: 1px solid var(--border);
	border-radius: var(--border-radius);
	padding: var(--padding);
	margin-bottom: 12px;
	cursor: pointer;
	transition: all var(--transition);
}

.market-item:hover {
	background-color: var(--gray-light);
	border-color: var(--primary);
	box-shadow: 0 2px 8px rgba(0, 122, 255, 0.1);
}

.market-header {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	margin-bottom: 8px;
}

.market-title {
	font-weight: 600;
	font-size: 15px;
	flex: 1;
	color: var(--text);
}

.market-price {
	font-weight: 600;
	color: var(--primary);
	font-size: 14px;
	min-width: 80px;
	text-align: right;
}

.market-subtitle {
	font-size: 13px;
	color: #8e8e93;
	margin-bottom: 8px;
}

.market-details {
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 12px;
	gap: 12px;
}

.market-bid-ask {
	display: flex;
	gap: 12px;
	flex: 1;
	color: #666;
}

.market-bid-ask .bid {
	color: #d32f2f;
}

.market-bid-ask .ask {
	color: #388e3c;
}

.market-spread {
	font-size: 12px;
	color: #8e8e93;
}

.market-status-badge {
	display: inline-block;
	padding: 4px 8px;
	background: var(--success);
	color: white;
	border-radius: 4px;
	font-size: 11px;
	font-weight: 600;
	text-transform: capitalize;
}

/* Loading Spinner */
.loading-spinner {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background: rgba(255, 255, 255, 0.95);
	z-index: 2000;
}

.loading-spinner.hidden {
	display: none;
}

.spinner {
	width: 40px;
	height: 40px;
	border: 4px solid #e5e5ea;
	border-top-color: var(--primary);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

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

#loading-spinner-text {
	margin-top: 16px;
	color: var(--text);
	font-size: 14px;
}

/* Error Messages - Enhanced */
.error-message {
	background: #ffebee;
	color: #c62828;
	padding: 12px;
	border-radius: 6px;
	font-size: 14px;
	margin-bottom: 12px;
	border-left: 4px solid #c62828;
}

.error-message.hidden {
	display: none;
}

/* Utilities */
.hidden {
	display: none !important;
}

/* Border Glow Effects */
body.border-glow-success {
	animation: glowPulseSuccess 0.8s ease-out;
}

body.border-glow-error {
	animation: glowPulseError 0.8s ease-out;
}

@keyframes glowPulseSuccess {
	0% {
		box-shadow: inset 0 0 0 0px var(--success);
	}
	30% {
		box-shadow: inset 0 0 40px 8px var(--success);
	}
	100% {
		box-shadow: inset 0 0 0 0px var(--success);
	}
}

@keyframes glowPulseError {
	0% {
		box-shadow: inset 0 0 0 0px var(--danger);
	}
	30% {
		box-shadow: inset 0 0 40px 8px var(--danger);
	}
	100% {
		box-shadow: inset 0 0 0 0px var(--danger);
	}
}
