/* ─── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Material Symbols ───────────────────────────────────────────────── */
.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  vertical-align: middle;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ─── Design tokens (mirrors Tailwind config) ────────────────────────── */
:root {
  --surface:            #0b1326;
  --surface-low:        #131b2e;
  --surface-mid:        #171f33;
  --surface-high:       #222a3d;
  --surface-highest:    #2d3449;
  --surface-lowest:     #060e20;
  --on-surface:         #dae2fd;
  --on-surface-var:     #c1c6d7;
  --primary:            #a7c8ff;
  --primary-container:  #3291ff;
  --on-primary-ct:      #002a55;
  --secondary-ct:       #3a4a5f;
  --on-secondary-ct:    #a9bad3;
  --tertiary:           #ffb695;
  --error:              #ffb4ab;
  --error-container:    #93000a;
  --outline:            #8b90a0;
  --outline-variant:    #414754;
}

/* ─── Global ─────────────────────────────────────────────────────────── */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--surface);
  color: var(--on-surface);
  line-height: 1.5;
}

/* Thin scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--outline-variant); border-radius: 10px; }
.custom-scrollbar { overflow-y: auto; }

/* ─── Utilities ──────────────────────────────────────────────────────── */
.primary-gradient {
  background: linear-gradient(135deg, #a7c8ff 0%, #3291ff 100%);
}
.glass-panel {
  background: rgba(45, 52, 73, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* ─── Top-nav buttons ────────────────────────────────────────────────── */
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid rgba(65, 71, 84, 0.4);
  border-radius: 0.125rem;
  color: var(--outline);
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.nav-btn:hover {
  color: var(--on-surface);
  background: var(--surface-high);
  border-color: rgba(167, 200, 255, 0.3);
}

/* ─── Sort select arrow ──────────────────────────────────────────────── */
.sort-select-arrow {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%238b90a0' d='M5 6L0 0h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px !important;
}

/* ─── Form Panel (slide-over) ────────────────────────────────────────── */
.form-panel {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
}
.form-panel.open { pointer-events: auto; }

.form-panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 14, 32, 0.7);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.form-panel.open .form-panel-backdrop { opacity: 1; }

.form-panel-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 90vw;
  background: var(--surface-low);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -8px 0 40px rgba(6, 14, 32, 0.5);
  overflow: hidden;
}
.form-panel.open .form-panel-drawer { transform: translateX(0); }

/* Form fields */
.form-field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--outline);
}
.field-input {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-lowest);
  border: 1px solid transparent;
  border-radius: 0.125rem;
  color: var(--on-surface);
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.field-input:focus {
  border-color: rgba(50, 145, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(50, 145, 255, 0.1);
}
.field-input::placeholder { color: var(--outline); }
.field-mono {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.8125rem;
  line-height: 1.6;
}

/* ─── Stitch Modal ───────────────────────────────────────────────────── */
.stitch-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(6, 14, 32, 0.7);
  backdrop-filter: blur(8px);
}
.stitch-modal[aria-hidden="false"] { display: flex; }

.stitch-modal-dialog {
  width: 90%;
  max-width: 440px;
  border-radius: 0.25rem;
  padding: 24px;
  box-shadow: 0 8px 40px rgba(6, 14, 32, 0.6);
}

.conflict-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  border-radius: 0.125rem;
  background: var(--surface-lowest);
  border: 1px solid rgba(65, 71, 84, 0.15);
  cursor: pointer;
  transition: background 0.15s, transform 0.12s;
  gap: 2px;
  font-family: 'Inter', sans-serif;
}
.conflict-btn:hover { background: var(--surface-highest); transform: translateY(-2px); }
.conflict-btn-primary { border-color: rgba(167, 200, 255, 0.4); background: var(--surface-high); }

/* ─── Prompts Grid ───────────────────────────────────────────────────── */
.prompts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* ─── Prompt Card ────────────────────────────────────────────────────── */
.prompt-card {
  background: var(--surface-low);
  border-radius: 0.125rem;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 0;
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  cursor: default;
}
.prompt-card:hover {
  background: var(--surface-mid);
  box-shadow: 0 8px 40px rgba(6, 14, 32, 0.4);
  transform: translateY(-2px);
}

/* Card header */
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.prompt-card h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--on-surface);
  line-height: 1.3;
  flex: 1;
  word-break: break-word;
  transition: color 0.15s;
}
.prompt-card:hover h3 { color: var(--primary); }

.card-copy-btn {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--outline);
  border-radius: 0.125rem;
  padding: 3px 8px;
  font-size: 0.6875rem;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: color 0.12s, background 0.12s;
  white-space: nowrap;
}
.card-copy-btn:hover {
  color: var(--primary);
  background: rgba(167, 200, 255, 0.1);
}

/* Meta row */
.meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.meta-model-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--secondary-ct);
  border-radius: 0.125rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--on-secondary-ct);
  white-space: nowrap;
}
.meta-date {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6875rem;
  color: var(--outline);
  margin-left: auto;
}

/* Stars */
.stars {
  display: flex;
  gap: 1px;
  align-items: center;
  margin-bottom: 10px;
}
.star {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--outline-variant);
  padding: 2px;
  border-radius: 0.125rem;
  transition: color 0.1s, transform 0.08s;
  line-height: 1;
  font-family: 'Material Symbols Outlined';
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}
.star:hover, .star:focus {
  color: var(--tertiary);
  transform: scale(1.25);
  outline: none;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}
.star.filled {
  color: var(--tertiary);
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}

/* Prompt preview */
.prompt-preview {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
  color: var(--on-surface-var);
  line-height: 1.55;
  opacity: 0.85;
  margin-bottom: 10px;
  background: var(--surface-lowest);
  border-radius: 0.125rem;
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow: hidden;
  max-height: 80px;
  position: relative;
  flex-grow: 1;
}
.prompt-preview::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 28px;
  background: linear-gradient(transparent, var(--surface-lowest));
}

/* Token estimates */
.meta-tokens { margin-bottom: 8px; }
.token-estimate {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 0.125rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6875rem;
  font-weight: 500;
}
.token-high {
  background: rgba(50, 145, 255, 0.1);
  color: #3fb950;
  border: 1px solid rgba(50, 145, 255, 0.15);
}
.token-medium {
  background: rgba(255, 182, 149, 0.08);
  color: var(--tertiary);
  border: 1px solid rgba(255, 182, 149, 0.15);
}
.token-low {
  background: rgba(255, 180, 171, 0.08);
  color: var(--error);
  border: 1px solid rgba(255, 180, 171, 0.15);
}

/* Card footer - open / delete row */
.prompt-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid rgba(65, 71, 84, 0.12);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--outline);
}

/* ─── Buttons (used by JS-generated card HTML) ────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 1px solid rgba(65, 71, 84, 0.3);
  border-radius: 0.125rem;
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
  text-decoration: none;
  background: transparent;
  color: var(--on-surface-var);
}
.btn-ghost {
  background: transparent;
  color: var(--outline);
  border-color: rgba(65, 71, 84, 0.3);
}
.btn-ghost:hover {
  background: var(--surface-high);
  color: var(--on-surface);
  border-color: rgba(167, 200, 255, 0.3);
}
.btn-primary {
  background: linear-gradient(135deg, #a7c8ff 0%, #3291ff 100%);
  color: var(--on-primary-ct);
  border-color: transparent;
  font-weight: 600;
}
.btn-primary:hover { opacity: 0.9; }
.btn-danger {
  background: transparent;
  color: var(--error);
  border-color: rgba(255, 180, 171, 0.2);
}
.btn-danger:hover {
  background: rgba(255, 180, 171, 0.08);
  border-color: rgba(255, 180, 171, 0.4);
}
.btn-sm { padding: 4px 9px; font-size: 0.6875rem; }

/* ─── Notes ───────────────────────────────────────────────────────────── */
.notes-container {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(65, 71, 84, 0.12);
}
.notes-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}
.notes-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.note-item {
  background: var(--surface-high);
  border-left: 2px solid rgba(167, 200, 255, 0.25);
  padding: 9px 12px;
  border-radius: 0.125rem;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.note-body { flex: 1 1 auto; min-width: 0; }
.note-text {
  color: var(--on-surface-var);
  font-size: 0.8125rem;
  margin-bottom: 3px;
  white-space: pre-wrap;
  word-break: break-word;
}
.note-meta {
  font-family: 'JetBrains Mono', monospace;
  color: var(--outline);
  font-size: 0.6875rem;
}
.note-actions { display: flex; gap: 4px; flex-shrink: 0; }
.notes-empty {
  color: var(--outline);
  font-size: 0.8rem;
  font-style: italic;
}
.note-editor {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.note-textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-lowest);
  border: 1px solid transparent;
  border-radius: 0.125rem;
  color: var(--on-surface);
  font-family: 'Inter', sans-serif;
  font-size: 0.8125rem;
  transition: border-color 0.15s;
  resize: vertical;
  outline: none;
}
.note-textarea:focus {
  border-color: rgba(50, 145, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(50, 145, 255, 0.1);
}
.note-editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.note-counter {
  font-family: 'JetBrains Mono', monospace;
  color: var(--outline);
  font-size: 0.6875rem;
}
.editor-actions { display: flex; gap: 6px; }

/* ─── Empty State ─────────────────────────────────────────────────────── */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 24px;
  border: 2px dashed rgba(65, 71, 84, 0.2);
  border-radius: 0.25rem;
  background: var(--surface-low);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 16px; opacity: 0.5; }
.empty-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--on-surface-var);
  margin-bottom: 6px;
}
.empty-sub { font-size: 0.875rem; color: var(--outline); }

/* ─── Toast Messages ──────────────────────────────────────────────────── */
.message-area {
  position: fixed;
  right: 20px;
  bottom: 36px;
  min-width: 260px;
  max-width: 380px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.message-area .msg {
  background: var(--surface-highest);
  color: var(--on-surface);
  padding: 12px 16px;
  border-radius: 0.125rem;
  font-size: 0.8125rem;
  box-shadow: 0 4px 24px rgba(6, 14, 32, 0.5);
  animation: slideInMsg 0.2s ease forwards;
  pointer-events: auto;
  border-left: 3px solid var(--primary);
}
@keyframes slideInMsg {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .form-panel-drawer { width: 100vw; }
  .prompts-grid { grid-template-columns: 1fr; }
}
