/* Modern Core Styles - Updated for 2024 */

/* ===== MODERN BASE RESET ===== */

/* Use box-sizing by default */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Remove default margins and set consistent font styles */
* {
  margin: 0;
  padding: 0;
  font: inherit;
}

/* Smooth scrolling for modern browsers */
html {
  scroll-behavior: smooth;
}

html:focus-within {
  scroll-behavior: smooth;
}

/* Responsive images and media */
img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Remove list styles on ul, ol with a class */
ul[class], ol[class] {
  list-style: none;
}

/* ===== ENHANCED ACCESSIBILITY ===== */

.skip-link {
  position: absolute;
  top: -40px;
  left: var(--space-4);
  background: var(--interactive-primary);
  color: var(--text-inverse);
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
  border-radius: 0 0 var(--radius-md) 0;
  z-index: var(--z-tooltip);
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  transform: translateY(-100%);
  transition: transform var(--transition-fast) ease-out;
}

.skip-link:focus {
  top: 0;
  transform: translateY(0);
  outline: none;
  box-shadow: var(--focus-ring);
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Enhanced focus indicators with proper contrast */
*:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  transition: outline var(--transition-fast) ease-out;
}

/* High contrast mode improvements */
@media (prefers-contrast: high) {
  *:focus-visible {
    outline-width: 3px;
    outline-offset: 3px;
  }

  .btn:focus-visible {
    outline-width: 4px;
  }
}

/* ===== MODERN LAYOUT SYSTEM ===== */

body {
  min-height: 100vh;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'kern' 1;
}

/* ===== MODERN HEADER WITH CSS GRID ===== */

header {
  position: relative;
  margin-bottom: var(--space-6);
  --header-banner-height: 80px;
  --header-banner-color: var(--brand-500);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto max-content;
  grid-template-rows: var(--header-banner-height) auto;
  align-items: center;
  column-gap: var(--space-4);
  row-gap: var(--space-2);
  padding: 0 var(--space-5) var(--space-3);
  background: var(--header-banner-color);
  border-radius: 0 0 var(--radius-2xl) var(--radius-2xl);
  overflow: visible;
}

header::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
              radial-gradient(circle at 70% 80%, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
  pointer-events: none;
}

header canvas {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: var(--header-banner-height);
  border-radius: inherit;
  object-fit: cover;
  opacity: 0.8;
}

header h1 {
  position: relative;
  grid-column: 1 / -1;
  grid-row: 1;
  justify-self: center;
  align-self: center;
  z-index: 2;
  font-family: var(--font-sans);
  font-size: clamp(1.4rem, 4vw, 1.9rem);
  font-weight: 600;
  color: var(--text-inverse);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  letter-spacing: 0.01em;
  text-align: center;
  margin: 0;
  white-space: nowrap;
}

header h1 .header-logo {
  height: 50px;
  width: auto;
  display: block;
}

/* Modern navigation positioning */
header nav {
  position: relative;
  grid-row: 2;
  font-size: var(--text-sm);
  z-index: 3;
  line-height: var(--leading-tight);
  white-space: nowrap;
}

header nav#modeLinks {
  grid-column: 1;
  justify-self: start;
}

header nav#headerLinks {
  grid-column: 3;
  justify-self: end;
  text-align: right;
}

header nav#headerLinks .header-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
}

header nav#headerLinks .header-menu-popout {
  display: none;
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: 200px;
  padding: var(--space-2);
  background: var(--surface-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
}

header nav#headerLinks .header-menu.is-open .header-menu-popout {
  display: block;
  animation: slideInUp 0.12s ease-out;
}

header nav#headerLinks .header-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast) ease-out;
}

header nav#headerLinks .header-menu-item:hover,
header nav#headerLinks .header-menu-item:focus-visible {
  background: var(--surface-secondary);
  color: var(--text-primary);
  outline: none;
}

header nav a,
header nav button.header-link-button {
  color: var(--text-inverse);
  text-decoration: none;
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-base);
  transition: all var(--transition-fast) ease-out;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
  background: transparent;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

header nav#headerLinks .header-menu-trigger {
  background: #ffffff;
  color: var(--brand-900);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.28);
  padding: 0.6rem 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 1rem;
  min-height: 40px;
}

header nav#headerLinks button#headerMenuBtn.header-menu-trigger {
  background: var(--brand-900);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.35);
  padding: 0.7rem 1.3rem;
  font-size: 1.125rem;
  min-height: 44px;
  line-height: 1;
}

header nav#headerLinks .header-menu-trigger[aria-expanded="true"] {
  background: var(--brand-100);
  border-color: var(--brand-200);
}

header nav#headerLinks button#headerMenuBtn.header-menu-trigger[aria-expanded="true"] {
  background: var(--brand-800);
  border-color: rgba(255, 255, 255, 0.85);
}

header nav#headerLinks .header-menu-trigger:hover,
header nav#headerLinks .header-menu-trigger:focus-visible {
  background: var(--brand-50);
  color: var(--brand-900);
}

header nav a:hover,
header nav a:focus-visible,
header nav button.header-link-button:hover,
header nav button.header-link-button:focus-visible {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  text-decoration: none;
  transform: translateY(-1px);
}

header nav#headerLinks button#headerMenuBtn.header-menu-trigger:hover,
header nav#headerLinks button#headerMenuBtn.header-menu-trigger:focus-visible {
  background: var(--brand-800);
  color: #fff;
  text-decoration: none;
}

/* ===== MODERN CONTROLS WITH CSS GRID ===== */

#controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  align-items: stretch;
  padding: 0 var(--space-6) var(--space-6);
  max-width: 1200px;
  margin: 0 auto;
}

/* Stats bar should align with controls width */
.stats-bar {
  padding: 0 var(--space-6) var(--space-6);
  max-width: 1200px;
  margin: 0 auto;
}

/* Mobile controls layout */
@media (max-width: 768px) {
  #controls {
    gap: 0.5rem;
    padding: 0 var(--space-4) var(--space-4);
  }

  .stats-bar {
    padding: 0 var(--space-4) var(--space-4);
  }
  
  .controls-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  
  .controls-row #search {
    min-width: auto;
    width: 100%;
    min-height: 40px;
    padding: 0.5rem 0.75rem;
  }
  
  .controls-row select {
    min-height: 40px;
    padding: 0.5rem 2rem 0.5rem 0.75rem;
  }
  
  .controls-row .controls-actions {
    margin-left: 0;
    width: 100%;
  }
  
  .controls-actions button {
    width: 100%;
    min-height: 40px;
  }
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  width: 100%;
}

.controls-row #search {
  flex: 1 1 260px;
}

.controls-row select {
  min-width: 150px;
}

.controls-row .controls-actions {
  margin-left: auto;
  display: flex;
  flex: 0 0 auto;
}

.controls-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

#controls.hidden {
  display: none;
}

/* View toggle with modern styling */
.viewToggle {
  display: flex;
  align-items: center;
  background: var(--surface-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-1);
  gap: 0;
}

.viewToggle input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.viewToggle label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast) ease-out;
  min-width: 60px;
}

.viewToggle input[type="radio"]:checked + label {
  background: var(--interactive-primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.viewToggle input[type="radio"]:focus-visible + label {
  box-shadow: var(--focus-ring);
}

/* Search input with modern styling */
#search {
  position: relative;
  background: var(--surface-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 0.4rem 0.75rem;
  font-size: var(--text-base);
  color: var(--text-primary);
  transition: all var(--transition-fast) ease-out;
  min-width: 240px;
  min-height: 44px;
  line-height: var(--leading-normal);
  text-overflow: ellipsis;
  overflow: hidden;
}

#search::placeholder {
  color: var(--text-tertiary);
}

#search:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--focus-ring);
  background: var(--bg-elevated);
}

/* Modern form controls */
select {
  background: var(--surface-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 0.4rem 2rem 0.4rem 0.75rem;
  font-size: var(--text-base);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast) ease-out;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1rem;
  appearance: none;
  min-height: 44px;
  line-height: var(--leading-normal);
  text-overflow: ellipsis;
  white-space: nowrap;
}

select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--focus-ring);
}

/* Modern buttons (integrates with modern-components.css) */
#controls button,
#controls label.file-btn {
  min-width: 120px;
  min-height: 44px;
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  border-radius: var(--radius-lg);
  line-height: var(--leading-tight);
}

/* New Prompt button should match control row height */
#controls .btn-primary {
  height: 44px;
  min-height: 44px;
  padding: 0 var(--space-4);
}

/* File input button modern styling */
label.file-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-weight: var(--font-semibold);
  font-size: var(--text-base);
  line-height: var(--leading-tight);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-secondary);
  color: var(--text-primary);
  border: 2px solid var(--border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: var(--transition-base);
  overflow: hidden;
}

label.file-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--surface-tertiary);
  opacity: 0;
  transition: opacity var(--transition-fast) ease-out;
  z-index: -1;
}

label.file-btn:hover::before {
  opacity: 1;
}

label.file-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-secondary);
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

label.file-btn input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

label.file-btn:focus-within {
  box-shadow: var(--focus-ring);
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.settings-section h4 {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.settings-actions .btn,
.settings-actions .file-btn {
  flex: 1 1 180px;
  min-width: 160px;
}

/* ===== MODERN MAIN CONTENT AREAS ===== */

#promptForm {
  display: none;
  background: var(--surface-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  padding: 1rem 1.25rem;
  margin: 0 var(--space-6) var(--space-6);
  max-width: 1000px;
  margin-left: auto;
  margin-right: auto;
  box-shadow: var(--shadow-lg);
}

#promptForm.open {
  display: grid;
  grid-template-columns: 1fr 140px 1fr;
  gap: 0.75rem;
  animation: slideInUp var(--transition-base) ease-out;
}

.prompt-modal {
  background: transparent;
  box-shadow: none;
  max-width: none;
  max-height: none;
  overflow: visible;
}

.prompt-modal.show {
  padding: var(--space-6);
}

.prompt-modal .modal-content {
  width: min(96vw, 980px);
  max-width: 980px;
  padding: var(--space-6);
}

.prompt-modal .prompt-modal-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.prompt-modal .prompt-modal-header h3 {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.prompt-modal .prompt-modal-subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.prompt-modal #promptForm {
  margin: 0;
  max-width: none;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

/* Form labels with modern styling */
#promptForm label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

#promptForm label span {
  color: var(--text-primary);
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
}

/* System Prompt takes 2 columns */
#promptForm label[for="systemPrompt"] {
  grid-column: 1 / 3;
}

/* Full-width form elements */
#promptForm label[style*="grid-column:1/3"],
#promptForm div[style*="grid-column:1/3"] {
  grid-column: 1 / -1;
}

/* Modern form inputs */
#promptForm input,
#promptForm textarea,
#promptForm select {
  background: var(--surface-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.65rem;
  font-size: var(--text-base);
  color: var(--text-primary);
  transition: all var(--transition-fast) ease-out;
  font-family: inherit;
  line-height: 1.4;
}

#promptForm textarea {
  resize: vertical;
  font-family: var(--font-mono);
  line-height: 1.5;
}

#promptForm textarea#systemPrompt {
  min-height: 60px;
  max-height: 100px;
}

#promptForm textarea#body {
  min-height: 140px;
  max-height: 300px;
}

#promptForm input:focus,
#promptForm textarea:focus,
#promptForm select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--focus-ring);
  background: var(--bg-elevated);
}

#promptForm input::placeholder,
#promptForm textarea::placeholder {
  color: var(--text-tertiary);
}

/* ===== MODERN CARD GRID SYSTEM ===== */

#list {
  display: grid;
  gap: var(--space-6);
  padding: 0 var(--space-6) var(--space-12);
  max-width: 1400px;
  margin: 0 auto;
  container-type: inline-size;
}

#list.hidden {
  display: none;
}

.organizer-layout {
  display: grid;
  gap: var(--space-6);
  grid-template-columns: minmax(0, 1fr);
  padding: 0 var(--space-6) var(--space-12);
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}

.organizer-layout.hidden {
  display: none;
}

.organizer-layout #list {
  padding: 0;
  max-width: none;
  margin: 0;
}

.builder-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-5);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-sm);
}

.builder-panel.builder-collapsed {
  gap: var(--space-3);
}

.builder-panel.builder-collapsed .builder-sections {
  display: none;
}

.builder-header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: flex-start;
}

.builder-header[data-builder-toggle] {
  cursor: pointer;
}

.builder-header > div {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.builder-header h2 {
  margin: 0;
  font-size: var(--text-lg);
}

.builder-header .text-muted {
  margin: 0;
  font-size: 0.8rem;
}

.builder-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
}

.builder-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.builder-toggle-btn::after {
  content: "▾";
  font-size: 0.85em;
  transition: transform 0.2s ease;
}

.builder-panel:not(.builder-collapsed) .builder-toggle-btn::after {
  transform: rotate(180deg);
}

.builder-sections {
  display: grid;
  gap: var(--space-4);
}

.builder-section {
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  background: var(--surface-secondary);
}

@media (min-width: 1024px) {
  .builder-sections {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .builder-section-output {
    grid-column: 1 / -1;
  }
}

.builder-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.builder-output-controls {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.builder-output-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.builder-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.builder-toggle select {
  min-width: 90px;
}

.builder-toggle-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-3);
  width: fit-content;
  max-width: 100%;
  margin: 0;
}

.builder-toggle-label {
  color: inherit;
}

.builder-radio-group {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
}

.builder-radio {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--text-xs);
  line-height: 1;
  border: none;
  padding: 0;
  background: transparent;
  flex-direction: row;
}

.builder-radio input {
  margin: 0;
  padding: 0;
  border: none;
  outline: none;
  box-shadow: none;
}

.builder-radio input:checked + span {
  font-weight: var(--font-semibold);
}

.builder-section-header h3 {
  margin: 0;
  font-size: var(--text-sm);
}

.builder-section-meta {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-full);
  padding: 0.1rem 0.5rem;
}

.builder-item {
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  background: var(--surface-elevated);
}

.builder-item + .builder-item {
  margin-top: var(--space-3);
}

.builder-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.builder-item-title {
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
}

.builder-item-body {
  margin: 0;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.4;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  max-height: calc(20 * 1.4em);
  overflow-y: scroll;
  overflow-x: hidden;
}

.builder-output {
  margin: 0;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-primary);
  max-height: 320px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3);
  background: var(--surface-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
}

.builder-output-disclosure {
  margin: 0;
}

.builder-output-summary {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-elevated);
  width: fit-content;
  max-width: 100%;
  margin: 0 0 var(--space-2);
}

.builder-output-summary::marker {
  content: '';
}

.builder-output-summary::-webkit-details-marker {
  display: none;
}

.builder-output-summary::before {
  content: '▸';
  color: var(--text-tertiary);
  display: inline-block;
  transition: transform 0.2s ease;
}

.builder-output-disclosure[open] .builder-output-summary::before {
  transform: rotate(90deg);
}

.builder-empty {
  text-align: center;
  padding: var(--space-4);
}

.builder-empty-title {
  margin: 0;
  font-weight: var(--font-semibold);
}

.builder-empty-hint {
  margin: var(--space-2) 0 0;
  color: var(--text-tertiary);
  font-size: var(--text-xs);
}

.type-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.08rem 0.35rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  border: 1px solid transparent;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.type-badge-prompt {
  background: var(--brand-100);
  color: var(--brand-700);
  border-color: var(--border-brand);
}

.type-badge-reference {
  background: var(--success-100);
  color: var(--success-700);
  border-color: var(--border-success);
}

/* Cards view - modern CSS Grid with auto-fit */
#list.cards {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  align-items: start;
}

/* List view - single column, compact */
#list:not(.cards) {
  grid-template-columns: 1fr;
  max-width: 960px;
  gap: var(--space-2);
}

/* ===== MODERN CARDS WITH IMPROVED STYLING ===== */

.card {
  position: relative;
  background: var(--surface-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: all var(--transition-base) cubic-bezier(0.4, 0, 0.2, 1);
  cursor: grab;
  container-type: inline-size;
  isolation: isolate;
}

.card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
  opacity: 0;
  border-radius: inherit;
  transition: opacity var(--transition-base) ease-out;
  z-index: -1;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-secondary);
}

.card:hover::before {
  opacity: 0.03;
}

.card:active {
  cursor: grabbing;
  transform: translateY(-2px);
}

.card:focus-within {
  border-color: var(--border-focus);
  box-shadow: var(--focus-ring);
}

/* Card content with modern typography */
.card h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: var(--font-semibold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.card p {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.35;
  color: var(--text-secondary);
}

.card .prompt-body {
  flex: 1;
  max-height: 120px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--border-secondary) transparent;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.4;
  background: var(--surface-secondary);
  color: var(--text-primary);
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
  margin-top: 0.25rem;
}

/* Modern scrollbar styling */
.card .prompt-body::-webkit-scrollbar {
  width: 6px;
}

.card .prompt-body::-webkit-scrollbar-track {
  background: transparent;
}

.card .prompt-body::-webkit-scrollbar-thumb {
  background: var(--border-secondary);
  border-radius: var(--radius-full);
}

.card .prompt-body::-webkit-scrollbar-thumb:hover {
  background: var(--border-focus);
}

/* Card actions with modern button styling */
.card .actions {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border-primary);
}

.card .actions button {
  flex: 0 0 auto;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: var(--leading-tight);
  padding: 0.25rem 0.5rem;
  min-width: 0;
  white-space: nowrap;
  border-radius: var(--radius-base);
}

/* Subdued delete button styling */
.card .actions button[data-del],
.card .actions .btn-danger {
  background: transparent;
  color: var(--danger-600);
  border: 1px solid var(--danger-300);
  box-shadow: none;
}

.card .actions button[data-del]:hover,
.card .actions .btn-danger:hover {
  background: var(--danger-500);
  color: var(--text-inverse);
  border-color: var(--danger-500);
}

/* ===== MODERN LIST ROWS - COMPACT DESKTOP ===== */

.list-row {
  background: var(--surface-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all var(--transition-fast) ease-out;
  cursor: grab;
  position: relative;
}

.list-row:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--border-secondary);
}

.list-row:active {
  cursor: grabbing;
}

.list-row .drag-handle {
  color: var(--text-tertiary);
  font-size: 0.9rem;
  font-weight: var(--font-bold);
  cursor: grab;
  user-select: none;
  transition: color var(--transition-fast) ease-out;
  padding: 0.1rem;
  flex-shrink: 0;
}

.list-row .drag-handle:hover {
  color: var(--text-secondary);
}

.list-row:active .drag-handle,
.list-row.dragging .drag-handle {
  cursor: grabbing;
  color: var(--interactive-primary);
}

.list-row .row-content {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

.list-row .row-title {
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.list-row .description {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.list-row .row-tags {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.2rem;
  margin-top: 0;
}

.list-row .actions {
  display: flex;
  gap: 0.3rem;
  flex: 0 0 auto;
}

.list-row .actions button {
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
  padding: 0.2rem 0.35rem;
  min-width: 0;
  border-radius: var(--radius-base);
}

/* Subdued delete button in list view (desktop) */
.list-row .actions button[data-del],
.list-row .actions .btn-danger {
  background: transparent;
  color: var(--danger-600);
  border: 1px solid var(--danger-300);
  box-shadow: none;
}

.list-row .actions button[data-del]:hover,
.list-row .actions .btn-danger:hover {
  background: var(--danger-500);
  color: var(--text-inverse);
  border-color: var(--danger-500);
}

/* ===== ENHANCED DRAG & DROP ===== */

.card.dragging,
.list-row.dragging {
  opacity: 0.95 !important;
  cursor: grabbing !important;
  z-index: var(--z-modal) !important;
  transform: scale(1.02) rotate(1deg) translateY(-8px) !important;
  box-shadow: var(--shadow-xl), 0 0 0 1px var(--interactive-primary) !important;
  border-color: var(--interactive-primary) !important;
  position: relative !important;
  transition: none !important;
}

.card.dragging::before,
.list-row.dragging::before {
  opacity: 0.1 !important;
}

.card.drag-over,
.list-row.drag-over {
  border: 2px dashed var(--interactive-primary) !important;
  box-shadow: 0 0 0 4px var(--brand-100) !important;
  background: var(--brand-50) !important;
  transform: scale(1.01) !important;
}

.drag-placeholder {
  border: 2px dashed var(--interactive-primary);
  border-radius: var(--radius-lg);
  background: var(--brand-50);
  margin-bottom: var(--space-6);
  animation: pulse-placeholder 1.5s ease-in-out infinite;
  pointer-events: none;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: var(--font-medium);
}

@keyframes pulse-placeholder {
  0%, 100% {
    opacity: 0.4;
    transform: scale(0.98);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.01);
  }
}

/* Keyboard navigation improvements */
.keyboard-selected {
  outline: 3px solid var(--interactive-primary) !important;
  outline-offset: 2px;
  background: var(--brand-50) !important;
}

.keyboard-selected::after {
  content: '↕ MOVING (Arrow keys to move, Enter to confirm, Esc to cancel)';
  position: absolute;
  top: -32px;
  left: 0;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  background: var(--interactive-primary);
  color: var(--text-inverse);
  padding: var(--space-1_5) var(--space-3);
  border-radius: var(--radius-md);
  white-space: nowrap;
  z-index: var(--z-tooltip);
  box-shadow: var(--shadow-sm);
}

/* ===== MODERN TAG SYSTEM ===== */

.tag {
  display: inline-flex;
  align-items: center;
  background: var(--surface-tertiary);
  color: var(--text-primary);
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  line-height: 1.2;
  font-weight: var(--font-medium);
  border: 1px solid var(--border-primary);
  gap: 0.2rem;
  transition: all var(--transition-fast) ease-out;
  text-decoration: none;
}

.tag:hover {
  background: var(--surface-secondary);
  border-color: var(--border-secondary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.tag button {
  background: none;
  border: none;
  color: var(--text-tertiary);
  padding: 0;
  margin: 0;
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: 1;
  border-radius: var(--radius-full);
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast) ease-out;
}

.tag button:hover {
  color: var(--danger-600);
  background: var(--danger-100);
  transform: none;
  box-shadow: none;
}

/* ===== TAG MULTI-SELECT COMBOBOX ===== */

.tag-input-wrapper {
  position: relative;
}

.tag-multiselect {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 38px;
  padding: 0.3rem 2rem 0.3rem 0.5rem;
  background: var(--surface-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  cursor: text;
  position: relative;
  transition: all var(--transition-fast) ease-out;
}

.tag-multiselect:focus-within {
  border-color: var(--border-focus);
  box-shadow: var(--focus-ring);
  background: var(--bg-elevated);
}

/* Selected tags area - positioned below dropdown */
.tag-multiselect-selected {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-top: 0.5rem;
  min-height: 0;
}

.tag-multiselect-selected:empty {
  display: none;
}

.tag-multiselect-selected .tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: var(--surface-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-secondary);
  padding: 0.2rem 0.3rem 0.2rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: 1.2;
  white-space: nowrap;
}

.tag-chip .tag-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: 1;
  transition: all var(--transition-fast) ease-out;
}

.tag-chip .tag-chip-remove:hover {
  background: var(--danger-500);
  color: white;
}

.tag-multiselect-input {
  flex: 1 1 80px;
  min-width: 80px;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--text-sm);
  color: var(--text-primary);
  padding: 0.15rem 0;
}

.tag-multiselect-input::placeholder {
  color: var(--text-tertiary);
}

.tag-multiselect-toggle {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0.2rem;
  font-size: var(--text-sm);
  line-height: 1;
  transition: transform var(--transition-fast) ease-out;
}

.tag-multiselect[aria-expanded="true"] .tag-multiselect-toggle {
  transform: translateY(-50%) rotate(180deg);
}

.tag-dropdown {
  display: none;
  position: absolute;
  top: calc(100% - 1.5rem);
  left: 0;
  right: 0;
  z-index: var(--z-dropdown);
  background: var(--surface-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  margin-top: 0.25rem;
  max-height: 180px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-secondary) transparent;
}

.tag-dropdown.show {
  display: block;
  animation: slideInUp 0.15s ease-out;
}

.tag-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.65rem;
  font-size: var(--text-sm);
  line-height: 1.2;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast) ease-out;
  border-bottom: 1px solid var(--border-primary);
}

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

.tag-dropdown-item:hover,
.tag-dropdown-item.highlighted {
  background: var(--surface-secondary);
}

.tag-dropdown-item.selected {
  background: var(--surface-tertiary);
  font-weight: var(--font-semibold);
}

.tag-dropdown-item.selected::after {
  content: '✓';
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.tag-dropdown-empty {
  padding: 0.75rem;
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  line-height: 1.2;
  font-style: italic;
}

.tag-dropdown-create {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.65rem;
  font-size: var(--text-sm);
  line-height: 1.2;
  color: var(--interactive-primary);
  cursor: pointer;
  background: var(--surface-secondary);
  border-top: 1px solid var(--border-primary);
}

.tag-dropdown-create:hover {
  background: var(--surface-tertiary);
}

.tag-dropdown-create::before {
  content: '+';
  font-weight: var(--font-bold);
}

/* Dark mode specific overrides for tag multiselect */
:root[data-theme="dark"] .tag-dropdown {
  background: #1a1a1a;
  border-color: #3e3e3e;
}

:root[data-theme="dark"] .tag-dropdown-item {
  color: #e0e0e0;
  border-bottom-color: #2e2e2e;
}

:root[data-theme="dark"] .tag-dropdown-item:hover,
:root[data-theme="dark"] .tag-dropdown-item.highlighted {
  background: #2a2a2a;
}

:root[data-theme="dark"] .tag-dropdown-item.selected {
  background: #3730a3;
  color: #e0e7ff;
}

:root[data-theme="dark"] .tag-dropdown-item.selected::after {
  color: #a5b4fc;
}

:root[data-theme="dark"] .tag-dropdown-create {
  background: #2a2a2a;
  color: #82aaff;
}

:root[data-theme="dark"] .tag-dropdown-create:hover {
  background: #3a3a3a;
}

:root[data-theme="dark"] .tag-chip {
  background: #3730a3;
  color: #e0e7ff;
  border-color: #4338ca;
}

:root[data-theme="dark"] .tag-chip .tag-chip-remove {
  color: #a5b4fc;
}

:root[data-theme="dark"] .tag-chip .tag-chip-remove:hover {
  background: #dc2626;
  color: white;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tag-dropdown {
    background: #1a1a1a;
    border-color: #3e3e3e;
  }

  :root:not([data-theme="light"]) .tag-dropdown-item {
    color: #e0e0e0;
    border-bottom-color: #2e2e2e;
  }

  :root:not([data-theme="light"]) .tag-dropdown-item:hover,
  :root:not([data-theme="light"]) .tag-dropdown-item.highlighted {
    background: #2a2a2a;
  }

  :root:not([data-theme="light"]) .tag-dropdown-item.selected {
    background: #3730a3;
    color: #e0e7ff;
  }

  :root:not([data-theme="light"]) .tag-dropdown-item.selected::after {
    color: #a5b4fc;
  }

  :root:not([data-theme="light"]) .tag-dropdown-create {
    background: #2a2a2a;
    color: #82aaff;
  }

  :root:not([data-theme="light"]) .tag-dropdown-create:hover {
    background: #3a3a3a;
  }

  :root:not([data-theme="light"]) .tag-chip {
    background: #3730a3;
    color: #e0e7ff;
    border-color: #4338ca;
  }

  :root:not([data-theme="light"]) .tag-chip .tag-chip-remove {
    color: #a5b4fc;
  }

  :root:not([data-theme="light"]) .tag-chip .tag-chip-remove:hover {
    background: #dc2626;
    color: white;
  }
}

/* ===== MODERN TOOL SECTIONS ===== */

#markdownSection,
#tokenSection,
#csvSection,
#smartOptimizerSection {
  display: none;
  background: var(--surface-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  margin: 0 var(--space-6) var(--space-8);
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  box-shadow: var(--shadow-lg);
}

#markdownSection.open,
#tokenSection.open,
#csvSection.open,
#smartOptimizerSection.open {
  display: block;
  animation: slideInUp var(--transition-base) ease-out;
}

#markdownSection {
  max-width: 96vw;
}

/* ===== MODERN FOOTER ===== */

footer {
  padding: var(--space-8) var(--space-6);
  text-align: center;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border-primary);
  background: var(--surface-secondary);
  margin-top: var(--space-12);
}

footer small {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-xs);
}

/* ===== RESPONSIVE DESIGN ===== */

@media (max-width: 1100px) {
  .organizer-layout {
    grid-template-columns: 1fr;
  }

  .builder-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Card grid responsive */
@container (max-width: 680px) {
  #list.cards {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }
}

/* Form responsive */
@container (max-width: 600px) {
  #promptForm {
    grid-template-columns: 1fr;
    gap: var(--space-4);
    padding: var(--space-6);
  }

  #promptForm label[style*="grid-column:1/3"],
  #promptForm div[style*="grid-column:1/3"] {
    grid-column: 1;
  }
}

/* Header responsive - Medium screens (prevent overlap) */
@media (max-width: 1024px) {
  header {
    --header-banner-height: 76px;
    padding: 0 var(--space-4) var(--space-2);
  }

  header h1 {
    font-size: clamp(1.1rem, 3vw, 1.4rem); /* Reduce logo size earlier */
  }

  header h1 .header-logo {
    height: 40px; /* Smaller logo */
  }

  header nav {
    font-size: 0.8rem; /* Smaller nav text */
  }

  header nav a,
  header nav button.header-link-button {
    padding: var(--space-1) 0.3rem; /* Reduce padding */
    font-size: 0.8rem;
  }
}

@media (max-width: 850px) {
  header {
    --header-banner-height: 72px;
    padding: 0 var(--space-3) var(--space-2);
  }

  header h1 {
    font-size: 1.1rem;
  }

  header h1 .header-logo {
    height: 35px;
  }

  header nav {
    font-size: var(--text-sm);
  }

  header nav a,
  header nav button.header-link-button {
    padding: 0.2rem 0.3rem;
    font-size: var(--text-sm);
  }

  /* Truncate very long nav items */
  header nav#modeLinks {
    max-width: 60%;
  }

  header nav#headerLinks {
    max-width: 30%;
  }
}

/* Header responsive - Mobile */
@media (max-width: 640px) {
  header {
    margin-bottom: var(--space-4);
    --header-banner-height: 64px;
    padding: 0 var(--space-3) var(--space-2);
  }

  header nav {
    font-size: var(--text-sm);
    white-space: normal;
  }

  header nav#modeLinks {
    max-width: 65%;
  }

  header nav#headerLinks {
    max-width: 30%;
  }

  header nav a,
  header nav button.header-link-button {
    padding: 0.2rem 0.3rem;
    font-size: var(--text-sm);
  }

  header h1 {
    font-size: 1.1rem;
  }

  header h1 .header-logo {
    height: 30px;
  }
  
  /* More compact controls on mobile */
  #controls {
    padding: 0 var(--space-3) var(--space-3);
  }
  
  #search,
  select {
    min-height: 38px;
    font-size: var(--text-base);
    padding: 0.35rem 0.75rem;
  }
  
  select {
    padding-right: var(--space-8);
  }
  
  #controls button,
  #controls .btn-primary {
    min-height: 38px;
    font-size: var(--text-sm);
  }
}

/* List row content layout - desktop (single-line compact) */
.list-row-content {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 0.4rem;
}

.list-row-left {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 auto;
  min-width: 150px;
}

.list-row-left h3 {
  margin: 0;
  font-size: var(--text-sm);
  white-space: nowrap;
}

.list-row-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 0 0 auto;
  justify-content: flex-end;
}

.list-row-tags {
  display: flex;
  gap: 0.15rem;
  flex-wrap: nowrap;
  max-width: 150px;
  overflow: hidden;
}

/* Compact tags in list view */
.list-row .tag {
  font-size: var(--text-sm);
  padding: 0.1rem 0.3rem;
  white-space: nowrap;
}

.list-row .actions {
  display: flex;
  gap: 0.25rem;
  flex-wrap: nowrap;
}

/* List row responsive - mobile stacked layout */
@media (max-width: 768px) {
  .list-row {
    padding: 0.6rem;
    position: relative;
  }

  .list-row-content {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }

  .list-row .drag-handle {
    display: none;
  }

  .list-row-left {
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
  }

  .list-row-left h3 {
    font-size: 0.9rem;
    margin: 0;
    white-space: normal;
  }

  .list-row .description {
    white-space: normal;
    max-width: none;
    overflow: visible;
    text-overflow: clip;
  }

  .list-row-right {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 0.4rem;
  }

  .list-row-tags {
    flex-wrap: wrap;
    width: 100%;
    max-width: none;
  }

  .list-row .tag {
    font-size: var(--text-sm);
    padding: 0.15rem 0.4rem;
  }

  .list-row .actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem;
    width: 100%;
    padding-top: 0.4rem;
    border-top: 1px solid var(--border-primary);
    margin-top: 0.2rem;
  }

  .list-row .actions button {
    justify-content: center;
    padding: 0.3rem 0.4rem;
    font-size: var(--text-sm);
    display: flex;
    align-items: center;
    gap: 0.2rem;
  }

  /* Delete button spans full width on mobile */
  .list-row .actions button[data-del],
  .list-row .actions .btn-danger {
    grid-column: 1 / -1;
    background: transparent;
    color: var(--danger-600);
    border: 1px solid var(--danger-300);
    box-shadow: none;
  }

  .list-row .actions button[data-del]:hover,
  .list-row .actions .btn-danger:hover {
    background: var(--danger-500);
    color: var(--text-inverse);
  }
}

/* ===== MODERN LOADING AND EMPTY STATES ===== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-8);
  text-align: center;
  background: var(--surface-secondary);
  border: 2px dashed var(--border-secondary);
  border-radius: var(--radius-xl);
  color: var(--text-secondary);
}

.empty-state h3 {
  margin: 0 0 var(--space-3);
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.empty-state p {
  margin: 0;
  font-size: var(--text-base);
  max-width: 400px;
}

.loading {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.loading::before {
  content: '';
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--border-primary);
  border-top-color: var(--interactive-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ===== IMPROVED STATUS MESSAGES ===== */

.status {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  margin: var(--space-3) 0;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  border: 1px solid;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.status.success {
  background: var(--success-50);
  color: var(--success-700);
  border-color: var(--success-200);
}

.status.error {
  background: var(--danger-50);
  color: var(--danger-700);
  border-color: var(--danger-200);
}

.status.warning {
  background: var(--warning-50);
  color: var(--warning-700);
  border-color: var(--warning-200);
}

.status.info {
  background: var(--info-50);
  color: var(--info-700);
  border-color: var(--info-200);
}

/* ===== UTILITY CLASSES ===== */

.list-fade-out {
  opacity: 0;
  transform: translateY(10px);
  transition: all var(--transition-fast) ease-out;
  pointer-events: none;
}

.list-fade-in {
  opacity: 1;
  transform: translateY(0);
  transition: all var(--transition-fast) ease-out;
  pointer-events: auto;
}

/* Modern focus management */
.focus-trap {
  position: relative;
}

.focus-trap:focus-within {
  isolation: isolate;
  z-index: var(--z-dropdown);
}

/* High performance scrolling */
.scroll-container {
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

.scroll-container::-webkit-scrollbar {
  width: 8px;
}

.scroll-container::-webkit-scrollbar-track {
  background: var(--surface-secondary);
  border-radius: var(--radius-full);
}

.scroll-container::-webkit-scrollbar-thumb {
  background: var(--border-secondary);
  border-radius: var(--radius-full);
  border: 2px solid var(--surface-secondary);
}

.scroll-container::-webkit-scrollbar-thumb:hover {
  background: var(--border-focus);
}
