@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@300;400;500&family=Newsreader:ital,wght@0,400;0,600;1,400&family=Inter:wght@400;500;600&display=swap');

/* Default to dark theme */
:root {
  --bg: #0c0e11;
  --bg-surface: #12151a;
  --bg-sidebar: #0f1114;
  --border: #1e2228;
  --text: #c8cdd5;
  --text-dim: #6b7280;
  --text-bright: #e8ecf1;
  --accent: #6ee7b7;
  --accent-dim: #22543d;
  --link: #67c7f0;
  --warn: #fbbf24;
  --err: #f87171;
  --mono: 'DM Mono', monospace;
  --serif: 'Newsreader', Georgia, serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Light theme */
html[data-theme="light"] {
  --bg: #fafaf8;
  --bg-surface: #f3f3f0;
  --bg-sidebar: #efefec;
  --border: #e0dfe0;
  --text: #333333;
  --text-dim: #888888;
  --text-bright: #111111;
  --accent: #3d9970;
  --accent-dim: #d4f0e3;
  --link: #0066cc;
  --warn: #d97706;
  --err: #dc2626;
}

/* Sepia theme */
html[data-theme="sepia"] {
  --bg: #f4eae0;
  --bg-surface: #ede0d3;
  --bg-sidebar: #e6dac7;
  --border: #d4cabb;
  --text: #5a4a3a;
  --text-dim: #8b7355;
  --text-bright: #3d2817;
  --accent: #8b6914;
  --accent-dim: #f5ead1;
  --link: #a85f3a;
  --warn: #bf8b00;
  --err: #b5443f;
}

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

html { font-size: 16px; }
html[data-font="serif"] { --body-font: var(--serif); }
html[data-font="sans"] { --body-font: var(--sans); }
html[data-font="mono"] { --body-font: var(--mono); }

:root { --body-font: var(--mono); }

body {
  font-family: var(--body-font);
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
}

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

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  justify-content: space-between;
}
.settings-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.settings-btn:hover {
  color: var(--text);
  background: var(--border);
}
.header-buttons {
  display: flex;
  gap: 0.5rem;
}
.logo-link { display: flex; align-items: center; gap: 0.5rem; color: var(--text-bright); }
.logo-link:hover { text-decoration: none; }
.logo-icon { font-size: 1.4rem; color: var(--accent); }
.logo-text { font-size: 0.85rem; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-bright); }
.sidebar h3 {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}
.recent-list {
  list-style: none;
}
.recent-list li {
  margin-bottom: 0.25rem;
}
.recent-list a {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  padding: 0.3rem 0.4rem;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s, color 0.15s;
}
.recent-list a:hover {
  background: var(--border);
  color: var(--text);
  text-decoration: none;
}
.recent-list .ts {
  font-size: 0.6rem;
  color: var(--text-dim);
  opacity: 0.5;
}

/* ---- Main ---- */
.main {
  padding: 2rem 3rem;
  max-width: 52rem;
}

/* ---- Hero (index) ---- */
.hero {
  margin-top: 12vh;
  text-align: center;
  margin-bottom: 3rem;
}
.hero-icon {
  font-size: 3rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}
.hero h1 {
  font-family: var(--serif);
  font-size: 2.4rem;
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 0.4rem;
}
.hero-sub {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 2rem;
}
.about-section {
  max-width: 36rem;
  margin: 0 auto;
  text-align: center;
}
.about-section h2 {
  font-family: var(--serif);
  font-size: 1.2rem;
  color: var(--text-bright);
  margin-bottom: 0.5rem;
}
.about-section p {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.8;
}

/* ---- Search / Nav ---- */
.search-form, .nav-form { width: 100%; max-width: 32rem; margin: 0 auto; }
.input-row {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  transition: border-color 0.2s;
}
.input-row:focus-within { border-color: var(--accent); }
.input-row input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-bright);
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.6rem 0.4rem;
  outline: none;
}
.input-row input::placeholder { color: var(--text-dim); opacity: 0.5; }
.input-row button {
  background: var(--accent-dim);
  color: var(--accent);
  border: none;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  transition: background 0.15s;
}
.input-row button:hover { background: #2f6e50; }

.quick-links {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.quick-links a {
  margin: 0 0.4rem;
  color: var(--accent);
  opacity: 0.7;
}
.quick-links a:hover { opacity: 1; }

/* ---- Topbar ---- */
.topbar { margin-bottom: 1rem; }
.nav-form { max-width: 100%; }

/* ---- Status bar ---- */
.status-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.badge {
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
}
.badge-ok { background: var(--accent-dim); color: var(--accent); }
.badge-warn { background: #422006; color: var(--warn); }
.badge-err { background: #450a0a; color: var(--err); }
.badge-cache { background: #1e1b4b; color: #a5b4fc; }

/* ---- Gemini content ---- */
.gemini-content {
  font-size: 0.88rem;
  line-height: 1.85;
}
.gemini-content h1 {
  font-family: var(--serif);
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--text-bright);
  margin: 1.5rem 0 0.8rem;
}
.gemini-content h2 {
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-bright);
  margin: 1.2rem 0 0.5rem;
}
.gemini-content h3 {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-bright);
  margin: 1rem 0 0.4rem;
}
.gemini-content p { margin-bottom: 0.5rem; }
.gemini-content a.gemlink {
  display: block;
  padding: 0.3rem 0;
  color: var(--accent);
  font-size: 0.82rem;
}
.gemini-content a.gemlink::before {
  content: '⇒ ';
  opacity: 0.4;
}
.gemini-content .pre-alt {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  padding: 0.6rem 1rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
  margin: 0.8rem 0 0 0;
}
.gemini-content .pre-alt + pre {
  margin: 0 0 0.8rem 0;
  border-radius: 0 0 4px 4px;
}
.gemini-content pre {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.78rem;
  margin: 0.8rem 0;
  line-height: 1.5;
}
.gemini-content blockquote {
  border-left: 3px solid var(--accent-dim);
  padding-left: 1rem;
  color: var(--text-dim);
  font-style: italic;
  font-family: var(--serif);
  margin: 0.8rem 0;
}
.gemini-content ul {
  padding-left: 1.2rem;
  margin: 0.5rem 0;
}
.gemini-content li { margin-bottom: 0.2rem; }

/* ---- Notices ---- */
.redirect-notice, .input-prompt, .error-notice {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.2rem;
  font-size: 0.85rem;
}
.prompt-form {
  margin-top: 0.8rem;
}
.prompt-form input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--mono);
  padding: 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}
.prompt-form button {
  background: var(--accent-dim);
  color: var(--accent);
  border: none;
  font-family: var(--mono);
  padding: 0.5rem 1.2rem;
  border-radius: 4px;
  cursor: pointer;
}

/* ---- Loading Spinner ---- */
.loading-spinner {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Settings ---- */
.settings-bar {
  display: flex;
  justify-content: flex-end;
  padding: 0.5rem 0 1rem 0;
}

.settings-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}
.settings-modal.show {
  display: flex;
}

.settings-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.settings-header h2 {
  font-size: 1.2rem;
  color: var(--text-bright);
  margin: 0;
}
.settings-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.settings-close:hover {
  color: var(--text);
  background: var(--border);
}

.settings-content {
  padding: 1.5rem;
}
.setting-group {
  margin-bottom: 1.5rem;
}
.setting-group:last-child {
  margin-bottom: 0;
}
.setting-group label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-bright);
  margin-bottom: 0.6rem;
  font-weight: 500;
}
.setting-group select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--body-font);
  font-size: 0.9rem;
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.setting-group select:hover {
  border-color: var(--accent);
}
.setting-group select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---- Auth Forms ---- */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 1rem;
}

.auth-form {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.auth-form h1 {
  margin: 0 0 1.5rem 0;
  font-size: 1.8rem;
  color: var(--text-bright);
  text-align: center;
}

.form-group {
  margin-bottom: 1.2rem;
}

.form-group:last-of-type {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-bright);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.form-group input {
  width: 100%;
  padding: 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--body-font);
  font-size: 0.95rem;
  border-radius: 4px;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 231, 183, 0.1);
}

html[data-theme="light"] .form-group input:focus {
  box-shadow: 0 0 0 3px rgba(61, 153, 112, 0.1);
}

.submit-btn {
  width: 100%;
  padding: 0.8rem 1rem;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.submit-btn:hover {
  background: var(--link);
}

.submit-btn:active {
  transform: scale(0.98);
}

.error-message {
  background: var(--err);
  color: #fff;
  padding: 0.8rem;
  border-radius: 4px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  border-left: 4px solid #dc2626;
}

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.auth-footer p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.auth-footer a {
  color: var(--link);
  text-decoration: none;
  font-weight: 500;
}

.auth-footer a:hover {
  text-decoration: underline;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 1rem;
  }
  .main { padding: 1.5rem 1rem; }
  .hero { margin-top: 4vh; }
}

/* ---- Admin Panel ---- */
.admin-container {
  max-width: 1000px;
  padding: 2rem;
}

.admin-tab {
  display: none;
}

.admin-tab.active {
  display: block;
}

.sidebar-menu {
  list-style: none;
  padding: 0;
  margin-bottom: 1rem;
}

.sidebar-menu li {
  margin-bottom: 0.5rem;
}

.sidebar-menu a {
  display: block;
  padding: 0.6rem 0.8rem;
  color: var(--text-dim);
  text-decoration: none;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}

.sidebar-menu a:hover {
  background: var(--border);
  color: var(--text);
}

.users-table-container,
.invites-table-container {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.data-table th {
  background: var(--bg-surface);
  color: var(--text-bright);
  padding: 0.8rem;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}

.data-table td {
  padding: 0.8rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.data-table tr:hover {
  background: var(--bg-surface);
}

.delete-btn {
  padding: 0.4rem 0.8rem;
  background: var(--err);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: opacity 0.15s;
}

.delete-btn:hover {
  opacity: 0.8;
}

.settings-form {
  margin-top: 1.5rem;
}

.setting-item {
  margin-bottom: 1rem;
}

.setting-item label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  color: var(--text);
}

.setting-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.error {
  color: var(--err);
  padding: 0.8rem;
  background: var(--bg-surface);
  border-left: 4px solid var(--err);
  border-radius: 4px;
}

code {
  background: var(--bg);
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  font-family: var(--mono);
  color: var(--accent);
}

/* ---- Settings Page ---- */
.settings-container {
  max-width: 800px;
  padding: 2rem;
}

.settings-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.settings-section h2 {
  margin-top: 0;
  margin-bottom: 1.5rem;
  font-size: 1.2rem;
  color: var(--text-bright);
}

.form-group {
  margin-bottom: 1.2rem;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-bright);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--body-font);
  font-size: 0.95rem;
  border-radius: 4px;
  transition: border-color 0.15s;
  box-sizing: border-box;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group small {
  display: block;
  margin-top: 0.3rem;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.bookmark-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.bookmark-item a {
  color: var(--link);
  text-decoration: none;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bookmark-item a:hover {
  text-decoration: underline;
}

.bookmarks-list .delete-btn {
  flex-shrink: 0;
  padding: 0.4rem 0.8rem;
  background: var(--err);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

.bookmarks-list .delete-btn:hover {
  opacity: 0.8;
}

.notification {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--accent);
  color: #000;
  padding: 1rem 1.5rem;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ---- Logout form/button styled as a link ---- */
.logout-form {
  margin: 0;
  padding: 0;
  display: inline;
}

.logout-link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--link);
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  text-decoration: none;
}

.logout-link-btn:hover {
  text-decoration: underline;
}

/* Logout button inside settings-bar inherits settings-btn look */
.logout-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: inherit;
  padding: 0;
}
