/* =========================
   THEME TOKENS
   ========================= */
:root {
  /* Brand / Accent */
  --primary-color: #6b7cff;
  --primary-hover-color: #8896ff;
  --secondary-color: #ff7a33; /* complementary orange for chips */
  --secondary-hover-color: #ff995f;

  /* Base (dark) */
  --background-color: #18181b;
  --lighter-background-color: #2a2a2f;
  --text-color: #e5e7eb;
  --subheading-color: #9aa1af;

  /* Inputs */
  --input-background-color: #232329;
  --input-text-color: #f0f0f3;
  --input-border-color: #2f3138;

  /* Buttons */
  --button-background-color: #3a3f47;
  --button-hover-background-color: #545b66;
  --button-disabled-background-color: #2b2f35;
  --button-disabled-text-color: #9aa1af;
  
  /* Disabled tags */
  --tag-disabled-background-color: #4a4f57;
  --tag-disabled-text-color: #9aa1af;
  --button-undo-background-color: #2bbf6a;
  --button-undo-hover-background-color: #42d07d;

  /* Tags / Chips (selected chain tags) */
  --chain-tag-bg: #d5c6ff;                 /* light purple */
  --chain-tag-hover-bg: #c6b3ff;
  --chain-tag-active-bg: #8a63ff;          /* darker purple */
  --chain-tag-text-color: #1a102d;
  --chain-tag-active-text-color: #ffffff;

  /* Chips row background (presets) */
  --tag-chain-background-color: #3b3f47;

  /* Lists / Highlights */
  --function-list-hover-background-color: #383b42;
  --function-highlight-color: #2e3440;

  /* Other */
  --store-chain-color: #333333;
  --chainable-background-color: #202126;
  --line-numbers-color: #8b8f99;
  --function-description-color: #b9bec9;


  /* Overlay */
  --overlay-button-text-color: #ffffff;

  /* Notification (dark) */
  --notification-bg: rgba(33, 34, 44, .82);
  --notification-text: #f3f4f6;

  /* Misc */
  --font-size: 15px;
  --line-height: 22px;

  /* Focus ring with glow */
  --focus-glow: none;

  /* Z-index layers */
  --z-base: 1;
  --z-dropdown: 10;
  --z-sticky: 20;
  --z-fixed: 30;
  --z-sidebar: 40;
  --z-overlay: 50;
  --z-modal: 60;
  --z-modal-overlay: 70;
  --z-popover: 80;
  --z-tooltip: 90;
  --z-notification: 100;
  --z-critical: 110;
}

/* ---- Light Theme ---- */
.light-theme {
  --primary-color: #111827;
  --primary-hover-color: #000000;

  --background-color: #f2f2f2;
  --lighter-background-color: #ffffff;
  --text-color: #111827;
  --subheading-color: #6b7280;

  --input-background-color: #ffffff;
  --input-text-color: #111827;
  --input-border-color: #e5e7eb;

  --button-background-color: #111827;
  --button-hover-background-color: #000000;
  --button-disabled-background-color: #e5e7eb;
  --button-disabled-text-color: #9ca3af;
  
  /* Disabled tags */
  --tag-disabled-background-color: #d1d5db;
  --tag-disabled-text-color: #6b7280;

  --function-list-hover-background-color: #f3f4f6;
  --function-highlight-color: #e5e7eb;

  --chainable-background-color: #ebebeb;
  --tag-chain-background-color: #e5e7eb;
  --line-numbers-color: #6b7280;
  --function-description-color: #4b5563;

  /* Chain tags (light) */
  --chain-tag-bg: #ece5ff;
  --chain-tag-hover-bg: #e0d6ff;
  --chain-tag-active-bg: #6f4cff;
  --chain-tag-text-color: #1a102d;
  --chain-tag-active-text-color: #ffffff;


  --overlay-button-text-color: #ffffff;

  /* Notification (light) */
  --notification-bg: rgba(17, 24, 39, .06);
  --notification-text: #111827;
}

/* Light theme specific overrides */
.light-theme .horizontal-toolbar {
  border-color: var(--input-border-color);
}

.light-theme .line-numbers span.active-line {
  color: #000000;
  font-weight: bold;
}

.light-theme .other-tools-dropdown .dropdown-btn {
  background-color: transparent;
  color: var(--subheading-color);
  opacity: 0.7;
}

.light-theme .other-tools-dropdown .dropdown-btn:hover {
  background-color: var(--button-background-color);
  color: var(--button-text-color);
  opacity: 0.9;
}

/* =========================
   BASE / LAYOUT
   ========================= */
html { box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }

body {
  background-color: var(--background-color);
  color: var(--text-color);
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font-family: inherit; }
button:focus-visible, input:focus-visible, .dropdown-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-glow);
  border-radius: 3px;
}

textarea:focus-visible {
  outline: none;
}

.container { width: 70%; margin: 0 auto; text-align: center; position: relative; flex: 1; }


/* =========================
   HEADER
   ========================= */
header {
  display: flex; justify-content: space-between; align-items: center;
  background-color: var(--chainable-background-color);
  padding: 10px 20px; margin-bottom: 10px; border-radius: 8px;
}

.header-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.title-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

header h1 { margin: 0; font-size: 1.3rem; font-weight: 700; color: var(--text-color); }
header .version { color: var(--subheading-color); font-size: 12px; margin-left: 6px; }

/* Other Tools Dropdown */
.other-tools-dropdown { position: relative; display: inline-block; }
.dropdown-btn {
  background-color: transparent;
  color: var(--subheading-color);
  padding: 8px 10px; font-size: 14px; border: 0; cursor: pointer; border-radius: 6px;
  display: flex; align-items: center; gap: 6px; transition: background-color .15s ease, color .15s ease;
  border: 1px solid transparent;
  opacity: 0.7;
}
.dropdown-btn:hover {
  background-color: var(--button-background-color);
  color: var(--button-text-color);
  opacity: 0.9;
}
.dropdown-btn i:first-child { font-size: 14px; }
.dropdown-btn i:last-child { font-size: 10px; transition: transform .2s ease; }
.other-tools-dropdown.open .dropdown-btn i:last-child { transform: rotate(180deg); }
.dropdown-content {
  display: none; position: absolute; right: 0; margin-top: 4px; min-width: 220px;
  background-color: var(--lighter-background-color);
  z-index: var(--z-dropdown); border-radius: 8px; overflow: hidden;
  border: 1px solid var(--input-border-color);
}
.dropdown-content a {
  color: var(--text-color); padding: 10px 12px; text-decoration: none; display: block; font-size: 13px;
  transition: background-color .15s ease, color .15s ease;
}
.dropdown-content a:hover { background-color: var(--primary-color); color: var(--button-text-color); }
.other-tools-dropdown.open .dropdown-content { display: block; }

/* Theme Toggle */
.theme-toggle { cursor: pointer; font-size: 20px; color: var(--primary-color); transition: color .2s ease; }
.theme-toggle:hover { color: var(--primary-hover-color); }

.heading { padding: 10px; }
.subheading { margin: 0; font-size: 14px; color: var(--subheading-color); }

/* =========================
   EDITOR SHELL (glow + toolbar border rule)
   ========================= */
#input-container { padding: 10px; background-color: var(--chainable-background-color); }

.textarea-container { position: relative; width: 100%; margin: 0 auto; }

/* Unified shell */
.editor-shell {
  background: var(--input-background-color);
  border: 1px solid var(--input-border-color);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 2s ease, box-shadow 2s ease;
}
.editor-shell:focus-within {
  box-shadow: var(--focus-glow);
  border-color: var(--primary-color); /* glow on outer shell */
}

/* Toolbar container with scroll indicators */
.toolbar-container {
  position: relative;
  margin-bottom: 6px;
}

.scroll-indicator {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 20px;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.scroll-indicator.left {
  left: 0;
  background: linear-gradient(to right, var(--background-color) 0%, transparent 100%);
  border-radius: 8px 0 0 8px;
}

.scroll-indicator.right {
  right: 0;
  background: linear-gradient(to left, var(--background-color) 0%, transparent 100%);
  border-radius: 0 8px 8px 0;
}

.scroll-indicator.visible {
  opacity: 1;
}

/* Horizontal toolbar (top) */
.horizontal-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: transparent;
  border: 1px solid var(--lighter-background-color);
  border-radius: 8px;
  padding: 4px 8px;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch; /* iOS momentum scrolling */
}

/* Custom scrollbar styling for horizontal toolbar */
.horizontal-toolbar::-webkit-scrollbar {
  height: 6px;
}

.horizontal-toolbar::-webkit-scrollbar-track {
  background: var(--lighter-background-color);
  border-radius: 3px;
}

.horizontal-toolbar::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 3px;
  opacity: 0.7;
}

.horizontal-toolbar::-webkit-scrollbar-thumb:hover {
  background: var(--primary-hover-color);
  opacity: 1;
}

/* Firefox scrollbar styling */
.horizontal-toolbar {
  scrollbar-width: thin;
  scrollbar-color: var(--primary-color) var(--lighter-background-color);
}

/* Mobile touch optimizations */
@media (max-width: 768px) {
  .horizontal-toolbar::-webkit-scrollbar {
    height: 8px; /* Slightly larger scrollbar for touch */
  }
  
  .horizontal-toolbar {
    padding: 4px 12px; /* More padding for touch targets */
  }
  
  .scroll-indicator {
    width: 24px; /* Wider indicators on mobile */
  }
}

/* Ensure toolbar doesn't shrink below minimum width */
.horizontal-toolbar .toolbar-group {
  flex-shrink: 0;
}

.horizontal-toolbar .toolbar-group-buttons {
  flex-shrink: 0;
}

/* Toolbar groups */
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--input-border-color);
  border-radius: 6px;
  padding: 2px;
  background: var(--input-background-color);
}


.toolbar-group-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all .2s ease;
  overflow: visible;
}


.horizontal-toolbar button {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  background-color: var(--button-background-color);
  color: var(--button-text-color);
  border: 1px solid transparent;
  border-radius: 5px;
  opacity: 0.5;
  transition: background-color .15s ease, border-color .15s ease, opacity .15s ease, transform .05s ease-in-out;
}

.horizontal-toolbar button:not(:disabled):hover {
  background-color: var(--button-hover-background-color);
  opacity: 0.8;
}

.horizontal-toolbar button:disabled {
  cursor: not-allowed;
  background-color: var(--button-disabled-background-color);
  color: var(--button-disabled-text-color);
}

.horizontal-toolbar button.active {
  background-color: var(--secondary-color);
  border-color: transparent;
  color: var(--button-text-color);
  opacity: 0.8;
}

.horizontal-toolbar button.active:hover {
  background-color: var(--secondary-hover-color);
  border-color: transparent;
  color: var(--button-text-color);
  opacity: 0.9;
}

/* Left side (text area + line numbers) */
.textarea-wrapper {
  position: relative;
  background-color: var(--input-background-color);
}

/* Line numbers */
.line-numbers {
  position: absolute; top: 0; left: 0; bottom: 0;
  width: 50px;
  background-color: var(--lighter-background-color);
  color: var(--line-numbers-color);
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono","Courier New", monospace;
  font-size: var(--font-size); line-height: var(--line-height);
  white-space: pre; user-select: none;
  border-right: 1px solid var(--input-border-color);
  padding: 5px 5px 5px 0;
  box-sizing: border-box;
  transform: translateY(0);
  z-index: var(--z-base);
}

textarea {
  width: 100%;
  background-color: var(--input-background-color);
  color: var(--input-text-color);
  resize: vertical; border: 0; outline: none; overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono","Courier New", monospace;
  font-size: var(--font-size); line-height: var(--line-height);
  padding: 5px 8px 5px 60px; /* room for line numbers */
  min-height: 300px;
  white-space: pre-wrap; word-wrap: break-word;
}
textarea.empty { overflow-y: hidden; }

#undoBtn:not(:disabled) { background-color: var(--button-undo-background-color); }
#undoBtn:not(:disabled):hover { background-color: var(--button-undo-hover-background-color); }

#redoBtn:not(:disabled) { background-color: #3b82f6; }
#redoBtn:not(:disabled):hover { background-color: #60a5fa; }

/* Notification Container (bottom-center, stackable) */
#notificationContainer {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-notification);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none; /* Allow clicks through container */
  max-width: 90vw;
  width: auto;
}

/* Individual Notification */
.notification {
  background-color: var(--notification-bg);
  color: var(--notification-text);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  text-align: left;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(99,102,241,.25);
  pointer-events: auto; /* Enable clicks on individual notifications */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 200px;
  max-width: min(400px, 90vw);
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.notification.show {
  opacity: 1;
  transform: translateY(0);
}

.notification.hide {
  opacity: 0;
  transform: translateY(-10px);
}

/* Notification content */
.notification-message {
  flex: 1;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
}

/* Close button */
.notification-close {
  background: none;
  border: none;
  color: var(--notification-text);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  opacity: 0.7;
  transition: opacity 0.15s ease, background-color 0.15s ease;
  flex-shrink: 0;
}

.notification-close:hover {
  opacity: 1;
  background-color: rgba(255, 255, 255, 0.1);
}

.notification-close i {
  font-size: 12px;
}

/* Stats */
.stats {
  margin-top: 6px; font-size: 14px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
}
.stats span { opacity: .9; }

/* =========================
   TAGS / SELECTED FUNCTIONS
   ========================= */
#tags {
  display: flex; flex-wrap: wrap; list-style: none; padding: 0; margin: 0 0 10px 0; justify-content: center;
}
#tags li.tag {
  display: flex; align-items: center; gap: 6px;
  background-color: var(--primary-color);      /* <- normal tag background uses primary color */
  color: var(--button-text-color);             /* <- white text for contrast */
  padding: 6px 10px; margin: 3px;
  border-radius: 999px; font-size: 13px; cursor: grab;
  transition: background-color .15s ease, transform .1s ease, box-shadow .1s ease, color .15s ease;
  position: relative; user-select: none;
}
#tags li.tag:hover { background-color: var(--primary-hover-color); }
/* Active tag should NOT look different than normal (no active highlighting) */
#tags li.tag.active {
  background-color: var(--primary-color);
  color: var(--button-text-color);
}
#tags li.tag.disabled {
  background-color: var(--tag-disabled-background-color);
  color: var(--tag-disabled-text-color);
  cursor: default;
}
#tags li.tag:active { cursor: grabbing; }
#tags li.tag.dragging { opacity: .6; transform: scale(.98); }

.drag-placeholder {
  border: 2px dashed var(--primary-color);
  background: color-mix(in srgb, var(--primary-color) 10%, transparent);
  margin: 3px; padding: 6px 10px; border-radius: 999px; font-size: 13px;
  min-width: 56px; min-height: 28px; align-self: center;
}

#tags li .link-icon { margin-right: 2px; cursor: pointer; font-size: 16px; }

/* Settings badge on link icon */
#tags li .settings-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  height: 12px;
  background-color: var(--secondary-color);
  color: var(--button-text-color);
  border-radius: 50%;
  font-size: 7px;
  pointer-events: none;
}

#tags li .settings-badge i {
  line-height: 1;
}

#tags li .tag-name { flex: 1; text-align: center; }

/* Close button (fixed) */
#tags li .remove-tag {
  margin-left: 2px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%; cursor: pointer;
  background: rgba(0,0,0,.18);
  transition: background .15s ease, transform .1s ease;
}
#tags li .remove-tag:hover { background: rgba(0,0,0,.28); transform: scale(1.06); }
#tags li .remove-tag i { font-size: 10px; line-height: 1; color: currentColor; }

/* Control Row and Control Tag styling */
.control-row {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}

.control-tag {
  display: flex;
  align-items: center;
  background-color: var(--input-background-color);
  color: var(--text-color);
  border: 1px solid var(--input-border-color);
  padding: 8px 20px;
  gap: 12px;
  border-radius: 999px;
  font-size: 14px;
}

.control-tag .special-btn {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 16px;
  border-radius: 8px;
  transition: background-color .15s ease, color .15s ease, border-radius .15s ease;
  margin: 0 2px;
}

.control-tag .special-btn:hover {
  background-color: var(--button-background-color);
  color: var(--button-text-color);
  border-radius: 50%;
}

#chainSelectorBtn:hover {
  border-radius: 16px !important;
}

.control-tag .special-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.control-tag .tag-divider {
  width: 1px;
  height: 24px;
  background-color: var(--input-border-color);
  margin: 0 10px;
}


/* =========================
   FUNCTION LIST
   ========================= */
#functionList {
  margin-top: 10px; width: 100%; text-align: left; color: var(--text-color);
  max-height: 200px; overflow-y: auto; background-color: var(--lighter-background-color);
  border-radius: 8px; border: 1px solid var(--input-border-color);
}
#functionList ul { list-style: none; padding: 0; margin: 0; }
#functionList li {
  padding: 10px 12px; border-bottom: 1px solid var(--input-border-color);
  cursor: pointer; transition: background-color .12s ease; background-color: var(--lighter-background-color);
  display: flex; flex-wrap: wrap; align-items: center; position: relative;
}
#functionList li:hover { background-color: var(--function-list-hover-background-color); }
#functionList .function-name { font-weight: 700; width: 100%; }
#functionList .function-description { font-size: 13px; color: var(--function-description-color); width: 100%; margin-top: 5px; }
#functionList li.highlight { background-color: var(--function-highlight-color); }
.function-list .add-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); opacity: 0; transition: opacity .15s ease; color: var(--text-color); }
#functionList li:hover .add-icon { opacity: .9; }

/* No Results State */
.no-results {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-color);
  opacity: 0.7;
}

.no-results-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.no-results-text h3 {
  margin: 0 0 8px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-color);
}

.no-results-text p {
  margin: 0;
  font-size: 14px;
  color: var(--function-description-color);
  line-height: 1.4;
}

.no-results.show {
  display: flex;
}

/* =========================
   INPUT & chip row
   ========================= */
.tags-input {
  position: relative; display: flex; align-items: center; width: 100%;
  padding: 10px; background-color: var(--lighter-background-color); color: #fff; margin: 0 auto; border-radius: 8px;
}
.tags-input input {
  flex: 1; border: none; background: transparent; color: var(--text-color);
  padding: 6px; font-size: 16px; outline: none; text-align: center;
}

.clear-input-btn {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease, background-color 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.clear-input-btn:hover {
  background-color: var(--button-background-color);
  color: var(--button-text-color);
}

.clear-input-btn i {
  font-size: 12px;
}

.tags-input.has-content .clear-input-btn {
  opacity: 0.7;
  visibility: visible;
}

.tags-input.has-content .clear-input-btn:hover {
  opacity: 1;
}

/* Add space above chainable container */
#chainable-container { margin-top: 20px; }

/* Footer */
footer { text-align: center; color: var(--text-color); opacity: .85; margin-top: auto; padding: 20px 0; }

/* Responsive */
@media (max-width: 900px) { #functionList li:hover .add-icon { opacity: 0; } }
@media (max-width: 600px) {
  .container { width: 100%; padding: 0 16px; }
  textarea { width: 100%; }
  .tags-input { width: 100%; }
  .function-row { flex-direction: column; align-items: center; }
  #functionList li { flex-direction: column; align-items: flex-start; }
  #functionList .function-name, #functionList .function-description { flex: 1 1 100%; }
  header { flex-direction: column; align-items: center; gap: 10px; }
  .header-left { align-items: center; }
  .header-right { gap: 8px; }
}

/* Pulse for GO button nudge */
.pulse-effect { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0% { opacity: .4; transform: scale(1.0); }
  50% { opacity: 1.0; transform: scale(1.05); }
  100% { opacity: .4; transform: scale(1.0); }
}

.editor-shell.typing {
  border-color: rgba(107, 124, 255, 0.4) !important;
}

/* When focused but not typing, show only static border */
.editor-shell:focus-within:not(.typing) {
  border-color: var(--primary-color);
  box-shadow: var(--focus-glow);
}

/* Current line number highlighting */
@keyframes fadeInOut {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

.line-numbers span.active-line {
  color: var(--button-text-color);
  animation: fadeInOut 2s ease-in-out infinite;
}

/* Individual line number spans */
.line-numbers span {
  display: block;
  text-align: right;
  padding-right: 5px;
  line-height: var(--line-height);
  width: 100%;
  left: 0;
  right: 0;
}

/* Fast Copy Mode Styles */
.fast-copy-mode {
  cursor: pointer !important;
}

/* Word Wrap Styles */
.textarea-wrapper textarea {
  white-space: pre-wrap; /* Default: word wrap ON */
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.textarea-wrapper.no-wrap textarea {
  white-space: pre; /* Word wrap OFF */
  word-wrap: normal;
  overflow-wrap: normal;
  overflow-x: auto; /* Allow horizontal scrolling when wrap is off */
}

.fast-copy-mode .word-highlight {
  background-color: var(--primary-color);
  color: var(--button-text-color);
  border-radius: 2px;
  padding: 1px 2px;
  transition: background-color .15s ease;
}

.fast-copy-mode .word-highlight:hover {
  background-color: var(--primary-hover-color);
}

/* Persistent highlight overlay */
.highlight-overlay {
  position: absolute;
  background-color: var(--primary-color);
  opacity: 0.6;
  pointer-events: none;
  z-index: var(--z-base);
  border-radius: 2px;
  border: 1px solid var(--primary-hover-color);
}

/* Fast Copy Dropdown Container */
.fast-copy-container {
  position: relative;
  display: inline-block;
}

/* Ensure the container extends to include any dropdown gap */
.fast-copy-container::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 4px;
  pointer-events: auto;
}

/* Fast Copy Dropdown */
.fast-copy-dropdown {
  position: fixed;
  background-color: var(--lighter-background-color);
  border: 1px solid var(--input-border-color);
  border-radius: 8px;
  padding: 12px;
  min-width: 200px;
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.fast-copy-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.fast-copy-container:hover .fast-copy-dropdown,
.fast-copy-dropdown:hover {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

/* Dropdown Sections */
.dropdown-section {
  margin-bottom: 16px;
}

.dropdown-section:last-child {
  margin-bottom: 0;
}

.dropdown-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Toggle Switch (Copy/Cut) */
.toggle-switch {
  position: relative;
  background-color: var(--input-background-color);
  border-radius: 20px;
  padding: 2px;
  border: 1px solid var(--input-border-color);
}

.toggle-switch input[type="radio"] {
  display: none;
}

.toggle-slider {
  display: flex;
  position: relative;
  background-color: var(--toggle-unchecked-bg);
  border-radius: 18px;
  overflow: hidden;
}

.toggle-option {
  flex: 1;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--button-disabled-text-color);
  position: relative;
  z-index: 2;
}

.toggle-option.active {
  color: var(--button-text-color);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  background-color: var(--primary-color);
  border-radius: 18px;
  transition: transform 0.2s ease;
  z-index: 1;
}

.toggle-slider.cut-mode::before,
.toggle-slider.toggled-right::before {
  transform: translateX(100%);
}

/* Slider Container */
.slider-container {
  position: relative;
}

#sensitivitySlider,
#cutDelaySlider {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background-color: var(--button-background-color);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

#sensitivitySlider::-webkit-slider-thumb,
#cutDelaySlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--primary-color);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

#sensitivitySlider::-webkit-slider-thumb:hover,
#cutDelaySlider::-webkit-slider-thumb:hover {
  background-color: var(--primary-hover-color);
}

#sensitivitySlider::-moz-range-thumb,
#cutDelaySlider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--primary-color);
  cursor: pointer;
  border: none;
  transition: background-color 0.15s ease;
}

#sensitivitySlider::-moz-range-thumb:hover,
#cutDelaySlider::-moz-range-thumb:hover {
  background-color: var(--primary-hover-color);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 10px;
  color: var(--subheading-color);
}

/* Checkbox Switch (Notifications) */
.checkbox-switch {
  display: flex;
  align-items: center;
}

.checkbox-switch input[type="checkbox"] {
  display: none;
}

.switch-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  gap: 8px;
}

.switch-slider {
  position: relative;
  width: 36px;
  height: 20px;
  background-color: var(--toggle-unchecked-bg);
  border-radius: 10px;
  border: 1px solid var(--input-border-color);
  transition: background-color 0.2s ease;
}

.switch-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background-color: var(--toggle-unchecked-thumb);
  border-radius: 50%;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.checkbox-switch input[type="checkbox"]:checked + .switch-label .switch-slider {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.checkbox-switch input[type="checkbox"]:checked + .switch-label .switch-slider::before {
  transform: translateX(16px);
  background-color: var(--button-text-color);
}

.switch-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-color);
  min-width: 24px;
}

/* Special Characters Dropdown */
.special-chars-container {
  position: relative;
  display: inline-block;
}

.special-chars-container::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 4px;
  pointer-events: auto;
}

.special-chars-dropdown {
  position: fixed;
  background-color: var(--lighter-background-color);
  border: 1px solid var(--input-border-color);
  border-radius: 8px;
  padding: 12px;
  min-width: 240px;
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.special-chars-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.special-chars-container:hover .special-chars-dropdown,
.special-chars-dropdown:hover {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.special-chars-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.char-btn {
  background-color: var(--input-background-color);
  color: var(--text-color);
  border: 1px solid var(--input-border-color);
  border-radius: 4px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.char-btn:hover {
  background-color: var(--primary-color);
  color: var(--button-text-color);
  transform: scale(1.1);
}

/* Mobile notification adjustments */
@media (max-width: 600px) {
  #notificationContainer {
    bottom: 10px;
    max-width: 95vw;
    padding: 0 10px;
  }
  
  .notification {
    min-width: 280px;
    max-width: 100%;
    font-size: 13px;
    padding: 10px 14px;
  }
  
  .notification-message {
    max-height: 80px;
    line-height: 1.3;
  }
}

/* =========================
   HELP MODAL
   ========================= */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-modal);
  display: none;
}

.modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1;
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--lighter-background-color);
  border: 1px solid var(--input-border-color);
  border-radius: var(--radius-2xl);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow: hidden;
  z-index: 2;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--input-border-color);
  background: var(--input-background-color);
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
}

.modal-header h2 {
  margin: 0;
  color: var(--text-color);
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-color);
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background-color 0.15s ease, color 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background-color: var(--button-background-color);
  color: var(--button-text-color);
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  max-height: calc(80vh - 100px);
}

.help-section {
  margin-bottom: 24px;
}

.help-section:last-child {
  margin-bottom: 0;
}

.help-section h3 {
  color: var(--primary-color);
  margin: 0 0 12px 0;
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.help-section h3 i {
  font-size: 1rem;
}

.help-section p {
  color: var(--text-color);
  line-height: 1.6;
  margin: 0 0 12px 0;
}

.help-section ul {
  color: var(--text-color);
  line-height: 1.6;
  margin: 0;
  padding-left: 20px;
}

.help-section li {
  margin-bottom: 8px;
}

.help-section li:last-child {
  margin-bottom: 0;
}

.help-section strong {
  color: var(--primary-color);
}

/* Mobile modal adjustments */
@media (max-width: 600px) {
  .modal-content {
    width: 95%;
    max-height: 90vh;
  }
  
  .modal-header {
    padding: 16px 20px;
  }
  
  .modal-header h2 {
    font-size: 0.9rem;
  }
  
  .modal-body {
    padding: 20px;
    max-height: calc(90vh - 100px);
  }
  
  .help-section {
    margin-bottom: 20px;
  }
}

/* =========================
   ROSTER PATTERN MODAL
   ========================= */
#rosterPatternModal .modal-content {
  background: var(--lighter-background-color);
}

#rosterPatternModal .modal-header {
  background: var(--input-background-color);
  border-bottom: 1px solid var(--input-border-color);
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
}

#rosterPatternModal .modal-header h2 {
  color: var(--input-text-color);
}

#rosterPatternModal .modal-body {
  background: var(--lighter-background-color);
}

.roster-pattern-option-btn {
  padding: 1rem;
  text-align: left;
  border: 2px solid var(--input-border-color);
  border-radius: 8px;
  background: var(--input-background-color);
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
}

.roster-pattern-option-btn:hover {
  border-color: var(--primary-color);
  background: var(--primary-color);
  color: var(--button-text-color);
  transform: translateY(-2px);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.2),
    0 2px 6px rgba(0, 0, 0, 0.15);
}

.roster-pattern-option-btn:hover .roster-pattern-option-title,
.roster-pattern-option-btn:hover .roster-pattern-option-description {
  color: var(--button-text-color);
  opacity: 1;
}

.roster-pattern-option-btn:focus {
  border-color: var(--primary-color);
  background: var(--lighter-background-color);
  box-shadow: 0 0 0 3px var(--focus-glow, var(--primary-color));
  outline: none;
}

.roster-pattern-option-btn:focus:not(:hover) {
  box-shadow:
    0 0 0 3px var(--focus-glow, var(--primary-color)),
    0 2px 8px rgba(0, 0, 0, 0.2);
}

.roster-pattern-option-btn:active {
  transform: translateY(0);
  background: var(--input-background-color);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.3),
    0 0 0 1px var(--input-border-color);
}

.roster-pattern-option-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--input-text-color);
  font-size: 1rem;
}

.roster-pattern-option-description {
  font-size: 0.875rem;
  color: var(--input-text-color);
  opacity: 0.7;
}

.roster-pattern-info p {
  margin: 0.5rem 0;
  color: var(--input-text-color);
}

.roster-pattern-info p:first-child {
  font-weight: 600;
  font-size: 1rem;
}

/* Roster Copy Sequence Badges */
.roster-sequence-badge {
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  border: 1px solid;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.roster-sequence-badge-available {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: var(--button-text-color);
}

.roster-sequence-badge-available:hover {
  opacity: 0.85;
}

.roster-sequence-badge-selected {
  background: var(--success-color, #10b981);
  border-color: var(--success-color, #10b981);
  color: white;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.roster-sequence-badge-selected:hover {
  opacity: 0.85;
}

.roster-sequence-badge-repeat {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 3px;
  padding: 0.0625rem 0.25rem;
  font-size: 0.625rem;
  font-weight: 600;
  color: white;
  line-height: 1;
}

.roster-sequence-badge-close {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: white;
  opacity: 0.8;
  font-size: 1rem;
  line-height: 1;
  transition: opacity 0.2s;
}

.roster-sequence-badge-close:hover {
  opacity: 1;
}

/* Roster copy sequence container */
.roster-copy-sequence-container {
  margin-top: 0.5rem;
}

.roster-sequence-available {
  margin-bottom: 1rem;
}

.roster-sequence-selected {
  margin-bottom: 0;
}

.roster-sequence-badges {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.roster-sequence-selected-badges {
  min-height: 2.5rem;
  padding: 0.5rem;
  border: 1px dashed var(--input-border-color);
  border-radius: 4px;
}

/* =========================
   OUTPUT REDIRECT MODAL
   ========================= */
.output-redirect-modal-content {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  border-radius: 0;
  position: relative;
  background: var(--input-background-color);
  border: none;
}

.output-redirect-modal .modal-body {
  position: absolute;
  top: 60px; /* Height of modal header */
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0;
  overflow: hidden;
}

.output-content {
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: var(--input-background-color);
}

.output-content pre {
  margin: 0;
  padding: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--input-text-color);
  background: transparent;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-sizing: border-box;
}

/* =========================
   FULLSCREEN MODAL MODIFIER
   ========================= */
.modal.show.modal--fullscreen {
  align-items: stretch;
}

.modal--fullscreen .modal-content {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  border-radius: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal--fullscreen .modal-header {
  flex: 0 0 auto;
  border-radius: 0;
}

.modal--fullscreen .modal-body {
  flex: 1 1 auto;
  overflow: auto;
  max-height: none;
  position: static;
  top: auto;
  right: auto;
  bottom: auto;
  left: auto;
  padding: 20px;
}

.modal--fullscreen .modal-footer {
  flex: 0 0 auto;
  border-radius: 0;
}

/* =========================
   CHAIN NAME MODAL
   ========================= */
.chain-name-modal-content {
  max-width: 480px;
  width: 90%;
}

.chain-name-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chain-name-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 2px;
}

.chain-name-input {
  width: 100%;
  padding: 8px 12px;
  border: 2px solid var(--input-border-color);
  border-radius: 6px;
  background-color: var(--input-background-color);
  color: var(--input-text-color);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chain-name-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.chain-name-input.error {
  border-color: #ff6b6b;
}

.chain-name-input.success {
  border-color: #51cf66;
}

.chain-name-feedback {
  min-height: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.feedback-message {
  font-size: 13px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 6px;
}

.feedback-message.error {
  color: #ff6b6b;
}

.feedback-message.success {
  color: #51cf66;
}

.feedback-message.info {
  color: var(--subheading-color);
}

.feedback-icon {
  font-size: 12px;
  flex-shrink: 0;
}

.modal-footer {
  padding: 10px 20px;
  border-top: 1px solid var(--input-border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-radius: 0 0 var(--radius-2xl) var(--radius-2xl);
  background: var(--input-background-color);
}

.chain-name-cancel-btn {
  background-color: var(--button-background-color);
  color: var(--button-text-color);
  border: 1px solid var(--input-border-color);
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chain-name-cancel-btn:hover {
  background-color: var(--button-hover-background-color);
  border-color: var(--primary-color);
}

.chain-name-save-btn {
  background-color: var(--primary-color);
  color: var(--button-text-color);
  border: none;
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.chain-name-save-btn:hover:not(:disabled) {
  background-color: var(--primary-hover-color);
}

.chain-name-save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chain-name-save-btn:focus-visible,
.chain-name-cancel-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-glow);
}

/* =========================
   FUNCTION OPTIONS MODAL
   ========================= */
#functionOptionsModal .modal-content {
  overflow: visible;
  max-width: 750px;
}

#functionOptionsModal .modal-header {
  padding: 12px 16px;
}


#functionOptionsModal .modal-body {
  overflow: visible;
  padding: 20px 20px;
}

#functionOptionsModal .modal-footer {
  padding: 12px 16px;
  gap: 8px;
}

#functionOptionsModal .chain-name-save-btn,
#functionOptionsModal .chain-name-cancel-btn {
  padding: 8px 16px;
  font-size: 13px;
}

#functionOptionsContent {
  overflow: visible;
}

.function-option-group {
  margin-bottom: 16px;
}

.function-option-group:last-child {
  margin-bottom: 0;
}

.function-option-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.9;
}

.function-option-select-container {
  position: relative;
  width: 100%;
}

.function-option-select {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-color);
  background-color: var(--input-background-color);
  border: 1px solid var(--input-border-color);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.function-option-select-text {
  flex: 1;
  text-align: left;
}

.function-option-select i {
  font-size: 12px;
  transition: transform 0.2s ease;
}

.function-option-select-container.open .function-option-select i {
  transform: rotate(180deg);
}

.function-option-select:hover {
  border-color: var(--primary-color);
}

.function-option-select:focus {
  outline: none;
  border-color: var(--primary-color);
}

.function-option-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: var(--lighter-background-color);
  border: 1px solid var(--input-border-color);
  border-radius: 4px;
  margin-top: 4px;
  z-index: var(--z-dropdown);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 250px;
  overflow-y: auto;
}

.function-option-select-container.open .function-option-select-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.function-option-select-option {
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: none;
  color: var(--text-color);
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  transition: background-color 0.15s ease;
  border-bottom: 1px solid var(--input-border-color);
}

.function-option-select-option:last-child {
  border-bottom: none;
}

.function-option-select-option:hover {
  background-color: var(--function-list-hover-background-color);
}

.function-option-select-option.selected {
  background-color: var(--primary-color);
  color: var(--button-text-color);
}

.function-option-radios {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 0;
}

.radio-option input[type="radio"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  margin: 0;
}

.radio-option label {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-color);
  margin: 0;
}

/* Toggle option */
.toggle-option {
  display: block;
  margin: 0;
  padding: 0;
}

.toggle-option input[type="checkbox"] {
  display: none;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  width: 100%;
  margin: 0;
  padding: 0;
}

.toggle-switch-slider {
  position: relative;
  width: 40px;
  height: 22px;
  background-color: var(--toggle-unchecked-bg);
  border-radius: 11px;
  border: 1px solid var(--input-border-color);
  transition: background-color 0.2s ease;
  flex-shrink: 0;
}

.toggle-switch-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background-color: var(--toggle-unchecked-thumb);
  border-radius: 50%;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.toggle-option input[type="checkbox"]:checked + .toggle-label .toggle-switch-slider {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.toggle-option input[type="checkbox"]:checked + .toggle-label .toggle-switch-slider::before {
  transform: translateX(18px);
  background-color: var(--button-text-color);
}

.toggle-text-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  text-align: left;
}

.toggle-label-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-color);
  text-align: left;
}

.toggle-description {
  font-size: 11px;
  color: var(--subheading-color);
  line-height: 1.3;
  text-align: left;
}

/* Function option toggle styles */
.function-option-toggle-container {
  display: block;
  margin: 0;
  padding: 0;
}

.function-option-toggle-input {
  display: none;
}

.function-option-toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  width: 100%;
  margin: 0;
  padding: 0;
}

.function-option-toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  background-color: var(--toggle-unchecked-bg);
  border-radius: 11px;
  border: 1px solid var(--input-border-color);
  transition: background-color 0.2s ease;
  flex-shrink: 0;
}

.function-option-toggle-switch::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background-color: var(--toggle-unchecked-thumb);
  border-radius: 50%;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.function-option-toggle-input:checked + .function-option-toggle-label .function-option-toggle-switch {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.function-option-toggle-input:checked + .function-option-toggle-label .function-option-toggle-switch::before {
  transform: translateX(18px);
  background-color: var(--button-text-color);
}

/* =========================
   CHAIN SELECTOR DROPDOWN
   ========================= */
.chain-selector-container {
  position: relative;
  display: inline-block;
}

#chainSelectorBtn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 130px;
  justify-content: space-between;
  padding: 8px 16px;
}

#chainSelectorBtn span {
  flex: 1;
  text-align: center;
  font-size: 14px;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#chainSelectorBtn i:last-child {
  font-size: 12px;
  transition: transform 0.2s ease;
}

.chain-selector-container.open #chainSelectorBtn i:last-child {
  transform: rotate(180deg);
}

.chain-selector-dropdown {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--lighter-background-color);
  border: 1px solid var(--input-border-color);
  border-radius: 8px;
  min-width: 200px;
  max-width: 300px;
  z-index: var(--z-dropdown);
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(-8px);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
  margin-top: 4px;
  max-height: 250px;
  overflow: hidden;
}

.chain-selector-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.chain-selector-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--input-border-color);
  background: var(--input-background-color);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chain-column-toggle {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 12px;
  transition: background-color 0.15s ease, color 0.15s ease;
  opacity: 0.7;
}

.chain-column-toggle:hover {
  background-color: var(--button-background-color);
  color: var(--button-text-color);
  opacity: 1;
}

.chain-column-toggle.active {
  color: var(--primary-color);
  opacity: 1;
}

.chain-selector-list {
  max-height: 180px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.chain-selector-list.two-columns {
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
}

.chain-selector-dropdown.two-columns {
  max-width: 500px;
}

.chain-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  border-bottom: 1px solid var(--input-border-color);
}

.chain-option:last-child {
  border-bottom: none;
}

.chain-option:hover {
  background-color: var(--function-list-hover-background-color);
}

.chain-option .chain-name {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
}

.chain-option .chain-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
  justify-content: flex-end;
  margin-left: auto;
}

.chain-option:hover .chain-actions {
  opacity: 1;
}

.chain-edit-btn {
  background: none;
  border: none;
  color: var(--primary-color);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 12px;
  transition: background-color 0.15s ease;
}

.chain-edit-btn:hover {
  background-color: rgba(107, 124, 255, 0.1);
}

.chain-delete-btn {
  background: none;
  border: none;
  color: #ff4444;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 12px;
  transition: background-color 0.15s ease;
}

.chain-delete-btn:hover {
  background-color: rgba(255, 68, 68, 0.1);
}

/* Muted ghost that stays in container and swaps positions */
.position-ghost {
  opacity: 0.4;
  background-color: rgba(156, 163, 175, 0.1) !important;
  border: 1px dashed rgba(156, 163, 175, 0.6);
  transition: all 0.2s ease;
}

/* Tag being actively dragged (follows cursor) - clean, no effects */
.tag.dragging-active {
  cursor: grabbing !important;
  z-index: var(--z-popover) !important;
}

/* =========================
   FIND AND REPLACE PANEL
   ========================= */
.find-replace-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, margin 0.3s ease;
  margin-bottom: 0;
}

.find-replace-panel.show {
  max-height: 200px;
  margin-bottom: 6px;
}

.find-replace-container {
  background-color: var(--lighter-background-color);
  border: 1px solid var(--input-border-color);
  border-radius: 8px;
  padding: 12px 16px;
}

.find-replace-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.find-replace-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.find-replace-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0.9;
}

.find-replace-label i {
  font-size: 10px;
}

.input-with-clear {
  position: relative;
  display: flex;
  align-items: center;
}

.find-replace-input {
  flex: 1;
  padding: 6px 28px 6px 8px;
  border: 1px solid var(--input-border-color);
  border-radius: 4px;
  background-color: var(--input-background-color);
  color: var(--input-text-color);
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.find-replace-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.clear-find-btn,
.clear-replace-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 4px;
  border-radius: 3px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease, background-color 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.input-with-clear.has-content .clear-find-btn,
.input-with-clear.has-content .clear-replace-btn {
  opacity: 0.5;
  visibility: visible;
}

.input-with-clear.has-content .clear-find-btn:hover,
.input-with-clear.has-content .clear-replace-btn:hover {
  opacity: 1;
  background-color: var(--button-background-color);
}

.clear-find-btn i,
.clear-replace-btn i {
  font-size: 10px;
}

.find-replace-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.find-replace-options {
  display: flex;
  align-items: center;
  gap: 4px;
}

.find-option-btn {
  background-color: var(--input-background-color);
  color: var(--text-color);
  border: 1px solid var(--input-border-color);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0.6;
}

.find-option-btn i {
  font-size: 9px;
}

.find-option-btn:hover {
  opacity: 0.8;
  border-color: var(--primary-color);
}

.find-option-btn.active {
  background-color: var(--primary-color);
  color: var(--button-text-color);
  border-color: var(--primary-color);
  opacity: 1;
}

.find-replace-match-info {
  font-size: 12px;
  color: var(--subheading-color);
  margin-left: auto;
  white-space: nowrap;
}

.find-replace-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.find-action-btn {
  background-color: var(--button-background-color);
  color: var(--button-text-color);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  opacity: 0.7;
}

.find-action-btn i {
  font-size: 11px;
}

.find-action-btn:hover {
  background-color: var(--button-hover-background-color);
  opacity: 1;
}

.find-action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.find-action-btn.replace-btn,
.find-action-btn.replace-all-btn {
  padding: 4px 12px;
}

.find-action-btn.replace-btn:hover:not(:disabled),
.find-action-btn.replace-all-btn:hover:not(:disabled) {
  background-color: var(--primary-color);
  opacity: 1;
}

.find-action-btn.close-btn:hover {
  background-color: #ff4444;
  opacity: 1;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .find-replace-row {
    grid-template-columns: 1fr;
  }

  .find-replace-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .find-replace-match-info {
    margin-left: 0;
    text-align: center;
  }

  .find-replace-actions {
    justify-content: center;
    flex-wrap: wrap;
  }
}

    /* Prevent flash of search UI before JS hides it */
    body.preload #tags-input,
    body.preload #functionList {
      display: none !important;
    }
