/* =============================================================================
   Elasticity demo widget — styles
   Matches the in-app screener heatmap (stocktimus_app/frontend/src/styles/ui.css)
   ============================================================================= */

/* The screener uses #218aff for column headers. Defined locally so the widget
   stays decoupled from the parent variables.css. */
:root {
  --ol-header-blue: #218aff;
  --ol-row-bg-even: #12121a;
  --ol-row-bg-odd:  #0c0c14;
  --ol-border:      #2a2a3a;
}

.ol-demo-shell {
  display: flex;
  flex-direction: column;
  gap: var(--space-4, 1rem);
  width: 100%;
}

/* --- Top toolbar (refresh button + attribution) ---------------------- */
.ol-demo-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4, 1rem);
  flex-wrap: wrap;
}

.ol-demo-attribution {
  color: var(--color-text-secondary, #94a3b8);
  font-size: var(--text-sm, 0.875rem);
}

.ol-demo-refresh-btn {
  background: var(--color-accent-primary, #00d4aa);
  color: var(--color-text-inverse, #0a0a0f);
  border: none;
  border-radius: var(--radius-md, 0.5rem);
  padding: var(--space-2, 0.5rem) var(--space-4, 1rem);
  font-family: var(--font-sans);
  font-size: var(--text-sm, 0.875rem);
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.ol-demo-refresh-btn:hover:not(:disabled) { opacity: 0.85; }
.ol-demo-refresh-btn:active:not(:disabled) { transform: translateY(1px); }
.ol-demo-refresh-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* =============================================================================
   FILTER DROPDOWNS — vanilla equivalents of react-select
   ============================================================================= */
.ol-filter-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  padding: 1rem;
  background: #1f2937;
  border-radius: 0.5rem;
}

.ol-filter {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.ol-filter-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text-secondary, #d1d5db);
}

.ol-filter-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  min-height: 38px;
  padding: 0.25rem 0.5rem;
  background: #121212;
  color: var(--color-text-primary, #f8fafc);
  border: 1px solid #333;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ol-filter-control:hover { border-color: var(--ol-header-blue); }

.ol-filter-open .ol-filter-control {
  border-color: var(--ol-header-blue);
  box-shadow: 0 0 0 1px var(--ol-header-blue);
}

.ol-filter-placeholder {
  color: #aaaaaa;
  padding-left: 0.25rem;
}

.ol-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.25rem 0.125rem 0.5rem;
  background: var(--ol-header-blue);
  color: #000;
  border-radius: 4px;
  font-size: 0.8125rem;
  font-weight: 600;
}

.ol-filter-chip-x {
  background: transparent;
  border: none;
  color: #000;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
  border-radius: 2px;
}

.ol-filter-chip-x:hover {
  background: rgba(255, 77, 77, 0.85);
  color: #fff;
}

.ol-filter-caret {
  margin-left: auto;
  color: var(--color-text-secondary, #94a3b8);
  font-size: 0.75rem;
}

.ol-filter-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: #121212;
  border: 1px solid #333;
  border-radius: 6px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  max-height: 260px;
  overflow-y: auto;
}

.ol-filter-panel[hidden] { display: none; }

.ol-filter-actions {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #2a2a2a;
}

.ol-filter-action {
  background: none;
  border: none;
  color: var(--ol-header-blue);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}

.ol-filter-action:hover { text-decoration: underline; }

.ol-filter-empty {
  padding: 0.75rem;
  color: var(--color-text-secondary, #94a3b8);
  font-size: 0.875rem;
  text-align: center;
}

.ol-filter-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  color: var(--color-text-primary, #f8fafc);
  font-size: 0.875rem;
}

.ol-filter-option:hover { background: var(--ol-header-blue); color: #000; }

.ol-filter-option input[type="checkbox"] {
  accent-color: var(--ol-header-blue);
  cursor: pointer;
}

/* =============================================================================
   HEATMAP SETTINGS PANEL — Days-to-Exit slider + scenario multi-select
   Mirrors stocktimus_app/frontend/src/components/Screener/HeatmapSettingsPanel.js
   ============================================================================= */
.ol-settings-panel {
  background: #1f2937;
  border-radius: 0.5rem;
  overflow: hidden;
}

.ol-settings-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
  color: #e5e7eb;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background-color 0.15s ease;
}

.ol-settings-header:hover { background: #283142; }

.ol-settings-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #e5e7eb;
}

.ol-settings-subtitle {
  font-size: 0.75rem;
  color: #94a3b8;
}

.ol-settings-subtitle-blue { color: var(--ol-header-blue); }

.ol-settings-chevron {
  margin-left: auto;
  color: #94a3b8;
  font-size: 1rem;
  line-height: 1;
  transition: transform 0.15s ease;
}

.ol-settings-header-open .ol-settings-chevron { transform: rotate(90deg); }

.ol-settings-body {
  padding: 0 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ol-settings-body[hidden] { display: none; }

.ol-settings-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ol-settings-row-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.ol-settings-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: #d1d5db;
}

.ol-settings-date {
  margin-left: auto;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--ol-header-blue);
}

.ol-mode-toggle {
  display: flex;
  gap: 0.25rem;
}

.ol-mode-button {
  background: #374151;
  color: #9ca3af;
  border: none;
  border-radius: 0.25rem;
  padding: 0.125rem 0.5rem;
  font-family: inherit;
  font-size: 0.6875rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.ol-mode-button:hover { background: #4b5563; }

.ol-mode-button.ol-selected {
  background: var(--ol-header-blue);
  color: #fff;
}

.ol-slider-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ol-settings-slider {
  width: 100%;
  height: 8px;
  background: #374151;
  border-radius: 0.5rem;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  accent-color: var(--ol-header-blue);
}

.ol-settings-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--ol-header-blue);
  border: 2px solid #1f2937;
  border-radius: 50%;
  cursor: pointer;
}

.ol-settings-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--ol-header-blue);
  border: 2px solid #1f2937;
  border-radius: 50%;
  cursor: pointer;
}

.ol-settings-slider:focus { outline: none; }

.ol-settings-slider:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px rgba(33, 138, 255, 0.2);
}

.ol-slider-marks {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #6b7280;
}

.ol-scenario-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.ol-scenario-button {
  background: #374151;
  color: #d1d5db;
  border: none;
  border-radius: 0.25rem;
  padding: 0.25rem 0.5rem;
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.ol-scenario-button:hover { background: #4b5563; }

.ol-scenario-button.ol-selected {
  background: var(--ol-header-blue);
  color: #fff;
}

.ol-settings-reset-row {
  padding-top: 0.5rem;
}

.ol-settings-reset-row[hidden] { display: none; }

.ol-settings-reset {
  width: 33.3333%;
  background: #374151;
  color: #d1d5db;
  border: none;
  border-radius: 0.25rem;
  padding: 0.5rem 1rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.ol-settings-reset:hover { background: #4b5563; }

@media (max-width: 768px) {
  .ol-settings-row-header { flex-direction: column; align-items: stretch; }
  .ol-settings-date { margin-left: 0; }
  .ol-settings-reset { width: 100%; }
}

/* =============================================================================
   TABLE — mirrors the screener's `.table-*` styles
   ============================================================================= */
.ol-table-container {
  position: relative;
  width: 100%;
  border: 1px solid var(--ol-border);
  border-radius: 0.375rem;
  background: var(--color-bg-primary, #0a0a0f);
  max-height: 75vh;
  display: flex;
  flex-direction: column;
}

.ol-table-scroll {
  overflow-x: auto;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.ol-table-scroll::-webkit-scrollbar { height: 8px; width: 8px; }
.ol-table-scroll::-webkit-scrollbar-track { background: var(--color-bg-secondary, #12121a); border-radius: 4px; }
.ol-table-scroll::-webkit-scrollbar-thumb { background: var(--ol-header-blue); border-radius: 4px; }
.ol-table-scroll::-webkit-scrollbar-thumb:hover { background: #10b981; }

.ol-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--color-text-primary, #f8fafc);
  min-width: 720px;
}

/* --- TH (column headers) — blue, uppercase, mirrors screener ----- */
.ol-th {
  padding: 0.75rem 0.75rem;
  text-align: center;
  vertical-align: middle;
  background-color: var(--color-bg-primary, #0a0a0f);
  color: var(--ol-header-blue);
  text-transform: uppercase;
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  white-space: pre-line;
  border-bottom: 1px solid var(--ol-border);
  position: sticky;
  top: 0;
  z-index: 2;
}

.ol-th-scenario {
  min-width: 72px;
}

/* --- Sticky columns — widths mirror screener ui.css:261-307 ----- */
.ol-th-sticky,
.ol-td-sticky {
  position: sticky;
  z-index: 3;
  background-color: var(--color-bg-primary, #0a0a0f);
}

.ol-th-sticky { z-index: 4; }

/* 5 sticky cols: Ticker · Position (Buy Call) · Strike · Expiration · Current Prem */
.ol-th-sticky-1, .ol-td-sticky-1 { left: 0;     min-width: 65px;  max-width: 65px; }
.ol-th-sticky-2, .ol-td-sticky-2 { left: 65px;  min-width: 90px;  max-width: 90px; }
.ol-th-sticky-3, .ol-td-sticky-3 { left: 155px; min-width: 75px;  max-width: 75px; }
.ol-th-sticky-4, .ol-td-sticky-4 { left: 230px; min-width: 110px; max-width: 110px; }
.ol-th-sticky-5, .ol-td-sticky-5 {
  left: 340px;
  min-width: 90px;
  max-width: 90px;
  border-right: 1px solid var(--ol-border);
  box-shadow: 4px 0 8px rgba(0, 0, 0, 0.15);
}

/* --- TD (body cells) --- */
.ol-td {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--ol-border);
}

.ol-td-context {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.ol-td-scenario {
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  min-width: 72px;
}

.ol-td-empty {
  color: var(--color-text-tertiary, #64748b);
  font-weight: 400;
}

/* --- Row striping (preserved through sticky columns) --- */
.ol-tr-even .ol-td,
.ol-tr-even .ol-td-sticky { background-color: var(--ol-row-bg-even); }

.ol-tr-odd .ol-td,
.ol-tr-odd .ol-td-sticky { background-color: var(--ol-row-bg-odd); }

/* Scenario cells get inline background colors (heatmap) — they override
   the row-stripe background. */
.ol-tr-even .ol-td-scenario,
.ol-tr-odd  .ol-td-scenario {
  background-color: transparent;
}

/* --- Empty state --- */
.ol-table-empty {
  padding: 2rem;
  text-align: center;
  color: var(--color-text-secondary, #94a3b8);
  font-size: 0.875rem;
  border: 1px dashed var(--ol-border);
  border-radius: 0.375rem;
  background: var(--color-bg-secondary, #12121a);
}

/* =============================================================================
   SKELETON — server-rendered placeholder for first paint (no CLS)
   ============================================================================= */
.ol-demo-skeleton-wrapper {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--ol-border);
  border-radius: 0.375rem;
  background: var(--color-bg-secondary, #12121a);
}

.ol-demo-skeleton {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--font-sans);
  font-size: 0.875rem;
}

.ol-demo-skeleton th,
.ol-demo-skeleton td {
  padding: 0.75rem 0.75rem;
  border-bottom: 1px solid var(--ol-border);
  height: 36px;
}

.ol-demo-skeleton th {
  background: var(--color-bg-primary, #0a0a0f);
  color: var(--ol-header-blue);
  font-size: 0.75rem;
  text-transform: uppercase;
  text-align: center;
  font-weight: 600;
}

.ol-demo-skeleton .ol-demo-skeleton-bar {
  display: block;
  width: 70%;
  height: 12px;
  border-radius: 0.25rem;
  background: linear-gradient(
    90deg,
    var(--color-bg-tertiary, #1a1a24) 0%,
    var(--color-bg-elevated, #22222e) 50%,
    var(--color-bg-tertiary, #1a1a24) 100%
  );
  background-size: 200% 100%;
  animation: ol-demo-shimmer 1.6s linear infinite;
}

@keyframes ol-demo-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* =============================================================================
   MOBILE TWEAKS
   ============================================================================= */
@media (max-width: 768px) {
  .ol-filter-bar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .ol-demo-toolbar {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .ol-demo-refresh-btn { width: 100%; }
}
