/* Core Styles - Combined Base and Components */

/* Accessibility Utilities */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--brand);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  border-radius: 0 0 4px 0;
  z-index: 1001;
  font-weight: 600;
}

.skip-link:focus {
  top: 0;
}

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

/* Focus Indicators */
*:focus {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

button:focus,
.file-btn:focus-within {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  *:focus {
    outline-width: 4px;
  }
}

/* Base Styles and Layout */
body {
  margin: 0;
  background: var(--bg);
  color: #111;
  line-height: 1.45;
}

/* Header */
header {
  position: relative;
  margin-bottom: .225rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto max-content;
  grid-template-rows: var(--header-banner-height, 80px) auto;
  align-items: center;
  column-gap: .75rem;
  row-gap: .35rem;
  padding: 0 12px 6px;
  --header-banner-color: #4e8cff;
  background: var(--header-banner-color);
}

header canvas {
  display: block;
  width: 100%;
  height: var(--header-banner-height, 80px);
  grid-column: 1 / -1;
  grid-row: 1;
  z-index: 0;
}

header h1 {
  position: relative;
  grid-column: 1 / -1;
  grid-row: 1;
  justify-self: center;
  align-self: center;
  z-index: 1;
  margin: 0;
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.4);
}

.header-tagline {
  position: relative;
  grid-column: 1 / -1;
  grid-row: 1;
  justify-self: center;
  align-self: end;
  z-index: 1;
  margin: 0;
  padding-bottom: 0.35rem;
  font-size: clamp(0.75rem, 1.8vw, 0.95rem);
  font-weight: 500;
  line-height: 1.15;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  letter-spacing: 0.02em;
  text-align: center;
  max-width: min(90%, 32rem);
}

header nav#modeLinks {
  position: relative;
  grid-column: 1;
  grid-row: 2;
  justify-self: start;
  font-size: var(--text-sm);
  color: #fff;
  white-space: nowrap;
}

header nav#modeLinks.mode-tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  padding: 0.25rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(6px);
}

header nav#modeLinks a, 
header nav#headerLinks a,
header nav#headerLinks button.header-link-button {
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.2s ease;
  background: transparent;
  border: none;
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
}

header nav#headerLinks .header-menu-trigger {
  background: #ffffff;
  color: #1e3a8a;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  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: #1e3a8a;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
  padding: 0.7rem 1.3rem;
  font-size: 1.125rem;
  min-height: 44px;
  line-height: 1;
}

header nav#headerLinks .header-menu-trigger:hover,
header nav#headerLinks .header-menu-trigger:focus-visible {
  background: #e0e7ff;
  color: #1e3a8a;
  text-decoration: none;
}

header nav#modeLinks .mode-tab {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.01em;
  gap: 0;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

header nav#modeLinks .mode-tab .mode-tab-icon {
  width: 1rem;
  height: 1rem;
  display: inline-block;
  margin-right: 0.3rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

@media (max-width: 720px) {
  header nav#modeLinks {
    white-space: normal;
  }

  header nav#modeLinks.mode-tabs {
    flex-wrap: wrap;
  }
}

header nav#modeLinks .mode-tab:hover {
  text-decoration: none;
  background: rgba(255, 255, 255, 0.22);
}

header nav#modeLinks .mode-tab.is-active,
header nav#modeLinks .mode-tab[aria-selected="true"] {
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

header nav#modeLinks .mode-tab:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

header nav#modeLinks a:hover, 
header nav#headerLinks a:hover,
header nav#headerLinks button.header-link-button:hover,
header nav#headerLinks button.header-link-button:focus-visible {
  text-decoration: underline;
  color: #e0e7ff;
}

header nav#headerLinks button#headerMenuBtn.header-menu-trigger:hover,
header nav#headerLinks button#headerMenuBtn.header-menu-trigger:focus-visible {
  background: #1d4ed8;
  color: #fff;
  text-decoration: none;
}

header nav#headerLinks {
  position: relative;
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
  text-align: right;
  font-size: var(--text-sm);
  color: #fff;
  white-space: nowrap;
}

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% + 0.35rem);
  right: 0;
  min-width: 180px;
  padding: 0.35rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.2);
  box-shadow: var(--shadow);
  z-index: 1000;
}

header nav#headerLinks .header-menu.is-open .header-menu-popout {
  display: block;
}

header nav#headerLinks .header-menu-item {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.6rem;
  border-radius: calc(var(--radius) * 0.9);
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

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

/* Controls Section */
#controls {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: 0 1rem .675rem;
}

.controls-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.25);
  box-shadow: var(--shadow);
  padding: 0.75rem;
}

#controls.hidden {
  display: none;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  width: 100%;
}

.controls-row .form-control {
  width: auto;
  min-width: 0;
  flex: 1 1 180px;
}

.controls-row #search {
  flex: 2 1 320px;
  min-height: 42px;
}

.controls-row select {
  flex: 1 1 160px;
  min-width: 140px;
}

#controls .controls-row select.form-select {
  flex: 0 0 auto;
  width: max-content;
  min-width: 0;
  max-width: 100%;
}

.favorites-filter {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  border: 2px solid var(--border-primary);
  background: var(--surface-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  min-height: 42px;
  white-space: nowrap;
  position: relative;
  transition: var(--transition-base);
  cursor: pointer;
}

.favorites-filter:hover {
  border-color: var(--border-secondary);
}

.favorites-filter:focus-within {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

.favorites-filter input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.favorites-filter-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding-left: 2.1rem;
  gap: 0.4rem;
}

.favorites-filter-icon {
  color: var(--warning, #eab308);
  line-height: 1;
}

.favorites-filter-label::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 1.7rem;
  height: 1rem;
  transform: translateY(-50%);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-primary) 55%, var(--border-primary) 45%);
  border: 1px solid color-mix(in srgb, var(--border-primary) 70%, transparent 30%);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.favorites-filter-label::after {
  content: "";
  position: absolute;
  left: 0.15rem;
  top: 50%;
  width: 0.7rem;
  height: 0.7rem;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--surface-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease, background 0.2s ease;
}

.favorites-filter input:checked + .favorites-filter-label::before {
  background: color-mix(in srgb, var(--brand) 80%, var(--card) 20%);
  border-color: color-mix(in srgb, var(--brand) 65%, transparent 35%);
}

.favorites-filter input:checked + .favorites-filter-label::after {
  transform: translate(0.7rem, -50%);
  background: #ffffff;
}

.favorites-filter input:focus-visible + .favorites-filter-label::before {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 35%, transparent 65%);
}

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

.controls-row .controls-actions .btn {
  min-height: 42px;
}

@media (max-width: 900px) {
  .controls-row .controls-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

/* Stats Bar */
.stats-bar {
  padding: 0 1rem 0.2rem;
}

.stats-bar.hidden {
  display: none;
}

.stats-grid {
  --stats-card-width: 231px;
  display: grid;
  grid-template-columns: repeat(auto-fit, var(--stats-card-width));
  justify-content: center;
  gap: 0.5rem;
}

.stat-card {
  --stat-accent: var(--brand-500);
  --stat-accent-soft: color-mix(in srgb, var(--stat-accent) 18%, var(--card) 82%);
  background: linear-gradient(135deg, var(--stat-accent-soft), var(--card));
  border: 1px solid color-mix(in srgb, var(--stat-accent) 28%, var(--border) 72%);
  border-radius: calc(var(--radius) * 1.25);
  padding: 0.32rem 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  box-shadow: var(--shadow);
}

.stat-card .stat-icon {
  width: 20px;
  height: 20px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--stat-accent) 20%, #ffffff 80%);
  border: 1px solid color-mix(in srgb, var(--stat-accent) 40%, transparent 60%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--stat-accent);
  flex-shrink: 0;
}

.stat-card .stat-icon .stat-icon-svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stat-card .stat-body {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  line-height: 1.1;
}

.stat-card .stat-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.stat-card .stat-label {
  font-size: 0.95rem;
  color: color-mix(in srgb, var(--text) 80%, var(--muted) 20%);
  font-weight: 600;
}

.stat-card.stat-favorites { --stat-accent: var(--warning-500, #eab308); }
.stat-card.stat-tags { --stat-accent: var(--success-500, #22c55e); }
.stat-card.stat-updated { --stat-accent: var(--accent-500, #ef4444); }

.controls-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

select {
  min-width: 110px;
}

#controls button,
#controls label.file-btn {
  min-width: 110px;
}

#controls label.file-btn {
  font-size: 1rem;
}

.settings-section {
  margin-bottom: 1rem;
}

.settings-section h4 {
  margin: 0 0 .5rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

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

.settings-modal #resetBtn {
  margin-right: auto;
}

/* Main Content Sections */
#promptForm {
  display: none;
  grid-gap: .6rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

/* Light theme placeholder and selection adjustments */
:root[data-theme="light"] ::placeholder {
  color: color-mix(in srgb, var(--fg) 40%, var(--bg) 60%);
  opacity: 1; /* Ensure consistent across browsers */
}

:root[data-theme="light"] ::selection {
  background: color-mix(in srgb, var(--accent) 25%, var(--bg) 75%);
  color: var(--fg);
}

/* Auto light scheme when system prefers light */
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] ::placeholder {
    color: color-mix(in srgb, var(--fg) 40%, var(--bg) 60%);
  }
  :root[data-theme="auto"] ::selection {
    background: color-mix(in srgb, var(--accent) 25%, var(--bg) 75%);
    color: var(--fg);
  }
}

#promptForm.open {
  display: grid;
}

.prompt-modal .modal-content {
  max-width: 920px;
  width: min(96vw, 920px);
}

.prompt-modal .prompt-modal-header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.prompt-modal .prompt-modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--fg, #111);
}

.prompt-modal .prompt-modal-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

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

#list {
  display: grid;
  align-items: start;
  gap: 1rem;
  padding: 0 1rem 3rem;
}

#list.hidden {
  display: none;
}

.organizer-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr);
  padding: 0 1rem 3rem;
  align-items: start;
}

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

.organizer-layout #list {
  padding: 0;
}

.builder-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

.builder-panel.builder-collapsed {
  gap: 0.5rem;
}

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

.builder-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

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

.builder-header h2 {
  margin: 0;
}

.builder-header .text-muted {
  margin: 0.25rem 0 0;
}

.builder-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.builder-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

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

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

.builder-sections {
  display: grid;
  gap: 1rem;
}

.builder-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  background: var(--bg-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: 0.5rem;
  margin-bottom: 0.5rem;
}

.builder-output-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.builder-output-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.builder-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--muted);
}

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

.builder-toggle-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.6rem;
  width: fit-content;
  max-width: 100%;
  margin: 0;
}

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

.builder-radio-group {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

.builder-radio {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  border: none;
  padding: 0;
  background: transparent;
}

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

.builder-radio input:checked + span {
  font-weight: 600;
}

.builder-section-header h3 {
  margin: 0;
  font-size: 1rem;
}

.builder-section-meta {
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}

.builder-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  background: var(--card-bg);
}

.builder-item + .builder-item {
  margin-top: 0.5rem;
}

.builder-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.builder-item-title {
  font-weight: 600;
  font-size: 0.9rem;
}

.builder-item-body {
  margin: 0;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted);
  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(--mono);
  font-size: 0.82rem;
  color: var(--text);
  max-height: 280px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

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

.builder-output-summary {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.6rem;
  background: var(--card-bg);
  width: fit-content;
  max-width: 100%;
  margin: 0 0 0.5rem;
}

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

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

.builder-output-summary::before {
  content: '▸';
  color: var(--muted);
  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: 0.75rem;
}

.builder-empty-title {
  margin: 0;
  font-weight: 600;
}

.builder-empty-hint {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

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

.type-badge-prompt {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.type-badge-reference {
  background: rgba(76, 175, 80, 0.15);
  color: var(--success);
  border-color: var(--success);
}

#markdownSection,
#tokenSection,
#csvSection {
  display: none;
  padding: 1rem;
  max-width: 900px;
  margin: 0 auto 3rem;
}

#markdownSection.open,
#tokenSection.open,
#csvSection.open {
  display: block;
}

/* Footer */
footer {
  padding: 1rem;
  text-align: center;
  font-size: .8rem;
  color: var(--muted);
}

footer small {
  display: block;
  margin-bottom: .4rem;
}

/* Mobile Responsive */
@media (max-width: 640px) {
  .controls-row {
    flex-wrap: wrap;
  }

  .controls-row .controls-actions {
    margin-left: 0;
    width: 100%;
    justify-content: stretch;
  }

  .controls-row .controls-actions button {
    width: 100%;
  }

  .organizer-layout {
    grid-template-columns: 1fr;
  }

  .builder-header {
    flex-direction: column;
  }

  #controls {
    gap: .25rem;
    padding: 0 .5rem .5rem;
  }
  
  #controls button,
  #controls label.file-btn {
    min-width: auto;
    flex: 1 1 auto;
    font-size: .8rem;
    padding: .35rem .4rem;
  }
  
  #search {
    flex: 1 1 100%;
    order: -1;
    margin-bottom: .25rem;
  }

  select {
    width: 120px;
    min-width: 100px;
    flex: 0 0 auto;
  }
}

@media (min-width: 680px) {
  #promptForm {
    grid-template-columns: 1fr 1fr;
  }
  
  #promptForm textarea {
    grid-column: 1/3;
  }
  
  #list.cards {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

@media (max-width: 679px) {
  #list.cards {
    grid-template-columns: 1fr;
    gap: .75rem;
  }
}

/* Component Styles */

/* Form Elements */
input, textarea, select, button, label {
  font: inherit;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  padding: .45rem .6rem;
  box-sizing: border-box;
}

input:not([type="checkbox"], [type="radio"]), 
textarea, 
select {
  cursor: text;
}

input[type="checkbox"], 
input[type="radio"] {
  cursor: pointer;
}

input:disabled, 
textarea:disabled, 
select:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* Buttons */
button {
  cursor: pointer;
  background: var(--brand);
  border: none;
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

button.secondary {
  background: #e5e7eb;
  color: #111;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,.15);
}

button:active {
  transform: translateY(0);
  box-shadow: var(--shadow);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
  box-shadow: var(--shadow);
}

/* File Input Button */
label.file-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

label.file-btn input {
  display: none;
}

label.file-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,.15);
}

/* View Toggle */
.viewToggle {
  display: flex;
  align-items: center;
  font-size: var(--text-sm);
  gap: .25rem;
}

.viewToggle input {
  margin-right: .25rem;
  cursor: pointer;
}

.viewToggle label {
  cursor: pointer;
}

.viewToggle label:hover {
  color: var(--brand);
}

/* Labels */
label {
  display: flex;
  flex-direction: column;
  font-size: var(--text-sm);
  gap: .25rem;
}

label span {
  font-weight: 600;
}

.builder-radio {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
}

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
  --card-top-label-size: 0.8rem;
  display: flex;
  flex-direction: column;
  transition: all 0.2s ease;
  border: 2px solid transparent;
  position: relative;
  cursor: grab;
}

.card-top-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin: 0 0 0.5rem;
}

.card-top-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.card-top-row .type-badge {
  flex: 0 0 auto;
}

.card-top-row .token-count {
  flex: 0 0 auto;
}

.card-top-row .system-prompt-icon,
.card-top-row .card-top-sys {
  flex: 0 0 auto;
}

.card .type-badge {
  font-size: var(--card-top-label-size, var(--text-xs));
}



.card .card-title {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.card:hover {
  box-shadow: 0 6px 16px rgba(0,0,0,.08);
  transform: translateY(-2px);
  cursor: grab;
}

.card:active {
  cursor: grabbing;
}

/* Drag and Drop Styles */
.card.dragging, .list-row.dragging {
  opacity: 0.9 !important;
  cursor: grabbing !important;
  z-index: 1000 !important;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3) !important;
  transform: scale(1.05) rotate(2deg) !important;
  border: 3px solid #007bff !important;
  background-color: #e3f2fd !important;
  position: relative !important;
  transition: none !important;
}

/* Ghost effect for original position */
.card.dragging::before, .list-row.dragging::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, #007bff, #0056b3);
  opacity: 0.1;
  border-radius: var(--radius);
  z-index: -1;
}

.card.drag-over, .list-row.drag-over {
  border: 3px dashed #007bff !important;
  box-shadow: 0 0 15px rgba(0, 123, 255, 0.4) !important;
  background-color: rgba(0, 123, 255, 0.05) !important;
  transform: scale(1.02) !important;
}

.drag-placeholder {
  border: 3px dashed #007bff;
  border-radius: var(--radius);
  background: linear-gradient(45deg, rgba(0, 123, 255, 0.1), rgba(0, 123, 255, 0.05));
  margin-bottom: 1rem;
  animation: pulse-placeholder 1s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes pulse-placeholder {
  from {
    opacity: 0.6;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1.02);
  }
}

.card:focus-within {
  border-color: var(--brand);
  outline: none;
}

.card h2 {
  margin: .2rem 0;
  font-size: 1rem;
}

.card p {
  margin: .2rem 0;
  color: var(--muted);
  font-size: .9rem;
}

.card .card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.5rem 0;
}

.card .tag {
  padding: 0.2rem 0.5rem;
  font-size: var(--text-sm);
  border-radius: 999px;
}

.card .card-date {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
}

.card .prompt-body {
  max-height: 12rem;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: .875rem;
  background: #f3f4f6;
  padding: .6rem;
  border-radius: var(--radius);
  flex: 1;
  border: 1px solid var(--border);
  margin-top: 0.5rem;
}

.card .prompt-body::-webkit-scrollbar {
  width: 10px;
}

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

.card .prompt-body::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

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

.card .actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.favorite-toggle {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.favorite-toggle:hover,
.favorite-toggle:focus-visible {
  color: var(--warning, #eab308);
  border-color: color-mix(in srgb, var(--warning, #eab308) 45%, transparent 55%);
  background: color-mix(in srgb, var(--warning, #eab308) 12%, transparent 88%);
}

.favorite-toggle.is-favorite {
  color: var(--warning, #eab308);
  background: color-mix(in srgb, var(--warning, #eab308) 18%, transparent 82%);
  border-color: color-mix(in srgb, var(--warning, #eab308) 55%, transparent 45%);
}

.favorite-toggle-compact {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.card .actions button {
  min-width: 0;
  flex: 0 0 auto;
  font-size: var(--text-sm);
  padding: .35rem .5rem;
  white-space: nowrap;
}

/* Subdued delete button */
.card .actions button[data-del] {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.card .actions button[data-del]:hover {
  background: var(--danger);
  color: white;
}

.token-count {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--primary);
  font-size: var(--text-xs, 0.75rem);
  font-weight: 500;
  color: var(--text);
  background: var(--primary-light);
  line-height: 1;
}

.card .token-count {
  font-size: var(--card-top-label-size, var(--text-xs, 0.75rem));
}

/* List Rows */
.list-row {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .6rem .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  transition: all 0.2s ease;
  cursor: grab;
}

/* Keyboard navigation states */
.keyboard-selected {
  outline: 4px dashed var(--brand) !important;
  outline-offset: 2px;
  background-color: rgba(var(--brand-rgb, 59, 130, 246), 0.1) !important;
}

.keyboard-selected::before {
  content: '↕ MOVING (Arrow keys to move, Enter to confirm, Esc to cancel)';
  position: absolute;
  top: -25px;
  left: 0;
  font-size: 0.75rem;
  background: var(--brand);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 10;
}

.list-row:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  transform: translateY(-1px);
  cursor: grab;
}

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

.list-row .drag-handle {
  color: #9ca3af;
  font-size: 1.2rem;
  font-weight: bold;
  margin-right: 0.5rem;
  cursor: grab;
  user-select: none;
  transition: color 0.2s ease;
  line-height: 1;
  padding: 0.2rem;
}

.list-row .drag-handle:hover {
  color: #6b7280;
}

.list-row:active .drag-handle,
.list-row.dragging .drag-handle {
  cursor: grabbing;
  color: #007bff;
}

.drag-instruction {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  color: #6c757d;
  font-size: 0.9rem;
  text-align: center;
}

.list-row .row-title {
  font-weight: 600;
  flex: 0 0 auto;
}

.list-row .row-tags {
  flex: 1 1 auto;
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  min-width: 0;
}

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

.list-row-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
}

.list-row-actions-group {
  display: flex;
  gap: 0.4rem;
}

.list-row .actions button {
  font-size: var(--text-sm);
  padding: .25rem .5rem;
  min-width: 0;
}

/* List row description - tighter spacing */
.list-row .description {
  margin: 0.25rem 0 0 0;
  color: var(--muted);
  font-size: .875rem;
}

/* Tag Pills */
.tag {
  display: inline-flex;
  align-items: center;
  background: #e5e7eb;
  color: #374151;
  padding: .2rem .5rem;
  border-radius: 999px;
  font-size: var(--text-sm);
  gap: .25rem;
  transition: all 0.2s ease;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem;
  border-radius: calc(var(--radius) * 1.25);
  border: 1px dashed var(--border);
  background: color-mix(in srgb, var(--card) 92%, var(--bg) 8%);
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
}

.empty-state::before {
  content: "🔍";
  font-size: 1.2rem;
}

.tag:hover {
  background: #d1d5db;
}

.tag button {
  background: none;
  border: none;
  color: inherit;
  padding: 0;
  margin: 0;
  margin-left: .25rem;
  cursor: pointer;
  line-height: 1;
  font-size: 1rem;
  min-width: 0;
  box-shadow: none;
  transition: color 0.2s ease;
}

.tag button:hover {
  color: #dc2626;
  transform: none;
  box-shadow: none;
}

/* Empty States */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.empty-state h3 {
  margin: 0 0 .5rem;
  color: #374151;
}

.empty-state p {
  margin: 0;
}

/* Loading States */
.loading {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  color: var(--muted);
}

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

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

/* Status Messages */
.status {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin: .5rem 0;
  font-size: .875rem;
}

.status.success {
  background: #d1fae5;
  color: #065f46;
}

.status.error {
  background: #fee2e2;
  color: #991b1b;
}

.status.warning {
  background: #fef3c7;
  color: #92400e;
}

.status.info {
  background: #dbeafe;
  color: #1e40af;
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  overflow: auto;
}

.modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.modal-content {
  background: var(--card, #fff);
  border-radius: var(--radius);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  padding: 2rem;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow: auto;
  position: relative;
  margin: auto;
}

.modal-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.modal-buttons button {
  min-width: 100px;
}

/* History Modal Specific Styles */
.history-entry {
  border: 1px solid #e5e7eb;
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.history-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.history-entry-time {
  font-size: 0.875rem;
  color: var(--muted);
}

.history-entry-preview {
  font-size: 0.875rem;
  line-height: 1.5;
}

.history-entry-preview pre {
  background: var(--bg-secondary);
  padding: 0.5rem;
  border-radius: var(--radius);
  overflow: auto;
  max-height: 200px;
  margin-top: 0.5rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  border: 1px solid var(--border);
}

/* Export Modal Specific Styles */
#exportModal.modal {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  transform: none;
  animation: none !important;
  background: var(--bg-overlay, rgba(0, 0, 0, 0.5));
  border-radius: 0;
  box-shadow: none;
  max-width: none;
  max-height: none;
}

#exportModal .modal-content {
  max-width: 400px;
  width: min(92vw, 400px);
  padding: 1.35rem;
  max-height: 72vh;
}

.export-preview {
  background: var(--bg-secondary);
  padding: 0.75rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  max-height: 90px;
  overflow: auto;
  border: 1px solid var(--border);
}

.export-info {
  background: #dbeafe;
  padding: 0.75rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--toast-bg-info);
  color: var(--toast-fg-info);
  padding: 1rem 1.5rem;
  border-radius: var(--radius);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 2000;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Toast severity variants */
.toast.info { 
  background: var(--toast-bg-info); 
  color: var(--toast-fg-info);
  border-color: var(--border);
}
.toast.warning { 
  background: var(--toast-bg-warning); 
  color: var(--toast-fg-warning);
  border-color: var(--warning);
}
.toast.error { 
  background: var(--toast-bg-error); 
  color: var(--toast-fg-error);
  border-color: var(--danger);
}
.toast.success {
  background: var(--toast-bg-success);
  color: var(--toast-fg-success);
  border-color: var(--success);
}

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

.show {
  display: block !important;
}

.hide {
  display: none !important;
}

/* List rendering transitions */
.list-fade-out {
  opacity: 0;
  transition: none;
  visibility: hidden;
}

.list-fade-in {
  opacity: 1;
  transition: opacity 0.2s ease;
  visibility: visible;
}
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
