:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --border: #e2e2e6;
  --text: #1a1a1e;
  --text-muted: #6b6b74;
  --accent: #f7901e;
  --accent-hover: #d97a0f;
  --danger: #d9534f;
  --danger-hover: #c9433f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
}

html[data-theme="dark"] {
  --bg: #1a1a19;
  --surface: #383835;
  --surface-2: #1d1d1c;
  --border: #3a3a37;
  --text: #faf9f5;
  --text-muted: #b0aea5;
  --accent: #f7901e;
  --accent-hover: #ff9f3d;
  --danger: #e57373;
  --danger-hover: #ef8888;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.15s ease, color 0.15s ease;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  padding: 9px 16px;
  font-size: 14px;
  transition: background 0.15s ease;
}
button:hover { background: var(--accent-hover); }
button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--border); }
button.danger { background: var(--danger); }
button.danger:hover { background: var(--danger-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: var(--surface-2);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.hidden { display: none !important; }

/* ---------- Site nav ---------- */
.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
}
.site-nav .nav-left {
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: nowrap;
  min-width: 0;
}
.site-nav .logo-link {
  display: flex;
  align-items: center;
}
.site-nav .logo-link:hover { text-decoration: none; }
.site-nav .logo-link img {
  height: 50px;
  display: block;
}
.site-nav .nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
}
.nav-link {
  position: relative;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-link.active { color: var(--text); background: var(--surface-2); }

.nav-dropdown { position: relative; }
.nav-dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  background: none !important;
}
.nav-dropdown-toggle.active { color: var(--text); }
.nav-dropdown-toggle .caret {
  font-size: 10px;
  transition: transform 0.15s ease;
}
.nav-dropdown.open .nav-dropdown-toggle .caret { transform: rotate(180deg); }
.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 170px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 60;
}
.nav-dropdown.open .nav-dropdown-menu { display: flex; }
.nav-dropdown-menu a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text);
}
.nav-dropdown-menu a:hover { background: var(--surface-2); text-decoration: none; }
.nav-dropdown-menu a.active { color: var(--accent); }

.site-nav .nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-badge {
  font-size: 13px;
  color: var(--text-muted);
}
.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  padding: 0;
}
.theme-toggle:hover { background: var(--border); }

@media (max-width: 720px) {
  .site-nav { padding: 10px 14px; }
  .site-nav .nav-left { gap: 14px; }
}

/* ---------- Auth page ---------- */
#auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}
.auth-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}
.auth-card p.sub {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 20px;
}
.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-card .error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
}
.auth-switch {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}
.auth-switch button {
  background: none;
  color: var(--accent);
  padding: 0;
  font-size: 13px;
}
.auth-switch button:hover { background: none; text-decoration: underline; }

/* ---------- Page shell ---------- */
.page-container { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }

.page-header { margin: 0 0 20px; }
.page-header h1 { font-size: 22px; margin: 0 0 4px; }
.page-header p { color: var(--text-muted); font-size: 14px; margin: 0; }

/* ---------- Home page ---------- */
.home-hero {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 0 28px;
}
.home-hero h1 { font-size: 26px; margin: 0; }
.home-hero p { color: var(--text-muted); font-size: 15px; margin: 0; max-width: 560px; }

.home-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.home-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.home-card h3 { margin: 0; font-size: 16px; }
.home-card p { margin: 0; color: var(--text-muted); font-size: 13.5px; flex: 1; }
.home-card a.button-link {
  align-self: flex-start;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
}
.home-card a.button-link:hover { background: var(--accent-hover); text-decoration: none; }

.placeholder-block {
  text-align: center;
  color: var(--text-muted);
  padding: 90px 20px;
  font-size: 15px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 4px;
  width: fit-content;
  border: 1px solid var(--border);
}
.tabs a {
  background: transparent;
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  display: inline-block;
}
.tabs a:hover { background: transparent; color: var(--text); text-decoration: none; }
.tabs a.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 16px 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.toolbar input[type="search"] {
  flex: 1 1 200px;
  min-width: 160px;
}
.toolbar select { min-width: 130px; }
.toolbar .spacer { flex: 1 1 auto; }

.results-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 2px 12px;
}

#prompt-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.badge.tool { color: var(--accent); border-color: var(--accent); background: transparent; }

.prompt-text {
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px;
  max-height: 110px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.meta-row {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.notes {
  font-size: 12.5px;
  color: var(--text-muted);
  font-style: italic;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  padding-top: 6px;
}
.card-actions button {
  font-size: 12.5px;
  padding: 6px 10px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  font-size: 14px;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 560px;
  padding: 24px;
}
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.modal form .full { grid-column: 1 / -1; }
.modal label {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.modal input, .modal select, .modal textarea { width: 100%; }
.modal textarea { resize: vertical; min-height: 90px; font-family: inherit; }
.modal .modal-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
.modal .error {
  grid-column: 1 / -1;
  color: var(--danger);
  font-size: 13px;
  min-height: 14px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }

@media (max-width: 560px) {
  .modal form { grid-template-columns: 1fr; }
}
