/* ========================================
   1. CSS VARIABLES
   ======================================== */

:root {
  color-scheme: dark;
  --bg: #080c18;
  --body-bg: #0a0f1e;
  --panel: #0e1428;
  --fg: #dfe6f5;
  --fg-strong: #ffffff;
  --muted: #6b7fa3;
  --accent: #4c9aff;
  --accent-2: #7c6aef;
  --accent-subtle: rgba(76, 154, 255, 0.12);
  --accent-border: rgba(76, 154, 255, 0.25);
  --accent-glow: rgba(76, 154, 255, 0.08);
  --error: #f05c5c;
  --ok: #34d399;
  --border: rgba(255,255,255,0.07);
  --border-mid: rgba(255,255,255,0.1);
  --border-strong: rgba(255,255,255,0.15);
  --surface: rgba(255,255,255,0.035);
  --surface-hover: rgba(255,255,255,0.065);
  --surface-mid: rgba(255,255,255,0.06);
  --surface-strong: rgba(255,255,255,0.08);
  --overlay: rgba(0,0,0,0.7);
  --header-bg: rgba(0,0,0,0.2);
  --check-border: rgba(255,255,255,0.3);
  --check-hover: rgba(255,255,255,0.08);
  --shadow: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --sidebar-bg: #1e1b4b;
  --sidebar-fg: rgba(255,255,255,0.5);
  --sidebar-fg-active: #ffffff;
  --sidebar-accent: #a78bfa;
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-active-bg: rgba(167, 139, 250, 0.18);
  --input-bg: var(--surface);
  --input-border: var(--border);
  --font-sans: 'DM Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Monaco, Consolas, monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.18s ease;
}

/* Light theme — modeled after MetaRouter UI */
[data-theme="light"] {
  color-scheme: light;
  --bg: #eaecf0;
  --body-bg: #f0f1f5;
  --panel: #ffffff;
  --fg: #1a1d26;
  --fg-strong: #0a0c12;
  --muted: #6b7280;
  --accent: #2b7de9;
  --accent-2: #6554c0;
  --accent-subtle: rgba(43, 125, 233, 0.08);
  --accent-border: rgba(43, 125, 233, 0.35);
  --accent-glow: rgba(43, 125, 233, 0.1);
  --error: #dc3545;
  --ok: #0d9f6e;
  --border: rgba(0,0,0,0.1);
  --border-mid: rgba(0,0,0,0.15);
  --border-strong: rgba(0,0,0,0.22);
  --surface: rgba(0,0,0,0.03);
  --surface-hover: rgba(0,0,0,0.06);
  --surface-mid: rgba(0,0,0,0.05);
  --surface-strong: rgba(0,0,0,0.08);
  --overlay: rgba(0,0,0,0.4);
  --header-bg: rgba(255,255,255,0.95);
  --check-border: rgba(0,0,0,0.3);
  --check-hover: rgba(0,0,0,0.08);
  --shadow: 0 8px 32px rgba(0,0,0,0.1);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --sidebar-bg: #1e1b4b;
  --sidebar-fg: rgba(255,255,255,0.55);
  --sidebar-fg-active: #ffffff;
  --sidebar-accent: #818cf8;
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-active-bg: rgba(129, 140, 248, 0.18);
  --input-bg: #ffffff;
  --input-border: rgba(0,0,0,0.15);
}

/* ========================================
   2. BASE RESET & ELEMENTS
   ======================================== */

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--body-bg);
  color: var(--fg);
  font-feature-settings: 'ss01', 'ss02';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

header, footer {
  position: relative;
  padding: 10px 20px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
header { position: relative; }
header .inline input[type="text"] { width: 240px; }
header .inline button { margin-right: 8px; }

header h1 { margin: 0; font-size: 18px; padding-left: 0; font-weight: 600; letter-spacing: -0.02em; }

main { padding: 20px; margin: 0 auto; }

/* App layout: sidebar + main content */
.app-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* Left sidebar */
.sidebar {
  width: 61px;
  min-width: 61px;
  box-sizing: border-box;
  background: var(--sidebar-bg);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 8px;
  overflow-y: auto;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-bottom {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--sidebar-fg);
  font-size: 13px;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.sidebar-btn:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-fg-active);
}

.sidebar-btn.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-accent);
  font-weight: 600;
}

.main-content {
  padding: 12px 24px 5px;
  background: var(--panel);
  width: 100%;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
}
section { background: var(--panel); padding: 16px; border-radius: var(--radius-lg); margin: 16px 0; border: 1px solid var(--border); }

h2 { font-size: 16px; margin: 0 0 12px; color: var(--muted); font-weight: 600; letter-spacing: -0.02em; }

label { color: var(--muted); font-size: 13px; letter-spacing: 0; font-weight: 500; }
label[title] { cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; }

input[type="text"], textarea, select {
  width: 100%;
  padding: 5px 8px;
  height: 34px;
  box-sizing: border-box;
  border-radius: 4px;
  border: 1px solid var(--input-border);
  background-color: var(--input-bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: border-color var(--transition), background-color var(--transition), box-shadow var(--transition);
}

textarea {
  height: auto;
}

select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7fa3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  max-width: 50ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

[data-theme="light"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235a6878'/%3E%3C/svg%3E");
}

input[type="text"]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background-color: var(--surface-hover);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

select option {
  max-width: 50ch; /* Limit to approximately 50 characters */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

textarea { min-height: 68px; resize: vertical; }

button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border: 0;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-weight: 500;
  transition: all var(--transition);
}

/* ========================================
   3. BUTTONS
   ======================================== */

/* Button variants */
.btn-primary, .btn-small {
  background: var(--accent-subtle);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition);
  font-family: var(--font-sans);
}
.btn-primary { padding: 10px 14px; border-radius: var(--radius); }

.btn-primary:hover, .btn-small:hover {
  background: rgba(76, 154, 255, 0.22);
  border-color: rgba(76, 154, 255, 0.45);
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-secondary {
  background: rgba(148, 163, 184, 0.1);
  color: #8a95a8;
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 10px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.btn-secondary:hover {
  background: rgba(148, 163, 184, 0.2);
  border-color: rgba(148, 163, 184, 0.4);
}

/* Anchor button */
.btn { display: inline-block; text-decoration: none; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; padding: 10px 14px; border-radius: var(--radius); font-weight: 500; }
.btn.secondary, button.secondary { background: var(--surface-mid); }

.inline { display: flex; gap: 8px 16px; align-items: center; }
.inline-break { flex-basis: 100%; height: 0; }

.grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 10px 14px;
  align-items: start;
}

.console {
  font-family: var(--font-mono);
  background: var(--bg);
  border: 1px solid var(--border);
  min-height: 140px;
  max-height: 280px;
  overflow: auto;
  padding: 10px;
  border-radius: var(--radius);
}

small { color: var(--muted); }

/* ========================================
   4. TABLES
   ======================================== */

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--surface-strong);
  max-width: 50ch; /* Limit to approximately 50 characters */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  font-weight: 500;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  font-family: var(--font-mono);
}

tbody tr:hover { background-color: var(--surface); }

.dropdown-menu {
  display: none;
  position: absolute;
  background-color: var(--panel);
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 10px;
  z-index: 10;
  min-width: 200px;
}
.dropdown-menu.show { display: block; }
.dropdown-menu label {
  display: block;
  margin-bottom: 5px;
  max-width: 50ch; /* Limit to approximately 50 characters */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   9. LOADING & SPINNERS
   ======================================== */

.spinner {
  width: 60px;
  height: 60px;
  border: 5px solid var(--accent-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ========================================
   10. TAG MANAGER STYLES
   ======================================== */

.app-container {
  height: 100vh;
  overflow: hidden;
}

.tag-manager-container {
  flex-shrink: 0;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  margin-top: 10px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 12px 20px;
  font-size: 15px;
  cursor: pointer;
  transition: all var(--transition);
  border-bottom: 2px solid transparent;
  font-weight: 500;
  font-family: var(--font-sans);
  letter-spacing: 0.01em;
}

.tab-btn:hover {
  color: var(--fg);
  background: var(--surface);
}

.tab-btn.active {
  color: var(--fg);
  border-bottom-color: var(--accent);
  background: var(--accent-glow);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease-in;
}

.tab-content.active:has(.split-panel-layout) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.tab-content.active:has(.split-panel-layout) > div {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Section Header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 15px;
}

.section-header h2 {
  margin: 0;
  color: var(--fg);
  font-size: 24px;
}

/* Button Variants */

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

/* ========================================
   11. FORMS & INPUTS
   ======================================== */

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  color: var(--fg);
  margin-bottom: 8px;
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
}

.form-group input,
.form-group select,
.form-group textarea,
.form-group-inline input,
.form-group-inline select,
.form-group-inline textarea {
  width: 100%;
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  padding: 5px 8px;
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--transition), background-color var(--transition), box-shadow var(--transition);
}

.form-group textarea,
.form-group-inline textarea {
  font-family: var(--font-mono);
  font-size: 13px;
  resize: vertical;
}
.form-group textarea { min-height: 150px; }
.form-group-inline textarea { min-height: 120px; }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.form-group-inline input:focus,
.form-group-inline select:focus,
.form-group-inline textarea:focus {
  outline: none;
  border-color: var(--accent);
  background-color: var(--surface-hover);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group small {
  display: block;
  color: var(--muted);
  margin-top: 5px;
  font-size: 12px;
}

/* Inline Form Group */
.form-group-inline {
  display: grid;
  grid-template-columns: 200px 1fr;
  align-items: center;
  gap: 15px;
  margin-bottom: 15px;
}

.form-group-inline label {
  color: var(--fg);
  font-weight: 500;
  font-size: 13px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  letter-spacing: 0;
  text-transform: none;
}

/* Required Asterisk */
.required {
  color: var(--error);
  font-weight: bold;
}

/* Help Icon */
.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: var(--accent-subtle);
  color: var(--accent);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 600;
  cursor: help;
  border: 1px solid var(--accent-border);
  margin-right: 4px;
  vertical-align: middle;
  transition: all var(--transition);
}

.help-icon:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ========================================
   12. TOOLTIPS
   ======================================== */

.custom-tooltip {
  background: var(--bg);
  color: var(--fg);
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  max-width: 300px;
  font-size: 13px;
  line-height: 1.5;
  z-index: 10000;
  animation: tooltipFadeIn 0.2s ease-out;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
   13. LAYOUT UTILITIES
   ======================================== */

/* Settings section title */
.settings-section h3 {
  color: var(--fg);
  margin-bottom: 15px;
}

/* Flex utilities */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }

/* Loading state - centered with spinner */
.loading-state {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
}

/* Conditions actions row */
.conditions-actions {
  display: flex;
  gap: 10px;
  margin-top: 15px;
  flex-wrap: wrap;
  align-items: center;
}

/* ========================================
   14. CARDS & LISTS
   ======================================== */

.items-list {
  margin-top: 30px;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: 66px;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  transition: all var(--transition);
}

.item-card:hover {
  border-color: var(--accent-border);
  background: var(--surface-hover);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.item-info {
  flex: 1;
}

.item-name {
  color: var(--fg);
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 5px;
}

.item-description {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.item-tag {
  display: inline-block;
  background: var(--accent-glow);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.03em;
  font-family: var(--font-mono);
}

.usage-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(124, 106, 239, 0.12);
  color: #a08ef0;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 500;
  font-family: var(--font-mono);
}

/* ========================================
   MISC UI COMPONENTS
   ======================================== */

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 15px;
  opacity: 0.5;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: var(--overlay);
  animation: fadeIn 0.2s ease-in;
}

.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--surface-strong);
  border-radius: var(--radius-lg);
  padding: 30px;
  max-width: 700px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  z-index: 2001;
  animation: slideUp 0.3s ease-out;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--surface-hover);
}

@keyframes slideUp {
  from { transform: translateY(50px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ========================================
   15. AUTOCOMPLETE
   ======================================== */

.variable-autocomplete {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-height: 200px;
  overflow-y: auto;
  z-index: 10000;
  min-width: 200px;
}

.variable-autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  color: var(--fg);
  font-size: 13px;
  border-bottom: 1px solid var(--accent-glow);
}

.variable-autocomplete-item:last-child {
  border-bottom: none;
}

.variable-autocomplete-item:hover,
.variable-autocomplete-item.selected {
  background: var(--accent-subtle);
}

.variable-autocomplete-item code {
  background: var(--accent-subtle);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 12px;
  color: var(--accent);
}

/* ========================================
   16. RESPONSIVE / MEDIA QUERIES
   ======================================== */

@media (max-width: 900px) {
  .tag-manager-container {
    padding: 10px;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab-btn {
    white-space: nowrap;
  }

  .item-card {
    flex-direction: column;
  }
}

/* ========================================
   17. ANIMATIONS & KEYFRAMES
   ======================================== */

@keyframes highlight-success {
    0% {
        background-color: rgba(46, 204, 113, 0.3);
    }
    100% {
        background-color: transparent;
    }
}

.build-highlight {
    animation: highlight-success 2s ease-out;
}

/* ========================================
   18. CHECKBOX & RADIO STYLING
   ======================================== */

input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--check-border);
    border-radius: 4px;
    background: var(--surface);
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

input[type="checkbox"]:hover {
    border-color: var(--border-strong);
    background: var(--surface-strong);
}

input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #1a1a1a;
    font-size: 14px;
    font-weight: bold;
}

/* Radio button styling */
input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--check-border);
    border-radius: 50%;
    background: var(--surface);
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

input[type="radio"]:hover {
    border-color: var(--border-strong);
    background: var(--surface-strong);
}

input[type="radio"]:checked {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.2);
}

input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
}

/* ========================================
   19. SETTINGS SECTIONS
   ======================================== */

.settings-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 20px;
}

.settings-section label:has(input[type="radio"]) {
    transition: all 0.2s ease;
}

.settings-section label:has(input[type="radio"]:checked) {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.settings-section label:has(input[type="radio"]):hover {
    border-color: var(--border-strong);
    background: var(--surface-hover);
}

.code-preview {
    max-height: 500px;
    overflow: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 15px;
}

.code-preview pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    color: #ffffff;
}

/* ========================================
   20. CODE EDITOR & SYNTAX HIGHLIGHTING
   ======================================== */

.code-editor-wrapper {
    position: relative;
    width: 100%;
    min-height: 250px;
    background: var(--surface);
    border: 1px solid var(--surface-strong);
    border-radius: 8px;
    overflow: auto;
    display: flex;
}

.code-editor-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea#action-custom-code,
textarea#variable-custom-code,
textarea#var-custom,
textarea#trigger-customjs,
textarea#action-track-properties,
textarea#action-page-properties,
textarea#action-identify-traits,
textarea#action-group-traits {
    position: absolute;
    top: 0;
    left: 45px;
    width: calc(100% - 45px);
    height: 100%;
    font-family: var(--font-mono) !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 12px !important;
    color: transparent !important;
    min-height: 250px;
    resize: none;
    box-sizing: border-box;
    z-index: 2;
    caret-color: #5b8cff;
}

textarea#action-custom-code:focus,
textarea#variable-custom-code:focus,
textarea#var-custom:focus,
textarea#trigger-customjs:focus,
textarea#action-track-properties:focus,
textarea#action-page-properties:focus,
textarea#action-identify-traits:focus,
textarea#action-group-traits:focus {
    outline: none;
}

/* ========================================
   22. CONDITIONS & MODALS
   ======================================== */

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.modal-container {
  background: var(--panel);
  border: 1px solid var(--border-mid);
  border-radius: 10px;
  padding: 30px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-body {
  margin-bottom: 20px;
}

.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding-top: 20px;
  border-top: 1px solid var(--border-mid);
}

/* Form Fields */
.form-field {
  margin-bottom: 15px;
}

.form-label {
  color: var(--fg);
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 8px;
  display: block;
}

.form-input,
.form-select {
  padding: 5px 8px;
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 14px;
  font-family: var(--font-sans);
  width: 100%;
  box-sizing: border-box;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Conditions Builder */
.conditions-builder {
  margin-bottom: 10px;
}

.conditions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Condition Item */
.condition-item {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--surface);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--surface-strong);
}

/* Condition Operator Row (AND/OR) */
.condition-operator-row {
  display: flex;
  justify-content: center;
  margin: 5px 0;
}

.condition-logic-select {
  width: 80px;
  background: var(--surface);
  border: 1px solid var(--surface-strong);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--fg);
  font-weight: 600;
  text-align: center;
}

/* Condition Selection Checkbox */
.condition-select-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
  align-self: center;
}

/* Condition Group */
.condition-group {
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 12px;
  background: var(--accent-glow);
  margin: 5px 0;
}

.condition-group .condition-item {
  background: var(--surface);
}

.condition-group .condition-operator-row {
  margin: 3px 0;
}

.condition-group .condition-logic-select {
  width: 70px;
  font-size: 12px;
  padding: 4px 8px;
}

/* Group Actions Button */
.conditions-group-actions {
  padding: 6px 12px;
  background: var(--accent-glow);
  border-radius: 8px;
  border: 1px solid var(--accent);
}

.btn-small { padding: 6px 12px; border-radius: 6px; font-size: 12px; }

.btn-small.btn-danger {
  background: rgba(255, 71, 87, 0.15);
  color: #ff4757;
  border: 1px solid rgba(255, 71, 87, 0.3);
}

.btn-small.btn-danger:hover {
  background: rgba(255, 71, 87, 0.25);
  border-color: rgba(255, 71, 87, 0.5);
}

/* Checkbox labels */
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 16px;
  font-size: 13px;
  color: var(--fg);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.hidden {
  display: none !important;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

.loading .spinner {
  margin: 0 auto 15px;
}

/* Danger button for reset */
.btn-danger {
  background: rgba(255, 71, 87, 0.15);
  color: #ff4757;
  border: 1px solid rgba(255, 71, 87, 0.3);
}

.btn-danger:hover {
  background: rgba(255, 71, 87, 0.25);
  border-color: rgba(255, 71, 87, 0.5);
}

/* ========================================
   SPLIT-PANEL LAYOUT
   ======================================== */

.split-panel-layout {
  display: flex;
  gap: 0;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.split-panel-rail {
  width: 400px;
  min-width: 400px;
  max-width: 400px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.split-panel-detail {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 24px;
  background: var(--panel);
  min-width: 0;
}

/* Rail header with Add button */
/* Rail header: New + Duplicate + Delete buttons */
.rail-header {
  display: flex;
  gap: 6px;
  padding: 12px 12px 0;
}

.rail-header-btn {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: var(--radius);
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(148, 163, 184, 0.1);
  color: #8a95a8;
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.rail-header-btn.primary {
  background: var(--accent-subtle);
  border-color: var(--accent-border);
  color: var(--accent);
}

.rail-header-btn.primary:hover {
  background: rgba(76, 154, 255, 0.22);
  border-color: rgba(76, 154, 255, 0.45);
  box-shadow: 0 0 20px var(--accent-glow);
}

.rail-header-btn:hover {
  background: rgba(148, 163, 184, 0.2);
  border-color: rgba(148, 163, 184, 0.4);
}

.rail-header-btn.danger {
  border-color: rgba(255, 71, 87, 0.3);
  color: #ff4757;
}

.rail-header-btn.danger:hover {
  background: rgba(255, 71, 87, 0.15);
}

.rail-header-bulk {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

/* Rail search row: select-all checkbox + search input */
.rail-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 30px;
}

.rail-select-all-container {
  flex-shrink: 0;
}

.rail-select-all-checkbox {
  cursor: pointer;
}

.rail-search-input {
  flex: 1;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--surface-strong);
  border-radius: 6px;
  color: var(--fg);
  font-size: 13px;
  box-sizing: border-box;
  min-width: 0;
}

.rail-search-input::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

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

/* Rail cards */
.rail-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rail-cards-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 8px 8px;
}

.rail-card {
  padding: 10px 12px;
  min-height: 66px;
  cursor: pointer;
  border-left: 3px solid transparent;
  border-radius: 6px;
  background: var(--surface);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.rail-card-checkbox {
  margin-top: 2px;
  flex-shrink: 0;
}

.rail-card-info {
  flex: 1;
  min-width: 0;
}

.rail-card:hover {
  background: var(--surface-hover);
}

.rail-card-selected {
  background: var(--accent-glow);
  border-left-color: var(--accent);
}

.rail-card-selected:hover {
  background: var(--accent-subtle);
}

.rail-card-inactive {
  opacity: 0.4;
}

.rail-card-inactive:hover {
  opacity: 0.6;
}

.rail-card-name {
  color: var(--fg);
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-card-type {
  display: inline-block;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--font-mono);
}

/* System badge for built-in triggers */
.rail-card-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: var(--accent-glow);
  border-radius: 3px;
  vertical-align: middle;
  font-family: var(--font-mono);
}

.rail-separator {
  height: 1px;
  background: var(--surface-strong);
  margin: 6px 12px;
}

/* Save toast notification */
.save-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 20px;
  background: var(--ok);
  color: #0a0f1e;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s;
  z-index: 10000;
  pointer-events: none;
}

.save-toast-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Rail empty state */
.rail-empty {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* Detail panel body */
.detail-panel-body {
  margin-bottom: 20px;
  max-width: 800px;
}

/* Managed tag code editor */
.managed-tag-code-section {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.managed-tag-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--hover);
  border-bottom: 1px solid var(--border);
}

.managed-tag-code-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}

.managed-tag-code-actions {
  display: flex;
  gap: 6px;
}

.managed-tag-code-actions .btn-sm {
  font-size: 12px;
  padding: 3px 10px;
}

.managed-tag-code-editor {
  background: var(--bg);
}

.managed-tag-code-editor textarea {
  width: 100%;
  min-height: 300px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--fg);
  border: none;
  outline: none;
  resize: vertical;
  tab-size: 2;
  box-sizing: border-box;
}

.managed-tag-code-editor .loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--muted);
}

.managed-tag-code-status {
  font-size: 12px;
  padding: 0 12px;
  min-height: 20px;
  line-height: 20px;
}

.managed-tag-code-status.success {
  color: #10b981;
}

.managed-tag-code-status.error {
  color: #ef4444;
}

/* Detail panel top bar (name input + save/cancel) */
.detail-panel-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 0 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--surface-strong);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 10;
}

.detail-topbar-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.detail-name-input {
  flex: 1;
  max-width: 50ch;
  padding: 5px 8px;
  height: 34px;
  box-sizing: border-box;
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans);
  letter-spacing: -0.02em;
  transition: border-color var(--transition);
}

.detail-name-input::placeholder {
  color: var(--muted);
  opacity: 0.6;
  font-weight: 400;
}

.detail-name-input:focus {
  outline: none;
  border-color: var(--accent);
}

.detail-description-input {
  flex: 1;
  max-width: 50ch;
  padding: 5px 8px;
  height: 34px;
  box-sizing: border-box;
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  font-family: var(--font-sans);
  transition: border-color var(--transition);
}

.detail-description-input::placeholder {
  color: var(--muted);
  opacity: 0.5;
}

.detail-description-input:focus {
  outline: none;
  border-color: var(--accent);
}

.detail-topbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto;
  visibility: hidden;
}

.detail-topbar-actions.dirty {
  visibility: visible;
}

/* Detail empty state */
.detail-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  text-align: center;
  color: var(--muted);
}

.detail-empty-state h3 {
  color: var(--fg);
  margin: 10px 0 5px;
}

.detail-empty-state p {
  margin-bottom: 20px;
}

/* Execution Timeline */
.execution-timeline-header {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
  padding: 0 16px;
}

.execution-timeline {
  position: relative;
}

.timeline-phase {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  position: relative;
  cursor: pointer;
  padding: 14px 16px;
  border-radius: var(--radius);
  transition: background var(--transition);
  margin-bottom: 2px;
}

.timeline-phase:hover {
  background: var(--surface-hover);
}

.timeline-dot-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 16px;
  flex-shrink: 0;
  padding-top: 2px;
}

.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.timeline-dot.empty {
  background: transparent;
  border: 2px solid var(--border-strong);
}

.timeline-line {
  width: 2px;
  flex: 1;
  background: var(--border);
  min-height: 20px;
}

.timeline-content {
  flex: 1;
  min-width: 0;
}

.timeline-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.timeline-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-strong);
}

.timeline-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface-mid);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.timeline-count.zero {
  opacity: 0.4;
}

.timeline-desc {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.4;
}

.timeline-arrow {
  color: var(--border-strong);
  font-size: 14px;
  align-self: center;
  flex-shrink: 0;
  transition: color var(--transition);
}

.timeline-phase:hover .timeline-arrow {
  color: var(--accent);
}

.timeline-var-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.timeline-var-link:hover {
  text-decoration: underline;
}

.var-order-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.var-order-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
}

.var-order-table td {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
}

.var-order-num {
  color: var(--muted);
  width: 40px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.var-order-type {
  color: var(--muted);
  font-size: 12px;
}

.timeline-phase:last-child .timeline-line {
  display: none;
}

/* ========================================
   SIDE PANEL — Inline Entity Creation
   ======================================== */

.detail-panel-wrapper {
  display: flex;
  gap: 0;
  height: 100%;
}

.detail-panel-main {
  flex: 1;
  min-width: 0;
  transition: opacity 0.2s ease;
}

.detail-panel-main.dimmed {
  opacity: 0.4;
  pointer-events: none;
}

.detail-side-panel {
  width: 0;
  overflow: hidden;
  transition: width 0.25s ease;
  border-left: 1px solid transparent;
}

.detail-side-panel.open {
  width: 40%;
  min-width: 340px;
  max-width: 480px;
  border-left: 1px solid var(--border-mid);
  overflow-y: auto;
  padding: 16px;
}

.side-panel-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.side-panel-breadcrumb-item {
  color: var(--muted);
  cursor: pointer;
  transition: color var(--transition);
}

.side-panel-breadcrumb-item:hover {
  color: var(--accent);
}

.side-panel-breadcrumb-item.current {
  color: var(--accent);
  font-weight: 600;
  cursor: default;
}

.side-panel-breadcrumb-separator {
  color: var(--border-strong);
}

.side-panel-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.side-panel-close:hover {
  color: var(--fg);
}

.side-panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.side-panel-actions .btn-primary,
.side-panel-actions .btn-secondary {
  flex: 1;
}

.detail-side-panel .form-field {
  grid-template-columns: 140px 1fr;
}

.detail-side-panel .form-input,
.detail-side-panel .form-select {
  max-width: none;
}

.detail-side-panel .form-textarea {
  max-width: none;
  min-height: 80px;
}

.side-panel-error {
  color: var(--danger);
  font-size: 13px;
  padding: 8px 0;
}

.form-field-with-create {
  position: relative;
}

.create-entity-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 5;
}

.form-field-with-create:hover .create-entity-btn,
.create-entity-btn:focus {
  opacity: 1;
}

.side-panel-origin {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px rgba(110, 168, 254, 0.2);
}

/* Build rail section headers */
.build-rail-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--surface-mid);
  font-family: var(--font-mono);
}

.build-rail-section-header.dev { color: #3b82f6; background: rgba(59, 130, 246, 0.05); }
.build-rail-section-header.staging { color: #f59e0b; background: rgba(245, 158, 11, 0.05); }
.build-rail-section-header.prod { color: #10b981; background: rgba(16, 185, 129, 0.05); }

.build-rail-empty {
  padding: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  opacity: 0.6;
}

.rail-card-badge.dev { color: #60a5fa; background: rgba(96, 165, 250, 0.1); }
.rail-card-badge.staging { color: #fbbf24; background: rgba(251, 191, 36, 0.1); }
.rail-card-badge.prod { color: #6ee7b7; background: rgba(110, 231, 183, 0.1); }
.rail-card-badge.deployed { color: #f87171; background: rgba(248, 113, 113, 0.1); }

[data-theme="light"] .rail-card-badge.dev { color: #2563eb; background: rgba(37, 99, 235, 0.08); }
[data-theme="light"] .rail-card-badge.staging { color: #d97706; background: rgba(217, 119, 6, 0.08); }
[data-theme="light"] .rail-card-badge.prod { color: #059669; background: rgba(5, 150, 105, 0.08); }
[data-theme="light"] .rail-card-badge.deployed { color: #dc2626; background: rgba(220, 38, 38, 0.08); }

.rail-card-date {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.7;
}

/* Build detail panel */
.build-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--surface-strong);
}

.build-detail-title {
  font-size: 18px;
  font-weight: 500;
  color: var(--fg);
}

.build-detail-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.build-detail-tag {
  padding: 3px 10px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--surface-mid);
  color: var(--muted);
}

.build-detail-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.build-detail-actions-left {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.build-detail-actions-right {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.build-detail-btn {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid var(--border-mid);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.build-detail-btn:hover {
  background: var(--surface-strong);
  color: var(--fg);
}

.build-detail-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.build-detail-btn.primary:hover {
  opacity: 0.9;
}

.build-detail-btn.danger {
  border-color: rgba(255, 71, 87, 0.3);
  color: #ff4757;
}

.build-detail-btn.danger:hover {
  background: rgba(255, 71, 87, 0.15);
}

.build-detail-code {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 200px;
}

.build-detail-code pre {
  margin: 0;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.build-detail-code .loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--muted);
}

/* Build file accordions */
.build-files-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.build-files-count {
  background: var(--hover);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  padding: 1px 7px;
  border-radius: 10px;
}

.build-files-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.build-file-accordion {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.build-file-accordion-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--hover);
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-family: var(--font-mono);
  transition: background 0.15s;
}

.build-file-accordion-header:hover {
  background: var(--border);
}

.build-file-accordion-arrow {
  font-size: 10px;
  color: var(--muted);
  width: 12px;
  text-align: center;
  flex-shrink: 0;
}

.build-file-accordion-name {
  color: var(--fg);
  flex-shrink: 0;
}

.build-file-accordion-badge {
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--font);
  text-transform: uppercase;
  margin-left: auto;
}

.build-file-accordion-badge.main {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent);
}

.build-file-accordion-badge.tag {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.build-file-url {
  flex: 1;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--font);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

.build-file-accordion-body {
  display: none;
  background: var(--bg);
  max-height: 500px;
  overflow: auto;
}

.build-file-accordion-body.open {
  display: block;
}

.build-file-accordion-body pre {
  margin: 0;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.build-file-accordion-body .loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--muted);
}

/* Build name editing */
.build-name-editable {
  cursor: text;
  border-bottom: 1px dashed var(--check-border);
}

.build-name-editable:hover {
  border-bottom-color: var(--accent);
}

.build-name-input {
  background: var(--border-mid);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--fg);
  font-size: 18px;
  font-weight: 500;
  width: 250px;
}

/* Responsive: collapse to stacked layout on small screens */
@media (max-width: 900px) {
  .split-panel-layout {
    flex-direction: column;
  }
  .split-panel-rail {
    width: 100%;
    min-width: unset;
    max-width: unset;
    max-height: 300px;
    border-right: none;
    border-bottom: 1px solid var(--surface-strong);
  }
}

/* ========================================
   ACTION LIST (ordered action selector with drag-and-drop)
   ======================================== */

/* Action list table spans full width below the inline search */
.action-list-container {
  grid-column: 1 / -1;
}

/* Search input — standard text box */
.action-list-search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.action-list-search {
  padding: 5px 8px;
  height: 34px;
  flex: 1;
  min-width: 0;
  box-sizing: border-box;
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 14px;
  font-family: var(--font-sans);
  outline: none;
}

.action-list-search::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

.action-list-search:focus {
  border-color: var(--accent);
  background-color: var(--surface-hover);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Dropdown */
.action-list-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--accent-border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow);
}

.action-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--fg);
  border-bottom: 1px solid var(--surface-hover);
  transition: background 0.1s ease;
}

.action-dropdown-item:last-child {
  border-bottom: none;
}

.action-dropdown-item:hover {
  background: var(--accent-subtle);
}

/* Action list table wrapper */
.action-list-table {
  border: 1px solid var(--border-mid);
  border-radius: 6px;
}

/* Table header */
.action-list-header {
  display: grid;
  grid-template-columns: 16px 45px 1fr 130px 70px 100px;
  gap: 12px;
  padding: 8px 10px;
  padding-right: 40px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 1px solid var(--border-mid);
  background: var(--surface);
}

.action-list-header span {
  text-align: center;
}

.action-list-header span:first-child,
.action-list-header span:nth-child(3) {
  text-align: left;
}

/* Empty state */
.action-list-empty {
  padding: 12px 10px;
  color: var(--muted);
  font-size: 13px;
}

/* Ordered list items */
.action-list-items {
  min-height: 8px;
}

.action-list-item {
  display: grid;
  grid-template-columns: 16px 45px 1fr 130px 70px 100px;
  align-items: center;
  gap: 12px;
  padding: 8px 30px 8px 10px;
  position: relative;
  border-bottom: 1px solid var(--surface-hover);
  font-size: 13px;
  color: var(--fg);
  transition: background 0.1s ease, opacity 0.15s ease;
}

.action-list-item:last-child {
  border-bottom: none;
}

.action-list-item:hover {
  background: var(--surface);
}

.action-list-item .drag-handle {
  color: var(--muted);
  font-size: 14px;
  cursor: grab;
  user-select: none;
  opacity: 0.4;
  transition: opacity 0.15s ease;
}

.action-list-item:hover .drag-handle {
  opacity: 1;
}

.action-list-order {
  text-align: center;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
}

.action-list-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-list-type-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--surface-strong);
  color: var(--muted);
  white-space: nowrap;
  text-align: center;
  justify-self: center;
}

/* Wait toggle */
.action-list-wait-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  justify-self: center;
}

.action-list-wait-toggle.disabled {
  opacity: 0.3;
  cursor: default;
}

.action-list-wait-toggle input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.action-list-wait-toggle.disabled input[type="checkbox"] {
  cursor: default;
}

/* Timeout input */
.action-list-timeout-wrapper {
  display: flex;
  align-items: center;
  gap: 2px;
  justify-self: center;
}

.action-list-timeout {
  width: 56px;
  padding: 3px 6px;
  background: var(--surface-mid);
  border: 1px solid var(--border-mid);
  border-radius: 3px;
  color: var(--fg);
  font-size: 12px;
  text-align: right;
}

.action-list-timeout:focus {
  border-color: var(--accent);
  outline: none;
}

.action-list-timeout-unit {
  font-size: 10px;
  color: var(--muted);
}

/* Remove button */
.action-list-remove {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--error);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.15s ease;
}

.action-list-remove:hover {
  opacity: 1;
}

/* Drag states */
.action-list-item.dragging {
  opacity: 0.4;
  cursor: grabbing;
}

.action-list-item.drag-over-top {
  box-shadow: inset 0 2px 0 0 var(--accent);
}

.action-list-item.drag-over-bottom {
  box-shadow: inset 0 -2px 0 0 var(--accent);
}

/* ========================================
   ENVIRONMENT CARDS
   ======================================== */

.env-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  border-left: 4px solid var(--border);
}

.env-card .env-title {
  font-weight: 600;
  font-size: 14px;
  margin: 0;
  min-width: 120px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.env-card .env-url-box {
  flex: 1;
  background: var(--surface-mid);
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.env-card .env-url-text {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg);
  word-break: break-all;
}

.env-card .env-meta {
  display: flex;
  gap: 20px;
  font-size: 12px;
  color: var(--muted);
  align-items: center;
  flex-wrap: wrap;
}

.env-card .env-meta .env-separator {
  color: var(--border);
}

/* ========================================
   LOGIN
   ======================================== */

.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 40px;
  text-align: center;
  max-width: 400px;
}

.login-title {
  font-size: 24px;
  color: var(--fg);
  margin-bottom: 10px;
}

.login-subtitle {
  color: var(--muted);
  margin-bottom: 30px;
}

.login-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: #4285f4;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.login-btn:hover { background: #357abd; }
.login-btn:disabled { background: #666; cursor: not-allowed; }

.login-error {
  color: #ef4444;
  margin-top: 20px;
  font-size: 14px;
}

.login-loading {
  color: var(--muted);
  margin-top: 20px;
}

.google-icon { width: 18px; height: 18px; }

.app-container.hidden { display: none; }

/* ========================================
   CONDITIONS
   ======================================== */

.condition-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--surface);
  padding: 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.condition-variable,
.condition-operator,
.condition-value {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  padding: 5px 8px;
  height: 34px;
  box-sizing: border-box;
  color: var(--fg);
}

.condition-remove-btn {
  background: var(--error);
  border: none;
  color: white;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 18px;
  min-width: 34px;
  height: 34px;
  line-height: 1;
  box-sizing: border-box;
}

/* ========================================
   FORM LAYOUT
   ======================================== */

.form-container {
  display: flex;
  flex-direction: column;
}

.form-section {
  display: flex;
  flex-direction: column;
}

.form-section-grouped {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 15px;
}

.form-field {
  display: grid;
  grid-template-columns: 200px 1fr;
  align-items: center;
  gap: 15px;
  margin-bottom: 15px;
}

.form-field.indented { margin-left: 0; }

.form-field.code-field-stacked {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.form-field.code-field-stacked .form-label { margin-bottom: 8px; }

.form-label {
  color: var(--fg);
  font-weight: 500;
  font-size: 14px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.form-label .help-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  border: none;
}

.form-input,
.form-select,
.form-textarea {
  padding: 5px 8px;
  height: 34px;
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 14px;
  width: 100%;
  box-sizing: border-box;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-textarea {
  height: auto;
  min-height: 100px;
  resize: vertical;
}

.form-textarea.code-input {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  min-height: 150px;
}

.form-input,
.form-select {
  max-width: none;
}

.form-textarea,
.form-textarea.code-input {
  max-width: none;
}

.form-help-text {
  grid-column: 2;
  font-size: 12px;
  color: var(--muted);
  margin-top: -10px;
  margin-bottom: 10px;
}

.form-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.form-field.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-field.checkbox-field .form-label {
  order: 2;
  width: auto;
}

.form-field.checkbox-field > .help-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  font-size: 11px;
  border: none;
}

.checkbox-label {
  font-size: 14px;
  color: var(--fg);
}

.checkbox-list {
  max-height: 150px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
  background: var(--surface);
}

.checkbox-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  cursor: pointer;
  font-size: 14px;
  color: var(--fg);
}

.checkbox-list-item:hover { background: var(--surface-hover); }

/* ========================================
   UNIFIED FORM MODAL
   ======================================== */

#unified-form-modal.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--overlay);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  animation: fadeIn 0.2s ease-in;
}

#unified-form-modal .modal-container {
  background: var(--panel);
  border: 1px solid var(--border-mid);
  border-radius: 10px;
  padding: 30px;
  width: 90%;
  max-width: 840px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

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

#unified-form-modal .modal-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--fg);
}

#unified-form-modal .modal-close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.2s;
  position: absolute;
  top: 20px;
  right: 20px;
}

#unified-form-modal .modal-close-btn:hover { color: var(--fg); }

#unified-form-modal .modal-body { margin-bottom: 20px; }

#unified-form-modal .modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* Package Cards */
.package-card {
    transition: border-color 0.15s ease, background-color 0.15s ease;
}
.package-card:hover {
    border-color: var(--accent, #3b82f6) !important;
}
.package-card.disabled {
    opacity: 0.7;
}
.package-card.disabled:hover {
    opacity: 1;
}
