/* ==========================================================================
   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 */
}

/* ==========================================================================
   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);
}

.metric-depth {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    padding: 4px 10px;
}

.metric-depth .metric-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted-foreground);
}

.metric-depth .metric-value {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.metric-depth .depth-asks {
    color: var(--ask);
}

.metric-depth .depth-bids {
    color: var(--bid);
}

#funding-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    padding: 4px 10px;
}

#funding-card .metric-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted-foreground);
}

#funding-card .metric-value {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.funding-positive { color: var(--bid); }
.funding-negative { color: var(--ask); }

.metric-sublabel {
    font-size: 10px;
    color: var(--muted-foreground);
}

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

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

/* ==========================================================================
   Bar 2 (lines + order book settings)
   ========================================================================== */
.bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    margin-bottom: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    flex-wrap: wrap;
}

.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;
}

.bar-secondary .bar-section {
    gap: 16px;
}

.bar-lines {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.bar-orderbook-settings {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.picker-group,
.timezone-group,
.hours-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.picker-group span,
.timezone-group span,
.hours-group span,
.label-short {
    color: var(--muted-foreground);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

#datetime-picker {
    text-align: center;
    width: 180px;
}

#hours-extend {
    width: 64px;
    text-align: center;
}

.price-display {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
}

.price-display label {
    color: var(--muted-foreground);
    margin: 0;
}

.price-display #current-price {
    color: var(--foreground);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-size: 14px;
}

/* ==========================================================================
   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="number"] {
    width: 80px;
    font-variant-numeric: tabular-nums;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    opacity: 0.5;
}

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

input[type="file"] {
    font-size: 13px;
}

#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: h-9, rounded-md, ring on focus)
   ========================================================================== */
.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-primary {
    background: var(--foreground);
    color: var(--primary-foreground);
    border: 1px solid var(--foreground);
}

.btn-primary:hover {
    background: #e4e4e7;
    border-color: #e4e4e7;
    color: var(--primary-foreground);
}

.btn-danger {
    background: var(--destructive);
    border: 1px solid var(--destructive);
}

.btn-danger:hover {
    background: #dc2626;
    border-color: #dc2626;
}

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

.btn-secondary:hover {
    background: #3f3f46;
    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;
}

.order-book-wrapper {
  position: relative;
}

.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); }
}

.order-book-wrapper .loading-spinner-overlay {
  min-height: 200px;
}

/* ==========================================================================
   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);
}

.chart-wrapper.has-toolbar .chart-container {
    margin-left: 40px;
    width: calc(100% - 40px);
}

.chart-wrapper.has-toolbar .loading-spinner-overlay {
    left: 40px;
}

/* ==========================================================================
   Drawing Toolbar
   ========================================================================== */
.drawing-toolbar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 40px;
    z-index: 8;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 0;
    gap: 2px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius) 0 0 var(--radius);
    overflow-y: auto;
    overflow-x: hidden;
}

.drawing-toolbar::-webkit-scrollbar {
    width: 0;
}

.drawing-toolbar-group {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.drawing-toolbar-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: calc(var(--radius) - 2px);
    background: transparent;
    color: var(--muted-foreground);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
    position: relative;
    flex-shrink: 0;
}

.drawing-toolbar-button:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--foreground);
}

.drawing-toolbar-button.drawing-toolbar-active {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

.drawing-toolbar-button:disabled,
.drawing-toolbar-button.drawing-toolbar-disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.drawing-toolbar-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.drawing-toolbar-icon svg {
    display: block;
}

.drawing-toolbar-primary-button {
    position: relative;
}

.drawing-toolbar-submenu-arrow {
    position: absolute;
    right: 1px;
    bottom: 1px;
    opacity: 0.5;
    line-height: 0;
}

/* Submenu flyout */
.drawing-toolbar-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: 0;
    margin-left: 2px;
    padding: 4px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 20;
    min-width: 160px;
}

.drawing-toolbar-submenu.drawing-toolbar-submenu-open {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.drawing-toolbar-submenu .drawing-toolbar-button {
    width: 100%;
    height: 30px;
    justify-content: flex-start;
    gap: 8px;
    padding: 0 8px;
    border-radius: calc(var(--radius) - 2px);
}

.drawing-toolbar-submenu .drawing-toolbar-icon {
    flex-shrink: 0;
}

.drawing-toolbar-tool-label {
    font-size: 12px;
    white-space: nowrap;
    color: inherit;
}

.drawing-toolbar-separator {
    width: 24px;
    height: 1px;
    background: var(--border);
    margin: 4px 0;
    flex-shrink: 0;
}

.drawing-toolbar-button.drawing-toolbar-active {
    box-shadow: inset 2px 0 0 #3b82f6;
}

.drawing-toolbar-submenu {
    transition: opacity 0.15s ease;
}

.drawing-toolbar-action-button {
    width: 32px;
    height: 32px;
}

/* ==========================================================================
   Drawing Properties Bar
   ========================================================================== */
.drawing-props-bar {
    display: none;
    position: absolute;
    top: 4px;
    left: 50px;
    z-index: 9;
    flex-direction: row;
    align-items: center;
    gap: 0;
    height: 34px;
    padding: 0 6px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.drawing-props-bar.drawing-properties-bar-visible {
    display: flex;
}

.drawing-properties-bar-swatch-wrap {
    position: relative;
}

.drawing-properties-bar-color-swatch {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    background: var(--background);
    cursor: pointer;
    transition: border-color 0.12s ease;
}

.drawing-properties-bar-color-swatch:hover {
    border-color: #3f3f46;
}

.drawing-properties-bar-swatch-color {
    display: block;
    width: 18px;
    height: 18px;
    border-radius: 3px;
}

.drawing-properties-bar-color-palette {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    padding: 6px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 25;
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
}

.drawing-properties-bar-color-palette.drawing-properties-bar-palette-open {
    display: grid;
}

.drawing-properties-bar-palette-swatch {
    width: 22px;
    height: 22px;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    transition: border-color 0.12s ease, transform 0.1s ease;
}

.drawing-properties-bar-palette-swatch:hover {
    transform: scale(1.15);
}

.drawing-properties-bar-palette-swatch.drawing-properties-bar-selected {
    border-color: #fff;
}

.drawing-properties-bar-separator {
    display: block;
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 6px;
    flex-shrink: 0;
}

.drawing-properties-bar-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.drawing-properties-bar-thickness-button,
.drawing-properties-bar-style-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 26px;
    padding: 0;
    border: none;
    border-radius: calc(var(--radius) - 2px);
    background: transparent;
    color: var(--muted-foreground);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.drawing-properties-bar-style-button {
    width: 34px;
}

.drawing-properties-bar-thickness-button:hover,
.drawing-properties-bar-style-button:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--foreground);
}

.drawing-properties-bar-thickness-button.drawing-properties-bar-active,
.drawing-properties-bar-style-button.drawing-properties-bar-active {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

/* Action buttons (clone, lock, delete) — selection mode only */
.drawing-properties-bar-actions {
    display: none;
}

.drawing-properties-bar-action-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--muted-foreground);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.drawing-properties-bar-action-button:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--foreground);
}

.drawing-properties-bar-action-button.drawing-properties-bar-active {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

.drawing-properties-bar-action-button[data-action="delete"]:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* ==========================================================================
   Zoom Selection Overlay
   ========================================================================== */
.zoom-selection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 7;
    cursor: crosshair;
}

.zoom-selection-rect {
    display: none;
    position: absolute;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.5);
    border-radius: 2px;
    pointer-events: none;
}

/* ==========================================================================
   Order Book Tables (dashboard style: horizontal dividers only, clean headers)
   ========================================================================== */
.order-book-container {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.order-book {
    flex: 1;
    background-color: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.order-book > 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);
}

.order-book > h3 span {
    color: var(--foreground);
    font-variant-numeric: tabular-nums;
}

.order-book table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    border-spacing: 0;
}

.order-book 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;
}

.order-book th:first-child {
    text-align: left;
    padding-left: 12px;
}

.order-book th:hover {
    color: var(--foreground);
}

.order-book 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;
}

.order-book td:first-child {
    text-align: left;
    padding-left: 12px;
}

.order-book tr:hover td {
    background-color: rgba(255, 255, 255, 0.03);
}

.order-book .bids td:nth-child(3),
.order-book .bids td:nth-child(3) .hoverable {
    color: var(--bid);
    font-weight: 600;
}

.order-book .asks td:nth-child(3),
.order-book .asks td:nth-child(3) .hoverable {
    color: var(--ask);
    font-weight: 600;
}

.order-book .bids td:first-child {
    color: var(--bid);
    font-weight: 600;
}

.order-book .asks td:first-child {
    color: var(--ask);
    font-weight: 600;
}

.order-book td.flash-up {
    animation: flash-green 0.45s ease-out;
}

.order-book td.flash-down {
    animation: flash-red 0.45s ease-out;
}

@keyframes flash-green {
    0% { background-color: rgba(34, 197, 94, 0.35); }
    100% { background-color: transparent; }
}

@keyframes flash-red {
    0% { background-color: rgba(239, 68, 68, 0.35); }
    100% { background-color: transparent; }
}

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

th:hover .sort-arrow {
    opacity: 0.7;
}

th.sorted-asc .sort-arrow,
th.sorted-desc .sort-arrow {
    display: none;
}

th.sorted-asc::after {
    content: " \2191";
    color: var(--foreground);
}

th.sorted-desc::after {
    content: " \2193";
    color: var(--foreground);
}

/* ==========================================================================
   Interactive Elements
   ========================================================================== */
.add-level-btn {
    background-color: transparent;
    color: var(--muted-foreground);
    border: 1px solid var(--border);
    padding: 2px 6px;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    font-size: 11px;
    transition: all 0.15s ease;
    line-height: 1;
}

.add-level-btn:hover {
    background-color: var(--bid);
    color: #fff;
    border-color: var(--bid);
}

.add-level-btn:active {
    opacity: 0.7;
}

/* ==========================================================================
   Tooltips
   ========================================================================== */
.hoverable {
    border-bottom: 1px dotted rgba(161, 161, 170, 0.3);
    cursor: help;
    transition: border-color 0.15s ease;
}

.hoverable:hover {
    border-bottom-color: var(--muted-foreground);
}

.custom-tooltip {
    position: fixed;
    background-color: var(--background);
    color: var(--popover-foreground);
    padding: 6px 10px;
    border-radius: calc(var(--radius) - 2px);
    border: 1px solid var(--border);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* ==========================================================================
   Modals (override Bootstrap dark)
   ========================================================================== */
.modal-content {
    background-color: var(--background);
    color: var(--foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
}

.modal-header {
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    border-top: 1px solid var(--border);
    padding: 12px 20px;
}

.btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
    opacity: 0.5;
    transition: opacity 0.15s ease;
}

.btn-close:hover {
    opacity: 1;
}

.modal .form-control {
    background-color: var(--background);
    border: 1px solid var(--border);
    color: var(--foreground);
    border-radius: calc(var(--radius) - 2px);
    font-size: 13px;
    padding: 8px 12px;
}

.modal .form-control:focus {
    background-color: var(--background);
    border-color: var(--ring);
    color: var(--foreground);
    box-shadow: 0 0 0 2px rgba(212, 212, 216, 0.1);
}

.modal .form-label {
    color: var(--muted-foreground);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
}

.modal .border-top {
    border-color: var(--border) !important;
}

/* ==========================================================================
   Confirm dialog (shadcn AlertDialog-style)
   ========================================================================== */
.orderbook-chart-confirm-dialog {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.orderbook-chart-confirm-dialog[hidden] {
    display: none !important;
}

.orderbook-chart-confirm-dialog-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}

.orderbook-chart-confirm-dialog-panel {
    position: relative;
    width: 100%;
    max-width: 400px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5);
}

.orderbook-chart-confirm-dialog-content {
    padding: 24px;
}

.orderbook-chart-confirm-dialog-title {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--foreground);
}

.orderbook-chart-confirm-dialog-description {
    margin: 0 0 24px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--muted-foreground);
}

.orderbook-chart-confirm-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.orderbook-chart-confirm-button {
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    border: none;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

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

.orderbook-chart-confirm-button-secondary {
    background: var(--secondary);
    color: var(--secondary-foreground);
}

.orderbook-chart-confirm-button-secondary:hover {
    background: #3f3f46;
    color: var(--foreground);
}

.orderbook-chart-confirm-button-destructive {
    background: var(--destructive);
    color: var(--destructive-foreground);
}

.orderbook-chart-confirm-button-destructive:hover {
    background: #dc2626;
}

#customLinePrice {
    width: 100%;
}

/* ==========================================================================
   Flatpickr dark overrides
   ========================================================================== */
.flatpickr-calendar {
    background: var(--background) !important;
    border: 1px solid var(--border) !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5) !important;
    border-radius: var(--radius) !important;
}

.flatpickr-months .flatpickr-month,
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-weekdays,
span.flatpickr-weekday {
    background: var(--background) !important;
    color: var(--muted-foreground) !important;
}

.flatpickr-day {
    color: var(--foreground) !important;
    border-radius: calc(var(--radius) - 2px) !important;
}

.flatpickr-day:hover {
    background: rgba(255, 255, 255, 0.06) !important;
    border-color: var(--border) !important;
}

.flatpickr-day.selected {
    background: var(--foreground) !important;
    color: var(--primary-foreground) !important;
    border-color: var(--foreground) !important;
}

.flatpickr-day.today {
    border-color: var(--muted-foreground) !important;
}

.flatpickr-time input,
.flatpickr-time .flatpickr-am-pm {
    color: var(--foreground) !important;
    background: var(--background) !important;
    border: 1px solid var(--border) !important;
    border-radius: calc(var(--radius) - 2px) !important;
}

.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
    fill: var(--muted-foreground) !important;
}

.flatpickr-months .flatpickr-prev-month:hover,
.flatpickr-months .flatpickr-next-month:hover {
    fill: var(--foreground) !important;
}

.flatpickr-current-month input.cur-year {
    color: var(--foreground) !important;
}

.numInputWrapper:hover {
    background: rgba(255, 255, 255, 0.06) !important;
}

.flatpickr-time .numInputWrapper span.arrowUp:after {
    border-bottom-color: var(--muted-foreground) !important;
}

.flatpickr-time .numInputWrapper span.arrowDown:after {
    border-top-color: var(--muted-foreground) !important;
}

/* ==========================================================================
   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;
}

/* ==========================================================================
   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;
}

/* ==========================================================================
   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;
    }

    .bar .bar-section {
        gap: 8px;
    }

    .bar-lines {
        gap: 12px;
    }
}

@media (max-width: 768px) {
    .app-container {
        padding: 68px 10px 8px; /* keep top for fixed navbar */
    }

    .order-book-container {
        min-width: 0;
    }

    .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;
    }

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

    .bar-lines {
        flex-direction: column;
        gap: 8px;
    }

    .bar-orderbook-settings {
        margin-left: 0;
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Drawing toolbar: horizontal row above chart on mobile */
    .drawing-toolbar {
        position: relative;
        left: auto;
        top: auto;
        bottom: auto;
        width: 100%;
        height: 36px;
        flex-direction: row;
        padding: 0 4px;
        gap: 1px;
        border-radius: var(--radius) var(--radius) 0 0;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .chart-wrapper.has-toolbar .chart-container {
        margin-left: 0;
        width: 100%;
    }

    .chart-wrapper.has-toolbar .loading-spinner-overlay {
        left: 0;
    }

    .drawing-props-bar {
        left: 0;
        right: 0;
        top: 38px;
        border-radius: 0;
        justify-content: center;
    }

    .drawing-toolbar-submenu {
        left: 0;
        top: 100%;
        margin-left: 0;
        margin-top: 2px;
    }

    .drawing-toolbar-separator {
        width: 1px;
        height: 20px;
        margin: 0 2px;
    }

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

    .order-book-container {
        flex-direction: column;
        gap: 8px;
    }

    .order-book > h3 {
        padding: 8px 12px;
        font-size: 11px;
    }

    .metric-card {
        padding: 6px 10px;
    }

    .metric-price .metric-value {
        font-size: 16px;
    }

    #datetime-picker {
        width: 100%;
    }
}

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

    .order-book th,
    .order-book td {
        padding: 6px 4px;
        font-size: 11px;
    }
}
