/* TradingView-inspired dark theme */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #131722;
    --bg-secondary: #1e222d;
    --bg-tertiary: #2a2e39;
    --bg-hover: #363a45;
    --border-color: #363a45;
    --text-primary: #d1d4dc;
    --text-secondary: #787b86;
    --text-muted: #5d606b;
    --accent-blue: #2962ff;
    --accent-green: #26a69a;
    --accent-red: #ef5350;
    --accent-orange: #f7931a;
    --accent-yellow: #ffeb3b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 24px;
    height: 24px;
    color: var(--accent-orange);
}

.title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.symbol-badge {
    background: var(--bg-tertiary);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.timeframe-badge {
    background: var(--accent-blue);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    color: white;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.price-display {
    text-align: right;
}

.current-price {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.price-change {
    font-size: 13px;
    margin-left: 8px;
}

.price-change.positive {
    color: var(--accent-green);
}

.price-change.negative {
    color: var(--accent-red);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.online {
    background: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
}

.status-dot.offline {
    background: var(--text-muted);
}

.status-dot.checking {
    background: var(--accent-yellow);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-text {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Chart Section */
.chart-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.ohlcv-display {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
}

.ohlcv-label {
    color: var(--text-muted);
    margin-left: 12px;
}

.ohlcv-label:first-child {
    margin-left: 0;
}

.ohlcv-value {
    color: var(--text-primary);
    font-weight: 500;
}

.ohlcv-value.high {
    color: var(--accent-green);
}

.ohlcv-value.low {
    color: var(--accent-red);
}

.ohlcv-value.volume {
    color: var(--accent-blue);
}

.chart-controls {
    display: flex;
    gap: 4px;
}

.chart-btn {
    background: var(--bg-tertiary);
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.chart-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.chart-btn.active {
    background: var(--accent-blue);
    color: white;
}

.refresh-btn {
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.refresh-icon {
    width: 14px;
    height: 14px;
}

.refresh-btn:hover {
    background: var(--accent-blue) !important;
    color: white !important;
}

.refresh-btn.spinning {
    animation: spin 0.5s linear;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

#chart {
    flex: 1;
    width: 100%;
    position: relative;
}

.outlook-widget {
    position: absolute;
    top: 12px;
    right: 120px;
    background: rgba(19, 23, 34, 0.95);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px 16px;
    z-index: 100;
    min-width: 160px;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: border-color 0.2s;
}

.outlook-widget:hover {
    border-color: var(--accent-blue);
}

.outlook-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 16px;
}

.outlook-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.outlook-label.quiet {
    color: var(--text-muted);
}

.outlook-label.building {
    color: #ffb74d;
}

.outlook-label.imminent {
    color: var(--accent-red);
    animation: pulse-text 1s infinite;
}

@keyframes pulse-text {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.outlook-next {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

.outlook-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.outlook-fill {
    height: 100%;
    width: 0%;
    border-radius: 2px;
    transition: width 0.5s ease, background 0.3s ease;
}

.outlook-fill.quiet {
    background: var(--text-muted);
}

.outlook-fill.building {
    background: linear-gradient(90deg, #ffb74d, #ff9800);
}

.outlook-fill.imminent {
    background: linear-gradient(90deg, #ef5350, #f44336);
}

.price-countdown {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(20px);
    background: rgba(19, 23, 34, 0.9);
    border: 1px solid var(--border-color);
    border-right: none;
    border-radius: 4px 0 0 4px;
    padding: 4px 10px;
    z-index: 100;
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Factors Modal */
.factors-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.factors-modal.visible {
    display: flex;
}

.factors-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 400px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.factors-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.factors-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.factors-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
}

.factors-close:hover {
    color: var(--text-primary);
}

.factors-score {
    text-align: center;
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.factors-total {
    font-size: 48px;
    font-weight: 700;
    color: var(--text-primary);
}

.factors-max {
    font-size: 24px;
    color: var(--text-muted);
}

.factors-list {
    padding: 16px 20px;
    max-height: 300px;
    overflow-y: auto;
}

.factor-item {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.factor-item:last-child {
    border-bottom: none;
}

.factor-info {
    flex: 1;
}

.factor-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.factor-detail {
    font-size: 11px;
    color: var(--text-secondary);
}

.factor-score {
    display: flex;
    align-items: center;
    gap: 8px;
}

.factor-bar {
    width: 60px;
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
}

.factor-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

.factor-fill.low {
    background: var(--text-muted);
}

.factor-fill.medium {
    background: #ffb74d;
}

.factor-fill.high {
    background: var(--accent-green);
}

.factor-value {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 24px;
    text-align: right;
}

.factors-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

/* Control Panel */
.control-panel {
    width: 300px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.panel-section {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.panel-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-icon {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.btn-icon {
    width: 14px;
    height: 14px;
    vertical-align: -2px;
    margin-right: 4px;
}

.control-group {
    margin-bottom: 12px;
}

.control-group label {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-group {
    display: flex;
    align-items: center;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.input-group:focus-within {
    border-color: var(--accent-blue);
}

.input-prefix,
.input-suffix {
    padding: 8px 10px;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
}

.input-group input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 8px 10px;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    min-width: 0;
}

.input-group input[type="number"] {
    -moz-appearance: textfield;
}

.input-group input::-webkit-outer-spin-button,
.input-group input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.webhook-input {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 12px;
    color: var(--text-primary);
    outline: none;
}

.webhook-input:focus {
    border-color: var(--accent-blue);
}

.webhook-input::placeholder {
    color: var(--text-muted);
}

/* Buttons */
.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent-blue);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #1e53e4;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    margin-top: 8px;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
}

.btn-danger {
    background: var(--accent-red);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #d32f2f;
}

.button-group {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.button-group .btn {
    flex: 1;
}

/* Monitor Status */
.monitor-status {
    background: var(--bg-primary);
    border-radius: 4px;
    padding: 12px;
}

.status-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 12px;
}

.status-row:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.status-row span:first-child {
    color: var(--text-secondary);
}

.status-value {
    color: var(--text-primary);
    font-weight: 500;
}

/* Consolidation Alert */
.consolidation-alert {
    background: rgba(38, 166, 154, 0.1);
    border: 1px solid var(--accent-green);
    border-radius: 4px;
    margin: 16px;
}

.consolidation-alert .panel-title {
    color: var(--accent-green);
}

.alert-details {
    background: var(--bg-primary);
    border-radius: 4px;
    padding: 12px;
}

.alert-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13px;
}

.alert-row span:first-child {
    color: var(--text-secondary);
}

.alert-row span:last-child {
    color: var(--accent-green);
    font-weight: 600;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-hover);
}

/* ================================
   MOBILE RESPONSIVE STYLES
   iPhone 14 Pro Max: 430x932px
   ================================ */

/* Tablet and below */
@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
    }
    
    .control-panel {
        width: 100%;
        max-height: 40vh;
        overflow-y: auto;
        border-left: none;
        border-top: 1px solid var(--border-color);
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    body {
        overflow: auto;
    }
    
    .container {
        height: auto;
        min-height: 100vh;
    }
    
    /* Header - stack on mobile */
    .header {
        flex-direction: column;
        gap: 8px;
        padding: 10px 12px;
    }
    
    .header-left {
        width: 100%;
        justify-content: center;
    }
    
    .header-right {
        width: 100%;
        justify-content: space-between;
    }
    
    .title {
        font-size: 14px;
    }
    
    .symbol-badge, .timeframe-badge {
        font-size: 11px;
        padding: 3px 6px;
    }
    
    .current-price {
        font-size: 18px;
    }
    
    .price-change {
        font-size: 12px;
    }
    
    /* Main content - stack vertically */
    .main-content {
        flex-direction: column;
        overflow: visible;
    }
    
    /* Chart section */
    .chart-section {
        min-height: 300px;
        height: 45vh;
    }
    
    .chart-header {
        flex-direction: column;
        gap: 8px;
        padding: 8px 10px;
    }
    
    .ohlcv-display {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        gap: 2px;
        font-size: 10px;
    }
    
    .ohlcv-label {
        margin-left: 6px;
    }
    
    .chart-controls {
        width: 100%;
        justify-content: center;
    }
    
    .chart-btn {
        padding: 6px 10px;
        font-size: 11px;
    }
    
    /* Chart container */
    #chart {
        position: relative;
        flex: 1;
        min-height: 250px;
    }
    
    /* Outlook widget - mobile position */
    .outlook-widget {
        top: 8px;
        left: 8px;
        padding: 8px 12px;
        min-width: 100px;
    }
    
    .outlook-label {
        font-size: 11px;
    }
    
    .outlook-next {
        font-size: 9px;
    }
    
    .outlook-bar {
        height: 3px;
    }
    
    /* Countdown */
    .price-countdown {
        bottom: 8px;
        right: 8px;
        padding: 4px 8px;
        font-size: 10px;
    }
    
    /* Control panel - full width on mobile */
    .control-panel {
        width: 100%;
        max-height: none;
        border-left: none;
        border-top: 1px solid var(--border-color);
        overflow: visible;
    }
    
    .panel-section {
        padding: 12px;
    }
    
    .panel-title {
        font-size: 12px;
    }
    
    .panel-icon {
        width: 14px;
        height: 14px;
    }
    
    .control-group {
        margin-bottom: 10px;
    }
    
    .control-group label {
        font-size: 11px;
    }
    
    .input-group input {
        font-size: 14px;
        padding: 8px;
    }
    
    .input-prefix, .input-suffix {
        font-size: 11px;
        padding: 8px;
    }
    
    /* Webhook input */
    .webhook-input {
        font-size: 11px;
        padding: 8px;
    }
    
    /* Buttons */
    .btn {
        padding: 10px 16px;
        font-size: 13px;
    }
    
    .btn-icon {
        width: 14px;
        height: 14px;
    }
    
    .button-group {
        gap: 8px;
    }
    
    /* Status rows */
    .status-row {
        font-size: 12px;
        padding: 6px 0;
    }
    
    /* Consolidation alert */
    .consolidation-alert {
        margin: 12px;
    }
    
    .alert-row {
        font-size: 12px;
    }
    
    /* Factors modal - fullscreen on mobile */
    .factors-modal {
        padding: 0;
    }
    
    .factors-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .factors-header h2 {
        font-size: 16px;
    }
    
    .factors-score {
        padding: 16px;
    }
    
    .factors-total {
        font-size: 36px;
    }
    
    .factors-max {
        font-size: 16px;
    }
    
    .factor-item {
        padding: 10px 12px;
    }
    
    .factor-name {
        font-size: 12px;
    }
    
    .factor-score {
        font-size: 14px;
    }
    
    .factor-detail {
        font-size: 10px;
    }
    
    .factor-bar {
        height: 3px;
    }
}

/* Extra small phones */
@media (max-width: 375px) {
    .header-left {
        gap: 6px;
    }
    
    .title {
        font-size: 13px;
    }
    
    .current-price {
        font-size: 16px;
    }
    
    .chart-section {
        min-height: 250px;
        height: 40vh;
    }
    
    .ohlcv-display {
        font-size: 9px;
    }
}

/* Landscape mode on phones */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 6px 12px;
    }
    
    .chart-section {
        height: 60vh;
    }
    
    .control-panel {
        max-height: 50vh;
        overflow-y: auto;
    }
}

/* iOS safe areas (notch support) */
@supports (padding-top: env(safe-area-inset-top)) {
    .header {
        padding-top: calc(8px + env(safe-area-inset-top));
        padding-left: calc(12px + env(safe-area-inset-left));
        padding-right: calc(12px + env(safe-area-inset-right));
    }
    
    .control-panel {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}
