:root{
    --bg: #111214;
    --bg-2: #15171a;
    --bg-3: #1a1d21;
    --surface: rgba(28, 30, 34, 0.82);
    --surface-2: rgba(36, 39, 44, 0.82);
    --surface-3: rgba(46, 50, 56, 0.78);

    --border: rgba(255,255,255,0.08);
    --border-soft: rgba(255,255,255,0.05);
    --hairline: rgba(255,255,255,0.035);

    --text: #f5f5f7;
    --text-soft: #d7d9de;
    --text-dim: #949aa5;

    --accent: #0a84ff;
    --accent-soft: rgba(10,132,255,0.14);
    --accent-line: rgba(10,132,255,0.24);

    --green: #30d158;
    --red: #ff5f57;
    --cyan: #64d2ff;

    --radius-xl: 24px;
    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 12px;
    --radius-pill: 999px;

    --shadow-soft: 0 12px 30px rgba(0,0,0,0.26);
    --shadow-elev: 0 22px 50px rgba(0,0,0,0.34);
    --shadow-focus: 0 0 0 3px rgba(10,132,255,0.14);

    --glass: saturate(180%) blur(20px);
}

*{
    box-sizing: border-box;
}

html,
body{
    margin: 0;
    padding: 0;
    min-height: 100%;
    overflow-x: hidden;
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background:
        radial-gradient(circle at top right, rgba(255,255,255,0.035), transparent 20%),
        radial-gradient(circle at top left, rgba(10,132,255,0.05), transparent 18%),
        linear-gradient(180deg, #101113 0%, #14161a 100%);
}

body{
    min-height: 100vh;
}

/* ===== GRID ===== */

.tsap-grid{
    display: grid;
    grid-template-columns: 72px minmax(0,1fr) minmax(0,1fr);
    grid-template-rows: 72px minmax(0,1fr) 94px;
    gap: 10px;
    padding: 10px;
    height: 100vh;
    width: 100%;
}

/* ===== SHARED SURFACES ===== */

.panel-shell,
.sidebar,
.topbar,
.bottompanel,
.floating-panel{
    border: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(29,31,36,0.78), rgba(22,24,28,0.88));
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    box-shadow: var(--shadow-soft);
}

/* ===== TOPBAR ===== */

.topbar{
    grid-column: 1 / 4;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 14px;
    border-radius: 20px;
    min-height: 72px;
    position: relative;
    z-index: 1000;
}

.topbar-left{
    display: flex;
    align-items: center;
    min-width: 0;
    flex-shrink: 0;
}

.topbar-right{
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-width: 0;
    flex: 1;
}

.logo-link{
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.terminal-title{
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.15px;
    color: var(--text);
    white-space: nowrap;
}

.terminal-title span{
    color: var(--accent);
}

.topbar-action-group{
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.topbar-action-group button,
.topbar-link-btn{
    min-height: 36px;
    padding: 0 13px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08px;
}

/* ===== BUTTONS ===== */

button{
    appearance: none;
    border: 1px solid rgba(255,255,255,0.09);
    outline: none;
    background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.025));
    color: var(--text-soft);
    cursor: pointer;
    transition:
        background .18s ease,
        color .18s ease,
        border-color .18s ease,
        box-shadow .18s ease,
        transform .14s ease;
}

button:hover{
    background: linear-gradient(180deg, rgba(255,255,255,0.075), rgba(255,255,255,0.035));
    color: var(--text);
    border-color: rgba(255,255,255,0.14);
}

button:active{
    transform: translateY(1px);
}

button:focus-visible,
.topbar-link-btn:focus-visible,
input:focus-visible,
select:focus-visible{
    box-shadow: var(--shadow-focus);
}

.btn-primary{
    border: none;
    background: linear-gradient(180deg, #2893ff 0%, #0a84ff 100%);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 10px 22px rgba(10,132,255,0.18);
}

.btn-primary:hover{
    background: linear-gradient(180deg, #46a3ff 0%, #0a84ff 100%);
    color: #fff;
}

.topbar-link-btn{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    white-space: nowrap;
    color: var(--text);
    border: 1px solid rgba(10,132,255,0.24);
    background: linear-gradient(180deg, rgba(17,37,52,0.95), rgba(13,28,40,0.98));
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
    transition: all .18s ease;
}

.topbar-link-btn:hover{
    color: #fff;
    border-color: rgba(10,132,255,0.4);
    background: linear-gradient(180deg, rgba(18,44,62,0.98), rgba(14,33,47,0.98));
}

/* premium highlight buttons */
#marketDataBtn{
    border-color: rgba(10,132,255,0.16);
}

#marketDataBtn:hover{
    color: var(--accent);
    border-color: rgba(10,132,255,0.30);
}

#tradebookBtn{
    border-color: rgba(100,210,255,0.16);
}

#tradebookBtn:hover{
    color: var(--cyan);
    border-color: rgba(100,210,255,0.30);
}

/* ===== SIDEBAR ===== */

.sidebar{
    grid-row: 2 / 3;
    border-radius: 22px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    min-width: 0;
    overflow: auto;
}

.tool-btn{
    width: 100%;
    min-height: 42px;
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
    color: var(--text-soft);
    border: 1px solid rgba(255,255,255,0.07);
    font-size: 12px;
    font-weight: 600;
}

.tool-btn:hover{
    transform: none;
}

.tool-btn-accent{
    color: var(--accent);
    border-color: rgba(10,132,255,0.22);
    background: linear-gradient(180deg, rgba(10,132,255,0.14), rgba(10,132,255,0.05));
}

#trendline:hover{ color: var(--accent); border-color: rgba(10,132,255,0.36); }
#hline:hover{ color: var(--green); border-color: rgba(48,209,88,0.34); }
#rectangle:hover{ color: var(--cyan); border-color: rgba(100,210,255,0.34); }
#smc:hover,
#ict:hover,
#short:hover{ color: var(--red); border-color: rgba(255,95,87,0.34); }
#long:hover{ color: var(--green); border-color: rgba(48,209,88,0.34); }

/* ===== CHART SURFACES ===== */

.chart-left,
.chart-right{
    position: relative;
    min-width: 0;
    min-height: 0;
    border-radius: 24px;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)),
        linear-gradient(180deg, #181a1e 0%, #14161a 100%);
}

.chart-left:hover,
.chart-right:hover{
    box-shadow:
        0 0 0 1px rgba(255,255,255,0.05),
        0 16px 32px rgba(0,0,0,0.18),
        inset 0 0 0 1px rgba(255,255,255,0.02);
}

.chart-header{
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 11px;
    border-radius: var(--radius-pill);
    background: rgba(20,22,26,0.72);
    border: 1px solid rgba(255,255,255,0.06);
    color: var(--text-dim);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.35px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.chartbox{
    width: 100%;
    height: 100%;
}

/* ===== DROP ZONE ===== */

.drop-zone{
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15,16,18,0.84);
    border: 2px dashed rgba(10,132,255,0.45);
    color: var(--accent);
    font-weight: 700;
    font-size: 18px;
    letter-spacing: 0.2px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
    z-index: 4;
}

.chart-left.dragover .drop-zone,
.chart-right.dragover .drop-zone{
    opacity: 1;
    pointer-events: auto;
}

/* ===== BOTTOM METRICS ===== */

.bottompanel{
    grid-column: 1 / 4;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 24px;
    padding: 14px 16px;
    min-width: 0;
}

.metrics{
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    gap: 12px;
    width: 100%;
}

.metric-card{
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    min-height: 64px;
    padding: 12px 14px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255,255,255,0.028), rgba(255,255,255,0.012));
    border: 1px solid rgba(255,255,255,0.055);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.015);
}

.metric-label{
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.75px;
    text-transform: uppercase;
    color: var(--text-dim);
}

.metric-value{
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
}

.metric-green{ color: var(--green); }
.metric-blue{ color: var(--accent); }
.metric-cyan{ color: var(--cyan); }
.metric-red{ color: var(--red); }

/* ===== FLOATING PANELS ===== */

.floating-panel{
    display: none;
    position: fixed;
    top: 120px;
    left: 200px;
    width: 320px;
    border-radius: 22px;
    z-index: 2000;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(30,33,38,0.94), rgba(21,23,27,0.97));
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    box-shadow: var(--shadow-elev);
}

.panel-header{
    cursor: move;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 15px;
    background: linear-gradient(180deg, rgba(40,43,48,0.92), rgba(28,31,36,0.96));
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.15px;
}

.close-btn{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 9px;
    cursor: pointer;
    color: var(--red);
    transition: all .16s ease;
}

.close-btn:hover{
    background: rgba(255,95,87,0.14);
    color: #fff;
}

.panel-body{
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
}

.panel-body hr{
    width: 100%;
    border: none;
    border-top: 1px solid var(--hairline);
    margin: 4px 0;
}

.panel-body label{
    font-size: 12px;
    font-weight: 600;
    color: var(--text-soft);
}

.panel-body input,
.panel-body select{
    width: 100%;
    height: 40px;
    padding: 0 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: all .16s ease;
}

.panel-body input:focus,
.panel-body select:focus{
    border-color: var(--accent);
    box-shadow: var(--shadow-focus);
}

#applyEMA,
#applyDrawingSettings{
    background: linear-gradient(180deg, #33a1ff 0%, #0a84ff 100%);
    color: #fff;
    border: none;
    font-weight: 700;
}

#applyEMA:hover,
#applyDrawingSettings:hover{
    color: #fff;
}

.danger-soft{
    background: rgba(255,95,87,0.08);
    border: 1px solid rgba(255,95,87,0.20);
    color: var(--red);
}

.danger-soft:hover{
    color: #fff;
    background: rgba(255,95,87,0.16);
    border-color: rgba(255,95,87,0.32);
    box-shadow: none;
}

/* ===== TRADEBOOK / MARKETDATA ===== */

.tradebook-panel,
.marketdata-panel{
    width: 348px;
    max-width: calc(100vw - 20px);
}

.tradebook-actions,
.marketdata-actions{
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.tradebook-actions button,
.marketdata-actions button{
    flex: 1;
}

.tradebook-status{
    min-height: 20px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-dim);
}

.tradebook-date-note{
    font-size: 12px;
    line-height: 1.45;
    color: var(--text-dim);
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.05);
}

/* ===== FULLSCREEN ===== */

.tsap-grid:fullscreen{
    height: 100vh;
    width: 100%;
}

/* ===== RESPONSIVE ===== */

@media (max-width: 1200px){
    .topbar{
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        min-height: auto;
        gap: 12px;
        padding: 12px 14px;
    }

    .topbar-right{
        width: 100%;
        justify-content: flex-start;
    }

    .topbar-action-group{
        justify-content: flex-start;
    }
}

@media (max-width: 900px){
    .tsap-grid{
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 42vh 42vh auto;
        height: auto;
        min-height: 100vh;
    }

    .topbar{
        grid-column: 1 / 2;
        border-radius: 18px;
    }

    .topbar-action-group{
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0,1fr));
        gap: 8px;
    }

    .topbar-action-group button,
    .topbar-link-btn{
        width: 100%;
        justify-content: center;
    }

    .sidebar{
        grid-column: 1 / 2;
        grid-row: auto;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        overflow-x: auto;
        border-radius: 18px;
    }

    .sidebar .tool-btn{
        width: auto;
        min-width: 82px;
        flex: 0 0 auto;
    }

    .chart-left,
    .chart-right{
        grid-column: 1 / 2;
        min-height: 42vh;
        border-radius: 20px;
    }

    .bottompanel{
        grid-column: 1 / 2;
        border-radius: 20px;
        padding: 12px;
    }

    .metrics{
        grid-template-columns: repeat(2, minmax(0,1fr));
        gap: 10px;
    }
}

@media (max-width: 600px){
    .tsap-grid{
        gap: 6px;
        padding: 6px;
        grid-template-rows: auto auto 38vh 38vh auto;
    }

    .terminal-title{
        font-size: 16px;
    }

    .topbar{
        padding: 10px;
        border-radius: 16px;
    }

    .topbar-action-group{
        grid-template-columns: 1fr;
    }

    .topbar-action-group button,
    .topbar-link-btn,
    button{
        min-height: 40px;
    }

    .sidebar{
        padding: 8px;
        border-radius: 16px;
    }

    .chart-left,
    .chart-right{
        min-height: 38vh;
        border-radius: 16px;
    }

    .chart-header{
        top: 8px;
        left: 8px;
        font-size: 10px;
        padding: 5px 9px;
    }

    .bottompanel{
        border-radius: 16px;
    }

    .metrics{
        grid-template-columns: 1fr 1fr;
    }

    .metric-card{
        min-height: 58px;
        padding: 10px;
    }

    .metric-value{
        font-size: 16px;
    }

    .drop-zone{
        font-size: 15px;
    }

    .floating-panel{
        width: calc(100vw - 20px);
        max-width: 348px;
        left: 50% !important;
        transform: translateX(-50%);
        top: 88px;
    }
}