* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #131722;
    color: #d1d4dc;
}

#app {
    display: grid;
    grid-template-columns: 210px 1fr;
    height: 100vh;
}

/* Sidebar */
#sidebar {
    background: #1c2030;
    padding: 10px;
    overflow-y: auto;
    border-right: 1px solid #2a2e39;
    display: flex;
    flex-direction: column;
}

#sidebar h2, #sidebar h3 {
    margin: 8px 0 4px;
    font-size: 11px;
    text-transform: uppercase;
    color: #787b86;
    letter-spacing: 0.8px;
}

#sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0 0 8px 0;
}

#sidebar li {
    padding: 5px 8px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: #d1d4dc;
}

#sidebar li:hover { background: #2a2e39; }
#sidebar li.active { background: #1d3a6e; color: #a3b8ff; }

.ticker-text { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ticker-sym { font-size: 13px; }
.ticker-name { font-size: 10px; color: #5d6475; }
#sidebar li.active .ticker-name { color: #8090cc; }

#sidebar li .del {
    opacity: 0;
    background: none;
    border: none;
    color: #f23645;
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
}
#sidebar li:hover .del { opacity: 1; }

.row {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.row input {
    flex: 1;
    width: 100%;
    padding: 5px 8px;
    background: #2a2e39;
    border: 1px solid #363c4e;
    color: #d1d4dc;
    border-radius: 4px;
    font-size: 12px;
    box-sizing: border-box;
}

.row input::placeholder { color: #5d6475; }
.row input:focus { outline: none; border-color: #2962ff; }

.ticker-input-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
}

.suggestions {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    background: #1c2030;
    border: 1px solid #363c4e;
    border-radius: 4px;
    z-index: 200;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.suggestions.hidden { display: none; }

.suggestion-item {
    padding: 5px 8px;
    cursor: pointer;
    display: flex;
    align-items: baseline;
    gap: 5px;
}
.suggestion-item:hover { background: #2a2e39; }
.sug-sym { font-size: 12px; font-weight: 700; color: #d1d4dc; white-space: nowrap; }
.sug-name { font-size: 11px; color: #787b86; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.sug-type { font-size: 10px; color: #5d6475; white-space: nowrap; }

.row button, #sidebar > button {
    background: #2962ff;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
.row button:hover, #sidebar > button:hover { background: #1a4fd8; }

/* Main area */
main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #131722;
    min-height: 0;
}

#chart-header {
    padding: 5px 10px;
    background: #1c2030;
    border-bottom: 1px solid #2a2e39;
    display: flex;
    flex-wrap: wrap;
    gap: 3px 5px;
    align-items: center;
    font-size: 12px;
}

#active-ticker {
    font-weight: 700;
    font-size: 14px;
    color: #e6edf3;
    min-width: 55px;
    margin-right: 4px;
    white-space: nowrap;
}
#active-ticker .hdr-sym { font-weight: 700; }
#active-ticker .hdr-sym-name { font-weight: 400; font-size: 11px; color: #787b86; }

#chart-header select {
    background: #2a2e39;
    color: #d1d4dc;
    border: 1px solid #363c4e;
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 12px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}
#chart-header select:focus { outline: none; border-color: #2962ff; }

/* Indicator pill toggles */
.ind-check { display: none; }

.ind-check + label {
    display: inline-block;
    padding: 2px 7px;
    background: #131722;
    border: 1px solid #2a2e39;
    border-radius: 10px;
    cursor: pointer;
    font-size: 11px;
    color: #6b7280;
    user-select: none;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
    line-height: 1.6;
    white-space: nowrap;
}

.ind-check + label:hover {
    background: #2a2e39;
    color: #b2b5be;
}

.ind-check:checked + label {
    background: #1a3260;
    border-color: #2962ff;
    color: #a3b8ff;
}

/* Ind-group: pill + gear joined */
.ind-group {
    display: inline-flex;
    align-items: stretch;
}

.ind-group .ind-check + label {
    border-radius: 10px 0 0 10px;
    border-right: none;
}

.ind-group .gear-btn {
    display: inline-flex;
    align-items: center;
    padding: 0 5px;
    background: #131722;
    border: 1px solid #2a2e39;
    border-radius: 0 10px 10px 0;
    cursor: pointer;
    font-size: 10px;
    color: #5d6475;
    line-height: 1;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.ind-group .ind-check:checked ~ .gear-btn {
    background: #1a3260;
    border-color: #2962ff;
    color: #a3b8ff;
}

.ind-group .gear-btn:hover { color: #e6edf3; background: #2a2e39; }

/* Standalone gear (not in group) */
.gear-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 3px;
    font-size: 12px;
    color: #5d6475;
}
.gear-btn:hover { color: #d1d4dc; }

/* Header separator */
.hdr-sep {
    display: inline-block;
    width: 1px;
    height: 16px;
    background: #2a2e39;
    align-self: center;
    margin: 0 2px;
    flex-shrink: 0;
}

/* Status */
#status {
    margin-left: auto;
    color: #4b5563;
    font-size: 11px;
    white-space: nowrap;
}

/* Chart wrapper + Draw panel (floating) */
#chart-wrapper {
    flex: 1;
    min-height: 0;
    position: relative;
}

#draw-panel {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 20;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 3px;
    gap: 2px;
}
#draw-panel.hidden { display: none; }

.draw-tool {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    padding: 0;
    line-height: 1;
}
.draw-tool:hover { background: #f1f5f9; color: #1e293b; }
.draw-tool.active { background: #dbeafe; color: #2563eb; }

.draw-sep { width: 20px; height: 1px; background: #e2e8f0; margin: 2px 0; }

.draw-toggle-btn {
    background: none;
    border: 1px solid #363c4e;
    border-radius: 4px;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 13px;
    color: #787b86;
    line-height: 1.4;
}
.draw-toggle-btn:hover { background: #2a2e39; color: #d1d4dc; }
.draw-toggle-btn.panel-open { background: #1a3260; border-color: #2962ff; color: #a3b8ff; }

#chart {
    width: 100%;
    height: 100%;
    position: relative;
}

/* Indikator-Panes (RSI, MACD, Stochastik, ...) */
#panes { flex-shrink: 0; }

.ind-pane {
    position: relative;
    border-top: 1px solid #2a2e39;
}

.pane-label {
    position: absolute;
    top: 4px;
    left: 8px;
    z-index: 5;
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    pointer-events: none;
}

/* Settings */
.settings-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.settings-backdrop.active { display: flex; }

.settings-modal {
    background: #1c2030;
    border: 1px solid #2a2e39;
    border-radius: 8px;
    padding: 18px 20px;
    width: 460px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    color: #d1d4dc;
}

.settings-modal h3 {
    margin: 0 0 12px;
    font-size: 13px;
    color: #e6edf3;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
}

.settings-form { display: flex; flex-direction: column; gap: 2px; }

.settings-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 5px 0;
    font-size: 12px;
    border-bottom: 1px solid #21262d;
    color: #9ca3af;
}

.settings-row input[type="text"],
.settings-row input[type="number"],
.settings-row select {
    padding: 4px 8px;
    border: 1px solid #363c4e;
    border-radius: 4px;
    font-size: 12px;
    width: 130px;
    background: #2a2e39;
    color: #d1d4dc;
}
.settings-row input:focus, .settings-row select:focus {
    outline: none;
    border-color: #2962ff;
}

.settings-row input[type="color"] {
    width: 40px;
    height: 26px;
    border: 1px solid #363c4e;
    border-radius: 4px;
    cursor: pointer;
    background: #2a2e39;
    padding: 1px;
}

.settings-row input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: #2962ff;
}

.settings-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #21262d;
}

.settings-actions button {
    padding: 5px 14px;
    border: 1px solid #363c4e;
    background: #2a2e39;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: #d1d4dc;
}
.settings-actions button:hover { background: #363c4e; }

.settings-actions button.primary {
    background: #2962ff;
    border-color: #2962ff;
    color: white;
}
.settings-actions button.primary:hover { background: #1a4fd8; }

hr {
    border: none;
    border-top: 1px solid #2a2e39;
    margin: 8px 0;
}

/* ─── Order Modal ────────────────────────────────────────────────────────── */
.order-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 9000;
    align-items: center;
    justify-content: center;
}

.order-modal-inner {
    background: #1c2030;
    border: 1px solid #2a2e39;
    border-radius: 8px;
    padding: 20px 24px;
    min-width: 280px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.order-modal-title {
    font-size: 13px;
    font-weight: 600;
    color: #d1d4dc;
    margin-bottom: 4px;
}

.order-modal-price {
    font-size: 11px;
    color: #787b86;
    margin-bottom: 14px;
}

.order-modal-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    font-size: 12px;
    color: #c0c4cf;
}

.order-modal-row label {
    width: 64px;
    flex-shrink: 0;
}

.order-modal-row input[type=number] {
    background: #131722;
    border: 1px solid #363c4e;
    color: #d1d4dc;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 13px;
}

.order-side-btns {
    display: flex;
    gap: 6px;
}

.order-side {
    padding: 4px 10px;
    border: 1px solid #363c4e;
    background: #2a2e39;
    color: #d1d4dc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.order-side.active[data-side="buy"] {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}

.order-side.active[data-side="sell"] {
    background: #dc2626;
    border-color: #dc2626;
    color: #fff;
}

.order-modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: flex-end;
}

.order-modal-actions button {
    padding: 5px 14px;
    border: 1px solid #363c4e;
    background: #2a2e39;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: #d1d4dc;
}

#order-confirm {
    background: #2962ff !important;
    border-color: #2962ff !important;
    color: white !important;
}

#order-confirm:hover { background: #1a4fd8 !important; }

/* ─── Header-Buttons & Dropdown-Gruppen ──────────────────────────────────── */
.hdr-btn {
    background: #131722;
    border: 1px solid #2a2e39;
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 11px;
    color: #787b86;
    line-height: 1.4;
    white-space: nowrap;
}
.hdr-btn:hover { background: #2a2e39; color: #d1d4dc; }
.hdr-btn.active { background: #1a3260; border-color: #2962ff; color: #a3b8ff; }

.dropdown { position: relative; display: inline-block; }

.dd-btn {
    background: #131722;
    border: 1px solid #2a2e39;
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 11px;
    color: #b2b5be;
    line-height: 1.4;
    white-space: nowrap;
}
.dd-btn:hover { background: #2a2e39; color: #e6edf3; }
.dropdown.open .dd-btn { background: #1a3260; border-color: #2962ff; color: #a3b8ff; }

.dd-panel {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 300;
    background: #1c2030;
    border: 1px solid #363c4e;
    border-radius: 6px;
    padding: 6px;
    min-width: 200px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.55);
    flex-direction: column;
    gap: 2px;
}
.dropdown.open .dd-panel { display: flex; }

.dd-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 1px 2px;
}
.dd-row .ind-check + label {
    flex: 1;
    border-radius: 4px;
    border: 1px solid transparent;
    background: transparent;
    padding: 3px 7px;
    font-size: 12px;
}
.dd-row .ind-check + label:hover { background: #2a2e39; }
.dd-row .ind-check:checked + label { background: #1a3260; border-color: #2962ff; color: #a3b8ff; }
.dd-row .gear-btn { padding: 2px 4px; font-size: 11px; }

.dd-divider { height: 1px; background: #2a2e39; margin: 3px 0; }

/* Vergleich */
#compare-ticker {
    width: 86px;
    padding: 3px 7px;
    background: #2a2e39;
    border: 1px solid #363c4e;
    color: #d1d4dc;
    border-radius: 4px;
    font-size: 11px;
}
#compare-ticker::placeholder { color: #5d6475; }
#compare-ticker:focus { outline: none; border-color: #2962ff; }

#compare-chip {
    font-size: 11px;
    color: #f59e0b;
    background: #2a2e39;
    border: 1px solid #363c4e;
    border-radius: 10px;
    padding: 2px 8px;
    white-space: nowrap;
}
#compare-chip.hidden { display: none; }
#compare-chip span { cursor: pointer; color: #787b86; margin-left: 3px; }
#compare-chip span:hover { color: #f23645; }

/* ─── Crosshair-Legende ──────────────────────────────────────────────────── */
#legend {
    display: none;
    position: absolute;
    top: 8px;
    left: 10px;
    z-index: 12;
    pointer-events: none;
    font-size: 12px;
    color: #334155;
    background: rgba(255,255,255,0.82);
    border-radius: 4px;
    padding: 4px 8px;
    line-height: 1.5;
}
#legend.visible { display: block; }
#legend-ohlc span { color: #475569; }
#legend-meta { font-size: 10px; color: #94a3b8; }

/* ─── Replay-Bar ─────────────────────────────────────────────────────────── */
#replay-bar {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 6px;
    background: #1c2030;
    border: 1px solid #363c4e;
    border-radius: 8px;
    padding: 6px 10px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.45);
}
#replay-bar.hidden { display: none; }
#replay-bar button {
    background: #2a2e39;
    border: 1px solid #363c4e;
    color: #d1d4dc;
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 12px;
}
#replay-bar button:hover { background: #363c4e; }
#replay-bar select {
    background: #2a2e39;
    color: #d1d4dc;
    border: 1px solid #363c4e;
    border-radius: 4px;
    font-size: 11px;
    padding: 2px 4px;
}
#replay-slider { width: 220px; accent-color: #2962ff; }
#replay-date { font-size: 11px; color: #b2b5be; white-space: nowrap; min-width: 150px; }

/* ─── Alert-Banner + Alert-Liste ─────────────────────────────────────────── */
#alert-banner {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    background: #f59e0b;
    color: #1c1304;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    padding: 7px 14px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
    max-width: 70%;
}
#alert-banner.hidden { display: none; }

.alert-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    border-bottom: 1px solid #2a2e39;
    font-size: 12px;
    color: #d1d4dc;
}
.alert-row > span:first-child { flex: 1; }
.alert-state { font-size: 11px; color: #787b86; }
.alert-del {
    background: none;
    border: none;
    color: #f23645;
    cursor: pointer;
    font-size: 13px;
}
.alert-empty { font-size: 12px; color: #787b86; padding: 8px 0; }

#alerts-modal select, #alerts-modal input[type=number] {
    background: #131722;
    border: 1px solid #363c4e;
    color: #d1d4dc;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
}

/* ─── Hilfe-Modal ────────────────────────────────────────────────────────── */
.help-section { margin-bottom: 14px; font-size: 12px; color: #d1d4dc; }
.help-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.help-table td {
    padding: 3px 8px 3px 0;
    border-bottom: 1px solid #2a2e39;
    font-size: 12px;
    color: #b2b5be;
    vertical-align: top;
}
.help-table td:first-child { white-space: nowrap; color: #e6edf3; font-weight: 600; width: 130px; }

/* ─── Multi-Chart-Grid (MTF / Multiscreen) ───────────────────────────────── */
#chart-area {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}
#chart-area.grid-2 { grid-template-columns: 1fr 1fr; }
#chart-area.grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

#slot-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.grid-slot {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    border-left: 1px solid #2a2e39;
    border-top: 1px solid #2a2e39;
}

.slot-header {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    background: #1c2030;
    border-bottom: 1px solid #2a2e39;
    font-size: 11px;
}
.slot-symbol {
    width: 76px;
    padding: 2px 6px;
    background: #2a2e39;
    border: 1px solid #363c4e;
    color: #d1d4dc;
    border-radius: 4px;
    font-size: 11px;
    text-transform: uppercase;
}
.slot-symbol:disabled { opacity: 0.55; }
.slot-tf {
    background: #2a2e39;
    color: #d1d4dc;
    border: 1px solid #363c4e;
    border-radius: 4px;
    padding: 2px 4px;
    font-size: 11px;
}
.slot-legend { color: #787b86; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-legend b { color: #d1d4dc; }
.slot-warn { color: #f59e0b; cursor: help; }
.slot-chart { flex: 1; min-height: 0; }

/* ─── MTF-Bias-Leiste ────────────────────────────────────────────────────── */
#bias-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    background: #161a27;
    border-bottom: 1px solid #2a2e39;
    font-size: 11px;
    flex-shrink: 0;
}
#bias-bar.hidden { display: none; }
.bias-title { color: #5d6475; text-transform: uppercase; letter-spacing: 0.5px; font-size: 10px; cursor: help; }
.bias-chip {
    padding: 1px 8px;
    border-radius: 9px;
    border: 1px solid #2a2e39;
    cursor: help;
    white-space: nowrap;
}
.bias-up { color: #4ade80; background: rgba(22,163,74,0.12); border-color: rgba(22,163,74,0.4); }
.bias-down { color: #f87171; background: rgba(220,38,38,0.12); border-color: rgba(220,38,38,0.4); }
.bias-na { color: #5d6475; }

.quality-warn { color: #b45309; cursor: help; }

/* ─── Mobile / PWA ───────────────────────────────────────────────────────── */
#sidebar-toggle { display: none; }

@media (max-width: 900px) {
    #app { grid-template-columns: 1fr; }
    #sidebar-toggle { display: inline-block; }
    #sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 240px;
        z-index: 500;
        transform: translateX(-100%);
        transition: transform 0.18s ease;
        box-shadow: 4px 0 18px rgba(0,0,0,0.5);
    }
    #sidebar.open { transform: translateX(0); }
    #chart-header { gap: 4px; padding: 4px 6px; }
    #status { display: none; }
    #compare-ticker { width: 64px; }
    #chart-area.grid-2, #chart-area.grid-4 {
        grid-template-columns: 1fr;
        grid-template-rows: none;
        grid-auto-rows: minmax(220px, 1fr);
        overflow-y: auto;
    }
    #replay-slider { width: 120px; }
    #replay-date { min-width: 0; }
}

@media (pointer: coarse) {
    .draw-tool { width: 38px; height: 38px; }
    .ind-check + label { padding: 5px 10px; }
    .hdr-btn, .dd-btn { padding: 6px 10px; }
    .dd-row .gear-btn { padding: 6px 8px; font-size: 13px; }
}
