:root, [data-theme="dark"] {
    --bg-primary: #0A0B16;
    --bg-secondary: #14162A;
    --bg-card: #1A1C35;
    --bg-overlay: rgba(26, 28, 53, 0.7);
    --bg-overlay-light: rgba(255,255,255,0.05);
    --bg-header: rgba(20, 22, 42, 0.9);
    --bg-modal-backdrop: rgba(0,0,0,0.8);
    --accent-blue: #2D7AFF;
    --accent-blue-dark: #1A5FD8;
    --accent-cyan: #00F3FF;
    --accent-purple: #8B5CFF;
    --text-primary: #FFFFFF;
    --text-secondary: #A0A7C2;
    --text-tertiary: #6A7185;
    --border-color: #2A3148;
    --success: #00D46A;
    --warning: #FFA800;
    --danger: #FF4757;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
    --shadow: 0 20px 40px rgba(0,0,0,0.5);
    --message-time: rgba(255,255,255,0.6);
    --marquee-color: rgba(255,255,255,0.03);
}
[data-theme="light"] {
    --bg-primary: #F0F2F8;
    --bg-secondary: #FFFFFF;
    --bg-card: #FFFFFF;
    --bg-overlay: rgba(255,255,255,0.9);
    --bg-overlay-light: rgba(0,0,0,0.05);
    --bg-header: rgba(255,255,255,0.95);
    --bg-modal-backdrop: rgba(0,0,0,0.5);
    --text-primary: #1A1D2E;
    --text-secondary: #4A5168;
    --text-tertiary: #6A7185;
    --border-color: #D8DCE8;
    --shadow: 0 20px 40px rgba(0,0,0,0.12);
    --message-time: rgba(0,0,0,0.5);
    --marquee-color: rgba(0,0,0,0.04);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background-color: var(--bg-primary); color: var(--text-primary); line-height: 1.5; overflow-x: hidden; position: relative; display: flex; flex-direction: column; min-height: 100vh; }
.page-wrap { flex: 1; display: flex; flex-direction: column; }
.background-animation { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; overflow: hidden; background: radial-gradient(circle at 20% 30%, rgba(45, 122, 255, 0.05) 0%, transparent 30%), radial-gradient(circle at 80% 70%, rgba(139, 92, 255, 0.05) 0%, transparent 30%), radial-gradient(circle at 40% 80%, rgba(0, 243, 255, 0.03) 0%, transparent 25%); }
[data-theme="light"] .background-animation { background: radial-gradient(circle at 20% 30%, rgba(45, 122, 255, 0.08) 0%, transparent 35%), radial-gradient(circle at 80% 70%, rgba(139, 92, 255, 0.06) 0%, transparent 35%), radial-gradient(circle at 40% 80%, rgba(0, 243, 255, 0.05) 0%, transparent 28%); }
.marquee-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: space-around; pointer-events: none; }
.marquee { display: flex; white-space: nowrap; overflow: hidden; }
.marquee-content { display: flex; animation: marquee linear infinite; }
.marquee-content span { font-family: 'Montserrat', sans-serif; font-weight: 900; font-size: clamp(60px, 12vw, 100px); color: var(--marquee-color); white-space: nowrap; margin-right: 0; user-select: none; }
@keyframes marquee { 0% { transform: translateX(-50%); } 100% { transform: translateX(0); } }
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
header { background: var(--bg-header); padding: 16px 0; border-bottom: 1px solid var(--border-color); position: sticky; top: 0; z-index: 100; backdrop-filter: blur(10px); }
.header-content { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.logo { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.logo-main { font-family: 'Montserrat', sans-serif; font-weight: 900; font-size: 42px; background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo-main::after { content: 'P2P'; position: absolute; bottom: -20px; left: 0; font-size: 12px; font-weight: 600; letter-spacing: 3px; color: var(--text-secondary); }
.user-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.theme-toggle { min-width: 44px; }
.theme-toggle .theme-toggle-label { margin-left: 4px; }
.balance { background: var(--bg-overlay); padding: 10px 18px; border-radius: var(--radius-sm); display: flex; align-items: center; gap: 10px; font-weight: 600; border: 1px solid var(--border-color); }
.balance-amount { color: var(--accent-cyan); font-family: 'Roboto Mono', monospace; }
.tabs-navigation { background: var(--bg-secondary); border-bottom: 1px solid var(--border-color); margin-top: 20px; border-radius: var(--radius) var(--radius) 0 0; backdrop-filter: blur(10px); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabs { display: flex; flex-wrap: nowrap; min-width: min-content; }
.tab { padding: 14px 20px; font-weight: 600; cursor: pointer; transition: var(--transition); border-bottom: 3px solid transparent; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; white-space: nowrap; flex-shrink: 0; }
.tab:hover { color: var(--text-primary); background: var(--bg-overlay-light); }
.tab.active { color: var(--accent-cyan); border-bottom: 3px solid var(--accent-cyan); background: rgba(0, 243, 255, 0.08); }
.tab-badge { background: var(--accent-blue); color: white; font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.tab-content { display: none; }
.tab-content.active { display: block; }
.main-content { padding: 25px 0; }
.order-book { background: var(--bg-secondary); border-radius: 0 0 var(--radius) var(--radius); border: 1px solid var(--border-color); backdrop-filter: blur(10px); }
.order-book-header { padding: 18px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.order-book-title { font-size: 20px; font-weight: 700; }
.order-book-title span { color: var(--accent-cyan); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-btn { padding: 8px 14px; background: var(--bg-overlay); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 13px; cursor: pointer; transition: var(--transition); text-decoration: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; }
.filter-btn.active, .filter-btn.primary { background: var(--accent-blue); color: #fff; border-color: var(--accent-blue); }
.filter-btn:hover { background: var(--bg-overlay-light); color: var(--text-primary); }
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
.orders-table { width: 100%; border-collapse: collapse; min-width: 520px; }
.orders-table thead { background: var(--bg-overlay); }
.orders-table th { padding: 12px 14px; text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 13px; border-bottom: 1px solid var(--border-color); white-space: nowrap; }
.orders-table tbody tr { border-bottom: 1px solid var(--border-color); transition: var(--transition); }
.orders-table tbody tr:hover { background: rgba(45, 122, 255, 0.08); }
.orders-table td { padding: 12px 14px; font-size: 14px; }
.seller-cell { display: flex; align-items: center; gap: 10px; }
.seller-avatar { width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple)); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; }
.seller-avatar-img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; display: block; }
.seller-name { font-weight: 600; }
.seller-rating { font-size: 11px; color: var(--text-secondary); }
.seller-rating .stars { color: var(--warning); }
.amount-cell { font-family: 'Roboto Mono', monospace; font-weight: 500; }
.price-cell { font-family: 'Roboto Mono', monospace; color: var(--text-tertiary); font-size: 12px; }
.status-badge { padding: 3px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.status-badge.online { background: rgba(0, 212, 106, 0.15); color: var(--success); }
.status-badge.offline { background: rgba(255, 71, 87, 0.15); color: var(--danger); }
.buy-btn { padding: 8px 16px; background: var(--accent-blue); color: #fff; border: none; border-radius: var(--radius-sm); font-weight: 600; font-size: 13px; cursor: pointer; transition: var(--transition); display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.buy-btn:hover { background: var(--accent-blue-dark); transform: translateY(-1px); color: #fff; }
.buy-btn:disabled { background: var(--text-tertiary); cursor: not-allowed; color: #fff; }
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg-modal-backdrop); z-index: 1000; justify-content: center; align-items: center; backdrop-filter: blur(5px); padding: 16px; box-sizing: border-box; overflow-y: auto; }
.modal.active { display: flex; align-items: flex-start; padding-top: 24px; padding-bottom: 24px; }
.modal-content { background: var(--bg-secondary); border-radius: var(--radius); width: 100%; max-width: 480px; padding: 24px; border: 1px solid var(--border-color); box-shadow: var(--shadow); max-height: calc(100vh - 48px); overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-shrink: 0; }
.modal-title { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-secondary); font-size: 24px; cursor: pointer; padding: 4px; min-width: 44px; min-height: 44px; }
.modal-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-weight: 600; color: var(--text-secondary); font-size: 14px; }
.form-input { padding: 12px 14px; background: var(--bg-overlay); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 16px; width: 100%; box-sizing: border-box; min-height: 48px; }
.form-input:focus { outline: none; border-color: var(--accent-blue); }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { opacity: 0; appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.form-hint { font-size: 12px; color: var(--text-tertiary); }
.modal-actions { display: flex; gap: 12px; margin-top: 20px; }
.modal-btn { flex: 1; padding: 14px; border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; border: none; font-size: 14px; }
.modal-btn.primary { background: var(--accent-blue); color: #fff; min-height: 48px; }
.modal-btn.secondary { background: var(--bg-overlay); color: var(--text-primary); border: 1px solid var(--border-color); min-height: 48px; }
.order-item { background: var(--bg-overlay); border-radius: var(--radius-sm); padding: 16px; margin-bottom: 12px; border: 1px solid var(--border-color); }
.order-item h4 { margin-bottom: 5px; }
.order-status { padding: 6px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.order-status-active { background: rgba(0, 212, 106, 0.2); color: var(--success); }
.order-status-paused { background: rgba(255, 71, 87, 0.2); color: var(--danger); }
.status-processing { background: rgba(255, 168, 0, 0.15); color: var(--warning); }
.status-waiting { background: rgba(0, 243, 255, 0.15); color: var(--accent-cyan); }
.status-completed { background: rgba(0, 212, 106, 0.15); color: var(--success); }
.status-dispute { background: rgba(255, 71, 87, 0.15); color: var(--danger); }
.status-cancelled { background: rgba(255, 71, 87, 0.15); color: var(--danger); border: 1px solid rgba(255, 71, 87, 0.35); }
.chat-modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg-modal-backdrop); z-index: 1000; justify-content: center; align-items: center; padding: 12px; box-sizing: border-box; }
.chat-modal.active { display: flex; }
.chat-modal-content { background: var(--bg-secondary); border-radius: var(--radius); width: 100%; max-width: 800px; height: min(85vh, 600px); max-height: 90vh; display: flex; flex-direction: column; border: 1px solid var(--border-color); }
.chat-header { padding: 16px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.chat-messages { flex: 1; padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.message { max-width: 85%; padding: 12px 16px; border-radius: 18px; word-wrap: break-word; overflow-wrap: break-word; word-break: break-word; }
.message > div:first-child { white-space: pre-wrap; overflow-wrap: anywhere; }
.message.sent { align-self: flex-end; background: var(--accent-blue); border-bottom-right-radius: 5px; }
.message.received { align-self: flex-start; background: var(--bg-overlay); border-bottom-left-radius: 5px; }
.message-time { font-size: 11px; color: var(--message-time); margin-top: 5px; }
.chat-role-badge { display: inline-block; margin-right: 6px; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; background: rgba(255, 71, 87, 0.25); color: var(--danger); }
.message.sent .chat-role-badge { background: rgba(255,255,255,0.25); color: #fff; }
.message-attachment { margin-top: 8px; }
.message-attachment a { color: var(--accent-cyan); text-decoration: none; }
.message-attachment a:hover { text-decoration: underline; }
.chat-attachment-img { max-width: 200px; max-height: 150px; border-radius: var(--radius-sm); display: block; }
.chat-input-area { padding: 16px; border-top: 1px solid var(--border-color); flex-shrink: 0; }
.chat-input-form { display: flex; gap: 10px; }
.chat-input { flex: 1; min-width: 0; padding: 12px 16px; background: var(--bg-overlay); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-primary); resize: none; min-height: 48px; font-size: 16px; }
.chat-send-btn { padding: 12px 24px; background: var(--accent-blue); color: white; border: none; border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; flex-shrink: 0; min-height: 48px; }
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; }
.alert-error { background: rgba(255, 71, 87, 0.15); color: var(--danger); }
.alert-success { background: rgba(0, 212, 106, 0.15); color: var(--success); }

/* Toast (push) notifications */
#p2p-toast-container { position: fixed; top: 72px; left: 16px; right: 16px; z-index: 1100; display: flex; flex-direction: column; gap: 10px; max-width: 360px; margin: 0 auto; pointer-events: none; }
.p2p-toast { pointer-events: auto; padding: 14px 18px; border-radius: var(--radius-sm); font-size: 14px; box-shadow: var(--shadow); border: 1px solid var(--border-color); background: var(--bg-secondary); color: var(--text-primary); animation: p2p-toast-in 0.25s ease; display: flex; align-items: center; gap: 10px; }
.p2p-toast.success { background: rgba(0, 212, 106, 0.2); color: var(--success); border-color: var(--success); }
.p2p-toast.error { background: rgba(255, 71, 87, 0.2); color: var(--danger); border-color: var(--danger); }
.p2p-toast.info { background: rgba(45, 122, 255, 0.2); color: var(--accent-cyan); border-color: var(--accent-blue); }
.p2p-toast .p2p-toast-icon { font-size: 18px; }
@keyframes p2p-toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
.p2p-toast.hide { animation: p2p-toast-out 0.2s ease forwards; }
@keyframes p2p-toast-out { to { opacity: 0; transform: translateX(20px); } }

/* Confirm modal */
#p2p-confirm-modal .modal-content { max-width: 400px; }
#p2p-confirm-modal .p2p-confirm-text { margin-bottom: 20px; color: var(--text-secondary); line-height: 1.5; }
#p2p-confirm-modal .modal-actions { justify-content: flex-end; }
.card { background: var(--bg-card); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; border: 1px solid var(--border-color); }
.card h2 { margin-bottom: 16px; font-size: 18px; }
footer { background: var(--bg-header); padding: 20px 0; margin-top: auto; border-top: 1px solid var(--border-color); }
.footer-content { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px; }
.copyright { color: var(--text-tertiary); font-size: 13px; }

/* Responsive: mobile first */
.container { padding: 0 16px; max-width: 1200px; margin: 0 auto; }
@media (min-width: 600px) { .container { padding: 0 20px; } }
@media (min-width: 900px) { .container { padding: 0 24px; } }

@media (max-width: 768px) {
    .header-content { gap: 10px; }
    .logo-main { font-size: 32px; }
    .user-nav { justify-content: center; }
    .theme-toggle .theme-toggle-label { display: none; }
    .main-content { padding: 16px 0; }
    .order-book-header { padding: 14px 16px; flex-direction: column; align-items: flex-start; }
    .order-book-title { font-size: 18px; }
    .modal-content { padding: 20px; max-height: calc(100vh - 32px); }
    .modal-title { font-size: 17px; }
    .order-item { padding: 14px; }
    .order-item .filter-btn { margin-top: 8px; }
    .form-input, .modal-btn { min-height: 48px; }
    .chat-modal-content { height: 90vh; max-height: none; }
}
@media (max-width: 480px) {
    .container { padding: 0 12px; }
    .logo-main { font-size: 28px; }
    .user-nav { gap: 6px; }
    .filter-btn { padding: 8px 12px; font-size: 12px; }
    .tab { padding: 12px 16px; font-size: 14px; }
    .orders-table { min-width: 400px; }
    .orders-table th, .orders-table td { padding: 10px 12px; font-size: 13px; }
    .seller-cell { flex-wrap: wrap; }
    .seller-avatar-img { width: 24px; height: 24px; }
    .buy-btn { padding: 10px 14px; font-size: 13px; min-height: 44px; }
    .modal { padding: 12px; }
    .modal.active { padding-top: 16px; padding-bottom: 16px; }
    .modal-content { width: 100%; padding: 16px; border-radius: var(--radius-sm); }
    #p2p-toast-container { left: 12px; right: 12px; top: 64px; }
}

/* Tables: wrap in .table-wrap for horizontal scroll on small screens */
.table-wrap { -webkit-overflow-scrolling: touch; }
.table-wrap .orders-table { margin: 0; }
