/* ═══════════════════════════════════════════════════════════════
   AppHurst - Dark Trading Theme
   Inspired by TradingView's professional dark interface
   ═══════════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #131722;
    --bg-secondary: #1e222d;
    --bg-tertiary: #2a2e39;
    --bg-hover: #363a45;
    --border-color: #363a45;
    --text-primary: #d1d4dc;
    --text-secondary: #787b86;
    --text-muted: #4c525e;
    --accent-blue: #2962ff;
    --accent-blue-hover: #1e53e5;
    --accent-green: #26a69a;
    --accent-red: #ef5350;
    --accent-orange: #ff9800;
    --accent-purple: #ab47bc;
    --accent-cyan: #00bcd4;
    --accent-yellow: #ffeb3b;
    --accent-pink: #e91e90;
    --shadow: 0 2px 8px rgba(0,0,0,0.4);
    --radius: 6px;
    --transition: all 0.2s ease;
}

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

body.apphurst-body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;
    font-size: 13px;
    overflow-x: hidden;
    min-height: 100vh;
}

/* ─── Top Bar ─── */
.ah-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    z-index: 100;
    position: sticky;
    top: 0;
}

.ah-topbar .ah-logo {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent-blue);
    margin-right: 12px;
    white-space: nowrap;
    letter-spacing: -0.5px;
}
.ah-topbar .ah-logo span {
    color: var(--accent-green);
}

.ah-separator {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 4px;
}

/* ─── Select / Dropdown styling ─── */
.ah-select {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 5px 28px 5px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23787b86'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    min-width: 100px;
}
.ah-select:hover { border-color: var(--accent-blue); }
.ah-select:focus { outline: none; border-color: var(--accent-blue); box-shadow: 0 0 0 2px rgba(41,98,255,0.2); }

.ah-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* ─── Buttons ─── */
.ah-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.ah-btn:hover { background: var(--bg-hover); border-color: var(--text-secondary); }
.ah-btn:active { transform: scale(0.97); }
.ah-btn.active { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }

.ah-btn-primary {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #fff;
}
.ah-btn-primary:hover { background: var(--accent-blue-hover); }

.ah-btn-danger {
    background: var(--accent-red);
    border-color: var(--accent-red);
    color: #fff;
}
.ah-btn-danger:hover { background: #d32f2f; border-color: #d32f2f; }

.ah-btn-icon {
    padding: 5px 8px;
    font-size: 14px;
}

/* ─── Timeframe pills ─── */
.ah-tf-group {
    display: flex;
    gap: 2px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    padding: 2px;
}
.ah-tf-btn {
    padding: 4px 10px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}
.ah-tf-btn:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.ah-tf-btn.active { background: var(--accent-blue); color: #fff; }

/* ─── Main Layout ─── */
.ah-main {
    display: flex;
    height: calc(100vh - 46px);
}

.ah-chart-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.ah-chart-container {
    flex: 1;
    position: relative;
    min-height: 0;
}

#ah-chart {
    width: 100%;
    height: 100%;
}

/* ─── Side Panel ─── */
.ah-sidepanel {
    width: 280px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    transition: width 0.3s ease;
    flex-shrink: 0;
}
.ah-sidepanel.collapsed { width: 0; overflow: hidden; }

.ah-panel-section {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}
.ah-panel-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

/* ─── Cycle Toggle Rows ─── */
.ah-cycle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
.ah-cycle-row label {
    flex: 1;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
}
.ah-cycle-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Toggle switch */
.ah-toggle {
    position: relative;
    width: 32px;
    height: 18px;
    flex-shrink: 0;
}
.ah-toggle input { display: none; }
.ah-toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-primary);
    border-radius: 9px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
}
.ah-toggle-slider::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    left: 2px;
    top: 2px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: var(--transition);
}
.ah-toggle input:checked + .ah-toggle-slider {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}
.ah-toggle input:checked + .ah-toggle-slider::before {
    transform: translateX(14px);
    background: #fff;
}

/* ─── Status Bar ─── */
.ah-statusbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    font-size: 11px;
    color: var(--text-secondary);
}
.ah-status-item { white-space: nowrap; }
.ah-status-item.green { color: var(--accent-green); }
.ah-status-item.red { color: var(--accent-red); }

/* ─── Loading overlay ─── */
.ah-loading {
    position: absolute;
    inset: 0;
    background: rgba(19,23,34,0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    gap: 12px;
    transition: opacity 0.3s ease;
}
.ah-loading.hidden { opacity: 0; pointer-events: none; }

.ah-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: ah-spin 0.8s linear infinite;
}
@keyframes ah-spin { to { transform: rotate(360deg); } }

.ah-loading-text {
    color: var(--text-secondary);
    font-size: 12px;
}

/* ─── Tooltip ─── */
.ah-tooltip {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 11px;
    z-index: 200;
    pointer-events: none;
    box-shadow: var(--shadow);
    max-width: 260px;
}

/* ─── Box Plot Legend ─── */
.ah-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}
.ah-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}
.ah-legend-item:hover { color: var(--text-primary); }
.ah-legend-color {
    width: 12px;
    height: 3px;
    border-radius: 1px;
}

/* ─── Scrollbar ─── */
.ah-sidepanel::-webkit-scrollbar { width: 6px; }
.ah-sidepanel::-webkit-scrollbar-track { background: var(--bg-secondary); }
.ah-sidepanel::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
.ah-sidepanel::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Range input ─── */
.ah-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--bg-primary);
    border-radius: 2px;
    outline: none;
}
.ah-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-blue);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
}

/* ─── Number input ─── */
.ah-input-num {
    width: 60px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 12px;
    text-align: center;
}
.ah-input-num:focus { outline: none; border-color: var(--accent-blue); }

/* ─── Cycle config table in panel ─── */
.ah-config-grid {
    display: grid;
    grid-template-columns: auto 1fr auto auto auto;
    gap: 4px 8px;
    align-items: center;
    font-size: 12px;
}
.ah-config-grid .head {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    padding-bottom: 4px;
}

/* ─── Responsive ─── */
@media (max-width: 900px) {
    .ah-sidepanel { width: 240px; }
    .ah-topbar { gap: 4px; padding: 4px 8px; }
}
@media (max-width: 600px) {
    .ah-sidepanel { display: none; }
}
