/* 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: .75rem;
}

header canvas {
  display: block;
  width: 100%;
  height: 80px;
}

header h1 {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.4);
}

header nav#modeLinks {
  position: absolute;
  bottom: 6px;
  left: 12px;
  font-size: .8rem;
  color: #fff;
}

header nav#modeLinks a, 
header nav#headerLinks a {
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.2s ease;
}

header nav#modeLinks a:hover, 
header nav#headerLinks a:hover {
  text-decoration: underline;
  color: #e0e7ff;
}

header nav#headerLinks {
  position: absolute;
  bottom: 6px;
  right: 12px;
  font-size: .8rem;
  color: #fff;
}

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

#controls.hidden {
  display: none;
}

#controls > * {
  flex: 0 0 auto;
}

#search {
  flex: 3 1 240px;
}

select {
  min-width: 110px;
}

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

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

/* 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;
}

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

#list.hidden {
  display: none;
}

#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 {
    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"]):not([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: .85rem;
  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: .85rem;
  gap: .25rem;
}

label span {
  font-weight: 600;
}

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

.card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  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: .875rem;
}

.card .prompt-body {
  max-height: 12rem;
  overflow: auto;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: .8rem;
  background: #f3f4f6;
  padding: .5rem;
  border-radius: var(--radius);
  flex: 1;
}

.card .actions {
  display: flex;
  gap: .4rem;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.card .actions button {
  min-width: 0;
  flex: 0 0 auto;
  font-size: .7rem;
  padding: .3rem .4rem;
  white-space: nowrap;
}

/* 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 button {
  font-size: .75rem;
  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: .75rem;
  gap: .25rem;
  transition: all 0.2s ease;
}

.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 */
.export-preview {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  max-height: 150px;
  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; }
