/* ============================================================
   Petri Net Simulator — Stylesheet
   Clean, modern, educational UI
   ============================================================ */

:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1d2939;
  --text-secondary: #667085;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #16a34a;
  --accent-hover: #15803d;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --node-stroke: #344054;
  --node-fill: #ffffff;
  --token-fill: #1d2939;
  --arc-stroke: #667085;
  --enabled-fill: #16a34a;
  --enabled-glow: rgba(22, 163, 74, 0.3);
  --selected-stroke: #6366f1;
  --radius: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* ============================================================
   Layout
   ============================================================ */

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 10;
  flex-shrink: 0;
  flex-wrap: wrap;
}

#main {
  display: flex;
  flex: 1;
  min-height: 0;
}

#canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle, #e5e7eb 1px, transparent 1px);
  background-size: 24px 24px;
  background-color: var(--bg);
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

#properties {
  width: 240px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#log-bar {
  height: 120px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

#log-bar.collapsed {
  height: 0;
  border-top: none;
}

#log {
  flex-grow: 1;
  overflow-y: auto;
  padding: 8px 16px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-secondary);
}

.log-entry {
  padding: 2px 0;
  border-bottom: 1px solid var(--border);
}

/* ============================================================
   Toolbar
   ============================================================ */

.toolbar-section {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.toolbar-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 8px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  transition: all 0.15s ease;
}

.tool-btn:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.tool-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.action-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  transition: all 0.15s ease;
}

.action-btn:hover {
  background: #f3f4f6;
}

.action-btn.accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.action-btn.accent:hover {
  background: var(--accent-hover);
}

.action-btn.danger {
  color: var(--text);
  border-color: var(--border);
}

.action-btn.danger:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.firing-mode-select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.firing-mode-select option {
  padding: 4px 8px;
}

#step-count {
  width: 56px;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  text-align: center;
}

.step-label {
  font-size: 12px;
  color: var(--text-secondary);
}

#example-select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  background: var(--surface);
}

/* ============================================================
   Marking bar
   ============================================================ */

#marking-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 16px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(4px);
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}

#marking-display {
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#marking-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.zoom-indicator {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.log-toggle-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  transition: color 0.2s;
}

.log-toggle-link:hover {
  color: var(--primary-hover);
}

/* ============================================================
   Properties panel
   ============================================================ */

.sidebar-main-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.2px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 4px;
}

.sidebar-section h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

#properties-content h4 {
  font-size: 15px;
  margin-bottom: 10px;
  color: var(--text);
}

.prop-row {
  margin-bottom: 10px;
}

.prop-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.prop-row input,
.prop-row select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  background: var(--surface);
}

.prop-row input:focus,
.prop-row select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.hint {
  font-size: 12px;
  color: var(--text-secondary);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.badge.enabled {
  background: #dcfce7;
  color: #166534;
}

.badge.disabled {
  background: #fee2e2;
  color: #991b1b;
}

/* ============================================================
   Shortcuts
   ============================================================ */

#shortcuts {
  border-top: 1px solid var(--border);
  padding-top: 4px;
}

.shortcut-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

kbd {
  display: inline-block;
  min-width: 24px;
  padding: 1px 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
  color: var(--text);
}

/* ============================================================
   Legend
   ============================================================ */

#legend {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ============================================================
   Sidebar Footer
   ============================================================ */

#sidebar-footer {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.github-link {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: color 0.2s;
}

.github-link:hover {
  color: var(--text);
}

.github-link svg {
  flex-shrink: 0;
}

.github-link img {
  margin-left: auto;
  height: 20px;
}

/* ============================================================
   SVG Elements
   ============================================================ */

.place {
  fill: var(--node-fill);
  stroke: var(--node-stroke);
  stroke-width: 2.5;
  cursor: pointer;
  transition: stroke 0.15s, filter 0.15s;
}

.place:hover {
  stroke-width: 3;
}

.place.selected {
  stroke: var(--selected-stroke);
  stroke-width: 3;
  filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.4));
}

.transition {
  fill: var(--node-stroke);
  stroke: var(--node-stroke);
  stroke-width: 1;
  cursor: pointer;
  transition: fill 0.2s, filter 0.2s, stroke 0.15s;
}

.transition:hover {
  filter: brightness(1.2);
}

.transition.enabled {
  fill: var(--enabled-fill);
  stroke: var(--enabled-fill);
  filter: drop-shadow(0 0 8px var(--enabled-glow));
}

.transition.selected {
  stroke: var(--selected-stroke);
  stroke-width: 3;
  filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.4));
}

.transition.enabled.selected {
  stroke: var(--selected-stroke);
  filter: drop-shadow(0 0 8px var(--enabled-glow)) drop-shadow(0 0 6px rgba(99, 102, 241, 0.4));
}

.token {
  fill: var(--token-fill);
  pointer-events: none;
}

.token-count {
  fill: var(--token-fill);
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.label {
  fill: var(--text);
  font-size: 12px;
  font-family: var(--font);
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.arc {
  stroke: var(--arc-stroke);
  stroke-width: 2;
  fill: none;
  transition: stroke 0.15s;
}

.arc.enabled {
  stroke: var(--accent);
  stroke-width: 2.5;
}

.arc.selected {
  stroke: var(--selected-stroke);
  stroke-width: 3;
}

.arc-hit-area {
  stroke: transparent;
  stroke-width: 16;
  fill: none;
  cursor: pointer;
}

.temp-arc {
  stroke: var(--primary);
  stroke-width: 2;
  stroke-dasharray: 8 4;
  opacity: 0.6;
}

.arc-weight {
  fill: var(--text);
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font);
  text-anchor: middle;
  dominant-baseline: central;
}

.arc-weight-bg {
  fill: var(--surface);
  stroke: var(--border);
  stroke-width: 1;
}

.arc-bidi-tag {
  fill: var(--primary);
  font-size: 10px;
  font-weight: 700;
  font-family: var(--mono);
  text-anchor: middle;
  dominant-baseline: central;
}

/* ============================================================
   Firing animation
   ============================================================ */

.anim-token {
  fill: var(--accent);
  filter: drop-shadow(0 0 6px var(--enabled-glow));
  pointer-events: none;
}

.anim-token.reverse {
  fill: var(--primary);
  filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.4));
}

.anim-flash {
  fill: var(--accent);
  opacity: 0.6;
  pointer-events: none;
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================================
   Modal
   ============================================================ */

.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  justify-content: center;
  align-items: center;
}

.modal.visible {
  display: flex;
}

.modal-content {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  max-width: 560px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 18px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}

.analysis-table {
  width: 100%;
  border-collapse: collapse;
}

.analysis-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: top;
}

.analysis-table td:first-child {
  font-weight: 600;
  color: var(--text-secondary);
  width: 160px;
}

/* ============================================================
   Keyboard shortcuts hint
   ============================================================ */

@media (max-width: 900px) {
  #properties {
    width: 200px;
  }
  .toolbar-label {
    display: none;
  }
}
