/* ─── Variables ───────────────────────────────────────────── */
:root {
  --bg:           #0a0f17;
  --bg-card:      #0f1620;
  --bg-input:     #131b27;
  --bg-hover:     #16202c;
  --border:       #1f2937;
  --border-light: #2c3a4d;
  --accent:       #06b6d4;
  --accent-hover: #0891b2;
  --accent-light: #22d3ee;
  --accent-glow:  rgba(6, 182, 212, 0.25);
  --accent2:      #0ea5e9;
  --text:         #e7eef5;
  --text-muted:   #8295a8;
  --text-dim:     #4d5d6e;
  --success:      #22c55e;
  --error:        #ef4444;
  --warning:      #f59e0b;
  --radius:       10px;
  --radius-sm:    7px;
}

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

/* ─── Base ────────────────────────────────────────────────── */
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
}

/* ─── Screens ─────────────────────────────────────────────── */
.screen { display: block; height: 100%; }
.screen.hidden { display: none; }
.hidden { display: none !important; }

#screen-main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.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, #06b6d4, #0ea5e9);
  color: #03222b;
  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(6, 182, 212, 0.3);
  white-space: nowrap;
}

.btn-primary:hover { background: linear-gradient(135deg, #22d3ee, #06b6d4); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(6, 182, 212, 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: 8px 14px;
  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); }

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ─── Toolbar ─────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  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 ───────────────────────────────────── */
.main-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ─── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: 168px;
  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(6,182,212,0.14); color: var(--text); box-shadow: inset 0 0 0 1px rgba(6,182,212,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(6,182,212,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(6,182,212,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(5, 8, 13, 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='%238295a8' 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; }
