/* CSS Variables for theming */
:root {
  /* Light theme (default) */
  --bg-primary: #f5f5f5;
  --bg-secondary: #ffffff;
  --bg-header: #e8e8e8;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border-color: #ddd;
  --accent-color: #2563eb;
  --call-color: #16a34a;
  --put-color: #dc2626;
  --atm-bg: #fef3c7;
  --row-hover: #f0f0f0;
  --positive: #16a34a;
  --negative: #dc2626;
}

[data-theme="dark"] {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-header: #0f3460;
  --text-primary: #eaeaea;
  --text-secondary: #b0b0b0;
  --text-muted: #707070;
  --border-color: #2a2a4a;
  --accent-color: #60a5fa;
  --call-color: #4ade80;
  --put-color: #f87171;
  --atm-bg: #3b3a1a;
  --row-hover: #1e1e3a;
  --positive: #4ade80;
  --negative: #f87171;
}

/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header Controls */
.controls {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.control-row + .control-row {
  margin-top: 12px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.control-group select {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  min-width: 140px;
  cursor: pointer;
}

.control-group select:focus {
  outline: none;
  border-color: var(--accent-color);
}

.control-group select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Theme Toggle */
.theme-toggle {
  margin-left: auto;
}

.theme-toggle button {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.light-icon { display: inline; }
.dark-icon { display: none; }

[data-theme="dark"] .light-icon { display: none; }
[data-theme="dark"] .dark-icon { display: inline; }

/* Underlying Display */
.underlying-display {
  text-align: right;
}

.underlying-display span {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent-color);
}

/* Time Controls */
.time-controls {
  justify-content: center;
}

.nav-btn {
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-btn:hover:not(:disabled) {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.time-slider-container {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  max-width: 500px;
}

.current-time {
  font-size: 16px;
  font-weight: 600;
  font-family: monospace;
  min-width: 80px;
}

#tickSlider {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border-color);
  border-radius: 3px;
  cursor: pointer;
}

#tickSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent-color);
  border-radius: 50%;
  cursor: pointer;
}

#tickSlider:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tick-info {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 70px;
  text-align: right;
}

/* Loading Overlay */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 1000;
  color: white;
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Options Chain Table */
.chain-container {
  flex: 1;
  overflow: auto;
  padding: 20px;
}

.chain-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-secondary);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chain-table th,
.chain-table td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border-color);
}

.chain-table thead tr:first-child th {
  background: var(--bg-header);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.calls-header {
  color: var(--call-color);
  border-right: 2px solid var(--border-color);
}

.puts-header {
  color: var(--put-color);
  border-left: 2px solid var(--border-color);
}

.strike-header {
  background: var(--bg-header) !important;
  text-align: center !important;
  font-weight: 700;
}

.sub-header th {
  background: var(--bg-primary);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

.sub-header th:nth-child(4) {
  border-right: 2px solid var(--border-color);
}

.sub-header th:nth-child(5) {
  text-align: center;
}

.sub-header th:nth-child(6) {
  border-left: 2px solid var(--border-color);
}

.chain-table tbody tr:hover {
  background: var(--row-hover);
}

.chain-table tbody td {
  font-family: monospace;
  font-size: 13px;
}

.chain-table tbody td:nth-child(4) {
  border-right: 2px solid var(--border-color);
}

.chain-table tbody td:nth-child(5) {
  text-align: center;
  font-weight: 600;
  background: var(--bg-primary);
  border-left: 2px solid var(--border-color);
  border-right: 2px solid var(--border-color);
}

.chain-table tbody td:nth-child(6) {
  border-left: 2px solid var(--border-color);
}

/* ATM row highlight */
.chain-table tbody tr.atm {
  background: var(--atm-bg);
}

.chain-table tbody tr.atm:hover {
  background: var(--atm-bg);
}

/* Delta coloring */
.delta-positive {
  color: var(--positive);
}

.delta-negative {
  color: var(--negative);
}

/* Empty/NaN values */
.empty-value {
  color: var(--text-muted);
}

.empty-message {
  text-align: center !important;
  color: var(--text-muted);
  font-style: italic;
  padding: 40px !important;
}

/* Footer */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
  .control-row {
    gap: 10px;
  }

  .control-group select {
    min-width: 100px;
  }

  .chain-table th,
  .chain-table td {
    padding: 6px 8px;
    font-size: 12px;
  }
}
