/* ─── Variables ───────────────────────────────────────────── */
:root {
  --bg:           #061a13;
  --bg-card:      #0a2118;
  --bg-input:     #0d2a1e;
  --bg-hover:     #113225;
  --border:       #18392a;
  --border-light: #1f4a36;
  --accent:       #10b981;
  --accent-hover: #059669;
  --accent-light: #34d399;
  --accent-glow:  rgba(16, 185, 129, 0.25);
  --accent2:      #047857;
  --groq:         #f97316;
  --gemini:       #3b82f6;
  --openai:       #22c55e;
  --text:         #e6f4ec;
  --text-muted:   #8fb3a0;
  --text-dim:     #4d6b5b;
  --success:      #22c55e;
  --error:        #ef4444;
  --warning:      #f59e0b;
  --radius:       10px;
  --radius-sm:    7px;
}

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

/* ─── Base ────────────────────────────────────────────────── */
html {
  width: 100%;
  height: 100%;
}

body {
  width: 100%;
  height: 100vh;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
}

.app-container {
  max-width: 900px;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
}

/* ─── Screens ─────────────────────────────────────────────── */
.screen { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.screen.hidden { display: none; }
.hidden { display: none !important; }

#screen-main { display: flex; flex-direction: column; }

.msg-error {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--error);
  font-size: 12px;
  padding: 8px 10px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius-sm);
  margin-top: 8px;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ─── Buttons ─────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: linear-gradient(135deg, #10b981, #047857);
  color: #04150d;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 12px rgba(16, 185, 129, 0.3);
  white-space: nowrap;
}

.btn-primary:hover { background: linear-gradient(135deg, #34d399, #10b981); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-full { width: 100%; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-ghost:hover { color: var(--text); border-color: var(--border-light); background: var(--bg-hover); }

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.btn-icon:hover { border-color: var(--border-light); color: var(--text); background: var(--bg-hover); }

.btn-link {
  background: none;
  border: none;
  color: var(--accent-light);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-link:hover { color: var(--accent); }

/* ─── Header ──────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

/* ─── Tab nav ─────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 9px 0;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn:hover { border-color: var(--border-light); color: var(--text); }
.tab-btn.active { border-color: var(--accent); color: var(--text); background: rgba(16,185,129,0.14); box-shadow: 0 0 0 1px rgba(16,185,129,0.25); }

/* ─── Main content / views ───────────────────────────────── */
.main-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.view.hidden { display: none; }

/* ─── Generator view ──────────────────────────────────────── */
#view-generator { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
#view-generator::-webkit-scrollbar { width: 5px; }
#view-generator::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.gen-subview { display: block; }
.gen-subview.hidden { display: none; }

.ai-selector {
  display: flex;
  gap: 6px;
  padding: 14px 16px 0;
}

.ai-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 0;
  cursor: pointer;
  transition: all 0.15s;
}

.ai-tab:hover { border-color: var(--border-light); color: var(--text); }

.ai-tab.active {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(16,185,129,0.12);
  box-shadow: 0 0 0 1px rgba(16,185,129,0.25);
}

.ai-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

.config-warning {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 10px 16px 0;
  padding: 8px 12px;
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: var(--radius-sm);
  color: var(--warning);
  font-size: 12px;
}

.form-section { padding: 14px 16px 0; }
.form-row { display: flex; gap: 12px; padding: 14px 16px 0; }
.form-half { flex: 1; padding: 0; }

.form-label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 8px;
}

.form-textarea, .form-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.form-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.form-textarea::placeholder { color: var(--text-dim); }

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238fb3a0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.form-textarea:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.input-group { padding: 16px 16px 16px; }

/* ─── Loading sub-view ───────────────────────────────────── */
.loading-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 20px;
  text-align: center;
  min-height: 320px;
  justify-content: center;
}

.loading-icon {
  position: relative;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
}

.loading-ring {
  position: absolute;
  inset: 0;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-msg { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.loading-sub { font-size: 12px; color: var(--text-muted); min-height: 18px; }

/* ─── Results sub-view ───────────────────────────────────── */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  gap: 8px;
  position: sticky;
  top: 0;
}

.results-meta { font-size: 11px; color: var(--text-dim); }

.results-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.result-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-light);
  background: rgba(16,185,129,0.14);
  padding: 3px 9px;
  border-radius: 20px;
}

.result-title-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 10px;
  outline: none;
  margin-bottom: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.result-title-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.result-text-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.55;
  padding: 10px 11px;
  outline: none;
  resize: vertical;
  margin-bottom: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.result-text-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); color: var(--text); }

.result-actions { display: flex; gap: 8px; }

.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.copy-btn:hover { border-color: var(--border-light); color: var(--text-muted); background: var(--bg-hover); }
.copy-btn.copied { color: var(--success); border-color: rgba(34,197,94,0.3); }

.btn-save-result {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(16,185,129,0.12);
  border: 1px solid rgba(16,185,129,0.3);
  color: var(--accent-light);
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-save-result:hover { background: rgba(16,185,129,0.2); border-color: var(--accent); }
.btn-save-result.saved { background: rgba(34,197,94,0.15); border-color: rgba(34,197,94,0.4); color: var(--success); }

/* ─── Library view: toolbar ──────────────────────────────── */
#view-library { flex-direction: column; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-wrap { position: relative; flex: 1; }

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 9px 12px 9px 32px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.search-input::placeholder { color: var(--text-dim); }

/* ─── Main body layout (library) ─────────────────────────── */
.main-body { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 158px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-title {
  font-size: 10.5px;
  color: var(--text-dim);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 8px 8px;
}

.cat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12.5px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  margin-bottom: 2px;
}

.cat-btn:hover { background: var(--bg-hover); color: var(--text); }
.cat-btn.active { background: rgba(16,185,129,0.14); color: var(--text); box-shadow: inset 0 0 0 1px rgba(16,185,129,0.3); }

.cat-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

.cat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count { font-size: 10.5px; color: var(--text-dim); flex-shrink: 0; }
.cat-btn.active .cat-count { color: var(--accent-light); }

.sidebar-divider { height: 1px; background: var(--border); margin: 10px 4px; }

.add-category-wrap { display: flex; gap: 5px; padding: 2px 2px 0; }

.add-category-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 11.5px;
  padding: 6px 8px;
  outline: none;
  min-width: 0;
}

.add-category-input:focus { border-color: var(--accent); }

.btn-add-category {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--accent-light);
  border-radius: 6px;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-add-category:hover { border-color: var(--accent); background: rgba(16,185,129,0.1); }

/* ─── Content / prompt list ──────────────────────────────── */
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.prompt-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.prompt-list::-webkit-scrollbar { width: 5px; }
.prompt-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 12.5px;
}

/* ─── Prompt card ─────────────────────────────────────────── */
.prompt-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  transition: border-color 0.15s;
}

.prompt-card:hover { border-color: var(--border-light); }

.prompt-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.prompt-title { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.35; flex: 1; }

.prompt-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.action-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  border-radius: 5px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.action-btn:hover { border-color: var(--border); color: var(--text-muted); background: var(--bg-hover); }
.action-btn.copy-action:hover { color: var(--accent-light); border-color: rgba(16,185,129,0.3); }
.action-btn.copy-action.copied { color: var(--success); border-color: rgba(34,197,94,0.3); }
.action-btn.delete-action:hover { color: var(--error); border-color: rgba(239,68,68,0.3); }

.prompt-snippet {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-line;
}

.prompt-card-bottom { display: flex; align-items: center; gap: 8px; font-size: 10.5px; color: var(--text-dim); }

.cat-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px; font-size: 10.5px; font-weight: 600; }

.uses-badge { display: inline-flex; align-items: center; gap: 3px; }

.date-text { margin-left: auto; }

/* ─── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 9, 6, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-box {
  width: 480px;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title { font-size: 14px; font-weight: 700; color: var(--text); }

.modal-body { padding: 16px; overflow-y: auto; flex: 1; }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 7px;
}

.field-input, .field-select, .field-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.field-input:focus, .field-select:focus, .field-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field-input::placeholder, .field-textarea::placeholder { color: var(--text-dim); }

.field-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238fb3a0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.field-textarea { resize: vertical; min-height: 110px; line-height: 1.5; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ─── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 11px 18px;
  font-size: 12.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  transform: translate(-50%, 16px);
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 100;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast-icon { font-size: 15px; }
