@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;700&family=Rajdhani:wght@400;600;700&display=swap');

:root {
    --neon: #4fd9ff;
    --bg: #020712;
    --panel: #0a0f1a;
    --border: #1a2940;
    --text: #c5d7ff;
    --frame-size: 80px;
    --notch-size: 20px;
    --cut: 15px;
    
    --red: #c0392b;
    --red-glow: rgba(192,57,43,0.5);
    --green: #00ff88;
    --green-glow: rgba(0,255,136,0.3);
    
    --mono: 'Fira Code', 'Courier New', monospace;
    --sans: 'Rajdhani', sans-serif;
}

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

html, body {
    height: 100%; width: 100%; overflow: hidden;
    background: #000; color: var(--text); font-family: var(--mono);
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; background: #000; }
::-webkit-scrollbar-track { background: rgba(26, 41, 64, 0.3); border-left: 1px solid var(--border); }
::-webkit-scrollbar-thumb { background: var(--border); border: 1px solid var(--neon); box-shadow: inset 0 0 5px var(--neon); }

/* GRID BG — GPU-promoted, no repaints */
body::after {
    content: ''; position: fixed; inset: 0;
    background-image: linear-gradient(rgba(79, 217, 255, 0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(79, 217, 255, 0.03) 1px, transparent 1px);
    background-size: 60px 60px; pointer-events: none; z-index: 0;
    transform: translateZ(0);
    will-change: transform;
}

/* OVERLAYS & LOADERS — no backdrop-filter for perf */
#loader, #auth-overlay {
    position: fixed; inset: 10px; background: rgba(2, 7, 18, 0.97);
    z-index: 9000; display: flex; flex-direction: column; justify-content: center; align-items: center;
    clip-path: polygon(0% var(--frame-size), var(--frame-size) 0%, 42% 0%, calc(42% + var(--cut)) var(--notch-size), calc(58% - var(--cut)) var(--notch-size), 58% 0%, calc(100% - var(--frame-size)) 0%, 100% var(--frame-size), 100% 30%, calc(100% - var(--notch-size)) calc(30% + var(--cut)), calc(100% - var(--notch-size)) calc(70% - var(--cut)), 100% 70%, 100% calc(100% - var(--frame-size)), calc(100% - var(--frame-size)) 100%, 58% 100%, calc(58% - var(--cut)) calc(100% - var(--notch-size)), calc(42% + var(--cut)) calc(100% - var(--notch-size)), 42% 100%, var(--frame-size) 100%, 0% calc(100% - var(--frame-size)), 0% 70%, var(--notch-size) calc(70% - var(--cut)), var(--notch-size) calc(30% + var(--cut)), 0% 30%);
    transform: translateZ(0);
}
#auth-overlay { z-index: 8000; }

/* Scan line — use transform instead of left for GPU */
.scan-line { width: 200px; height: 2px; background: var(--neon); position: relative; overflow: hidden; box-shadow: 0 0 15px var(--neon); margin-bottom: 20px; }
.scan-line::after {
    content: ""; position: absolute; top: 0; left: 0; width: 80px; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.8), transparent);
    animation: sweep 1.5s infinite linear;
    will-change: transform;
}
@keyframes sweep { from { transform: translateX(-100px); } to { transform: translateX(280px); } }
/* Flicker: opacity-only — no filter = GPU stays happy */
@keyframes frame-flicker-busy { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes text-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

#loader-text { animation: text-blink 0.8s infinite; color: var(--neon); margin-top: 15px; font-weight: bold; letter-spacing: 2px; }

/* AUTH BOX */
.auth-box {
    background: var(--panel); border: 1px solid var(--neon); border-top: 3px solid var(--neon);
    width: 400px; padding: 40px; display: flex; flex-direction: column; align-items: center; gap: 20px;
    clip-path: polygon(0 0, calc(100% - 15px) 0, 100% 15px, 100% 100%, 15px 100%, 0 calc(100% - 15px));
    box-shadow: 0 0 30px rgba(79, 217, 255, 0.2);
}
.auth-title { font-size: 1.2rem; letter-spacing: 5px; color: var(--neon); text-shadow: 0 0 10px var(--neon); text-transform: uppercase; text-align: center;}
.auth-btn-google {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    background: #fff; color: #333; border: none; padding: 12px 24px;
    font-family: var(--sans); font-size: 0.95rem; font-weight: bold; cursor: pointer; width: 100%; transition: 0.2s;
}
.auth-btn-google:hover { background: #f0f0f0; }
.auth-status { font-size: 0.75rem; color: var(--text); min-height: 20px; text-align: center; }

/* GENERIC OVERLAY — no backdrop-filter, use solid dark bg instead */
.overlay {
    position: fixed; inset: 0; z-index: 9000;
    display: flex; align-items: center; justify-content: center;
    background: rgba(2, 7, 18, 0.92);
    transform: translateZ(0);
}

/* CYBER TERMINAL BOX */
.terminal-box {
    background: var(--panel);
    border: 2px solid var(--neon);
    border-top: 3px solid var(--neon);
    padding: 35px 40px;
    width: 460px;
    max-width: 90vw;
    box-shadow: 0 0 40px rgba(79,217,255,0.2), inset 0 0 60px rgba(79,217,255,0.04);
    clip-path: polygon(0 0, calc(100% - 20px) 0, 100% 20px, 100% 100%, 20px 100%, 0 calc(100% - 20px));
    position: relative;
    animation: box-fade-in 0.3s ease;
}
.terminal-box::before {
    content: 'QUANTUM LINK :: ACTIVE';
    position: absolute; top: -1px; left: 20px;
    font-size: 8px; color: var(--neon); letter-spacing: 3px;
    background: var(--panel); padding: 0 8px;
    transform: translateY(-50%);
}
@keyframes box-fade-in { from { opacity:0; transform: scale(0.95); } to { opacity:1; transform:scale(1); } }

.logo {
    font-size: 22px; letter-spacing: 6px; color: var(--neon);
    text-shadow: 0 0 15px var(--neon); text-align: center;
    margin-bottom: 14px; display: block; font-family: var(--mono);
}

/* Character select buttons */
.char-btn {
    display: flex; align-items: center; gap: 12px;
    background: rgba(79,217,255,0.04); border: 1px solid var(--border);
    color: var(--text); padding: 12px 16px; width: 100%;
    font-family: var(--mono); font-size: 13px; cursor: pointer;
    transition: all 0.2s; text-align: left; letter-spacing: 1px;
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
}
.char-btn:hover {
    background: rgba(79,217,255,0.1); border-color: var(--neon);
    color: var(--neon); box-shadow: 0 0 12px rgba(79,217,255,0.15);
}

/* TERMINAL LAYOUT */
.terminal-window { position: relative; height: 100vh; width: 100vw; padding: 80px; display: flex; align-items: center; justify-content: center; z-index: 10; }
.frame-container { position: absolute; inset: 10px; z-index: 1; pointer-events: none;}
.frame-glow {
    position: absolute; inset: 0; background: var(--neon);
    clip-path: polygon(0% 80px, 80px 0%, 42% 0%, calc(42% + 15px) 20px, calc(58% - 15px) 20px, 58% 0%, calc(100% - 80px) 0%, 100% 80px, 100% 30%, calc(100% - 20px) calc(30% + 15px), calc(100% - 20px) calc(70% - 15px), 100% 70%, 100% calc(100% - 80px), calc(100% - 80px) 100%, 58% 100%, calc(58% - 15px) calc(100% - 20px), calc(42% + 15px) calc(100% - 20px), 42% 100%, 80px 100%, 0% calc(100% - 80px), 0% 70%, 20px calc(70% - 15px), 20px calc(30% + 15px), 0% 30%);
}
.frame-glow::after { content: ""; position: absolute; inset: 3px; background: var(--bg); clip-path: inherit; }
.system-busy .frame-container { animation: frame-flicker-busy 0.4s infinite alternate; }

.main-container { position: relative; z-index: 10; width: 100%; height: 100%; display: flex; flex-direction: column; overflow-y: auto; padding-right: 10px; }

header { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 3px solid #2a3b5f; padding-bottom: 10px; margin-bottom: 20px; flex-shrink: 0; }
.sig { font-size: 10px; color: #566a94; line-height: 1.2; }
h1 { font-size: clamp(16px, 3vw, 32px); letter-spacing: 5px; color: #6fb7ff; text-shadow: 0 0 10px var(--neon); flex: 1; text-align: center; }
.admin-badge { background: var(--red); color: #fff; padding: 2px 8px; font-size: 10px; cursor: pointer; border: 1px solid var(--red); text-shadow: none; display:none; }
.admin-badge:hover { background: #fff; color: var(--red); }
.top-actions { display: flex; gap: 10px; align-items:flex-end; }
.btn-logout { background: none; border: 1px solid var(--border); color: #566a94; font-size: 10px; padding: 4px 8px; cursor: pointer; font-family:var(--mono); }
.btn-logout:hover { border-color: var(--neon); color: var(--neon); }

/* CONTROLS */
.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin-bottom: 20px; padding: 15px; border: 3px solid var(--border); background: rgba(15, 32, 60, 0.4); flex-shrink: 0; }
.c-box { display: flex; flex-direction: column; }
label { font-size: 11px; color: #566a94; margin-bottom: 5px; text-transform: uppercase; }
select, input { background: #071528; border: 2px solid #2a3b5f; color: var(--neon); padding: 8px; font-size: 14px; font-family: var(--mono); outline: none; }
select:focus, input:focus { border-color: var(--neon); }
button { font-family: var(--mono); cursor: pointer; outline: none; }

/* SW DATE BAR */
.sw-datebar { display: flex; align-items: center; gap: 15px; padding: 8px 15px; background: rgba(0, 10, 5, 0.7); border: 2px solid #0d3b26; margin-bottom: 15px; flex-shrink: 0; flex-wrap: wrap; }
.sw-date-label { font-size: 9px; color: #566a94; letter-spacing: 2px; }
.sw-date-value { font-size: 13px; color: var(--green); font-weight: bold; margin-right: auto;}

/* MAIN BODY AREA */
.app-body { display: flex; flex-direction: column; flex: 1; }
.gielda-panel { display: flex; flex-direction: column; flex: 1; }


/* ANALYTICS */
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 15px; flex-shrink: 0; }
.a-card { background: rgba(10, 25, 47, 0.6); border: 2px solid var(--border); text-align: center; padding: 10px; }
.a-label { font-size: 10px; color: #566a94; margin-bottom: 4px; }
.a-value { font-size: clamp(14px, 2vw, 18px); font-weight: bold; color: #fff; }

/* PRICE TILES */
.price-tiles-wrap { display: flex; flex-wrap: wrap; gap: 5px; padding: 10px; background: rgba(0, 0, 0, 0.2); max-height: 120px; overflow-y: auto; border: 1px solid var(--border); border-bottom: none; }
.price-tile { display: flex; flex-direction: column; align-items: center; padding: 4px 6px; background: #0a0f1a; border: 1px solid var(--border); border-radius: 3px; cursor: pointer; min-width: 58px; }
.price-tile:hover { border-color: var(--neon); }
.price-tile.selected { border-color: var(--green); background: rgba(0, 255, 136, 0.08); box-shadow: 0 0 8px rgba(0,255,136,0.2); }
.price-tile-date { font-size: 0.65rem; color: #566a94; }
.price-tile-val { font-size: 0.8rem; font-weight: bold; color: #c5d7ff; }
.price-tile.selected .price-tile-date, .price-tile.selected .price-tile-val { color: var(--green); }
.price-tiles-header { padding: 4px 10px; display: flex; justify-content: space-between; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--border); font-size: 10px; color: #566a94;}

/* PANELS — use contain to limit repaint scope */
.wallet-section { border: 3px solid #0d3b26; background: rgba(0, 20, 10, 0.6); margin-bottom: 20px; flex-shrink: 0; contain: layout style; }
.chart-area { flex: 1; min-height: 250px; border: 3px solid var(--border); background: rgba(0,0,0,0.5); margin-bottom: 15px; position: relative; padding: 10px; contain: layout; }
.wallet-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 15px; border-bottom: 1px solid #0d3b26; }
.wallet-title { color: var(--green); font-size: 12px; letter-spacing: 3px; font-weight: bold; }
.wallet-balance { color: var(--neon); font-size: 14px; font-weight: bold; margin-right: auto; padding-left: 20px;}
.wallet-sync-badge { font-size: 9px; color: #566a94; }
.wallet-sync-badge.online { color: var(--green); }
.wallet-actions { display: flex; gap: 10px; padding: 10px 15px; border-bottom: 1px solid #0d3b26; align-items: center; flex-wrap: wrap; }
.wallet-input { background: #071528; border: 1px solid var(--border); color: var(--neon); padding: 4px 8px; width: 80px; text-align: center;}
.wallet-btn { background: none; border: 2px solid; padding: 4px 12px; font-size: 11px; cursor: pointer; color: #fff; transition: background 0.15s, color 0.15s; }
.buy { border-color: var(--green); color: var(--green); } .buy:hover { background: rgba(0,255,136,0.15); }
.sell { border-color: #ff4f4f; color: #ff4f4f; } .sell:hover { background: rgba(255,79,79,0.15); }
.wallet-scroll { max-height: 150px; overflow-y: auto; }
.wallet-table { width: 100%; border-collapse: collapse; font-size: 11px; text-align: left;}
.wallet-table th { color: #566a94; padding: 6px 15px; border-bottom: 1px solid var(--border); font-size: 9px; }
.wallet-table td { padding: 6px 15px; border-bottom: 1px solid rgba(26, 41, 64, 0.5); }

/* FOOTER */
footer { border-top: 3px solid #2a3b5f; padding: 15px 0; flex-shrink: 0; text-align: center;}
.barcode { font-size: 14px; letter-spacing: 2px; font-family: monospace; color: var(--neon); white-space: pre;}
.code-id { font-size: 10px; color: #566a94; margin-bottom: 5px; }

/* MISC ADMIN PANEL VIEW */
.admin-panel { display: none; flex-direction: column; gap: 20px; }
.admin-card { background: rgba(192,57,43,0.05); border: 2px solid var(--red); padding: 20px;}
.admin-card h2 { color: var(--red); font-size: 14px; margin-bottom: 15px; letter-spacing:2px;}
.admin-row { display: flex; gap: 10px; margin-bottom: 10px; align-items: center; flex-wrap:wrap;}
.primary-btn { background: var(--red); color: white; border: none; padding: 8px 16px; cursor: pointer; font-size:12px; letter-spacing: 1px;}
.primary-btn:hover { background: #e74c3c; }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.admin-hint { font-size:10px; color: #566a94; margin-bottom:10px;}
.status-log { font-size:12px; color: var(--green); padding: 10px; background: rgba(0,0,0,0.5); border: 1px solid #0d3b26;}

/* TOM-SELECT CYBERPUNK OVERRIDES */
.ts-control {
    background: #071528 !important;
    border: 2px solid #2a3b5f !important;
    color: var(--neon) !important;
    font-family: var(--mono) !important;
    border-radius: 0 !important;
    padding: 8px !important;
    box-shadow: none !important;
}
.ts-control > input {
    color: var(--neon) !important;
    font-family: var(--mono) !important;
}
.ts-control.focus { border-color: var(--neon) !important; }
.ts-dropdown {
    background: #071528 !important;
    border: 2px solid var(--neon) !important;
    color: #fff !important;
    font-family: var(--mono) !important;
    border-radius: 0 !important;
    margin-top: 2px !important;
}
.ts-dropdown .optgroup-header {
    background: rgba(0, 0, 0, 0.5) !important;
    color: #566a94 !important;
    font-weight: bold;
    letter-spacing: 2px;
}
.ts-dropdown .option {
    color: #c5d7ff !important;
}
.ts-dropdown .option.active, .ts-dropdown .option:hover {
    background: #1a2940 !important;
    color: var(--neon) !important;
}
.ts-control .item { color: var(--neon) !important; }
