/* Base styles */
:root {
  --background-color: #ffffff;
  --text-color: #333333;
  --card-background: #f8f9fa;
  --border-color: #dee2e6;
  --primary-color: #0d6efd;
  --success-color: #198754;
  --danger-color: #dc3545;
  --warning-color: #ffc107;
  --code-background: #f5f5f5;
}

[data-theme="dark"] {
  --background-color: #121212;
  --text-color: #f8f9fa;
  --card-background: #2a2a2a;
  --border-color: #444444;
  --primary-color: #3d8bfd;
  --success-color: #2ea868;
  --danger-color: #e35d6a;
  --warning-color: #ffca2c;
  --code-background: #2d2d2d;
}

body {
  background-color: var(--background-color);
  color: var(--text-color);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Theme switch styling */
.theme-switch-wrapper {
  display: flex;
  align-items: center;
}

.theme-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s;
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--primary-color);
}

input:checked + .slider:before {
  transform: translateX(26px);
}

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

/* Card styling */
.card, .log-card {
  background-color: var(--card-background);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1rem;
  margin-bottom: 1rem;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.card-header {
  background-color: rgba(0, 0, 0, 0.05);
  border-bottom: 1px solid var(--border-color);
}

/* Input styling */
.form-control {
  background-color: var(--background-color);
  color: var(--text-color);
  border-color: var(--border-color);
  border-radius: 0.375rem;
}

.form-control:focus {
  background-color: var(--background-color);
  color: var(--text-color);
}

#loadButton, #getTokenButton {
  border-radius: 0.375rem;
  font-weight: bold;
  white-space: nowrap;
}

/* Status indicators */
.success-text {
  color: var(--success-color);
}

.error-text {
  color: var(--danger-color);
}

/* JSON viewer */
pre {
  background-color: var(--card-background);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1rem;
  overflow: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Log card styling */
.log-card {
  background-color: var(--card-background);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1rem;
  margin-bottom: 1rem;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Custom JSON Modal styling - uses .json-modal to avoid Bootstrap modal conflicts */
.json-modal {
  display: none;
  position: fixed;
  z-index: 1050;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
  background-color: var(--background-color);
  color: var(--text-color);
  margin: 5% auto;
  padding: 20px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 80%;
  max-width: 1200px;
  max-height: 85vh;
  overflow: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.close-modal {
  color: var(--text-color);
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.close-modal:hover,
.close-modal:focus {
  color: var(--primary-color);
  text-decoration: none;
}

/* View JSON button styling */
.view-json-btn {
  margin-top: 10px;
}

/* JSON content styling */
#jsonContent {
  max-height: 80vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* JSON Modal additional styling */
#jsonModal .modal-content {
  max-width: 100%;
}

#nestedJsonContainer {
  border-top: 1px solid var(--border-color);
  padding-top: 15px;
  margin-top: 15px;
}

#jsonContent, #nestedJsonContent {
  background-color: var(--card-background);
  border-radius: 4px;
  padding: 15px;
  overflow: auto;
  max-height: 100vh;
  font-family: monospace;
}

#toggleNestedJson:focus {
  box-shadow: none;
}

/* Nested JSON tabs styling */
#nestedJsonTabs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}

#nestedJsonTabs button {
  border-radius: 4px;
  padding: 3px 10px;
  transition: all 0.2s ease;
}

#nestedJsonTabs button:hover {
  transform: translateY(-1px);
}

#nestedJsonTabs button.btn-info {
  font-weight: bold;
}

/* Prism.js enhanced styling */
.code-container {
  background-color: var(--code-background);
  border-radius: 4px;
  padding: 15px;
  max-height: 50vh;
  overflow: auto;
}

/* Make sure code spans the full width of the container */
.code-container code {
  display: block;
  width: 100%;
}

/* Custom styling for JSON property names */
.token.property {
  color: var(--primary-color);
  font-weight: bold;
}

/* Improve the readability of JSON syntax in dark mode */
[data-theme="dark"] .token.punctuation {
  color: #969696;
}

[data-theme="dark"] .token.string {
  color: #7ec699;
}

[data-theme="dark"] .token.number,
[data-theme="dark"] .token.boolean {
  color: #c38bff;
}

/* Add a subtle border to the code blocks */
pre[class*="language-"] {
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

/* Make the JSON structure more visible with indentation guides */
.code-container code {
  position: relative;
}

/* Improve code formatting in JSON viewer */
.code-container pre {
  margin: 0;
  tab-size: 2;
  -moz-tab-size: 2;
}

.code-container pre code {
  white-space: pre;
}

/* Make sure syntax highlighting preserves indentation */
.token.punctuation, .token.property, .token.string, 
.token.number, .token.boolean, .token.null {
  white-space: pre !important;
}

/* Input group styling */
.input-group {
  margin-bottom: 1rem;
}

.input-group .row {
  display: flex;
  align-items: center;
}

.input-group .col-md-8 {
  padding-right: 10px;
}

.input-group .col-md-4 {
  padding-left: 10px;
}

#endpointSelect, #apiToken, #executionId {
  border-radius: 0.375rem;
}

.container {
  max-width: 800px;
  margin: auto;
}

/* Updated 2-column layout styling */
.form-label {
  font-weight: 500;
  margin-bottom: 0.5rem;
}

/* Improve responsiveness on smaller screens */
@media (max-width: 768px) {
  #page-execution .sidebar .d-flex {
    flex-direction: column;
  }

  #apiToken, #executionId {
    margin-right: 0 !important;
    margin-bottom: 0.5rem;
  }

  #loadButton, #getTokenButton {
    width: 100%;
  }
}

/* Sidebar Sticky Positioning */
.sidebar {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

/* Step Navigation Styles */
.step-nav-container {
    max-height: 300px;
    overflow-y: auto;
}

.step-nav-tree .step-link,
.step-nav-tree .loop-link {
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.9rem;
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.step-nav-tree .step-link:hover,
.step-nav-tree .loop-link:hover {
    text-decoration: underline;
}

.step-nav-tree .toggle-step {
    background: transparent;
    border: none;
    color: var(--text-color);
    padding: 0;
    margin-right: 5px;
}

.step-nav-tree .loop-list {
    margin-left: 20px;
}

.step-nav-tree .loop-link {
    color: var(--secondary-color);
    font-size: 0.85rem;
}

/* Dark theme support for step navigation */
[data-theme="dark"] .step-nav-container {
    background-color: #2d2d2d !important;
    border-color: #444 !important;
}

[data-theme="dark"] .step-nav-tree .step-link,
[data-theme="dark"] .step-nav-tree .loop-link,
[data-theme="dark"] .step-nav-tree .toggle-step {
    color: #e1e1e1;
}

/* Execution Header Styles */
.execution-header {
    background-color: var(--light-bg-color);
    border-color: var(--border-color);
    border-radius: 8px;
}

.execution-header h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
}

/* Dark theme support */
[data-theme="dark"] .execution-header {
    background-color: #2d2d2d !important;
    border-color: #444 !important;
}

[data-theme="dark"] .execution-header h3 {
    color: #6ea8fe;
}

/* Sticky Header Styles */
.sticky-header-container {
    position: relative;
    z-index: 100;
}

.sticky-header {
    background-color: var(--light-bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.3s ease;
    margin-bottom: 1.5rem;
    position: -webkit-sticky; /* Safari */
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Dark theme support */
[data-theme="dark"] .sticky-header {
    background-color: #2d2d2d !important;
    border-color: #444 !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* Add these styles to make header sticky with pure CSS */
.results-container {
    /* Keep your existing styles */
    position: relative;
}

/* Execution Details Styles */
.execution-details {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    background-color: var(--light-bg-color);
}

.execution-details h5 {
    color: var(--primary-color);
    font-size: 1rem;
    margin-bottom: 10px;
}

.execution-details strong {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.execution-details .text-truncate {
    max-width: 100%;
}

/* Dark theme support */
[data-theme="dark"] .execution-details {
    background-color: #2d2d2d;
    border-color: #444;
}

[data-theme="dark"] .execution-details h5 {
    color: #6ea8fe;
    border-bottom-color: #444;
}

[data-theme="dark"] .execution-details strong {
    color: #adb5bd;
}

.modal-lg {
  width: 90%;
  max-width: 1200px;
}

.jsoneditor {
  border: 1px solid #ddd;
}

.jsoneditor-search {
  position: absolute;
  right: 2px;
  top: 2px;
}

.json-modal-container {
  display: flex;
  flex-direction: column;
  height: 80vh;
  overflow: hidden;
}

.modal-content.modal-lg {
  height: 85vh;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow: hidden;
}

#jsonContainer, #nestedJsonContent {
  overflow: hidden; 
}

#nestedJsonContainer.nested-json-section {
  flex-shrink: 0;
}

.resizable-container {
  display: flex;
  flex-direction: column;
  height: calc(100% - 60px); /* Account for header */
  min-height: 300px;
  position: relative;
  overflow: hidden;
  will-change: transform; /* Optimize for animations */
}

.editor-container {
  width: 100%;
  overflow: hidden;
  will-change: height; /* Hint to browser about what will change */
}

.main-editor {
  height: 60%;
  min-height: 60px;
  transition: height 0.2s;
}

.nested-json-wrapper {
  display: flex;
  flex-direction: column;
  height: 40%; /* Default height, dynamically updated */
  min-height: 60px;
  overflow: hidden;
}

.nested-editor {
  flex-grow: 1;
  height: 100%; /* Ensure it fills the nested wrapper */
  min-height: 20px;
  overflow: hidden;
}

.nested-json-tabs-container {
  flex-shrink: 0; /* Prevent tab container from shrinking */
  padding: 5px 5px 0;
  border-bottom: 1px solid #dee2e6;
  background-color: #f8f9fa;
  height: 40px;
  overflow-x: auto;
  white-space: nowrap;
  display: flex;
}

.nested-json-tabs {
  display: flex;
  gap: 5px;
  padding: 0 5px;
}

.resize-handle {
  flex-shrink: 0; /* Prevent handle from shrinking */
  height: 6px;
  background-color: #e9ecef;
  cursor: ns-resize !important;
  width: 100%;
  border-top: 1px solid #ced4da;
  border-bottom: 1px solid #ced4da;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
}

.resize-handle::after {
  content: "≡";
  color: #6c757d;
  font-size: 12px;
}

.resize-handle:hover {
  background-color: #dee2e6;
}

/* Prevent content selection during resize for better performance */
.resizing * {
  user-select: none !important;
}

[data-theme="dark"] .resize-handle {
  background-color: #343a40;
  border-color: #495057;
}

[data-theme="dark"] .nested-json-tabs-container {
  background-color: #343a40;
  border-color: #495057;
}

[data-theme="dark"] .resize-handle:hover {
  background-color: #495057;
}

[data-theme="dark"] .resize-handle::after {
  color: #adb5bd;
}

/* ============================================
   Navbar Styles
   ============================================ */

.navbar {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.navbar-brand {
  font-weight: bold;
  font-size: 1.25rem;
}

.navbar .nav-link {
  padding: 0.5rem 1rem;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.navbar .nav-link:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.navbar .nav-link.active {
  background-color: rgba(255, 255, 255, 0.2);
  font-weight: 500;
}

.navbar .theme-switch-wrapper {
  padding: 0.25rem 0;
}

/* Auth status indicator */
#authNavLink.text-success {
  color: #90EE90 !important;
}

#authNavLink.text-warning {
  color: #FFD700 !important;
}

#authNavLink.text-danger {
  color: #ff6b6b !important;
}

#authNavLink.text-muted {
  color: #adb5bd !important;
}

/* ============================================
   Main Content & Page Container Styles
   ============================================ */

.main-content {
  min-height: calc(100vh - 56px);
}

.page-container {
  animation: fadeIn 0.3s ease;
}

.page-container.active {
  display: block !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============================================
   Auth Page Styles
   ============================================ */

#page-auth .card {
  max-width: 420px;
  margin: 0 auto;
  border-radius: 0.5rem;
}

#page-auth .card-body {
  padding: 1.5rem;
}

#page-auth .form-label {
  margin-bottom: 0.25rem;
  font-weight: 500;
}

#page-auth .input-group .btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

[data-theme="dark"] #page-auth .card {
  background-color: var(--card-background);
  border-color: var(--border-color);
}

/* ============================================
   Instances Page Styles
   ============================================ */

.sticky-sidebar {
  position: sticky;
  top: 76px; /* navbar height + padding */
  max-height: calc(100vh - 100px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sticky-sidebar .card-body {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.instances-list {
  overflow-y: auto;
  max-height: calc(100vh - 250px);
  flex: 1;
}

.instance-item {
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.instance-item:hover {
  background-color: rgba(13, 110, 253, 0.1);
}

.instance-item.active {
  background-color: var(--primary-color) !important;
  color: white !important;
}

.instance-item.active .text-muted {
  color: rgba(255, 255, 255, 0.8) !important;
}

.instance-item.active .text-success,
.instance-item.active .text-warning {
  color: white !important;
}

.min-width-0 {
  min-width: 0;
}

/* Dark theme for instances */
[data-theme="dark"] .instance-item:hover {
  background-color: rgba(61, 139, 253, 0.2);
}

[data-theme="dark"] .sticky-sidebar .card-header {
  background-color: #2a2a2a;
  border-color: var(--border-color);
}

/* ============================================
   Executions Table Styles
   ============================================ */

#executionsContent .table {
  margin-bottom: 0;
}

#executionsContent .table th {
  border-top: none;
  font-weight: 600;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-color);
  opacity: 0.7;
}

#executionsContent .table td {
  vertical-align: middle;
}

[data-theme="dark"] #executionsContent .table {
  color: var(--text-color);
}

[data-theme="dark"] #executionsContent .table th,
[data-theme="dark"] #executionsContent .table td {
  border-color: var(--border-color);
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 991.98px) {
  .sticky-sidebar {
    position: static;
    max-height: none;
    margin-bottom: 1.5rem;
  }

  .instances-list {
    max-height: 300px;
  }
}

@media (max-width: 767.98px) {
  .navbar-brand {
    font-size: 1rem;
  }

  .navbar .theme-switch-wrapper span {
    display: none;
  }

  #page-instances .col-lg-4 {
    margin-bottom: 1rem;
  }

  #executionsContent .table {
    font-size: 0.875rem;
  }

  .view-execution-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }
}

/* ============================================
   Dark Theme Adjustments for New Components
   ============================================ */

[data-theme="dark"] .card {
  background-color: var(--card-background);
  border-color: var(--border-color);
}

[data-theme="dark"] .card-header {
  background-color: #343a40;
  border-color: var(--border-color);
}

[data-theme="dark"] .border-bottom {
  border-color: var(--border-color) !important;
}

[data-theme="dark"] .table-hover tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .btn-outline-primary {
  color: var(--primary-color);
  border-color: var(--primary-color);
}

[data-theme="dark"] .btn-outline-primary:hover {
  background-color: var(--primary-color);
  color: white;
}

/* ============================================
   Filter Bar Styles
   ============================================ */

#executionsFilterBar {
  background-color: #f8f9fa;
}

#executionsFilterBar .form-control-sm,
#executionsFilterBar .form-select-sm {
  min-width: 180px;
}

#executionsFilterBar .form-label {
  font-weight: 500;
  color: var(--text-color);
  opacity: 0.8;
}

[data-theme="dark"] #executionsFilterBar {
  background-color: #2a2a2a;
}

[data-theme="dark"] #executionsFilterBar .form-control {
  background-color: #343a40;
  border-color: #495057;
  color: var(--text-color);
}

[data-theme="dark"] #executionsFilterBar .form-control:focus {
  background-color: #3d4349;
  border-color: var(--primary-color);
}

/* Share button feedback */
#shareFilterBtn.btn-success {
  background-color: #198754;
  border-color: #198754;
  color: white;
}

/* Responsive filter bar */
@media (max-width: 767.98px) {
  #executionsFilterBar .row {
    flex-direction: column;
  }

  #executionsFilterBar .col-auto {
    width: 100%;
    margin-bottom: 0.5rem;
  }

  #executionsFilterBar .form-control-sm,
  #executionsFilterBar .form-select-sm {
    width: 100%;
    min-width: unset !important;
  }

  #executionsFilterBar .ms-auto {
    margin-left: 0 !important;
  }
}

/* ============================================
   Step Navigation Styles (Step Results)
   ============================================ */

.step-nav-container {
  font-size: 0.875rem;
}

[data-theme="dark"] .step-nav-container {
  background-color: var(--card-background) !important;
  border-color: var(--border-color) !important;
}

.step-nav-header {
  padding: 2px 0;
  border-radius: 4px;
  transition: background-color 0.15s ease;
}

.step-nav-header:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .step-nav-header:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.step-status-icon {
  font-size: 0.75rem;
}

.step-link {
  color: var(--text-color);
  text-decoration: none;
  font-size: 0.8125rem;
}

.step-link:hover {
  color: var(--primary-color);
  text-decoration: underline;
}

/* Output-only steps (no logs) - non-clickable styling */
.step-label-no-logs {
  color: var(--text-color);
  font-size: 0.8125rem;
  opacity: 0.7;
  font-style: italic;
}

.output-only-badge {
  border: 1px solid var(--border-color);
  font-weight: normal;
}

[data-theme="dark"] .step-label-no-logs {
  opacity: 0.6;
}

[data-theme="dark"] .output-only-badge {
  background-color: var(--card-bg) !important;
  border-color: var(--border-color);
  color: var(--text-muted) !important;
}

.toggle-step {
  background: none;
  border: none;
  color: var(--text-color);
  opacity: 0.6;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toggle-step:hover {
  opacity: 1;
}

.loop-iterations-list,
.iteration-steps-list {
  border-left: 2px solid var(--border-color);
  padding-left: 8px;
}

.loop-iteration-item {
  padding: 2px 0;
}

.sub-step-item {
  font-size: 0.75rem;
  padding: 1px 0;
}

.sub-step-item .step-link {
  font-size: 0.75rem;
}

/* ============================================
   Execution Details Text Styling
   ============================================ */

.detail-text {
  word-break: break-word;
  overflow-wrap: break-word;
  font-size: 0.85rem;
  max-height: 3.6em; /* Approximately 3 lines */
  overflow: hidden;
  cursor: help;
}

.detail-text:hover {
  max-height: none;
  overflow: visible;
}

/* ============================================
   Linked Executions Styles
   ============================================ */

.linked-executions {
  padding: 0.75rem;
  border-radius: 6px;
  background-color: rgba(0, 0, 0, 0.02);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .linked-executions {
  background-color: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.05);
}

.linked-executions h5 {
  font-size: 0.9rem;
}

.execution-chain-summary {
  font-size: 0.75rem;
}

/* Flow group styling */
.flow-group-header {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.flow-group-header:hover {
  background-color: rgba(0, 0, 0, 0.06) !important;
}

[data-theme="dark"] .flow-group-header {
  background-color: rgba(255, 255, 255, 0.03) !important;
}

[data-theme="dark"] .flow-group-header:hover {
  background-color: rgba(255, 255, 255, 0.08) !important;
}

.flow-name {
  font-size: 0.8rem;
}

/* Execution chip styling */
.execution-chip {
  padding: 0.15rem 0.35rem;
  font-size: 0.7rem;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  min-width: 36px;
  justify-content: center;
}

.execution-chip.current {
  cursor: default;
  font-weight: 600;
}

.execution-chip:not(.current):hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.execution-chip i {
  font-size: 0.65rem;
}

/* Execution list item styling (with datetime) */
.execution-list-item {
  font-size: 0.75rem;
  transition: background-color 0.15s ease;
}

.execution-list-item.current-execution {
  background-color: rgba(13, 110, 253, 0.1);
  border: 1px solid rgba(13, 110, 253, 0.3);
}

.execution-list-item.hoverable-execution:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .execution-list-item.current-execution {
  background-color: rgba(99, 179, 237, 0.15);
  border-color: rgba(99, 179, 237, 0.3);
}

[data-theme="dark"] .execution-list-item.hoverable-execution:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.execution-index {
  font-size: 0.65rem;
  padding: 0.1rem 0.3rem;
}

.execution-time {
  font-size: 0.7rem;
}

/* Legacy styles for backwards compatibility */
.execution-chain {
  flex-wrap: wrap;
}

.execution-chain-item {
  min-width: 40px;
  padding: 0.25rem 0.5rem;
}

.execution-chain-item.btn-primary {
  cursor: default;
}

.execution-chain-item:not(.btn-primary):hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Log Highlight Animation
   ============================================ */

.highlight-log {
  animation: highlightPulse 2s ease-out;
}

@keyframes highlightPulse {
  0% {
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.5);
    background-color: rgba(13, 110, 253, 0.1);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(13, 110, 253, 0);
    background-color: transparent;
  }
}

[data-theme="dark"] .highlight-log {
  animation: highlightPulseDark 2s ease-out;
}

@keyframes highlightPulseDark {
  0% {
    box-shadow: 0 0 0 4px rgba(99, 179, 237, 0.5);
    background-color: rgba(99, 179, 237, 0.1);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(99, 179, 237, 0);
    background-color: transparent;
  }
}

/* ============================================
   Step Navigation Item Highlight
   ============================================ */

.highlight-step-item {
  animation: highlightStepPulse 1.5s ease-out;
  border-radius: 4px;
}

@keyframes highlightStepPulse {
  0% {
    background-color: rgba(13, 110, 253, 0.2);
  }
  100% {
    background-color: transparent;
  }
}

[data-theme="dark"] .highlight-step-item {
  animation: highlightStepPulseDark 1.5s ease-out;
}

@keyframes highlightStepPulseDark {
  0% {
    background-color: rgba(99, 179, 237, 0.2);
  }
  100% {
    background-color: transparent;
  }
}

/* ============================================
   Step Output View Button
   ============================================ */

.step-nav-header .btn-outline-info {
  font-size: 0.625rem;
  line-height: 1;
  padding: 2px 4px;
}

.step-nav-header .btn-outline-info:hover {
  transform: scale(1.1);
}

/* ============================================
   Loading States for Steps
   ============================================ */

.step-loading {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   Auth Dropdown Styles
   ============================================ */

.auth-dropdown-menu {
  min-width: 300px;
  max-width: 340px;
  padding: 0;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-color);
  background-color: var(--background-color);
}

.auth-dropdown-content {
  background-color: var(--background-color);
}

.auth-dropdown-content h6 {
  color: var(--text-color);
  font-weight: 600;
}

.auth-dropdown-content .form-label {
  color: var(--text-color);
}

.auth-dropdown-content .form-control,
.auth-dropdown-content .form-select {
  background-color: var(--background-color);
  border-color: var(--border-color);
  color: var(--text-color);
}

.auth-dropdown-content .form-control:focus,
.auth-dropdown-content .form-select:focus {
  background-color: var(--background-color);
  border-color: var(--primary-color);
  color: var(--text-color);
}

/* Dark theme adjustments */
[data-theme="dark"] .auth-dropdown-menu {
  background-color: var(--card-background);
  border-color: var(--border-color);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .auth-dropdown-content {
  background-color: var(--card-background);
}

[data-theme="dark"] .auth-dropdown-content .form-control,
[data-theme="dark"] .auth-dropdown-content .form-select {
  background-color: #2a2a2a;
  border-color: #495057;
}

[data-theme="dark"] .auth-dropdown-content .form-control:focus,
[data-theme="dark"] .auth-dropdown-content .form-select:focus {
  background-color: #333;
  border-color: var(--primary-color);
}

[data-theme="dark"] .auth-dropdown-content .btn-outline-secondary {
  color: var(--text-color);
  border-color: #495057;
}

[data-theme="dark"] .auth-dropdown-content .btn-outline-secondary:hover {
  background-color: #495057;
}

/* Responsive dropdown */
@media (max-width: 767.98px) {
  .auth-dropdown-menu {
    min-width: 280px;
    max-width: calc(100vw - 20px);
  }
}

/* ============================================
   Improved Instance List Item Styles
   ============================================ */

/* Instance name - allow wrapping to 2 lines instead of truncating */
.instance-item .instance-name {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

/* Customer and integration info - keep single line truncate */
.instance-item .instance-meta {
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Instance item hover tooltip */
.instance-item[title] {
  position: relative;
}

/* ============================================
   Integrations Page Styles (Three-Column Layout)
   ============================================ */

.integrations-list {
  overflow-y: auto;
  max-height: calc(100vh - 250px);
  flex: 1;
}

.integration-item {
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.integration-item:hover {
  background-color: rgba(13, 110, 253, 0.1);
}

.integration-item.active {
  background-color: var(--primary-color) !important;
  color: white !important;
}

.integration-item.active .text-muted {
  color: rgba(255, 255, 255, 0.8) !important;
}

.integration-item.active .badge {
  background-color: rgba(255, 255, 255, 0.2) !important;
  color: white !important;
}

/* Dark theme for integrations */
[data-theme="dark"] .integration-item:hover {
  background-color: rgba(61, 139, 253, 0.2);
}

/* Template Information Panel (Middle Column) */
#versionControlPanel {
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

#versionControlPanel .card-header {
  padding: 0.75rem 1rem;
  background-color: var(--card-background);
}

#versionControlPanel .card-body {
  padding: 0;
}

/* Template Header Section */
.template-header-section {
  background-color: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .template-header-section {
  background-color: rgba(255, 255, 255, 0.02);
}

#selectedIntegrationName {
  font-size: 0.95rem;
  line-height: 1.3;
}

#templateIdDisplay {
  font-family: monospace;
  font-size: 0.7rem;
  cursor: help;
}

/* Open in Designer Button */
#openDesignerBtn {
  font-size: 0.8rem;
}

#openDesignerBtn:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Version Section */
.version-section {
  background-color: var(--background-color);
}

#versionSelect {
  width: 100%;
}

/* Version Comment Display */
#versionCommentSection #versionCommentDisplay {
  font-size: 0.75rem;
  max-height: 80px;
  overflow-y: auto;
  word-wrap: break-word;
}

[data-theme="dark"] #versionCommentDisplay {
  background-color: #2a2a2a !important;
  border-color: var(--border-color) !important;
  color: var(--text-color);
}

/* Version Metadata Section */
.version-metadata-section {
  background-color: rgba(0, 123, 255, 0.03);
}

[data-theme="dark"] .version-metadata-section {
  background-color: rgba(0, 123, 255, 0.05);
}

.version-metadata-section .badge {
  font-size: 0.65rem;
  font-weight: 500;
}

/* Metadata display spans with tooltips */
#latestPublishedDisplay {
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

/* Edit Mode Section */
#editModeSection {
  background-color: rgba(255, 193, 7, 0.05);
}

[data-theme="dark"] #editModeSection {
  background-color: rgba(255, 193, 7, 0.08);
}

/* Actions Section */
.actions-section {
  background-color: var(--background-color);
}

/* YAML Validation Status */
#yamlValidationStatus {
  transition: all 0.3s ease;
}

#yamlValidationStatus.valid {
  background-color: rgba(25, 135, 84, 0.1);
  border-color: var(--success-color) !important;
}

#yamlValidationStatus.invalid {
  background-color: rgba(220, 53, 69, 0.1);
  border-color: var(--danger-color) !important;
}

[data-theme="dark"] #yamlValidationStatus {
  background-color: #2a2a2a;
}

[data-theme="dark"] #yamlValidationStatus.valid {
  background-color: rgba(46, 168, 104, 0.15);
}

[data-theme="dark"] #yamlValidationStatus.invalid {
  background-color: rgba(227, 93, 106, 0.15);
}

/* YAML Editor Panel */
#yamlEditorPanel .card-header {
  padding: 0.75rem 1rem;
}

#yamlEditorContainer {
  background-color: var(--card-background);
  height: calc(100vh - 160px) !important;
  min-height: 400px;
}

/* Make the editor panel card fill available height */
#yamlEditorPanel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 100px);
}

#yamlEditorPanel .card-body {
  flex: 1;
  overflow: hidden;
}

/* Toast container */
.toast-container {
  z-index: 1100;
}

/* Editor mode badges */
#editorReadOnlyBadge, #editorEditableBadge, #editorViewModeBadge {
  font-size: 0.7rem;
  font-weight: normal;
}

#unsavedChangesBadge {
  font-size: 0.75rem;
  animation: pulse 2s infinite;
}

/* Edit mode button styling */
#enableEditModeBtn {
  transition: all 0.2s ease-in-out;
}

#enableEditModeBtn.btn-warning {
  animation: editModePulse 2s infinite;
}

@keyframes editModePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.4); }
  50% { box-shadow: 0 0 8px 2px rgba(255, 193, 7, 0.6); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Save button styling */
#saveYamlBtn:not(:disabled) {
  animation: glow 1.5s ease-in-out infinite alternate;
}

@keyframes glow {
  from { box-shadow: 0 0 3px rgba(25, 135, 84, 0.4); }
  to { box-shadow: 0 0 8px rgba(25, 135, 84, 0.6); }
}

/* Import confirmation modal */
.import-confirm-modal .modal-body {
  max-height: 60vh;
  overflow-y: auto;
}

.import-preview-container {
  background-color: var(--card-background);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1rem;
  max-height: 200px;
  overflow: auto;
  font-family: monospace;
  font-size: 0.8rem;
}

/* Initial Loading - Consistent Column Heights */
#page-integrations .row > div {
  min-height: 200px;
}

/* Placeholder Cards - Consistent Sizing */
#versionControlPlaceholder,
#yamlEditorPlaceholder {
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#versionControlPlaceholder .card-body,
#yamlEditorPlaceholder .card-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* Ensure consistent column widths on load */
#page-integrations .col-12.col-lg-3.col-xl-2 {
  flex: 0 0 auto;
}

#page-integrations .col-12.col-lg-6.col-xl-8 {
  flex: 1 1 auto;
}

/* Responsive adjustments for integrations page (Three-Column) */
@media (min-width: 992px) {
  #page-integrations .row {
    flex-wrap: nowrap;
  }

  /* Ensure middle column doesn't collapse */
  #versionControlColumn {
    min-width: 220px;
  }
}

@media (max-width: 991.98px) {
  #page-integrations .sticky-sidebar {
    position: static;
    max-height: none;
    margin-bottom: 1rem;
  }

  .integrations-list {
    max-height: 250px;
  }

  #versionControlColumn {
    order: 2;
  }

  #yamlEditorContainer {
    height: 50vh !important;
    min-height: 300px !important;
  }

  #yamlEditorPanel {
    height: auto;
  }

  #versionControlPanel {
    max-height: none;
  }
}

@media (max-width: 767.98px) {
  .integrations-list {
    max-height: 200px;
  }

  #yamlEditorContainer {
    height: 40vh !important;
    min-height: 250px !important;
  }
}

/* Ensure Monaco editor line numbers have enough width for 5+ digits */
#yamlEditorContainer .monaco-editor .margin-view-overlays .line-numbers {
  min-width: 50px;
  text-align: right;
  padding-right: 10px;
}

/* YAML error markers in editor */
.yaml-error-marker {
  background-color: rgba(220, 53, 69, 0.3);
}

.yaml-warning-marker {
  background-color: rgba(255, 193, 7, 0.3);
}

/* ============================================
   Execution Chain Card Styles
   ============================================ */

.execution-chains-container {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.execution-chain-card {
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}

.execution-chain-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.execution-chain-card .card-header {
  background-color: var(--card-background);
  border-bottom: none;
  transition: background-color 0.15s ease;
}

.execution-chain-card .card-header.chain-header-toggle:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

.execution-chain-card .chain-toggle-icon {
  transition: transform 0.2s ease;
  font-size: 0.75rem;
  opacity: 0.6;
}

.execution-chain-card .card-body {
  background-color: rgba(0, 0, 0, 0.02);
  border-top: 1px solid var(--border-color);
}

.chain-executions-table {
  font-size: 0.85rem;
}

.chain-executions-table thead th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-color);
  opacity: 0.7;
  border-bottom: 1px solid var(--border-color);
}

.chain-execution-row {
  transition: background-color 0.15s ease;
}

.chain-execution-row:hover {
  background-color: rgba(0, 0, 0, 0.03);
}

.chain-execution-row td {
  vertical-align: middle;
  padding: 0.5rem 0.75rem;
}

/* Cursor helper */
.cursor-pointer {
  cursor: pointer;
}

/* Dark theme for execution chain cards */
[data-theme="dark"] .execution-chain-card {
  border-color: var(--border-color);
}

[data-theme="dark"] .execution-chain-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .execution-chain-card .card-header {
  background-color: var(--card-background);
}

[data-theme="dark"] .execution-chain-card .card-header.chain-header-toggle:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .execution-chain-card .card-body {
  background-color: rgba(255, 255, 255, 0.02);
  border-top-color: var(--border-color);
}

[data-theme="dark"] .chain-executions-table thead th {
  border-bottom-color: var(--border-color);
}

[data-theme="dark"] .chain-execution-row:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .chain-executions-table thead.table-light {
  background-color: #343a40 !important;
}

[data-theme="dark"] .chain-executions-table thead.table-light th {
  background-color: #343a40 !important;
  color: var(--text-color);
}

/* Responsive adjustments for chain cards */
@media (max-width: 767.98px) {
  .execution-chain-card .card-header {
    padding: 0.5rem;
  }

  .chain-executions-table {
    font-size: 0.8rem;
  }

  .chain-execution-row td {
    padding: 0.35rem 0.5rem;
  }

  .execution-chain-card .badge {
    font-size: 0.65rem;
    padding: 0.2rem 0.4rem;
  }
}

/* ============================================
   Analysis Page Styles
   ============================================ */

#page-analysis {
  background-color: var(--background-color);
}

/* KPI Cards */
.kpi-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.kpi-card .display-6 {
  font-size: 1.75rem;
  font-weight: 700;
}

[data-theme="dark"] .kpi-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Time Range Buttons */
#timeRangeButtons .btn {
  font-size: 0.8rem;
  padding: 0.25rem 0.75rem;
}

#timeRangeButtons .btn.active {
  font-weight: 600;
}

/* Analysis Selection Lists */
.analysis-list {
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.analysis-list::-webkit-scrollbar {
  width: 6px;
}

.analysis-list::-webkit-scrollbar-track {
  background: transparent;
}

.analysis-list::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 3px;
}

.analysis-list-item {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.analysis-list-item:hover {
  background-color: rgba(13, 110, 253, 0.08);
}

.analysis-list-item.active {
  background-color: var(--primary-color) !important;
  color: white !important;
}

.analysis-list-item.active .text-muted {
  color: rgba(255, 255, 255, 0.8) !important;
}

.analysis-list-item.active .badge {
  background-color: rgba(255, 255, 255, 0.2) !important;
  color: white !important;
}

.analysis-list-item.active i {
  color: white !important;
}

[data-theme="dark"] .analysis-list-item:hover {
  background-color: rgba(61, 139, 253, 0.15);
}

[data-theme="dark"] .analysis-selection-header {
  background-color: #2a2a2a !important;
}

/* Chart Containers */
.chart-container {
  position: relative;
}

.chart-container canvas {
  max-width: 100%;
}

/* Chart Type Buttons */
#chartTypeButtons .btn {
  padding: 0.25rem 0.5rem;
}

#chartTypeButtons .btn i {
  font-size: 0.875rem;
}

/* Recent Executions List */
.recent-executions-list {
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.recent-executions-list::-webkit-scrollbar {
  width: 6px;
}

.recent-executions-list::-webkit-scrollbar-track {
  background: transparent;
}

.recent-executions-list::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 3px;
}

.recent-execution-item {
  transition: background-color 0.15s ease;
}

.recent-execution-item:hover {
  background-color: rgba(0, 0, 0, 0.03);
}

[data-theme="dark"] .recent-execution-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

/* Breadcrumb Styles */
#page-analysis .breadcrumb {
  background-color: transparent;
  padding: 0;
  margin: 0;
}

#page-analysis .breadcrumb-item a {
  color: var(--primary-color);
}

#page-analysis .breadcrumb-item a:hover {
  text-decoration: underline;
}

#page-analysis .breadcrumb-item.active {
  color: var(--text-color);
}

/* Auto-refresh Toggle */
#page-analysis .form-switch .form-check-input {
  cursor: pointer;
}

#page-analysis .form-switch .form-check-input:checked {
  background-color: var(--success-color);
  border-color: var(--success-color);
}

/* Responsive Adjustments for Analysis Page */
@media (max-width: 1199.98px) {
  #page-analysis .col-xl-2 {
    flex: 0 0 auto;
    width: 25%;
  }

  #page-analysis .col-xl-10 {
    flex: 0 0 auto;
    width: 75%;
  }
}

@media (max-width: 991.98px) {
  #page-analysis .sticky-sidebar {
    position: static;
    max-height: none;
    margin-bottom: 1rem;
  }

  #page-analysis #kpiCardsRow {
    flex-wrap: wrap;
  }

  #page-analysis #kpiCardsRow > .col {
    flex: 0 0 50%;
    max-width: 50%;
    margin-bottom: 1rem;
  }

  #page-analysis .chart-container {
    height: 250px !important;
  }
}

@media (max-width: 767.98px) {
  #page-analysis .kpi-card .display-6 {
    font-size: 1.5rem;
  }
}

/* Dark Theme Chart.js Adjustments */
[data-theme="dark"] .chart-container {
  color: var(--text-color);
}

/* Analysis Page Card Headers */
#page-analysis .card-header h6 {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0;
}

#page-analysis .card-header h6 i {
  opacity: 0.7;
}

/* Metric Selectors in Chart Headers */
#page-analysis .card-header .form-select {
  font-size: 0.75rem;
  padding: 0.2rem 1.5rem 0.2rem 0.5rem;
  background-position: right 0.3rem center;
}

/* Loading States */
#page-analysis .spinner-border-sm {
  width: 1rem;
  height: 1rem;
  border-width: 0.15em;
}

/* Analysis Drill Down Panel */
#page-analysis #clearDrilldownBtn {
  padding: 0.15rem 0.35rem;
  font-size: 0.7rem;
}

#page-analysis #clearDrilldownBtn:hover {
  background-color: var(--danger-color);
  border-color: var(--danger-color);
  color: white;
}

/* ============================================
   Mobile Optimizations
   ============================================ */

/* --- Auth Page Mobile --- */
.auth-page-container {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: calc(100vh - 80px);
}

@media (max-width: 575.98px) {
  .auth-page-container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  #page-auth .card {
    max-width: 100%;
    border-radius: 0.5rem;
  }

  #page-auth .card-body {
    padding: 1rem;
  }

  #page-auth .form-select,
  #page-auth .form-control {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }
}

/* --- Navbar Mobile Adjustments --- */
@media (max-width: 991.98px) {
  .navbar .navbar-nav {
    padding: 0.5rem 0;
  }

  .navbar .nav-link {
    padding: 0.5rem 0.75rem;
    margin: 0.125rem 0;
  }

  .navbar .theme-switch-wrapper {
    padding: 0.5rem 0.75rem;
  }

  /* On mobile, auth nav-item behaves like a regular link */
  .navbar .nav-item.dropdown .auth-dropdown-menu {
    display: none !important;
  }
}

/* --- Analysis Page Mobile --- */
.analysis-controls {
  gap: 0.5rem;
}

.analysis-date-inputs {
  gap: 0.25rem;
}

.analysis-date-inputs input[type="date"] {
  width: 130px;
  min-width: 0;
}

@media (max-width: 767.98px) {
  .analysis-controls {
    flex-direction: column;
    align-items: stretch !important;
  }

  .analysis-controls-left {
    flex-direction: column;
    align-items: stretch !important;
    width: 100%;
  }

  .analysis-controls-right {
    width: 100%;
    justify-content: space-between;
  }

  .analysis-date-inputs {
    width: 100%;
  }

  .analysis-date-inputs input[type="date"] {
    width: auto;
    flex: 1;
    font-size: 0.8rem;
  }

  #timeRangeButtons {
    width: 100%;
    display: flex !important;
  }

  #timeRangeButtons .btn {
    flex: 1;
    font-size: 0.75rem;
    padding: 0.3rem 0.25rem;
  }

  /* KPI cards - 2 columns on small mobile */
  #kpiCardsRow {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  #kpiCardsRow > .col {
    flex: none !important;
    max-width: 100% !important;
    padding: 0 !important;
  }

  #kpiCardsRow > .col:last-child {
    grid-column: 1 / -1;
  }

  .kpi-card .card-body {
    padding: 0.75rem !important;
  }

  .kpi-card .display-6 {
    font-size: 1.25rem !important;
  }

  .kpi-card .small {
    font-size: 0.7rem;
  }

  /* Distribution charts - stack fully */
  #page-analysis .col-md-4 {
    margin-bottom: 0.75rem;
  }

  #page-analysis .chart-container {
    height: 200px !important;
  }

  /* Recent executions - compact on mobile */
  .recent-execution-item {
    padding: 0.5rem !important;
  }

  /* Drill down sidebar */
  #page-analysis .sticky-sidebar {
    margin-bottom: 1rem;
  }

  #page-analysis .analysis-list {
    max-height: 200px !important;
  }

  #page-analysis .card-header h6 {
    font-size: 0.8rem;
  }

  /* Top by volume/errors */
  #page-analysis .col-md-6 {
    margin-bottom: 0.75rem;
  }
}

@media (max-width: 400px) {
  /* Extra small screens: KPI single column */
  #kpiCardsRow {
    grid-template-columns: 1fr !important;
  }

  #kpiCardsRow > .col:last-child {
    grid-column: auto;
  }
}

/* --- Integrations Page Mobile --- */
@media (max-width: 991.98px) {
  #page-integrations .container-fluid {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  /* Stack columns properly */
  #page-integrations .sticky-sidebar {
    position: static;
    max-height: none;
  }

  .integrations-list {
    max-height: 200px;
  }

  /* Version control panel - horizontal layout on tablet */
  #versionControlPanel {
    max-height: none;
  }

  #yamlEditorPanel {
    height: auto;
  }

  #yamlEditorContainer {
    height: 50vh !important;
    min-height: 300px !important;
  }
}

@media (max-width: 767.98px) {
  #page-integrations .container-fluid {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .integrations-list {
    max-height: 150px;
  }

  #yamlEditorContainer {
    height: 40vh !important;
    min-height: 250px !important;
  }

  /* Template info sections - more compact */
  #versionControlPanel .template-header-section,
  #versionControlPanel .version-section,
  #versionControlPanel .version-metadata-section,
  #versionControlPanel .actions-section,
  #versionControlPanel #editModeSection {
    padding: 0.5rem !important;
  }

  #versionControlPanel .form-label {
    font-size: 0.7rem;
    margin-bottom: 0.25rem;
  }

  /* Action buttons - grid on mobile for better touch targets */
  #versionControlPanel .actions-section .d-grid {
    gap: 0.375rem !important;
  }

  /* Integration items - compact */
  .integration-item {
    padding: 0.5rem !important;
  }

  .integration-item .fw-semibold {
    font-size: 0.85rem;
  }

  /* Make version control collapsible look on mobile */
  #versionControlColumn {
    order: 2;
  }
}

/* --- Instances Page Mobile --- */
@media (max-width: 767.98px) {
  #page-instances .container-fluid {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .instances-list {
    max-height: 180px;
  }

  /* Execution filter bar - full-width stacked */
  #executionsFilterBar .col-auto {
    width: 100%;
  }

  #executionsFilterBar .form-select-sm,
  #executionsFilterBar .form-control-sm {
    width: 100%;
  }
}

/* --- Execution Page Mobile --- */
@media (max-width: 767.98px) {
  #page-execution .sidebar {
    position: static;
    margin-bottom: 1rem;
  }

  #page-execution .d-flex {
    flex-direction: column;
  }

  #page-execution #executionId {
    margin-right: 0 !important;
    margin-bottom: 0.5rem;
  }

  #page-execution #loadButton {
    width: 100%;
  }
}

/* --- General Mobile Utilities --- */
@media (max-width: 767.98px) {
  /* Reduce padding on container-fluid for mobile */
  .container-fluid {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  /* Card headers - tighter on mobile */
  .card-header {
    padding: 0.5rem 0.75rem;
  }

  .card-header h5 {
    font-size: 0.95rem;
  }

  .card-header h6 {
    font-size: 0.85rem;
  }

  /* Prevent inputs from being too small to tap */
  .form-control-sm,
  .form-select-sm {
    min-height: 36px;
    font-size: 0.85rem;
  }

  .btn-sm {
    min-height: 34px;
    padding: 0.3rem 0.5rem;
  }

  /* Modal adjustments for mobile */
  .modal-content {
    margin: 2% auto;
    width: 95%;
    max-height: 90vh;
  }

  .modal-lg {
    width: 95%;
  }

  /* JSON modal */
  .json-modal-container {
    height: 85vh;
  }

  /* Breadcrumb on mobile */
  .breadcrumb {
    font-size: 0.8rem;
  }

  /* Badge sizing */
  .badge {
    font-size: 0.65rem;
  }
}

/* ==========================================
   Live Polling Indicators
   ========================================== */

/* Live indicator container */
.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 4px;
    background: rgba(220, 53, 69, 0.08);
    border: 1px solid rgba(220, 53, 69, 0.2);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
}

[data-theme="dark"] .live-indicator {
    background: rgba(220, 53, 69, 0.15);
    border-color: rgba(220, 53, 69, 0.3);
}

/* Pulsing dot */
.live-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #dc3545;
    animation: live-pulse 1.5s ease-in-out infinite;
}

@keyframes live-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

/* Live text label */
.live-text {
    color: #dc3545;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Live indicator for execution detail sidebar */
#execution-live-indicator {
    margin-bottom: 8px;
}

/* Live indicator for execution list header */
.executions-live-indicator {
    display: inline-flex;
    margin-left: 8px;
}

/* Subtle flash animation for newly arrived log entries */
.live-log-new {
    animation: live-log-flash 1.5s ease-out;
}

@keyframes live-log-flash {
    0% { background-color: rgba(13, 110, 253, 0.12); }
    100% { background-color: transparent; }
}

[data-theme="dark"] .live-log-new {
    animation: live-log-flash-dark 1.5s ease-out;
}

@keyframes live-log-flash-dark {
    0% { background-color: rgba(61, 139, 253, 0.15); }
    100% { background-color: transparent; }
}

/* Execution list row status update flash */
.execution-status-updated {
    animation: status-flash 1s ease-out;
}

@keyframes status-flash {
    0% { background-color: rgba(25, 135, 84, 0.12); }
    100% { background-color: transparent; }
}