/* ==========================================================================
   CSS Variables (shadcn/ui inspired dark palette)
   ========================================================================== */
:root {
    --background: #09090b;
    --foreground: #fafafa;
    --card: #0a0a0c;
    --card-foreground: #fafafa;
    --popover: #0a0a0c;
    --popover-foreground: #fafafa;
    --primary: #fafafa;
    --primary-foreground: #18181b;
    --secondary: #27272a;
    --secondary-foreground: #fafafa;
    --muted: #27272a;
    --muted-foreground: #a1a1aa;
    --accent: #27272a;
    --accent-foreground: #fafafa;
    --destructive: #ef4444;
    --destructive-foreground: #fafafa;
    --border: #27272a;
    --input: #27272a;
    --ring: #d4d4d8;
    --radius: 0.5rem;
    --bid: #22c55e;
    --bid-muted: rgba(34, 197, 94, 0.12);
    --ask: #ef4444;
    --ask-muted: rgba(239, 68, 68, 0.12);
    --chart-bg: #09090b;
}

/* ==========================================================================
   Base / Reset
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', system-ui, sans-serif;
    background-color: var(--background);
    color: var(--foreground);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Layout
   ========================================================================== */
.app-container {
    max-width: 100%;
    padding: 68px 16px 12px; /* 56px fixed navbar + 12px */
}

/* ==========================================================================
   "UNDER DEVELOPMENT" Diagonal Watermark
   ========================================================================== */
.under-development-watermark {
    position: fixed;
    inset: 0;
    z-index: 9998;
    pointer-events: none;
    overflow: hidden;
}

.under-development-watermark::before {
    content: 'UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT    UNDER DEVELOPMENT';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    gap: 60px;
    font-size: 28px;
    font-weight: 900;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.04);
    transform: rotate(-35deg);
    white-space: nowrap;
    word-spacing: 80px;
    line-height: 120px;
}

/* ==========================================================================
   Top bar (title + metrics + trading + chart controls in one row)
   ========================================================================== */
.top-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
    padding: 12px 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.dashboard-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--foreground);
    margin-right: 8px;
}

.top-bar .dashboard-metrics {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.metric-card {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 6px 10px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.metric-price {
    align-items: center;
    gap: 10px;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--bid);
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bid);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
    animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.metric-price .metric-value {
    font-size: 18px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--foreground);
}

.top-bar .bar-chart-controls {
    flex: 1;
    min-width: 120px;
}

.top-bar .bar-status {
    margin-left: auto;
}

/* ==========================================================================
   Bar sections
   ========================================================================== */
.bar-section {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.bar-trading {
    gap: 8px;
}

.bar-chart-controls {
    flex: 1;
    min-width: 0;
    justify-content: center;
    gap: 6px;
}

.bar-chart-controls .chart-hint {
    margin-right: 2px;
    font-size: 10px;
}

.bar-status {
    margin-left: auto;
    gap: 6px;
}

/* ==========================================================================
   Form Controls (inputs, selects, checkboxes)
   ========================================================================== */
select,
input[type="text"],
input[type="number"] {
    padding: 6px 12px;
    height: 36px;
    border-radius: 0.375rem;
    background: var(--background);
    color: var(--foreground);
    border: 1px solid var(--border);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus,
input[type="text"]:focus,
input[type="number"]:focus {
    border-color: var(--ring);
    box-shadow: 0 0 0 2px rgba(212, 212, 216, 0.2);
}

select:hover,
input[type="text"]:hover,
input[type="number"]:hover {
    border-color: #3f3f46;
}

select {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

label {
    color: var(--muted-foreground);
    font-size: 13px;
    font-weight: 500;
    user-select: none;
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--foreground);
    cursor: pointer;
    vertical-align: middle;
    margin-right: 4px;
}

#market-type-selector,
#symbol-selector,
#timezone-selector,
.chart-hint {
    font-size: 11px;
    color: var(--muted-foreground);
    white-space: nowrap;
}

#timeframe-selector {
    min-width: 100px;
}

/* ==========================================================================
   Connection Status Indicator
   ========================================================================== */
.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted-foreground);
    padding: 4px 10px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ask);
    transition: background-color 0.3s ease;
}

.status-dot.connected {
    background: var(--bid);
    box-shadow: 0 0 4px rgba(34, 197, 94, 0.5);
}

.app-version {
    font-size: 11px;
    color: var(--muted-foreground);
    margin-left: 4px;
    padding: 2px 6px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
}

/* ==========================================================================
   Buttons (shadcn-style)
   ========================================================================== */
.btn {
    font-size: 0.875rem;
    font-weight: 500;
    height: 36px;
    padding: 0 16px;
    border-radius: 0.375rem;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--ring);
}

.btn-outline-secondary {
    color: var(--muted-foreground);
    border: 1px solid var(--border);
    background: transparent;
}

.btn-outline-secondary:hover {
    color: var(--foreground);
    background: rgba(255, 255, 255, 0.06);
    border-color: #3f3f46;
}

.btn-sm {
    height: 36px;
    padding: 0 12px;
    font-size: 0.8125rem;
}

/* ==========================================================================
   Loading spinners
   ========================================================================== */
.chart-wrapper {
  position: relative;
  min-height: 520px;
  margin-bottom: 10px;
}

.loading-spinner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  z-index: 10;
  border: 1px solid var(--border);
}

.loading-spinner-overlay.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-label {
  font-size: 13px;
  color: var(--muted-foreground);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   Chart
   ========================================================================== */
.chart-container {
    height: 520px;
    min-height: 400px;
    width: 100%;
    box-sizing: border-box;
    overflow: visible;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--background);
}

/* ==========================================================================
   TradingView Attribution (Apache 2.0 requirement)
   ========================================================================== */
.tv-attribution {
    font-size: 11px;
    color: var(--muted-foreground);
    text-decoration: none;
    padding: 2px 6px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.tv-attribution:hover {
    color: var(--foreground);
    border-color: #3f3f46;
}

/* ==========================================================================
   Strategy Performance Summary Table
   ========================================================================== */
.strategy-performance-summary-container {
    margin-top: 12px;
    background-color: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.strategy-performance-summary-container > h3 {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--muted-foreground);
    padding: 10px 16px;
    margin: 0;
    border-bottom: 1px solid var(--border);
    background: var(--background);
}

#strategy-performance-summary-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    border-spacing: 0;
}

#strategy-performance-summary-table th {
    color: var(--muted-foreground);
    cursor: pointer;
    user-select: none;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    text-align: right;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    background: var(--background);
    white-space: nowrap;
    transition: color 0.15s ease;
    position: sticky;
    top: 0;
    z-index: 1;
}

#strategy-performance-summary-table th:first-child {
    text-align: left;
    padding-left: 12px;
}

#strategy-performance-summary-table th:hover {
    color: var(--foreground);
}

/* Sort indicators */
#strategy-performance-summary-table th .sort-arrow {
    display: inline-block;
    opacity: 0.4;
    font-size: 10px;
}

#strategy-performance-summary-table th:hover .sort-arrow {
    opacity: 0.7;
}

#strategy-performance-summary-table th.sorted-asc .sort-arrow,
#strategy-performance-summary-table th.sorted-desc .sort-arrow {
    display: none;
}

#strategy-performance-summary-table th.sorted-asc::after {
    content: " \2191";
    color: var(--foreground);
}

#strategy-performance-summary-table th.sorted-desc::after {
    content: " \2193";
    color: var(--foreground);
}

#strategy-performance-summary-table td {
    text-align: right;
    padding: 8px;
    border-bottom: 1px solid rgba(39, 39, 42, 0.4);
    overflow: hidden;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: #e4e4e7;
    transition: background-color 0.12s ease;
}

#strategy-performance-summary-table td:first-child {
    text-align: left;
    padding-left: 12px;
}

#strategy-performance-summary-table tr:hover td {
    background-color: rgba(255, 255, 255, 0.03);
}

.strategy-performance-profit-positive {
    color: var(--bid) !important;
    font-weight: 600;
}

.strategy-performance-profit-negative {
    color: var(--ask) !important;
    font-weight: 600;
}

.strategy-performance-drawdown-value {
    color: var(--ask) !important;
    opacity: 0.85;
}

.strategy-performance-status-running {
    color: var(--bid);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.strategy-performance-status-stopped {
    color: var(--muted-foreground);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Empty state */
.strategy-performance-empty-state-row td {
    text-align: center !important;
    padding: 48px 16px !important;
    border-bottom: none !important;
}

.strategy-performance-empty-state-row:hover td {
    background-color: transparent !important;
}

.strategy-performance-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.strategy-performance-empty-state-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--muted-foreground);
}

.strategy-performance-empty-state-description {
    margin: 0;
    font-size: 13px;
    color: rgba(161, 161, 170, 0.7);
    max-width: 400px;
}

/* ==========================================================================
   Scrollbar
   ========================================================================== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3f3f46;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1024px) {
    .top-bar {
        gap: 10px;
        padding: 8px 10px;
    }

    .top-bar .bar-chart-controls {
        flex: none;
        width: 100%;
        justify-content: flex-start;
    }
}

@media (max-width: 768px) {
    .app-container {
        padding: 68px 10px 8px;
    }

    .top-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 10px;
    }

    .dashboard-title {
        margin-right: 0;
        text-align: center;
    }

    .top-bar .dashboard-metrics {
        justify-content: center;
    }

    .top-bar .bar-trading,
    .top-bar .bar-chart-controls {
        justify-content: center;
        flex-wrap: wrap;
    }

    .top-bar .bar-status {
        margin-left: 0;
        justify-content: center;
    }

    .chart-container {
        height: 380px;
        min-height: 300px;
        margin-bottom: 8px;
    }
}

@media (max-width: 480px) {
    .chart-container {
        height: 320px;
        min-height: 260px;
    }
}
