:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d9dee8;
  --text: #111827;
  --muted: #667085;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --danger: #b42318;
  --success: #067647;
  --shadow: none;
  --radius: 2px;
  --font-main: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #111827;
  --panel-soft: #182236;
  --line: #26334d;
  --text: #e5e7eb;
  --muted: #9aa4b2;
  --accent: #60a5fa;
  --accent-2: #3b82f6;
  --danger: #f87171;
  --success: #34d399;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, .button, summary { -webkit-tap-highlight-color: transparent; }

button, a.button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

button:hover, a.button:hover { border-color: var(--accent); }
button[type="submit"], .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button[type="submit"]:hover, .button.primary:hover { background: var(--accent-2); }
.button.ghost { background: var(--panel); }

input, select, textarea {
  width: 100%;
  padding: 0.58rem 0.7rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
}

.shell {
  width: min(1500px, calc(100vw - 36px));
  margin: 0 auto;
  padding: 18px 0 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 14px 16px;
  margin-bottom: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar.public { align-items: center; }
.kicker {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0 0 0.25rem;
}
.topbar h1, .auth-copy h2, .card h2 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 1.9rem);
  letter-spacing: -0.035em;
}

.version-pill {
  display: inline-flex;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-family: var(--font-mono);
}

.nav { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.nav a, .nav button {
  padding: 0.38rem 0.55rem;
  border-radius: var(--radius);
  color: var(--text);
  background: transparent;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.nav a.active {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border: 1px solid var(--accent);
}
.theme-toggle { border: 1px solid var(--line) !important; text-decoration: none !important; }

.content { display: grid; gap: 16px; }
.card, .auth-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 16px; }

/* ThinkDashboard-inspired dashboard structure: controls, title/search, grid columns, text-first links. */
.dash-command {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin: 4px 0 28px;
}

.command-search {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 42px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  color: var(--muted);
}
.command-search span { color: var(--accent); font-weight: 700; }
.command-search input {
  border: 0;
  background: transparent;
  padding-left: 0;
  font-family: var(--font-mono);
  color: var(--text);
  outline: none;
}
.command-search input::placeholder { color: var(--muted); }

.command-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.command-panel { position: relative; }
.command-panel summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  background: var(--panel);
  font-family: var(--font-mono);
  font-size: 0.9rem;
}
.command-panel summary::-webkit-details-marker { display: none; }
.command-panel[open] summary { border-color: var(--accent); }
.command-panel[open] {
  min-width: min(680px, calc(100vw - 36px));
}
.command-panel[open] > :not(summary) {
  margin-top: 8px;
}
.command-panel .compact-form, .command-panel .drop-zone, .command-panel .mini-actions {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}
.compact-form {
  display: grid;
  grid-template-columns: 1fr 1.3fr 0.85fr auto;
  gap: 8px;
  align-items: center;
}
.compact-form-category { grid-template-columns: 1fr auto; }
.drop-zone {
  color: var(--muted);
  background: var(--panel-soft);
  border-style: dashed !important;
}
.mini-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.text-button {
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 0.25rem 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.think-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 34px 48px;
  align-items: start;
}
.think-category {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding-left: 0.4rem;
  border-left: 2px solid color-mix(in srgb, var(--cat-accent, var(--accent)) 72%, transparent);
}
.category-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  min-height: 30px;
}
.category-head h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: 0.055em;
  color: var(--muted);
  text-transform: lowercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.category-head h3::before { content: '// '; color: var(--cat-accent, var(--accent)); }
.category-count {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
}
.category-delete {
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--danger);
  padding: 0;
  font-size: 0.78rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.think-category:hover .category-delete,
.category-delete:focus { opacity: 1; }

.bookmark-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 30px;
  padding: 2px 0 8px;
  border-radius: var(--radius);
  border: 1px dashed transparent;
}
.bookmark-list.drag-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.bookmark {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0;
}
.bookmark.dragging { opacity: 0.45; }
.bookmark-link {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  grid-template-areas: "icon text" "icon host";
  column-gap: 0.55rem;
  row-gap: 0.05rem;
  align-items: center;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
  padding: 0.28rem 0;
  transition: transform 0.15s ease;
}
.bookmark-link:hover { transform: translateX(4px); }
.bookmark-icon {
  grid-area: icon;
  width: 16px;
  height: 16px;
  object-fit: contain;
  opacity: 0.88;
}
.bookmark-text {
  grid-area: text;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
  font-size: 0.96rem;
}
.bookmark-host {
  grid-area: host;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.74rem;
}
.bookmark-actions {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.bookmark:hover .bookmark-actions,
.bookmark:focus-within .bookmark-actions { opacity: 1; }
.icon-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 0.75rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.icon-button:hover { color: var(--accent); }
.danger, .danger:hover { color: var(--danger); }
.empty-hint {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  opacity: 0.75;
}

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.settings-grid .wide { grid-column: 1 / -1; }
.changelog-viewer pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 0.86rem; line-height: 1.45; }
.profile-grid .wide { grid-column: 1 / -1; }
.stack { display: grid; gap: 10px; }
.stack.narrow { max-width: 420px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.simple-list { margin: 0.75rem 0 0; padding-left: 1.1rem; }
.callout, .flash {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-soft);
}
.flash.success { border-color: rgba(16, 185, 129, 0.35); background: rgba(16, 185, 129, 0.10); }
.flash.error { border-color: rgba(239, 68, 68, 0.35); background: rgba(239, 68, 68, 0.10); }
.muted { color: var(--muted); }

.auth-shell { max-width: 1180px; margin: 0 auto; padding: 22px; }
.auth-card { display: grid; grid-template-columns: 0.9fr 1.1fr; gap: 16px; align-items: stretch; }
.auth-copy { padding: 24px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.auth-form { padding: 24px; }
.auth-form form { display: grid; gap: 10px; }
.inline { display: flex; gap: 10px; align-items: center; }
.inline input { width: auto; }
.install-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.install-card { width: min(840px, 100%); }

.footer-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 22px;
  padding: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-family: var(--font-mono);
}
.footer-meta a { text-decoration: underline; text-underline-offset: 3px; }
.mfa-setup { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; margin: 12px 0; }
.mfa-qr { padding: 10px; border: 1px solid var(--line); background: var(--panel-soft); display: grid; place-items: center; }
.mfa-qr img { display: block; width: 220px; height: 220px; image-rendering: pixelated; }

@supports not (color: color-mix(in srgb, red 50%, blue)) {
  .think-category { border-left-color: var(--cat-accent, var(--accent)); }
  .bookmark-list.drag-over { background: transparent; }
}

@media (min-width: 1200px) {
  .think-board { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (min-width: 900px) and (max-width: 1199px) {
  .think-board { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .settings-grid, .auth-card { grid-template-columns: 1fr; }
  .compact-form, .compact-form-category, .grid-2 { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .dash-command { grid-template-columns: 1fr; }
  .command-actions { justify-content: flex-start; }
  .command-panel[open] { min-width: 100%; }
}
@media (max-width: 720px) {
  .mfa-setup { grid-template-columns: 1fr; }
  .mfa-qr { max-width: 240px; }
  .shell { width: min(100% - 24px, 1500px); }
}
