/* Vector Clock & Frontier Explorer — Styles */

:root {
  --bg: #fafafa;
  --card-bg: #ffffff;
  --text: #212121;
  --text-secondary: #616161;
  --text-muted: #9e9e9e;
  --border: #e0e0e0;
  --accent: #1976d2;
  --cursor-color: #f44336;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Operation state colors — read by renderer.js via getComputedStyle(). */
  --state-pending-fill: #e8e8e8;
  --state-pending-stroke: #bbb;
  --state-pending-text: #999;
  --state-ready-fill: #fff3e0;
  --state-ready-stroke: #ef6c00;
  --state-ready-text: #e65100;
  --state-in-flight-fill: #c8e6c9;
  --state-in-flight-stroke: #2e7d32;
  --state-in-flight-text: #1b5e20;
  --state-retired-fill: #bbdefb;
  --state-retired-stroke: #1565c0;
  --state-retired-text: #0d47a1;

  /* SVG structural colors — also read by renderer.js. */
  --arrow-sat: #43a047;
  --arrow-unsat: #bdbdbd;
  --arrow-hl: #c62828;
  --lane-even: #fafafa;
  --lane-odd: #f5f5f5;
  --grid-line: #e0e0e0;
  --grid-label: #9e9e9e;
  --lane-label: #424242;
  --hw-sublabel: #aaa;
  --edge-label: #999;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 24px;
}

/* ----- Header ----- */

header {
  text-align: center;
  margin-bottom: 24px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

header .subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ----- Layout ----- */

main {
  max-width: 1100px;
  margin: 0 auto;
}

/* ----- Cards ----- */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.card h2.section-divider {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #f0f0f0;
}

/* ----- Scenario selector ----- */

.scenario-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.scenario-header label {
  font-weight: 600;
  font-size: 0.9rem;
}

#scenario-select {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: var(--sans);
  background: var(--card-bg);
  color: var(--text);
}

#scenario-description {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ----- Scaling controls ----- */

.scaling-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #f0f0f0;
}

.scaling-slider-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scaling-slider-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  min-width: 40px;
}

.scaling-slider-group input[type="range"] {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.scaling-slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.scaling-slider-group input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.scaling-slider-group input[type="range"]:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.scaling-slider-group input[type="range"]:disabled::-webkit-slider-thumb {
  background: #999;
  cursor: not-allowed;
}

.scaling-slider-group input[type="range"]:disabled::-moz-range-thumb {
  background: #999;
  cursor: not-allowed;
}

.scaling-value {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 1ch;
  color: var(--text);
}

.scaling-value.disabled {
  color: var(--text-muted);
}

.scaling-times {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 300;
}

.scaling-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.scaling-summary {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--mono);
  margin-left: auto;
}

/* Scrollable state tables for scaled scenarios. */
#sem-state,
#op-frontiers {
  max-height: 300px;
  overflow-y: auto;
}

/* ----- DAG and Timeline views ----- */

#dag-container,
#timeline-container {
  overflow-x: auto;
  padding: 4px 0;
}

#dag-container svg,
#timeline-container svg {
  display: block;
}

/* ----- Transport controls ----- */

#controls-section {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}

.transport {
  display: flex;
  gap: 4px;
}

.transport button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.1s, color 0.1s;
}

.transport button:hover {
  background: #f0f0f0;
  color: var(--text);
}

.transport button:active {
  background: #e0e0e0;
}

#time-slider {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}

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

#time-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.time-display {
  font-size: 0.85rem;
  font-family: var(--mono);
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 90px;
  text-align: right;
}

/* ----- Annotation callout ----- */

.annotation {
  min-height: 5.4rem;
  background: var(--card-bg);
  border-color: var(--border);
  transition: background 0.2s, border-color 0.2s;
}

.annotation.active {
  background: #f1f8e9;
  border-color: #aed581;
}

#annotation-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  font-style: italic;
}

.annotation.active #annotation-text {
  color: #33691e;
  font-style: normal;
}

/* ----- Bottom panels ----- */

#bottom-panels {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 760px) {
  #bottom-panels {
    grid-template-columns: 1fr;
  }
}

/* ----- Tables ----- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

thead th {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody td {
  padding: 5px 8px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: top;
}

.frontier {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
  word-break: break-all;
}

.sem-name,
.op-name {
  font-weight: 500;
  white-space: nowrap;
}

td.frontier:not(:empty) {
  transition: color 0.2s;
}

/* ----- Events ----- */

.event {
  padding: 3px 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.event.retired  { color: #1565c0; }
.event.signaled { color: #2e7d32; }
.event.ready    { color: #ef6c00; }
.event.issued   { color: #388e3c; }

.no-events {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ----- Tooltip ----- */

#tooltip {
  position: fixed;
  background: #333;
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  pointer-events: none;
  z-index: 1000;
  max-width: 320px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  line-height: 1.4;
}

#tooltip.hidden {
  display: none;
}

#tooltip strong {
  display: block;
  margin-bottom: 3px;
  font-size: 0.85rem;
}

.tt-row {
  margin: 2px 0;
}

.tt-frontier {
  font-family: var(--mono);
  font-size: 0.75rem;
}

/* ----- Footer ----- */

footer {
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 8px;
}

.legend-item {
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.legend-item.pending {
  background: var(--state-pending-fill);
  border: 1px solid var(--state-pending-stroke);
  color: var(--state-pending-text);
}

.legend-item.ready {
  background: var(--state-ready-fill);
  border: 1px solid var(--state-ready-stroke);
  color: var(--state-ready-text);
}

.legend-item.in-flight {
  background: var(--state-in-flight-fill);
  border: 1px solid var(--state-in-flight-stroke);
  color: var(--state-in-flight-text);
}

.legend-item.retired {
  background: var(--state-retired-fill);
  border: 1px solid var(--state-retired-stroke);
  color: var(--state-retired-text);
}

/* ----- Dark mode ----- */

body.dark {
  --bg: #121212;
  --card-bg: #1e1e1e;
  --text: #e0e0e0;
  --text-secondary: #aaa;
  --text-muted: #888;
  --border: #333;
  --accent: #42a5f5;
  --cursor-color: #ef5350;

  --state-pending-fill: #2a2a2a;
  --state-pending-stroke: #666;
  --state-pending-text: #999;
  --state-ready-fill: #3e2723;
  --state-ready-stroke: #ff9800;
  --state-ready-text: #ffb74d;
  --state-in-flight-fill: #1b3a1b;
  --state-in-flight-stroke: #66bb6a;
  --state-in-flight-text: #81c784;
  --state-retired-fill: #0d2137;
  --state-retired-stroke: #42a5f5;
  --state-retired-text: #64b5f6;

  --arrow-sat: #66bb6a;
  --arrow-unsat: #555;
  --arrow-hl: #ef5350;
  --lane-even: #1a1a1a;
  --lane-odd: #1f1f1f;
  --grid-line: #444;
  --grid-label: #888;
  --lane-label: #ccc;
  --hw-sublabel: #999;
  --edge-label: #999;
}

body.dark .card h2.section-divider {
  border-top-color: #333;
}

body.dark .scaling-controls {
  border-top-color: #333;
}

body.dark .scaling-slider-group input[type="range"]:disabled::-webkit-slider-thumb {
  background: #666;
}

body.dark .scaling-slider-group input[type="range"]:disabled::-moz-range-thumb {
  background: #666;
}

body.dark .transport button:hover {
  background: #333;
}

body.dark .transport button:active {
  background: #444;
}

body.dark .annotation.active {
  background: #1a2e1a;
  border-color: #558b2f;
}

body.dark .annotation.active #annotation-text {
  color: #aed581;
}

body.dark tbody td {
  border-bottom-color: #2a2a2a;
}

body.dark .event.retired  { color: #42a5f5; }
body.dark .event.signaled { color: #66bb6a; }
body.dark .event.ready    { color: #ff9800; }
body.dark .event.issued   { color: #81c784; }

body.dark #tooltip {
  background: #e0e0e0;
  color: #212121;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

/* ----- Inline mode (for iframe embedding) ----- */

body.inline {
  padding: 8px;
}

body.inline header,
body.inline footer,
body.inline #scenario-description,
body.inline #bottom-panels {
  display: none;
}

body.inline .card {
  margin-bottom: 8px;
  padding: 10px;
}

body.inline #controls-section {
  padding: 6px 10px;
  margin-bottom: 8px;
}

body.inline .annotation {
  min-height: auto;
}

/* ----- Utilities ----- */

.hidden {
  display: none !important;
}
