/* Main Styles - General layout and UI */

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* Main Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Header */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(135deg, var(--header-gradient-start) 0%, var(--header-gradient-end) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
  box-shadow: 0 2px 10px var(--shadow-color);
  transition: right 0.3s ease;
}

.app-header h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  line-height: 1;
}

.app-header .header-info {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: nowrap;
  white-space: nowrap;
  height: 32px;
}

.header-auth-section {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
  height: 32px;
}

#header-stats {
  display: flex;
  align-items: center;
  white-space: nowrap;
  height: 32px;
}

/* Sidebar */
.sidebar {
  position: fixed;
  left: 0;
  top: 40px;
  bottom: 0;
  width: 300px;
  background-color: var(--sidebar-bg);
  box-shadow: 2px 0 10px var(--shadow-color);
  overflow-y: auto;
  z-index: 900;
  padding: 20px;
}

.sidebar-section {
  margin-bottom: 30px;
}

.sidebar-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 15px;
  color: var(--accent-primary);
  border-bottom: 2px solid var(--accent-primary);
  padding-bottom: 5px;
}

/* Main Wrapper — flex row to the right of sidebar, below header */
.main-wrapper {
  margin-left: 300px;
  margin-top: 40px;
  width: calc(100vw - 300px);
  height: calc(100vh - 40px);
  display: flex;
  flex-direction: row;
  overflow: hidden;
  transition: width 0.3s ease;
}

/* Main Content Area */
.content-area {
  flex: 1;
  min-width: 0;
  height: 100%;
  position: relative;
  font-size: 0; /* Remove whitespace between inline-block elements */
  transition: flex 0.3s ease;
}

/* View Mode Buttons */
.view-mode-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.view-mode-buttons button {
  flex: 1;
  padding: 10px 15px;
  border: 2px solid var(--accent-primary);
  background-color: var(--bg-secondary);
  color: var(--accent-primary);
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.3s ease;
}

.view-mode-buttons button:hover {
  background-color: var(--bg-tertiary);
}

.view-mode-buttons button.active {
  background-color: var(--accent-primary);
  color: white;
}

/* Filter Controls */
.filter-group {
  margin-bottom: 15px;
}

.filter-group label {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
  font-weight: 500;
}

.filter-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-checkboxes label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.filter-checkboxes input[type="checkbox"] {
  cursor: pointer;
}

/* Select Dropdown */
select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 14px;
  background-color: var(--input-bg);
  color: var(--text-primary);
}

select:focus {
  outline: none;
  border-color: var(--accent-primary);
}

/* Buttons */
button {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  background-color: var(--accent-primary);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 100%;
  margin-top: 10px;
}

button:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--shadow-color);
}

button:active {
  transform: translateY(0);
}

button.secondary {
  background-color: var(--btn-secondary-bg);
}

button.secondary:hover {
  background-color: var(--btn-secondary-hover);
}

button.danger {
  background-color: var(--accent-danger);
}

button.danger:hover {
  background-color: #c0392b;
}

/* Search Box */
.search-container {
  margin-bottom: 20px;
}

.search-input-wrapper {
  display: flex;
  gap: 5px;
}

#search-input {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  font-size: 14px;
  background-color: var(--input-bg);
  color: var(--text-primary);
}

#search-input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

#search-btn {
  width: auto;
  margin-top: 0;
  padding: 10px 15px;
}

#clear-search-btn {
  width: auto;
  margin-top: 8px;
  padding: 10px 15px;
  background-color: var(--btn-secondary-bg);
}

#search-results {
  margin-top: 10px;
  padding: 10px;
  background-color: var(--search-results-bg);
  border-radius: 5px;
  max-height: 200px;
  overflow-y: auto;
  color: var(--text-primary);
}

#search-results:empty {
  display: none;
}

#search-results ul {
  list-style: none;
  padding: 0;
}

#search-results li {
  padding: 5px 0;
}

#search-results a {
  color: var(--accent-primary);
  text-decoration: none;
}

#search-results a:hover {
  text-decoration: underline;
}

/* Statistics Display */
#statistics-display {
  background-color: var(--statistics-bg);
  padding: 15px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--text-primary);
}

#statistics-display h3 {
  font-size: 14px;
  margin-bottom: 10px;
  color: var(--accent-primary);
}

#statistics-display h4 {
  font-size: 13px;
  margin-top: 10px;
  margin-bottom: 5px;
}

#statistics-display p {
  margin: 5px 0;
}

#statistics-display ul {
  list-style: none;
  padding-left: 10px;
}

#statistics-display li {
  margin: 3px 0;
}

/* Clustering Status */
#clustering-status {
  background-color: var(--statistics-bg);
  padding: 10px;
  border-radius: 5px;
  font-size: 13px;
  margin-top: 10px;
  color: var(--text-primary);
}

#clustering-status p {
  margin: 5px 0;
}

/* Loading Indicator */
#loading-indicator {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: var(--overlay-color);
  color: white;
  padding: 20px 40px;
  border-radius: 10px;
  z-index: 9999;
  font-size: 16px;
  font-weight: 600;
  display: none;
  box-shadow: 0 4px 20px var(--shadow-strong);
}

/* Error Message */
#error-message {
  position: fixed;
  top: 80px;
  right: 20px;
  background-color: #e74c3c;
  color: white;
  padding: 15px 20px;
  border-radius: 5px;
  z-index: 9999;
  font-size: 14px;
  display: none;
  box-shadow: 0 4px 20px rgba(231, 76, 60, 0.3);
  max-width: 400px;
}

/* Toggle Switches */
.toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}

.toggle-wrapper label {
  font-size: 14px;
  font-weight: 500;
}

input[type="checkbox"].toggle {
  width: 40px;
  height: 20px;
}

/* Scrollbar Styles */
.sidebar::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* Responsive Design */
@media (max-width: 1200px) {
  .sidebar {
    width: 250px;
  }

  .main-wrapper {
    margin-left: 250px;
    width: calc(100vw - 250px);
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-wrapper {
    margin-left: 0;
    width: 100vw;
  }

  .app-header h1 {
    font-size: 18px;
  }
}

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

.text-center {
  text-align: center;
}

.mt-10 {
  margin-top: 10px;
}

.mb-10 {
  margin-bottom: 10px;
}

.p-10 {
  padding: 10px;
}

/* Modal Panel Base Styles */
.modal-panel {
  display: none;
  position: fixed;
  top: 80px;
  right: 20px;
  background-color: var(--modal-bg);
  padding: 0;
  border-radius: 8px;
  width: 480px;
  max-height: 600px;
  overflow-y: auto;
  box-shadow: 0 4px 20px var(--shadow-strong);
  z-index: 10000;
  border: 1px solid var(--card-border);
  color: var(--text-primary);
}

#documentModal {
  width: 400px;
  max-height: 500px;
  padding: 20px;
}

#documentModal #modalTitle {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 16px;
  color: var(--text-primary);
}

/* Node Viewer Modal Styles */
#nodeModal {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Compact modal in hybrid view */
#nodeModal[data-hybrid-mode="true"] {
  width: 380px;
  max-height: 400px;
}

#nodeModal[data-hybrid-mode="true"] .node-info-card {
  padding: 14px;
}

#nodeModal[data-hybrid-mode="true"] .node-title {
  font-size: 15px;
}

#nodeModal[data-hybrid-mode="true"] .node-header {
  margin-bottom: 10px;
  padding-bottom: 10px;
  gap: 8px;
}

#nodeModal[data-hybrid-mode="true"] .node-section {
  margin-bottom: 8px;
}

.node-info-card {
  padding: 20px;
}

.node-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
  gap: 12px;
  padding-bottom: 15px;
  border-bottom: 2px solid var(--card-border);
}

.node-title {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  flex: 1;
}

.node-type-badge {
  padding: 5px 12px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.facility-badge {
  background-color: #f1c40f;
  color: #333;
}

.company-badge {
  background-color: #228B22;
  color: white;
}

.location-badge {
  background-color: #95a5a6;
  color: white;
}

.bottleneck-badge {
  background-color: #e74c3c;
  color: white;
}

.component-badge {
  background-color: #f06292;
  color: white;
}

.material-badge {
  background-color: #9b59b6;
  color: white;
}

.alternative-badge {
  background-color: #1abc9c;
  color: white;
}

.contract-badge {
  background-color: #90EE90;
  color: #1a5f1a;
}

.agency-badge {
  background-color: #34495e;
  color: white;
}

.default-badge {
  background-color: #7f8c8d;
  color: white;
}

.node-section {
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--card-border);
}

.node-section:last-of-type {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.node-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.node-text {
  font-size: 14px;
  color: var(--text-primary);
  margin: 5px 0;
  line-height: 1.5;
}

.node-metric {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 8px 0;
  font-size: 13px;
  color: var(--text-primary);
}

.metric-label {
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 70px;
  flex-shrink: 0;
  white-space: nowrap;
}

/* Block-level metric for arrays/lists (not flex row) */
.node-metric-block {
  margin: 8px 0;
  font-size: 13px;
  color: var(--text-primary);
}

.node-metric-block .metric-label {
  display: block;
  margin-bottom: 4px;
}

.rating-badge {
  background-color: var(--accent-primary);
  color: white;
  padding: 3px 10px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12px;
}

.status-badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-success {
  background-color: #c6f6d5;
  color: #22543d;
}

.status-warning {
  background-color: #faf089;
  color: #744210;
}

.status-danger {
  background-color: #fed7d7;
  color: #742a2a;
}

.status-neutral {
  background-color: #e2e8f0;
  color: #2d3748;
}

.status-info {
  background-color: #bee3f8;
  color: #2c5282;
}

.status-closed {
  background-color: #e53e3e;
  color: white;
  font-weight: 700;
}

/* Additional Details section for dynamic properties */
.additional-details {
  background-color: var(--bg-tertiary);
  border-radius: 8px;
  padding: 15px;
  margin-top: 15px;
  border: 1px solid var(--card-border);
}

.additional-details .node-section-title {
  color: var(--text-muted);
  font-size: 13px;
}

.node-subsection {
  margin: 12px 0;
  padding: 12px;
  background-color: var(--bg-secondary);
  border-radius: 6px;
  border: 1px solid var(--card-border);
}

.node-subsection-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--card-border);
}

/* Nested object styles for complex data */
.nested-object {
  margin: 8px 0;
  padding: 10px;
  background-color: var(--bg-secondary);
  border-radius: 6px;
  border: 1px solid var(--card-border);
}

.nested-object-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.nested-object-content {
  font-size: 13px;
}

.nested-object-content .node-metric {
  margin: 4px 0;
  font-size: 12px;
}

.nested-object-content .metric-label {
  min-width: 90px;
  font-size: 12px;
}

.node-text-muted {
  color: var(--text-muted);
  font-style: italic;
}

.node-list {
  margin: 5px 0;
  padding-left: 20px;
  color: var(--text-primary);
}

.node-list li {
  margin: 3px 0;
  font-size: 13px;
}

.node-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--accent-primary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.node-link:hover {
  background-color: var(--bg-elevated);
  border-color: var(--accent-primary);
  color: var(--accent-hover);
  text-decoration: none;
}

/* Source links - simple text style */
.source-link-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.source-link {
  color: var(--accent-primary);
  text-decoration: underline;
  font-size: 13px;
  display: block;
  margin: 4px 0;
  word-break: break-all;
}

.source-link:hover {
  color: var(--accent-hover);
}

/* Fix source links inside flex metric rows (Additional Details) */
.node-metric .source-link {
  display: block;
  width: 100%;
}

/* Document items in node viewer */
.document-item {
  background-color: var(--bg-tertiary);
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 10px;
  border: 1px solid var(--card-border);
}

.document-item:last-child {
  margin-bottom: 0;
}

.document-filename {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.document-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.document-preview {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  font-style: italic;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--card-border);
}

/* Dark Mode Overrides for Modal and Status Badges */
[data-theme="dark"] .modal-panel {
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .status-success {
  background-color: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

[data-theme="dark"] .status-warning {
  background-color: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

[data-theme="dark"] .status-danger {
  background-color: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

[data-theme="dark"] .status-neutral {
  background-color: rgba(148, 163, 184, 0.2);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

[data-theme="dark"] .status-info {
  background-color: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

[data-theme="dark"] .status-closed {
  background-color: rgba(220, 38, 38, 0.3);
  color: #fca5a5;
  border: 1px solid rgba(220, 38, 38, 0.4);
}

[data-theme="dark"] .rating-badge {
  background-color: var(--accent-primary);
  color: white;
}

/* ===== Icon Button (gear/tune) ===== */
.icon-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
  transform: none;
  box-shadow: none;
}

/* ===== Floating Modal (Physics Tuner) ===== */
.floating-modal {
  position: fixed;
  top: 80px;
  right: 340px;
  width: 320px;
  max-height: calc(100vh - 100px);
  z-index: 1000;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 8px 32px var(--shadow-strong);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.floating-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--accent-primary);
  color: #fff;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
  border-radius: 8px 8px 0 0;
  font-weight: 600;
  font-size: 14px;
}

.floating-modal-header:active {
  cursor: grabbing;
}

.floating-modal-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.floating-modal-close,
.floating-modal-icon-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.floating-modal-close:hover,
.floating-modal-icon-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: none;
  box-shadow: none;
}

.floating-modal-icon-btn {
  font-size: 16px;
}

.floating-modal-body {
  padding: 14px;
  overflow-y: auto;
  flex: 1;
}

.floating-modal-body hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 12px 0;
}

/* Solver dropdown in modal */
.floating-modal-body select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 13px;
}

/* ===== Physics Param Slider Rows ===== */
.physics-param {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.physics-param label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 110px;
  max-width: 110px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.physics-param input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 6px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.physics-param input[type="number"] {
  width: 64px;
  flex-shrink: 0;
  padding: 3px 5px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 12px;
  text-align: right;
}

.physics-param input[type="number"]:focus {
  outline: none;
  border-color: var(--accent-primary);
}

/* Section label for global params */
.physics-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

/* Disabled state when physics is off */
.floating-modal-body.physics-disabled {
  opacity: 0.5;
  pointer-events: none;
}
