/* ==========================================================================
   NFA Visualizer - Stylesheet
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design Tokens - High Contrast Dark Theme
   -------------------------------------------------------------------------- */
:root {
  /* Background colors */
  --color-bg: #0f0f12;
  --color-surface: #18181c;
  --color-surface-raised: #36363f;
  --color-border: #3a3a45;

  /* Code/Editor colors */
  --color-code-bg: #0a0a0c;
  --color-code-border: #474759;

  /* Text colors - High Contrast */
  --color-text: #f5f5f7;
  --color-text-secondary: #b8b8c0;
  --color-text-muted: #7a7a85;

  /* Accent colors */
  --color-primary: #6c9eff;
  --color-primary-hover: #5088ff;
  --color-success: #4ade80;
  --color-error: #f87171;
  --color-epsilon: #a78bfa;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
  --font-size-xs: 11px;
  --font-size-code: 12px;
  --font-size-sm: 13px;
  --font-size-md: 14px;
  --font-size-lg: 16px;

  /* Borders & Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  /* Transitions */
  --transition-fast: 0.15s ease;
}

/* --------------------------------------------------------------------------
   Base Reset & Styles
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-md);
  line-height: 1.5;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-xl);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);

  h1 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-text);
  }
}

.header-links {
  font-size: var(--font-size-sm);

  a {
    color: var(--color-text-secondary);

    &:hover {
      color: var(--color-primary);
    }
  }
}

/* --------------------------------------------------------------------------
   Three-Panel App Layout
   -------------------------------------------------------------------------- */
.app-layout {
  display: grid;
  grid-template-columns: 380px 1fr 280px;
  height: calc(100vh - 53px);
  overflow: hidden;
  transition: grid-template-columns var(--transition-fast);

  &.config-collapsed {
    grid-template-columns: 0 1fr 280px;
  }
}

/* --------------------------------------------------------------------------
   Panel Base Styles
   -------------------------------------------------------------------------- */
.panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--color-border);
  overflow: hidden;

  &:last-child {
    border-right: none;
  }
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;

  h2 {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .examples-select {
    background: var(--color-surface-raised);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0 8px;
    font-size: var(--font-size-xs);
    font-family: var(--font-sans);
    outline: none;
    cursor: pointer;

    &:hover {
      border-color: var(--color-text-secondary);
    }

    &:focus {
      border-color: var(--color-primary);
    }
  }
}

/* Config Tabs */
.config-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-md);
  padding: 0 var(--space-sm);

  .config-tab {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--color-text-secondary);
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: -1px;
    border-radius: 0;

    &:hover {
      color: var(--color-text);
    }

    &.active {
      background: transparent;
      color: var(--color-text);
      font-weight: 500;
      border-bottom-color: var(--color-primary);
    }
  }
}

/* Panel toggle button */
.panel-toggle-btn {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  padding: var(--space-sm) var(--space-xs);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--color-text-secondary);
  cursor: pointer;
  z-index: 10;

  &::before {
    content: '\25C0';
  }

  &:hover {
    background: var(--color-surface-raised);
    color: var(--color-text);
  }

  .config-collapsed &::before {
    content: '\25B6';
  }
}

.config-collapsed .panel-config {
  overflow: hidden;
  border-right: none;

  .panel-header,
  .input-section,
  .button-row {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   Left Panel: Configuration
   -------------------------------------------------------------------------- */
.panel-config {
  background: var(--color-surface);

  .input-section {
    flex: 1;
    overflow-y: auto;
    padding: 0 var(--space-lg) var(--space-md) var(--space-sm);
    font-size: var(--font-size-code);
  }

  .button-row {
    padding: var(--space-lg);
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
  }
}

/* --------------------------------------------------------------------------
   Middle Panel: Visualization
   -------------------------------------------------------------------------- */
.panel-viz {
  background: var(--color-bg);
  position: relative;

  #cy-container {
    flex: 1;
    width: 100%;
    min-height: 400px;
    position: relative;
  }

  .empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    text-align: center;
    pointer-events: none;
  }

  .graph-tooltip {
    display: none;
    position: absolute;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: var(--space-xs) var(--space-sm);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--color-text);
    white-space: pre-line;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

/* --------------------------------------------------------------------------
   Right Panel: Metadata
   -------------------------------------------------------------------------- */
.panel-meta {
  background: var(--color-surface);
  overflow-y: auto;

  .metadata-section,
  .test-section,
  .state-list-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-lg);
  }

  .metadata-section,
  .test-section {
    border-bottom: 1px solid var(--color-border);
  }

  h3 {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
  }

  .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}

/* --------------------------------------------------------------------------
   Stats Display
   -------------------------------------------------------------------------- */
.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs) var(--space-md);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.stat-value {
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--color-text);
}

.stat-value-dead {
  color: var(--color-text-muted);
}

.toggle-small {
  font-size: var(--font-size-xs);
}

/* --------------------------------------------------------------------------
   State List
   -------------------------------------------------------------------------- */
.state-list {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);

  &:empty {
    display: none;
  }

  .state-item {
    padding: var(--space-xs) var(--space-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);

    &:hover {
      background: var(--color-surface-raised);
    }

    &.expanded {
      background: var(--color-surface-raised);
    }

    .state-header {
      display: flex;
      align-items: center;
      gap: var(--space-xs);
      flex-wrap: wrap;
    }

    .state-id {
      color: var(--color-primary);
      font-weight: 500;
    }

    .state-label {
      color: var(--color-text);
    }

    .state-flags {
      color: var(--color-text-muted);
    }

    .state-sources-list {
      display: inline-block;
      margin-left: var(--space-xs);
    }

    .state-source-item {
      color: var(--color-text);
      padding-left: var(--space-sm);
    }

    .state-transitions {
      margin-top: var(--space-sm);
      padding-left: var(--space-md);
      border-left: 2px solid var(--color-border);
    }

    .transition-row {
      padding: 2px 0;
      color: var(--color-text-secondary);

      .symbol-label {
        color: var(--color-text);
      }

      .symbol-epsilon {
        color: var(--color-epsilon);
        font-family: 'Times New Roman', serif;
        font-style: italic;
        font-weight: bold;
        font-size: 18px;
        line-height: 1em;
      }
    }
  }
}

/* --------------------------------------------------------------------------
   Code Blocks
   -------------------------------------------------------------------------- */
.code-block {
  font-family: var(--font-mono);
  font-size: var(--font-size-code);
  margin-bottom: var(--space-xs);
  padding-left: var(--space-sm);
}

.code-line {
  display: flex;
  align-items: center;
}

/* Inline code decoration (highlighted by Prism) */
.code-decoration {
  font: inherit;
  background: transparent;
  padding: 0;
  white-space: pre;
  display: block;

  &:not(:first-child):not(.code-line) {
    display: inline;
  }
}

/* Override Prism's inline code background */
:not(pre)>code[class*="language-"] {
  background: transparent;
  padding: 0;
}

/* Make comments less prominent */
.token.comment {
  color: var(--color-text-muted);
}

/* --------------------------------------------------------------------------
   Form Elements
   -------------------------------------------------------------------------- */
input[type="text"] {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  background: transparent;
  border: none;
  outline: none;

  &::placeholder {
    color: var(--color-text-muted);
  }
}

/* --------------------------------------------------------------------------
   CodeJar Editors
   -------------------------------------------------------------------------- */
.code-editor,
.code-editor-inline {
  font-family: var(--font-mono);
  font-size: var(--font-size-code);
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-code-border);
  border-radius: var(--radius-sm);

  &:hover {
    background: var(--color-code-bg);
  }

  &:focus {
    outline: none;
    border-color: var(--color-primary);
    background: var(--color-code-bg);
  }
}

.code-editor {
  padding: calc(var(--space-sm) - 1px);
  min-height: 1.6em;
  white-space: pre-wrap;
  overflow: auto;

  &.indented-code {
    margin-left: calc(var(--space-sm) - 2px);
  }
}

.code-editor-inline {
  display: inline;
  min-width: 2em;
  padding: 0 var(--space-xs);
  cursor: text;
}

/* Resizable editor wrapper */
.editor-resize-wrapper {
  resize: vertical;
  overflow: hidden;
  min-height: 2.5em;
  max-height: 50vh;

  .code-editor {
    height: 100%;
    min-height: 100%;
    box-sizing: border-box;
  }
}

.editor-resize-wrapper-large {
  min-height: 300px;
  max-height: 80vh;
}

/* --------------------------------------------------------------------------
   Toggle Switch
   -------------------------------------------------------------------------- */
.toggle-label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);

  input[type="checkbox"] {
    appearance: none;
    width: 36px;
    height: 20px;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    position: relative;
    cursor: pointer;
    transition: var(--transition-fast);

    &::after {
      content: '';
      position: absolute;
      top: 2px;
      left: 2px;
      width: 14px;
      height: 14px;
      background: var(--color-text-muted);
      border-radius: 50%;
      transition: var(--transition-fast);
    }

    &:checked {
      background: var(--color-primary);
      border-color: var(--color-primary);

      &::after {
        left: 18px;
        background: var(--color-text);
      }
    }
  }
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
button {
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-md);
  transition: var(--transition-fast);
}

.primary-btn {
  width: 100%;
  padding: var(--space-md) var(--space-lg);
  background: var(--color-primary);
  color: var(--color-bg);

  &:hover {
    background: var(--color-primary-hover);
  }

  &:active {
    transform: scale(0.98);
  }
}

.secondary-btn {
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface-raised);
  color: var(--color-text);
  border: 1px solid var(--color-border);

  &:hover {
    background: var(--color-border);
  }

  &:active {
    transform: scale(0.98);
  }

  &.small-btn {
    font-size: var(--font-size-xs);
    padding: var(--space-xs) var(--space-sm);
  }
}

/* --------------------------------------------------------------------------
   Test Section
   -------------------------------------------------------------------------- */
.test-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);

  input[type="text"] {
    flex: 0 0 auto;
    width: 160px;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-code-bg);
    border: 1px solid var(--color-code-border);
    border-radius: var(--radius-sm);

    &:focus {
      border-color: var(--color-primary);
    }
  }
}

.test-result {
  font-size: var(--font-size-sm);
  font-family: var(--font-mono);

  &:empty {
    display: none;
  }

  &.accepted {
    color: var(--color-success);
  }

  &.rejected {
    color: var(--color-error);
  }
}

/* --------------------------------------------------------------------------
   Error Display
   -------------------------------------------------------------------------- */
.error-display {
  margin: var(--space-lg);
  margin-top: 0;
  padding: var(--space-md);
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid var(--color-error);
  border-radius: var(--radius-md);
  color: var(--color-error);
  font-size: var(--font-size-sm);
  font-family: var(--font-mono);
  white-space: pre-wrap;
}

/* --------------------------------------------------------------------------
   Utility Classes
   -------------------------------------------------------------------------- */
.hidden {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Responsive Adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .app-layout {
    grid-template-columns: 320px 1fr 240px;

    &.config-collapsed {
      grid-template-columns: 0 1fr 240px;
    }
  }
}

@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: auto;
    min-height: 100vh;

    &.config-collapsed {
      grid-template-columns: 1fr;
    }
  }

  .panel {
    border-right: none;
    border-bottom: 1px solid var(--color-border);

    &:last-child {
      border-bottom: none;
    }
  }

  .panel-toggle-btn {
    display: none;
  }

  .config-collapsed .panel-config {

    .panel-header,
    .input-section,
    .button-row {
      display: flex;
    }

    .input-section {
      display: block;
    }
  }

  .panel-viz {
    min-height: 400px;
  }
}

/* --------------------------------------------------------------------------
   Pipeline Slider
   -------------------------------------------------------------------------- */
.pipeline-container {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  margin-top: var(--space-md);
  padding: var(--space-sm) 0;
  height: 140px;
  border-top: 1px solid var(--color-border);
}

.pipeline-track {
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;

  #pipeline-slider {
    /* Rotate to make vertical.
       Standard range is horizontal.
       Rotate 90deg: Left becomes Top (min), Right becomes Bottom (max).
    */
    transform: rotate(90deg);
    width: 120px;
    /* Becomes height */
    height: 40px;
    /* Becomes width */
    cursor: pointer;
    margin: 0;
    /* Reset appearance */
    -webkit-appearance: none;
    appearance: none;
    background: transparent;

    /* Progress fill logic */
    --slider-progress: 0%;

    /* Slider Track */
    &::-webkit-slider-runnable-track {
      width: 100%;
      height: 4px;
      background: linear-gradient(to right, var(--color-primary) var(--slider-progress), var(--color-surface-raised) var(--slider-progress));
      border-radius: 2px;
      cursor: pointer;
    }

    &::-moz-range-track {
      width: 100%;
      height: 4px;
      background: linear-gradient(to right, var(--color-primary) var(--slider-progress), var(--color-surface-raised) var(--slider-progress));
      border-radius: 2px;
      cursor: pointer;
    }

    /* Slider Thumb */
    &::-webkit-slider-thumb {
      -webkit-appearance: none;
      height: 16px;
      width: 16px;
      border-radius: 50%;
      background: var(--color-primary);
      cursor: pointer;
      margin-top: -6px;
      /* Center on track */
      box-shadow: 0 0 0 2px var(--color-bg);
    }

    &::-moz-range-thumb {
      height: 16px;
      width: 16px;
      border: none;
      border-radius: 50%;
      background: var(--color-primary);
      cursor: pointer;
      box-shadow: 0 0 0 2px var(--color-bg);
    }
  }
}

.pipeline-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: 1;
  padding: 4px 0 4px var(--space-sm);
  /* Padding to align with slider ends */

  .pipeline-step {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    line-height: 1;

    &.active {
      color: var(--color-primary);
      font-weight: 600;
    }

    &:hover {
      color: var(--color-text);
    }
  }
}