:root { --bg: #131722; --panel: #1e222d; --border: #2a2e39; --hover: #2a2e39; --accent: #2962ff; --text: #d1d4dc; --icon: #787b86; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; height: 100vh; overflow: hidden; }

/* --- APP LAYOUT --- */
#app-shell { display: flex; width: 100%; height: 100%; overflow: hidden; }
#main-wrapper { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#app-container { flex: 1; display: flex; overflow: hidden; position: relative; }
#main-grid { flex: 1; display: grid; gap: 1px; background: #000; overflow: hidden; }

/* --- RIGHT NAV BAR (DOCK) --- */
#right-nav-bar { width: 50px; background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding-top: 10px; z-index: 50; flex-shrink: 0; }
.nav-icon { width: 34px; height: 34px; margin-bottom: 12px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--icon); transition: all 0.2s; }
.nav-icon:hover { background: var(--hover); color: #fff; }
.nav-icon.active { background: #2a2e39; color: var(--accent); border-left: 2px solid var(--accent); }
.nav-icon svg { width: 20px; height: 20px; fill: currentColor; }

/* --- SIDE PANELS (RESIZABLE) --- */
.side-panel { 
    display: none; 
    /* Width is controlled by JS now via inline style, default 320px */
    width: 320px; 
    background: var(--panel); 
    border-left: 1px solid var(--border); 
    flex-direction: column; 
    overflow: hidden; 
    position: relative;
    /* No animation on slide to allow smooth resizing, logic handles display */
}
.side-panel.open { display: flex; }

/* SIDEBAR RESIZER HANDLE (Left Edge) */
.panel-resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: ew-resize;
    z-index: 100;
    background: transparent;
    transition: background 0.2s;
}
.panel-resize-handle:hover, .panel-resize-handle.resizing {
    background: var(--accent);
}

.panel-header { padding: 10px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: var(--panel); }
.panel-title-area { display: flex; align-items: center; gap: 8px; flex: 1; }
.panel-select { background: transparent; border: none; color: #fff; font-weight: bold; font-size: 14px; outline: none; cursor: pointer; max-width: 160px; }
.panel-select option { background: var(--panel); color: #d1d4dc; }
.btn-icon-sm { background: transparent; border: none; color: #787b86; cursor: pointer; padding: 4px; border-radius: 4px; display: flex; align-items: center; }
.btn-icon-sm:hover { background: var(--hover); color: #fff; }
.panel-list { flex: 1; overflow-y: auto; padding: 0; margin: 0; list-style: none; }
.panel-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; color: #d1d4dc; cursor: pointer; }
.panel-item:hover { background: rgba(255,255,255,0.02); }
.panel-item .sym { font-weight: 500; }
.panel-item .del { opacity: 0; transition: 0.2s; }
.panel-item:hover .del { opacity: 1; }

/* --- WATCHLIST GRID LAYOUT (RESIZABLE COLS) --- */
#watchlist-sidebar {
    --wl-col-1: 1fr;
    --wl-col-2: 80px;
    --wl-col-3: 60px;
    --wl-col-4: 60px;
    --wl-col-5: 24px;
}

#watchlist-sidebar .panel-list { padding: 0; }

.wl-header, .wl-item { 
    display: grid; 
    grid-template-columns: var(--wl-col-1) var(--wl-col-2) var(--wl-col-3) var(--wl-col-4) var(--wl-col-5);
    /* Removed gap to allow borders to touch */
    padding: 0; 
    border-bottom: 1px solid var(--border); 
    align-items: stretch; /* Stretch to fill height for borders */
}

.wl-header { background: #1e222d; font-size: 11px; color: #787b86; font-weight: bold; user-select: none; }
.wl-item { font-size: 13px; color: #d1d4dc; cursor: pointer; transition: background 0.1s; min-height: 32px; }
.wl-item:hover { background: rgba(255, 255, 255, 0.03); }

/* CELL STYLING (Borders & Alignment) */
.wl-header span, .wl-item span {
    display: flex;
    align-items: center;
    padding: 8px 6px; /* Vertical padding here */
    border-right: 1px solid #2a2e39; /* Visible Separator */
    position: relative;
    overflow: hidden;
}
.wl-header span:last-child, .wl-item span:last-child { border-right: none; }

/* Text Alignment */
.wl-header span:nth-child(1), .wl-item span:nth-child(1) { justify-content: flex-start; text-align: left; }
.wl-header span:nth-child(2), .wl-item span:nth-child(2) { justify-content: flex-end; text-align: right; }
.wl-header span:nth-child(3), .wl-item span:nth-child(3) { justify-content: flex-end; text-align: right; }
.wl-header span:nth-child(4), .wl-item span:nth-child(4) { justify-content: flex-end; text-align: right; padding-right: 2px; /* Tight padding for % */ }

/* COLUMN RESIZERS */
.wl-resizer {
    position: absolute;
    left: -4px;
    top: 0; bottom: 0; width: 8px;
    cursor: col-resize; z-index: 10;
}
.wl-resizer:hover { background: rgba(41, 98, 255, 0.3); }

/* Cell Content */
.wl-sym { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wl-last { font-family: monospace; font-weight: 500; }
.wl-chg, .wl-pct { font-family: monospace; font-size: 12px; }
.wl-del { justify-content: center !important; color: #555; cursor: pointer; opacity: 0; transition: 0.2s; }
.wl-item:hover .wl-del { opacity: 1; }
.wl-del:hover { color: #FF5252; }

.text-up { color: #00E676 !important; }
.text-down { color: #FF5252 !important; }
.text-neutral { color: #d1d4dc; }

/* --- REST OF CSS --- */
#context-menu { display: none; position: fixed; background: #1e222d; border: 1px solid #2a2e39; box-shadow: 0 4px 12px rgba(0,0,0,0.5); z-index: 9999; border-radius: 4px; padding: 4px 0; min-width: 160px; }
.ctx-item { padding: 8px 12px; font-size: 13px; color: #d1d4dc; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.ctx-item:hover { background: #2962ff; color: #fff; }
.ctx-sep { height: 1px; background: #2a2e39; margin: 4px 0; }

#toolbar { height: 40px; background: var(--bg); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 4px; gap: 2px; overflow: visible; z-index: 40; flex-shrink: 0; }
.separator { width: 1px; height: 16px; background: #363a45; margin: 0 6px; flex-shrink: 0; }
.tool-btn { background: transparent; border: none; color: #d1d4dc; height: 30px; padding: 0 10px; border-radius: 4px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 500; transition: 0.1s; position: relative; white-space: nowrap; flex-shrink: 0; text-decoration: none; }
.tool-btn:hover, .tool-btn.active { background: var(--hover); color: #fff; }
.tool-btn svg { width: 18px; height: 18px; fill: currentColor; }

.chart-reset-btn { position: absolute; bottom: 35px; right: 65px; z-index: 20; width: 26px; height: 26px; border-radius: 50%; border: 1px solid #363a45; background: #1e222d; color: #787b86; cursor: pointer; display: none; align-items: center; justify-content: center; box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: 0.2s; }
.chart-reset-btn:hover { color: #fff; background: #2a2e39; border-color: #555; }
.dd-wrapper { position: relative; }
.dd-menu { position: absolute; top: 100%; left: 0; margin-top: 4px; background: #1e222d; border: 1px solid var(--border); border-radius: 4px; box-shadow: 0 4px 12px rgba(0,0,0,0.5); z-index: 1000; min-width: 120px; display: none; padding: 4px 0; }
.dd-wrapper.open .dd-menu { display: block; }
.dd-item { padding: 8px 12px; cursor: pointer; font-size: 13px; color: #d1d4dc; display: flex; align-items: center; }
.dd-item:hover { background: #2a2e39; color: var(--accent); }
.dd-item.active { color: var(--accent); }
.dd-item svg { width: 18px; height: 18px; margin-right: 8px; fill: currentColor; }

/* Layout Icons Grid */
#dd-layout .dd-menu { padding: 0; width: 230px; max-height: 80vh; overflow-y: auto; }
.layout-section { border-bottom: 1px solid #2a2e39; padding: 4px 8px; }
.layout-row { display: flex; align-items: center; }
.count-label { width: 24px; color: #787b86; font-size: 14px; font-weight: 500; text-align: center; }
.layout-icons { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.l-icon { width: 34px; height: 26px; cursor: pointer; border-radius: 3px; display: grid; gap: 2px; padding: 2px; transition: 0.1s; }
.l-icon:hover { background: #363a45; }
.l-icon span { border: 1px solid #787b86; border-radius: 1px; }
.l-icon:hover span { border-color: var(--accent); }
.l-icon.active { background: rgba(41, 98, 255, 0.15); }
.l-icon.active span { border-color: var(--accent); }
.i-1x1 { grid-template-columns: 1fr; } .i-1x2 { grid-template-columns: 1fr 1fr; } .i-2x1 { grid-template-rows: 1fr 1fr; }
.i-1x3 { grid-template-columns: 1fr 1fr 1fr; } .i-3x1 { grid-template-rows: 1fr 1fr 1fr; }
.i-1-2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; } .i-1-2 span:nth-child(1) { grid-row: 1 / span 2; } 
.i-2-1 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; } .i-2-1 span:nth-child(3) { grid-row: 1 / span 2; grid-column: 2; }
.i-2x2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.i-1-3 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; } .i-1-3 span:nth-child(1) { grid-row: 1 / span 3; }
.i-4-grid { grid-template-columns: 1fr 1fr 1fr 1fr; }
.i-2x3 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; } .i-3x2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; }
.i-2x4 { grid-template-columns: 1fr 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; } .i-4x2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr 1fr 1fr; }
.i-4x3 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(3, 1fr); }
.i-3x4 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(4, 1fr); }
.i-6x2 { grid-template-columns: repeat(6, 1fr); grid-template-rows: 1fr 1fr; }
.i-2x6 { grid-template-columns: 1fr 1fr; grid-template-rows: repeat(6, 1fr); }
.i-12x1 { grid-template-columns: repeat(12, 1fr); } .i-1x12 { grid-template-rows: repeat(12, 1fr); }

.sync-menu { padding: 10px 14px; }
.sync-header { font-size: 11px; color: #787b86; font-weight: bold; margin-bottom: 8px; text-transform: uppercase; }
.sync-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 13px; color: #d1d4dc; cursor: pointer; }
.toggle { position: relative; display: inline-block; width: 32px; height: 18px; pointer-events: none; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #363a45; transition: .4s; border-radius: 18px; }
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 2px; bottom: 2px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: #2962ff; }
input:checked + .slider:before { transform: translateX(14px); }

.chart-cell { position: relative; background: var(--bg); overflow: hidden; border: 1px solid transparent; }
.chart-cell.active { border: 1px solid var(--accent); z-index: 10; } 
.cell-legend { position: absolute; top: 8px; left: 12px; pointer-events: none; z-index: 5; font-size: 13px; font-weight: bold; color: #fff; display: flex; gap: 6px; }
.cell-legend span { font-weight: normal; font-size: 11px; color: var(--accent); background: rgba(41,98,255,0.15); padding: 1px 5px; border-radius: 3px; }
.cell-legend .legend-tag { background: #333 !important; color: #aaa !important; }

#search-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: none; justify-content: center; align-items: center; z-index: 2000; }
#search-modal.open { display: flex; }
.search-box { width: 90%; max-width: 500px; max-height: 80vh; background: #1e222d; border: 1px solid #2a2e39; border-radius: 6px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.search-input-wrap { padding: 12px; border-bottom: 1px solid #2a2e39; display: flex; align-items: center; }
#sym-input { background: transparent; border: none; color: #fff; font-size: 16px; width: 100%; outline: none; margin-left: 10px; }
.search-tabs { display: flex; border-bottom: 1px solid #2a2e39; background: #131722; }
.search-tab { flex: 1; padding: 12px; text-align: center; cursor: pointer; font-size: 13px; color: #787b86; border-bottom: 2px solid transparent; }
.search-tab.active { color: #2962ff; border-bottom: 2px solid #2962ff; font-weight: bold; }
#sym-list { flex: 1; overflow-y: auto; padding: 0; margin: 0; list-style: none; -webkit-overflow-scrolling: touch; }
.sym-item { padding: 12px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #2a2e39; font-size: 14px; }
.sym-item:hover { background: #2a2e39; }
.sym-left { display: flex; flex-direction: column; }
.sym-tag { font-size: 10px; padding: 2px 4px; border-radius: 3px; background: #2a2e39; color: #787b86; }
.sym-tag.opt { background: rgba(41, 98, 255, 0.1); color: #2962ff; }
.sym-tag.basket-tag { background: rgba(224, 64, 251, 0.2); color: #E040FB; }

@media (max-width: 768px) {
    #app-shell { flex-direction: column; }
    #right-nav-bar { width: 100%; height: 50px; flex-direction: row; order: 3; border-top: 1px solid var(--border); border-left: none; justify-content: space-around; padding: 0; }
    .nav-icon { margin: 0; }
    .side-panel { width: 100% !important; height: 50vh; position: absolute; bottom: 50px; z-index: 60; border-top: 1px solid var(--border); }
    #main-grid { display: flex !important; flex-direction: column; overflow-y: auto; }
    .chart-cell { min-height: 50vh; width: 100% !important; border-bottom: 4px solid #000; flex-shrink: 0; }
    .dd-menu { position: fixed !important; top: auto !important; bottom: 0 !important; width: 100% !important; max-height: 60vh; border-radius: 12px 12px 0 0; }
    #dd-tz { bottom: 60px !important; right: 16px !important; }
}