/* Mirrors the wls-share console stylesheet (console.share.wildlife.io) so both
   consoles look like one product family. Wild RAG-only pieces live at the end. */

:root {
  --bg: #0f1419;
  --surface: #161c23;
  --surface-2: #1e2731;
  --surface-3: #2a3441;
  --border: #2a3441;
  --text: #e6edf3;
  --text-dim: #8b98a5;
  --text-faint: #5a6776;
  --accent: #5eead4;
  --accent-strong: #14b8a6;
  --danger: #f87171;
  --danger-strong: #dc2626;
  --warn: #fbbf24;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* Modern scrollbars — Firefox + WebKit/Chromium */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
  background-clip: padding-box;
}
::-webkit-scrollbar-corner {
  background: transparent;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  height: 30px;
  width: 30px;
  display: block;
  border-radius: 4px;
}

.brand-sub {
  color: var(--accent);
  font-weight: 500;
}

.user {
  font-size: 13px;
  color: var(--text-dim);
  font-family: var(--mono);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px;
}

/* --- tabs --- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tab {
  display: inline-block;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

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

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.panel.hidden { display: none; }

/* --- landing page --- */
.hero {
  margin: 0 0 32px;
  max-width: 760px;
}

.lead {
  font-size: 15px;
  color: var(--text);
  margin: 0 0 18px;
  text-wrap: pretty;
}

.url-pattern {
  display: inline-block;
  font-family: var(--mono);
  font-size: 14px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  letter-spacing: 0.01em;
}

.url-pattern .dim { color: var(--text-dim); }
.url-pattern .hl {
  color: var(--accent);
  font-weight: 600;
  padding: 0 2px;
  background: rgba(94, 234, 212, 0.08);
  border-radius: 3px;
}

[data-panel="about"] h2 {
  font-size: 17px;
  margin: 32px 0 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

[data-panel="about"] h2:first-of-type {
  border-top: none;
  padding-top: 0;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin: 0 0 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.01em;
}

.card pre {
  margin: 0 0 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
}

.card pre code {
  font-size: 12px;
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text);
  font-family: var(--mono);
  white-space: pre;
}

.card p {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}

.card p a, .lead a, .bullets a {
  color: var(--accent);
  text-decoration: none;
}
.card p a:hover, .lead a:hover, .bullets a:hover { text-decoration: underline; }

.perm-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 6px 18px;
  margin: 0 0 16px;
  font-size: 13px;
}

.perm-grid dt {
  font-weight: 600;
  color: var(--accent);
  padding: 8px 0;
}

.perm-grid dd {
  margin: 0;
  padding: 8px 0;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.perm-grid dt + dd { border-bottom: 1px solid var(--border); }
.perm-grid > :nth-last-child(-n+2) { border-bottom: none; }

.bullets {
  margin: 0 0 16px;
  padding-left: 22px;
  color: var(--text);
  font-size: 13px;
}

.bullets li { margin: 4px 0; }

.callout {
  background: rgba(94, 234, 212, 0.06);
  border: 1px solid rgba(94, 234, 212, 0.25);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text);
  margin: 16px 0;
}

.callout.warn {
  background: rgba(251, 191, 36, 0.08);
  border-color: rgba(251, 191, 36, 0.35);
}

.callout.hidden { display: none; }

/* --- section divider (Browse under Your libraries) --- */
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 40px 0 12px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.section-head h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px;
}

.footer-link {
  margin: 32px 0 12px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-dim);
}

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

/* --- search row (browse) --- */
.search-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}

.search-row input[type="search"] {
  flex: 1;
  font-family: var(--font);
}

.search-count {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

.browse-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.browse-toggle input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.hint {
  color: var(--text-dim);
  margin: 0;
  font-size: 13px;
}

.state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.state.hidden, table.hidden { display: none; }

.state-loading {
  flex-direction: row;
  align-items: center;
  color: var(--text-dim);
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.empty-title, .error-title { margin: 0; font-weight: 600; font-size: 15px; }
.error-title { color: var(--danger); }
.empty-body, .error-body { margin: 0; color: var(--text-dim); }

code {
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 1px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* --- buttons --- */
.btn {
  font: inherit;
  font-size: 13px;
  padding: 7px 14px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--accent-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border); }

.btn-primary {
  background: var(--accent-strong);
  color: #0a0d12;
  border-color: var(--accent-strong);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }

.btn-danger {
  background: var(--danger-strong);
  color: #fff;
  border-color: var(--danger-strong);
  font-weight: 600;
}
.btn-danger:hover { background: var(--danger); border-color: var(--danger); }

.btn-ghost {
  padding: 6px 12px;
  font-size: 12.5px;
}

.btn-row-action {
  padding: 4px 9px;
  font-size: 12px;
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--accent);
  padding: 4px 6px;
  font-size: 12px;
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

/* --- table --- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

th, td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 13px;
}

tbody tr:last-child td { border-bottom: none; }

th {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  background: var(--surface-2);
}

tbody tr:hover { background: var(--surface-2); }

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 240px;
}

.tag {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 2px 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  white-space: nowrap;
}

.tag.tag-squad { color: var(--accent); }
.tag.tag-self { color: #fcd34d; }
.tag.tag-everyone {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.08);
  font-weight: 600;
}
.tag.tag-empty { font-style: italic; color: var(--text-faint); border-style: dashed; }

.col-sync { white-space: nowrap; }
td.col-sync { color: var(--text-dim); }
.col-actions { white-space: nowrap; }
.col-actions .btn { margin-right: 4px; }

.never { color: var(--text-faint); font-style: italic; }

/* --- chips (used in modals) --- */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
  min-height: 24px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 12px;
  padding: 3px 4px 3px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-dim);
  word-break: break-all;
}

.chip-remove {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 4px;
  border-radius: 50%;
}
.chip-remove:hover { color: var(--danger); background: var(--surface-3); }

/* --- dialog (modal) --- */
.dialog {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0;
  max-width: 520px;
  width: 92vw;
  max-height: 88vh;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog form { padding: 22px 22px 18px; }

.field {
  display: block;
  margin: 12px 0;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 6px;
}

fieldset.field {
  border: none;
  padding: 0;
  margin: 14px 0;
}

fieldset.field legend.field-label {
  padding: 0;
  margin-bottom: 6px;
}

.field-help {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin: 4px 0 8px;
}

.field-help .warn {
  color: var(--warn);
}

.field-help.bad { color: var(--danger); }

input[type="text"],
input[type="email"],
input[type="search"],
input[type="password"],
input[type="date"],
textarea,
select {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
}
textarea { resize: vertical; min-height: 60px; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-strong);
}

.add-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 6px 0;
}
.add-row > :first-child { flex: 1; }

.everyone-toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 13px;
}

.everyone-toggle:has(input:checked) {
  border-color: var(--warn);
  background: rgba(251, 191, 36, 0.08);
}

.everyone-toggle input[type="checkbox"] {
  width: auto;
  margin: 2px 0 0;
  accent-color: var(--warn);
  flex: 0 0 auto;
}

.everyone-toggle strong { color: var(--text); }
.everyone-toggle .field-help { display: block; margin-top: 2px; }

[data-role="squads-section"].dim {
  opacity: 0.55;
}

.danger-block {
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid rgba(220, 38, 38, 0.3);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin: 8px 0;
}

.dialog-error {
  color: var(--danger);
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.3);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  margin: 10px 0 0;
}
.dialog-error.hidden { display: none; }

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* --- toast --- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  z-index: 1000;
  max-width: 80vw;
}
.toast.hidden { display: none; }
.toast.toast-success { border-color: var(--accent-strong); }
.toast.toast-error { border-color: var(--danger); color: var(--danger); }

/* === Wild RAG additions ================================================= */

.toast.toast-warn { border-color: var(--warn); }

.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* library cell: slug is the identifier agents use, name + description below */
.lib-link {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
}
.lib-link:hover { text-decoration: underline; }
.lib-link, .lib-name, .lib-desc { overflow-wrap: anywhere; }
.lib-name { color: var(--text); margin-top: 2px; }
.lib-desc { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

/* Fixed column widths keep long slugs, emails and squads from starving the
   other columns; tags wrap inside their cell (emails prefer the @). */
.table-scroll { overflow-x: auto; }
.lib-table { table-layout: fixed; }
.lib-table .col-lib { width: 17%; }
.lib-table .col-owners, .lib-table .col-users { width: 18%; }
.lib-table .col-squads { width: 15%; }
.lib-table .col-sync { width: 100px; }
.lib-table .col-actions { width: 230px; }
#browse-table .col-lib { width: 28%; }
#browse-table .col-owners, #browse-table .col-users { width: 22%; }
#browse-table .col-squads { width: 18%; }
td .tag { white-space: normal; overflow-wrap: anywhere; }

/* sync status */
.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
  background: var(--text-faint);
}
.dot.succeeded { background: var(--accent-strong); }
.dot.running, .dot.creating, .dot.waiting { background: var(--warn); animation: pulse 1.8s ease-in-out infinite; }
.dot.failed { background: var(--danger); }
.status.failed { color: var(--danger); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.kv {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 6px 14px;
  margin: 0;
  font-size: 13px;
}
.kv dt { color: var(--text-faint); font-size: 12px; }
.kv dd { margin: 0; word-break: break-word; white-space: pre-line; }
.kv dd.mono { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.dialog.dialog-wide { max-width: 720px; }

.field-narrow { width: 100%; max-width: 420px; }

.buttons-note { margin: 0 auto 0 0; align-self: center; }

.date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.passages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.passage {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent-strong);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  white-space: pre-wrap;
}

.passage-src {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: normal;
}
.passage-src a { color: var(--accent); text-decoration: none; word-break: break-all; }
.passage-src a:hover { text-decoration: underline; }
.passage-score { margin-left: auto; font-family: var(--mono); color: var(--text-faint); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 760px) {
  header, .tabs { padding-left: 16px; padding-right: 16px; }
  header { flex-wrap: wrap; }
  .user-bar { flex-wrap: wrap; min-width: 0; }
  .user { word-break: break-all; }
  main { padding: 24px 16px; }
  .page-head, .section-head { flex-direction: column; align-items: flex-start; }
  .search-row { flex-wrap: wrap; }
  .table-scroll table { min-width: 1000px; }
  .date-row { grid-template-columns: 1fr; }
}

/* Last on purpose: a utility that must beat every component's display rule. */
.hidden { display: none; }
