/* Main Layout and General Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f8f9fa;
  height: 100vh;
  overflow: hidden;
}

.converter-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f8f9fa;
}

/* Banner Section */
.app-banner {
  background: linear-gradient(to right, #1e3a8a, #3b82f6);
  color: white;
  padding: 16px 24px;
  text-align: center;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.app-banner h1 {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 12px 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.banner-info {
  display: flex;
  justify-content: center;
  gap: 24px;
}

.banner-info p {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
}

/* Menu Bar */
.menu-bar {
  background-color: #ffffff;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.menu-container {
  display: flex;
  align-items: center;
  padding: 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  background-color: #f0f4f8;
}

/* Dropdown Menus */
.dropdown {
  position: relative;
  margin-right: 12px;
}

.dropdown-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background-color: #2563eb;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background-color 0.2s;
}

.dropdown-btn:hover {
  background-color: #1d4ed8;
}

.dropdown-content {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background-color: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  min-width: 200px;
  display: none;
}

.dropdown-content.active {
  display: block;
}

.dropdown-content button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 16px;
  background-color: transparent;
  border: none;
  font-size: 14px;
  font-weight: 500;
  color: #1f2937;
  cursor: pointer;
  transition: background-color 0.2s;
}

.dropdown-content button:hover {
  background-color: #f3f4f6;
  color: #2563eb;
}

.divider-menu {
  width: 100%;
  height: 1px;
  margin: 6px 0;
  background-color: #e5e7eb;
}

/* Settings Info */
.settings-info {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
  padding: 0 16px;
  font-size: 14px;
  background-color: #f8fafc;
  border-radius: 6px;
  padding: 8px 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.settings-info .label {
  font-weight: 700;
  color: #334155;
}

.convert-btn {
  padding: 10px 20px;
  background-color: #10b981;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  margin-left: 12px;
  transition: background-color 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.convert-btn:hover {
  background-color: #059669;
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.convert-st-btn {
  background-color: #3b82f6;
}

.convert-st-btn:hover {
  background-color: #2563eb;
}

.ladder-simulator-btn {
  background-color: #8b5cf6;
}

.ladder-simulator-btn:hover {
  background-color: #7c3aed;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background-color: #f0f4f8;
  border-bottom: 2px solid #e2e8f0;
}

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 6px;
  background-color: white;
  cursor: pointer;
  font-weight: bold;
  font-size: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: all 0.2s;
}

.tool-btn:hover {
  background-color: #f8fafc;
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.tool-btn.active {
  background-color: #bfdbfe;
  color: #1e40af;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.divider {
  width: 2px;
  height: 30px;
  margin: 0 10px;
  background-color: #cbd5e1;
}

.mode-info {
  margin-left: auto;
  font-size: 15px;
  font-weight: 600;
  color: #334155;
  background-color: #f8fafc;
  padding: 8px 16px;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Main Content Area */
.content-area {
  display: flex;
  flex: 1;
  overflow: hidden;
  background-color: #f1f5f9;
}

.canvas-container {
  flex: 1;
  padding: 20px;
}

.canvas-wrapper {
  height: 100%;
  background-color: #ffffff;
  padding: 20px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  overflow: auto;
  position: relative;
}

.petri-canvas {
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  cursor: crosshair;
  display: block;
  width: 100%;
  height: 100%;
  background-color: #f8fafc;
}

.ladder-canvas {
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  cursor: crosshair;
  display: block;
  width: 100%;
  height: 100%;
  background-color: #f8fafc;
}

/* Grid Styling */
.canvas-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Side Panel */
.side-panel {
  width: 500px;
  padding: 20px;
}

.panel-container {
  height: 100%;
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
}

.tabs {
  display: flex;
  border-bottom: 2px solid #e2e8f0;
}

.tab-btn {
  flex: 1;
  padding: 14px 8px;
  background-color: transparent;
  border: none;
  font-size: 15px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  color: #3b82f6;
  border-bottom: 3px solid #3b82f6;
}

.tab-btn:hover:not(.active) {
  color: #1e40af;
  background-color: #f8fafc;
}

.tab-content {
  flex: 1;
  padding: 20px;
  overflow: auto;
}

.panel {
  height: 100%;
  width: 100%;
  display: none;
}

.panel.active {
  display: block;
}

.code-output {
  background-color: #f8fafc;
  padding: 20px;
  border-radius: 8px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  height: 100%;
  width: 100%;
  overflow: auto;
  border: 1px solid #e2e8f0;
  color: #334155;
  box-sizing: border-box;
}

/* I/O Configuration */
.io-config-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 16px;
}

.io-config-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: #f8fafc;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.io-label {
  width: 60px;
  font-weight: 700;
  font-size: 15px;
  color: #334155;
}

.io-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 14px;
  background-color: white;
  transition: border-color 0.2s;
}

.io-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

h3 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  color: #1e293b;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 10px;
}

h4 {
  font-size: 16px;
  font-weight: 600;
  margin: 16px 0 12px 0;
  color: #334155;
}

/* Analysis History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.history-item {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s;
}

.history-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.history-header {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  background-color: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
}

.history-type {
  font-weight: 700;
  color: #334155;
}

.history-timestamp {
  color: #64748b;
  font-size: 14px;
  font-weight: 500;
}

.history-result {
  padding: 16px;
  font-family: 'Consolas', monospace;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 300px;
  overflow: auto;
  margin: 0;
  background-color: #f8fafc;
  color: #334155;
}

/* Modal Dialog */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1050;
  backdrop-filter: blur(4px);
}

.modal-content {
  width: 450px;
  background-color: #ffffff;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-content h3 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  color: #1e293b;
  text-align: center;
}

.form-group {
  margin-bottom: 24px;
}

.form-group label {
  display: block;
  margin-bottom: 10px;
  font-size: 16px;
  font-weight: 600;
  color: #334155;
}

.form-group input {
  width: 100%;
  padding: 12px;
  border: 2px solid #cbd5e1;
  border-radius: 8px;
  font-size: 16px;
  transition: all 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.button-group {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 10px;
}

.primary-btn {
  padding: 12px 24px;
  background-color: #3b82f6;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 16px;
  transition: all 0.2s;
}

.primary-btn:hover {
  background-color: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.secondary-btn {
  padding: 12px 24px;
  background-color: #e2e8f0;
  color: #334155;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background-color: #cbd5e1;
  transform: translateY(-2px);
}

/* Reachability Graph and State Space Table */
.reachability-container {
  margin-top: 20px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
}

.reachability-header {
  background-color: #f1f5f9;
  padding: 12px 16px;
  font-weight: 700;
  border-bottom: 1px solid #e2e8f0;
}

.state-table {
  width: 100%;
  border-collapse: collapse;
}

.state-table th, .state-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

.state-table th {
  background-color: #f8fafc;
  font-weight: 600;
}

.state-table tr:hover {
  background-color: #f1f5f9;
}

.bounded-place {
  color: #10b981;
  font-weight: 600;
}

.unbounded-place {
  color: #ef4444;
  font-weight: 600;
}

.dragging {
  cursor: move;
  z-index: 1000;
  opacity: 0.8;
}

/* Ladder Diagram Styles */
.rung {
  stroke: #475569;
  stroke-width: 2;
}

.contact {
  stroke: #334155;
  stroke-width: 2;
  fill: none;
}

.contact-no {
  stroke: #334155;
  stroke-width: 2;
  fill: none;
}

.contact-nc {
  stroke: #334155;
  stroke-width: 2;
  fill: none;
}

.contact.active {
  stroke: #10b981;
  stroke-width: 3;
}

.contact-label {
  fill: #334155;
  font-family: 'Consolas', monospace;
  font-size: 12px;
  text-anchor: middle;
}

.coil {
  stroke: #334155;
  stroke-width: 2;
  fill: white;
}

.coil.energized {
  stroke: #10b981;
  stroke-width: 3;
  fill: #dcfce7;
}

.coil-label {
  fill: #334155;
  font-family: 'Consolas', monospace;
  font-size: 12px;
  text-anchor: middle;
}

.timer {
  stroke: #334155;
  stroke-width: 1.5;
  fill: white;
}

.timer.active {
  stroke: #3b82f6;
  fill: #eff6ff;
}

.timer-label {
  fill: #334155;
  font-family: 'Consolas', monospace;
  font-size: 10px;
  text-anchor: middle;
}

/* Ladder Simulation Panel */
.ladder-controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.control-section {
  padding: 16px;
  background-color: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.variable-monitor {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-height: 200px;
  overflow-y: auto;
}

.variable-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  background-color: white;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}

.variable-name {
  font-weight: 600;
  color: #334155;
}

.variable-value {
  font-family: 'Consolas', monospace;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: #f1f5f9;
}

.variable-value.true {
  background-color: #dcfce7;
  color: #047857;
}

.variable-value.false {
  background-color: #fee2e2;
  color: #b91c1c;
}

.manual-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.control-btn {
  padding: 8px 12px;
  background-color: white;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.control-btn:hover {
  background-color: #f8fafc;
  border-color: #94a3b8;
}

.control-btn.active {
  background-color: #dbeafe;
  border-color: #3b82f6;
  color: #1e40af;
}

.simulation-status {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status-indicator {
  display: flex;
  justify-content: space-between;
  background-color: white;
  padding: 10px 16px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}

.status-indicator .label {
  font-weight: 600;
  color: #334155;
}

.status-indicator .value {
  font-family: 'Consolas', monospace;
  font-weight: 500;
}

#ladder-sim-status.running {
  color: #10b981;
}

#ladder-sim-status.stopped {
  color: #ef4444;
}

#ladder-sim-status.paused {
  color: #f59e0b;
}