/* ==========================================================================
   STABLEARB — PREMIUM DARK DASHBOARD
   ========================================================================== */

/* === Design Tokens === */
:root {
    /* Backgrounds */
    --bg-base: #06090f;
    --bg-surface: #0d1117;
    --bg-elevated: #161b22;
    --bg-card: rgba(22, 27, 34, 0.72);
    --bg-card-hover: rgba(30, 38, 52, 0.88);
    --bg-inset: rgba(0, 0, 0, 0.28);

    /* Borders */
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);
    --border-accent: rgba(99, 102, 241, 0.35);

    /* Text */
    --text-1: #f0f2f5;
    --text-2: #8b949e;
    --text-3: #484f58;

    /* Accents */
    --accent: #818cf8;       /* Indigo-400 */
    --accent-glow: rgba(99, 102, 241, 0.25);
    --cyan: #22d3ee;
    --emerald: #34d399;
    --emerald-glow: rgba(52, 211, 153, 0.2);
    --rose: #fb7185;
    --rose-glow: rgba(251, 113, 133, 0.2);
    --amber: #fbbf24;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-heading: 'Outfit', var(--font-sans);
    --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

    /* Geometry */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Effects */
    --blur: blur(16px);
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.32);
    --shadow-glow: 0 0 20px var(--accent-glow);
    --ease: cubic-bezier(0.4, 0, 0.2, 1);

    /* Layers */
    --z-topbar: 40;
    --z-popover: 80;
    --z-modal: 120;
    --z-toast: 140;
}

/* Light mode */
body.light-mode {
    --bg-base: #f6f8fa;
    --bg-surface: #ffffff;
    --bg-elevated: #f0f2f5;
    --bg-card: rgba(255, 255, 255, 0.82);
    --bg-card-hover: rgba(255, 255, 255, 0.95);
    --bg-inset: rgba(0, 0, 0, 0.04);
    --border: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(0, 0, 0, 0.14);
    --border-accent: rgba(99, 102, 241, 0.25);
    --text-1: #1f2937;
    --text-2: #6b7280;
    --text-3: #d1d5db;
    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.06);
}

/* === Reset === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background: var(--bg-base);
    color: var(--text-1);
    font-family: var(--font-sans);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Ambient gradient glow */
body::before {
    content: '';
    position: fixed;
    top: -20%;
    left: -10%;
    width: 60%;
    height: 60%;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.06) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}
body::after {
    content: '';
    position: fixed;
    bottom: -20%;
    right: -10%;
    width: 50%;
    height: 50%;
    background: radial-gradient(circle, rgba(34, 211, 238, 0.04) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

body.light-mode::before,
body.light-mode::after {
    opacity: 0.5;
}

/* === App Shell === */
.app-shell {
    position: relative;
    z-index: 1;
    max-width: 1560px;
    margin: 0 auto;
    padding: 16px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 100vh;
}

/* === Topbar === */
.topbar {
    position: relative;
    z-index: var(--z-topbar);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-card);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

.topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-mark {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon-wrap {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--cyan));
    color: white;
    font-size: 16px;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
    flex-shrink: 0;
}

.brand-label {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.brand-name {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 18px;
    letter-spacing: -0.03em;
}

.gradient-text {
    background: linear-gradient(135deg, var(--accent) 0%, var(--cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-sub {
    font-size: 11px;
    color: var(--text-2);
    letter-spacing: 0.02em;
}

/* Live badge */
.live-badge {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 14px;
    border-radius: 20px;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
    transition: all 0.3s var(--ease);
}

.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    transition: all 0.3s var(--ease);
}

.live-badge.connected .live-dot {
    background: var(--emerald);
    box-shadow: 0 0 8px var(--emerald);
    animation: pulse 1.8s infinite;
}

.live-badge.connected {
    color: var(--emerald);
    border-color: rgba(52, 211, 153, 0.2);
}

.live-badge.disconnected .live-dot {
    background: var(--rose);
    box-shadow: 0 0 8px var(--rose);
}

.live-badge.disconnected {
    color: var(--rose);
}

/* Buttons */
.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-inset);
    color: var(--text-2);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s var(--ease);
}

.icon-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-1);
    transform: scale(1.05);
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 13px;
    border: none;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    background: linear-gradient(135deg, var(--accent), #6366f1);
    color: white;
    box-shadow: 0 3px 12px rgba(99, 102, 241, 0.3);
}

.action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 16px rgba(99, 102, 241, 0.4);
}

.action-btn.accent {
    background: var(--cyan);
    color: #030712;
    box-shadow: 0 3px 12px rgba(34, 211, 238, 0.25);
}

.action-btn.accent:hover {
    background: #67e8f9;
}

/* === Push Control Wrapper === */
.push-control-wrapper {
    position: relative;
    z-index: 1;
}

.push-control-wrapper.open {
    z-index: var(--z-popover);
}

.push-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid rgba(52, 211, 153, 0.22);
    background: rgba(52, 211, 153, 0.08);
    color: var(--emerald);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s var(--ease);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.push-toggle-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.1) 0%, rgba(34, 211, 238, 0.05) 100%);
    opacity: 0;
    transition: opacity 0.3s var(--ease);
}

.push-toggle-btn:hover::before {
    opacity: 1;
}

.push-toggle-btn:hover {
    border-color: rgba(52, 211, 153, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(52, 211, 153, 0.15);
}

.push-btn-indicator {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--emerald);
    box-shadow: 0 0 8px var(--emerald);
    animation: pulse 1.8s infinite;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.push-toggle-btn .push-btn-label {
    position: relative;
    z-index: 1;
}

.push-toggle-btn i {
    position: relative;
    z-index: 1;
}

.push-btn-arrow {
    font-size: 9px;
    transition: transform 0.3s var(--ease);
    opacity: 0.7;
}

.push-control-wrapper.open .push-btn-arrow {
    transform: rotate(180deg);
}

.push-toggle-btn.paused {
    border-color: rgba(251, 113, 133, 0.28);
    background: rgba(251, 113, 133, 0.08);
    color: var(--rose);
}

.push-toggle-btn.paused::before {
    background: linear-gradient(135deg, rgba(251, 113, 133, 0.1) 0%, rgba(251, 113, 133, 0.05) 100%);
}

.push-toggle-btn.paused:hover {
    border-color: rgba(251, 113, 133, 0.45);
    box-shadow: 0 4px 12px rgba(251, 113, 133, 0.15);
}

.push-toggle-btn.paused .push-btn-indicator {
    background: var(--rose);
    box-shadow: 0 0 8px var(--rose);
    animation: none;
}

/* === Push Panel Dropdown === */
.push-panel {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    width: 340px;
    background: var(--bg-surface);
    backdrop-filter: blur(24px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.38), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px) scale(0.98);
    transform-origin: top right;
    transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
    z-index: 2;
    overflow: hidden;
    isolation: isolate;
}

.push-control-wrapper.open .push-panel {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.push-panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--border);
}

.push-panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 14px;
    color: var(--text-1);
}

.push-panel-title i {
    color: var(--accent);
    font-size: 13px;
}

.push-panel-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--bg-inset);
    border-radius: 50%;
    color: var(--text-2);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.push-panel-close:hover {
    background: var(--bg-elevated);
    color: var(--text-1);
}

.push-panel-section {
    padding: 12px 18px;
}

.push-panel-section-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
}

.push-panel-section-title i {
    font-size: 12px;
}

.push-panel-divider {
    height: 1px;
    background: var(--border);
    margin: 0 18px;
}

/* Push Row */
.push-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--bg-inset);
    transition: background 0.2s var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.push-row:hover {
    background: var(--bg-elevated);
}

.push-row-global {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.06) 0%, rgba(34, 211, 238, 0.04) 100%);
    border: 1px solid rgba(99, 102, 241, 0.1);
}

.push-row-global:hover {
    border-color: rgba(99, 102, 241, 0.2);
}

.push-row-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.push-row-name {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-1);
}

.push-row-desc {
    font-size: 11px;
    color: var(--text-3);
}

.push-device-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.push-device-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    min-height: 48px;
    border-radius: var(--radius-sm);
    background: var(--bg-inset);
    transition: all 0.2s var(--ease);
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}

.push-device-row:hover {
    background: var(--bg-elevated);
}

.push-device-row.disabled {
    opacity: 0.6;
}

.push-device-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.push-device-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), var(--cyan));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 13px;
    flex-shrink: 0;
}

.push-device-meta {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.push-device-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-1);
}

.push-device-key {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-3);
}

.push-panel-footer {
    padding: 10px 18px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.push-panel-reset-hint {
    font-size: 10px;
    color: var(--text-3);
    font-family: var(--font-mono);
}

.push-panel-time {
    font-size: 10px;
    color: var(--text-3);
    font-family: var(--font-mono);
}

/* === Toggle Switch (iOS-style) === */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    cursor: pointer;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    transition: all 0.35s var(--ease);
}

.switch-slider::before {
    content: '';
    position: absolute;
    height: 22px;
    width: 22px;
    left: 2px;
    bottom: 2px;
    background: var(--text-2);
    border-radius: 50%;
    transition: all 0.35s var(--ease);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.switch input:checked + .switch-slider {
    background: linear-gradient(135deg, var(--emerald), #2dd4bf);
    border-color: rgba(52, 211, 153, 0.4);
    box-shadow: 0 0 16px rgba(52, 211, 153, 0.2);
}

.switch input:checked + .switch-slider::before {
    transform: translateX(20px);
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.switch:active .switch-slider::before {
    width: 26px;
}

.switch:hover .switch-slider {
    border-color: rgba(255, 255, 255, 0.2);
}

.switch input:checked:hover + .switch-slider {
    border-color: rgba(52, 211, 153, 0.6);
}

/* Light mode switch adjustments */
body.light-mode .switch-slider {
    background: rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.12);
}

body.light-mode .switch-slider::before {
    background: #9ca3af;
}

body.light-mode .switch input:checked + .switch-slider {
    background: linear-gradient(135deg, #059669, #0d9488);
    border-color: rgba(5, 150, 105, 0.4);
}

body.light-mode .switch input:checked + .switch-slider::before {
    background: white;
}

/* === Password Modal === */
.password-modal-panel {
    max-width: 380px;
}

.password-modal-panel .form-label {
    display: flex;
    align-items: center;
    gap: 6px;
}

body.light-mode .push-panel {
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.04) inset;
}

body.light-mode .push-toggle-btn.paused .push-btn-indicator {
    background: #e11d48;
    box-shadow: 0 0 8px rgba(225, 29, 72, 0.4);
}

/* Push Panel - Mobile overlay backdrop */
.push-panel-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1;
    background: rgba(3, 7, 18, 0.52);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s var(--ease);
}

.push-control-wrapper.open .push-panel-backdrop {
    opacity: 1;
    pointer-events: auto;
}

body.light-mode .push-panel-backdrop {
    background: rgba(15, 23, 42, 0.18);
}

/* === Sections === */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
}

.section {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.section-head-left,
.section-head-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-icon {
    font-size: 16px;
    color: var(--accent);
}

.section-head h2 {
    font-family: var(--font-heading);
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* Chips */
.chip {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.chip-live {
    background: rgba(52, 211, 153, 0.12);
    color: var(--emerald);
    border: 1px solid rgba(52, 211, 153, 0.2);
    animation: chipPulse 2s infinite;
}

@keyframes chipPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Toggle Group */
.toggle-group {
    display: flex;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.toggle-btn {
    padding: 6px 16px;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    transition: all 0.2s var(--ease);
    position: relative;
}

.toggle-btn.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.toggle-btn:not(.active):hover {
    color: var(--text-1);
    background: rgba(255, 255, 255, 0.04);
}

/* === Arbitrage Scroll Area === */
.arb-scroll-area {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 6px;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    min-height: 100px;
}

.arb-scroll-area::-webkit-scrollbar {
    height: 5px;
}
.arb-scroll-area::-webkit-scrollbar-track {
    background: transparent;
}
.arb-scroll-area::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 10px;
}

.arb-empty-state {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 24px 20px;
    color: var(--text-2);
    font-size: 13px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    width: 100%;
    justify-content: center;
}

/* === Cross-Exchange Arb Card === */
.cross-card {
    flex: 0 0 320px;
    scroll-snap-align: start;
    background: var(--bg-card);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: all 0.25s var(--ease);
    position: relative;
    overflow: hidden;
}

.cross-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-card);
}

.cross-card.has-arb {
    border-color: rgba(52, 211, 153, 0.3);
    box-shadow: 0 0 20px rgba(52, 211, 153, 0.08);
}

.cross-card.has-arb::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--emerald), var(--cyan));
}

.cross-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cross-pair-name {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.02em;
}

.profit-tag {
    padding: 3px 8px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
}

.profit-tag.positive {
    background: var(--emerald-glow);
    color: var(--emerald);
    border: 1px solid rgba(52, 211, 153, 0.25);
}

.profit-tag.neutral {
    background: var(--bg-inset);
    color: var(--text-2);
    border: 1px solid var(--border);
}

.cross-card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cross-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-inset);
    border-radius: 6px;
    font-size: 12px;
}

.cross-label {
    color: var(--text-2);
    display: flex;
    align-items: center;
    gap: 5px;
}

.cross-label i {
    font-size: 10px;
}

.cross-val {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 13px;
}

.cross-ex {
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 11px;
    color: var(--cyan);
    background: rgba(34, 211, 238, 0.08);
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 5px;
    text-transform: capitalize;
}

/* === Triangular Arb Card === */
.tri-card {
    flex: 0 0 340px;
    scroll-snap-align: start;
    background: var(--bg-card);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all 0.25s var(--ease);
    position: relative;
    overflow: hidden;
}

.tri-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-card);
}

.tri-card.has-profit {
    border-color: rgba(52, 211, 153, 0.3);
    box-shadow: 0 0 20px rgba(52, 211, 153, 0.08);
}

.tri-card.has-profit::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--emerald));
}

.tri-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tri-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tri-loop-name {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 13px;
}

.tri-ex-chip {
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(34, 211, 238, 0.08);
    color: var(--cyan);
    border: 1px solid rgba(34, 211, 238, 0.15);
}

.tri-route {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    color: var(--text-2);
    padding: 5px 8px;
    background: var(--bg-inset);
    border-radius: 5px;
    letter-spacing: 0.01em;
}

.tri-steps {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.tri-step {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-2);
}

.tri-step-price {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-2);
}

/* === Uniswap Quote Card === */
.quote-card {
    flex: 0 0 380px;
    scroll-snap-align: start;
    background: var(--bg-card);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all 0.25s var(--ease);
    position: relative;
    overflow: hidden;
}

.quote-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-card);
}

.quote-card.is-live {
    border-color: rgba(34, 211, 238, 0.24);
    box-shadow: 0 0 20px rgba(34, 211, 238, 0.07);
}

.quote-card.is-live::before,
.quote-card.has-error::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
}

.quote-card.is-live::before {
    background: linear-gradient(90deg, var(--cyan), var(--emerald));
}

.quote-card.has-error::before {
    background: linear-gradient(90deg, var(--amber), var(--rose));
}

.quote-card-head,
.quote-card-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.quote-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.quote-chain {
    padding: 2px 7px;
    border-radius: 4px;
    background: rgba(34, 211, 238, 0.08);
    border: 1px solid rgba(34, 211, 238, 0.16);
    color: var(--cyan);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
}

.quote-side {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.quote-error {
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--rose);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.45;
    padding: 7px 9px;
}

.quote-price-row {
    display: grid;
    grid-template-columns: minmax(64px, auto) minmax(0, 1fr) auto auto;
    align-items: baseline;
    gap: 8px;
    padding: 7px 8px;
    margin: 0 -8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font: inherit;
    text-align: left;
    transition: all 0.2s var(--ease);
}

.quote-price-row:hover {
    background: var(--bg-inset);
    border-color: var(--border);
}

.quote-price-row:focus-visible {
    outline: 2px solid rgba(34, 211, 238, 0.5);
    outline-offset: 2px;
}

.quote-price-row:disabled {
    cursor: default;
}

.quote-price-row:disabled:hover {
    background: transparent;
    border-color: transparent;
}

.quote-price-label,
.quote-meta-label {
    color: var(--text-3);
    font-size: 11px;
    font-weight: 700;
}

.quote-price-label {
    white-space: nowrap;
}

.quote-price {
    color: var(--text-1);
    font-family: var(--font-mono);
    font-size: 24px;
    font-weight: 800;
    line-height: 1;
    text-align: right;
}

.quote-price-unit {
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 11px;
    white-space: nowrap;
}

.quote-price-hint {
    align-self: center;
    padding: 2px 5px;
    border-radius: 4px;
    background: rgba(34, 211, 238, 0.08);
    color: var(--cyan);
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
}

.quote-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.quote-meta-grid > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 7px 9px;
    background: var(--bg-inset);
    border-radius: 6px;
}

.quote-meta-value {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quote-card-foot {
    color: var(--text-3);
    font-size: 11px;
}

.quote-order-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 9px;
    border-radius: 6px;
    background: rgba(129, 140, 248, 0.12);
    border: 1px solid rgba(129, 140, 248, 0.22);
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
    transition: all 0.2s var(--ease);
}

.quote-order-link:hover {
    background: rgba(129, 140, 248, 0.18);
    color: var(--text-1);
}

/* === Tab Bar === */
.tab-bar {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tab-bar::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    flex-shrink: 0;
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-inset);
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    white-space: nowrap;
}

.tab-btn:hover {
    border-color: var(--border-hover);
    color: var(--text-1);
}

.tab-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

/* === Book Grid === */
.book-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* === Pair Group === */
.pair-group {
    margin-bottom: 8px;
    width: 100%;
}

.pair-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 8px 12px;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.pair-group-name {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.01em;
}

.pair-group-meta {
    font-size: 12px;
    color: var(--text-3);
}

.pair-remove-btn {
    background: none;
    border: none;
    color: var(--text-3);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s var(--ease);
}

.pair-remove-btn:hover {
    color: var(--rose);
    background: var(--rose-glow);
}

.pair-exchanges-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 12px;
}

/* === Exchange Card (Orderbook) === */
.ex-book-card {
    background: var(--bg-card);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all 0.25s var(--ease);
}

.ex-book-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-card);
}

.ex-book-card.best-buy {
    border-color: rgba(34, 211, 238, 0.35);
    box-shadow: 0 0 12px rgba(34, 211, 238, 0.08);
}

.ex-book-card.best-sell {
    border-color: rgba(129, 140, 248, 0.35);
    box-shadow: 0 0 12px rgba(129, 140, 248, 0.08);
}

/* Card header */
.ex-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ex-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ex-dot-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ex-name-label {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 14px;
    text-transform: capitalize;
}

.ex-tags {
    display: flex;
    gap: 4px;
    align-items: center;
}

.badge-sim {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 4px;
    border-radius: 3px;
    background: rgba(251, 191, 36, 0.12);
    color: var(--amber);
    border: 1px solid rgba(251, 191, 36, 0.2);
}

.badge-best {
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
}

.badge-best.buy {
    background: rgba(34, 211, 238, 0.1);
    color: var(--cyan);
    border: 1px solid rgba(34, 211, 238, 0.2);
}

.badge-best.sell {
    background: rgba(129, 140, 248, 0.1);
    color: var(--accent);
    border: 1px solid rgba(129, 140, 248, 0.2);
}

/* Flat Orderbook Side-by-Side Tables */
.ob-tables-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    position: relative;
    margin-top: 2px;
}

.ob-table-side {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ob-side-title {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-3);
    margin-bottom: 6px;
}

.ob-tbl-header {
    display: grid;
    grid-template-columns: 24px 1.2fr 1fr;
    padding-bottom: 4px;
    font-size: 9.5px;
    font-weight: 600;
    color: var(--text-3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 6px;
}

body.light-mode .ob-tbl-header {
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

.ob-tbl-header span {
    text-transform: lowercase;
}

.ob-tbl-header span:nth-child(2) {
    text-align: right;
}

.ob-tbl-header span:nth-child(3) {
    text-align: right;
}

/* Orderbook Row & Content */
.ob-row {
    display: grid;
    grid-template-columns: 24px 1.2fr 1fr;
    align-items: center;
    height: 20px;
    position: relative;
    font-size: 11.5px;
}

.ob-idx {
    font-family: var(--font-mono);
    font-size: 9.5px;
    font-weight: 500;
    color: var(--text-3);
    text-align: left;
}

.ob-price {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 11px;
    text-align: right;
}

.ob-price.ask-color { color: var(--rose); }
.ob-price.bid-color { color: var(--emerald); }

.ob-qty {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 11px;
    color: var(--text-2);
    text-align: right;
}

/* Fresh indicator & labels */
.ex-fresh-indicator {
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 600;
    color: var(--emerald);
    opacity: 0.85;
    transition: color 0.3s ease;
}

body.light-mode .ex-fresh-indicator {
    color: #059669;
}



/* Flash animations */
.flash-green {
    animation: flashG 0.7s var(--ease);
}

.flash-red {
    animation: flashR 0.7s var(--ease);
}

@keyframes flashG {
    0% { background-color: rgba(52, 211, 153, 0.2); }
    100% { background-color: transparent; }
}

@keyframes flashR {
    0% { background-color: rgba(251, 113, 133, 0.2); }
    100% { background-color: transparent; }
}

/* === Footer === */
.app-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 11px;
    color: var(--text-3);
}

.footer-exchanges {
    display: flex;
    gap: 14px;
}

.ex-tag {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
}

.ex-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

/* === Modal === */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s var(--ease);
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-panel {
    background: var(--bg-surface);
    width: 100%;
    max-width: 460px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
    transform: scale(0.94) translateY(10px);
    transition: all 0.25s var(--ease);
    overflow: hidden;
}

.modal-backdrop.open .modal-panel {
    transform: scale(1) translateY(0);
}

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

.modal-top h3 {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-2);
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-1);
}

.modal-content {
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
}

.form-hint {
    font-size: 12px;
    color: var(--text-2);
}

.form-hint code {
    background: var(--bg-inset);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 11px;
}

.input-row {
    display: flex;
    gap: 8px;
}

.password-row input {
    max-width: 190px;
}

.input-row select,
.input-row input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-1);
    font-family: var(--font-mono);
    font-size: 13px;
    transition: border-color 0.2s var(--ease);
}

.input-row select {
    flex: 0 0 118px;
    cursor: pointer;
}

.input-row select:focus,
.input-row input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-error {
    font-size: 12px;
    color: var(--rose);
    min-height: 16px;
}

.pair-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 300px;
    overflow-y: auto;
}

.pair-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.pair-list li .pair-name {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 13px;
}

.pair-list li .del-btn {
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    transition: color 0.2s var(--ease);
}

.pair-list li .del-btn:hover {
    color: var(--rose);
}

.exchange-pair-group {
    align-items: stretch !important;
    flex-direction: column;
    gap: 8px;
}

.managed-ex-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 13px;
}

.managed-count {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-3);
}

.managed-pair-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.managed-pair-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-1);
    font-family: var(--font-mono);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s var(--ease);
}

.managed-pair-tag i {
    color: var(--text-3);
    font-size: 10px;
}

.managed-pair-tag:hover {
    border-color: rgba(251, 113, 133, 0.35);
    background: var(--rose-glow);
}

.managed-pair-tag:hover i {
    color: var(--rose);
}

.managed-empty {
    font-size: 12px;
    color: var(--text-3);
}

/* === Toast === */
.toast-stack {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: var(--z-toast);
}

.toast-item {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    backdrop-filter: var(--blur);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    transform: translateX(120%);
    animation: toastSlideIn 0.3s var(--ease) forwards;
}

.toast-item.success {
    border-left: 3px solid var(--emerald);
}

.toast-item.error {
    border-left: 3px solid var(--rose);
}

@keyframes toastSlideIn {
    to { transform: translateX(0); }
}

/* === Spinner === */
.spinner-sm {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.6; }
}

@media (prefers-reduced-motion: reduce) {
    .push-panel,
    .push-panel-backdrop,
    .modal-backdrop,
    .modal-panel,
    .toast-item {
        animation: none !important;
        transition-duration: 0.01ms !important;
    }
}

/* === Exchange Colors === */
.ex-color-binance { background: #f0b90b; }
.ex-color-okx { background: #ffffff; }
.ex-color-bitget { background: #00f0ff; }
.ex-color-bybit { background: #f3a536; }
.ex-color-osl { background: #0066ff; }

/* === Responsive === */
@media (max-width: 768px) {
    .topbar {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    .topbar-right {
        justify-content: space-between;
    }
    .app-footer {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }
    .pair-exchanges-row {
        grid-template-columns: 1fr;
    }

    /* Push panel as full-screen overlay on mobile */
    .push-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        z-index: 2;
        transform: translateY(100%);
        opacity: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .push-control-wrapper.open .push-panel {
        transform: translateY(0);
    }

    /* Keep the backdrop above page content and below the sheet. */
    .push-panel-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(3, 7, 18, 0.62);
        z-index: 1;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s var(--ease);
    }

    .push-control-wrapper.open .push-panel-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .push-panel-head {
        padding: 20px 20px 14px;
        position: sticky;
        top: 0;
        background: var(--bg-surface);
        z-index: 2;
    }

    .push-panel-section {
        padding: 14px 20px;
    }

    .push-panel-divider {
        margin: 0 20px;
    }

    .push-row {
        padding: 14px 16px;
        min-height: 56px;
    }

    .push-row-name {
        font-size: 15px;
    }

    .push-row-desc {
        font-size: 12px;
    }

    .push-device-row {
        padding: 14px 16px;
        min-height: 60px;
    }

    .push-device-name {
        font-size: 15px;
    }

    .push-device-key {
        font-size: 11px;
    }

    .push-device-icon {
        width: 38px;
        height: 38px;
        font-size: 15px;
    }

    .switch {
        width: 52px;
        height: 30px;
    }

    .switch-slider::before {
        height: 24px;
        width: 24px;
    }

    .switch input:checked + .switch-slider::before {
        transform: translateX(22px);
    }

    .switch:active .switch-slider::before {
        width: 28px;
    }

    .push-panel-footer {
        padding: 14px 20px;
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 480px) {
    .app-shell {
        padding: 12px 12px 16px;
    }
    .cross-card {
        flex: 0 0 280px;
    }
    .tri-card {
        flex: 0 0 300px;
    }
    .quote-card {
        flex: 0 0 320px;
    }
    .quote-price {
        font-size: 21px;
    }
}
