/*
  Clawd Output Dashboard UI
  - dark/light via html[data-theme]
  - mobile nav via html.nav-open

  Aesthetic direction:
  - Editorial + utilitarian: "research terminal meets magazine"
  - Crisp typography (Newsreader + IBM Plex Sans)
  - Subtle grain + ruled lines, no gaudy gradients
*/

:root {
  --bg: #0b0f16;
  --panel: #0f172a;
  --panel2: #0b1223;
  --text: #e5e7eb;
  --muted: rgba(229,231,235,0.66);
  --border: rgba(148, 163, 184, 0.18);
  --link: #7dd3fc;
  --btn: rgba(255,255,255,0.06);
  --btnText: #e5e7eb;
  --btnHover: rgba(255,255,255,0.10);
  --shadow: 0 1px 0 rgba(255,255,255,0.04), 0 18px 40px rgba(0,0,0,0.45);
  --codeBg: rgba(15, 23, 42, 0.9);
  --badgeBg: rgba(148, 163, 184, 0.10);
  --badgeBorder: rgba(148, 163, 184, 0.20);
  --focus: #38bdf8;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;

  --font-sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
  --font-serif: "Newsreader", ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --z-overlay: 40;
  --z-sidebar: 50;
}

html[data-theme="light"] {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel2: #ffffff;
  --text: #0b1220;
  --muted: rgba(2, 6, 23, 0.66);
  --border: rgba(15, 23, 42, 0.12);
  --link: #0284c7;
  --btn: rgba(2, 6, 23, 0.06);
  --btnText: #0b1220;
  --btnHover: rgba(2, 6, 23, 0.10);
  --shadow: 0 1px 0 rgba(15,23,42,0.04), 0 16px 34px rgba(15,23,42,0.10);
  --codeBg: rgba(15, 23, 42, 0.06);
  --badgeBg: rgba(2, 132, 199, 0.08);
  --badgeBorder: rgba(2, 132, 199, 0.18);
  --focus: #0284c7;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

/* subtle ruled + grain overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.55;
  background:
    radial-gradient(1200px 800px at 20% 10%, rgba(56,189,248,0.10), transparent 65%),
    radial-gradient(900px 650px at 95% 0%, rgba(148,163,184,0.10), transparent 60%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.04) 0, rgba(255,255,255,0.04) 1px, transparent 1px, transparent 16px);
  mix-blend-mode: soft-light;
}

html[data-theme="light"] body::before {
  opacity: 0.40;
  background:
    radial-gradient(1200px 800px at 20% 10%, rgba(2,132,199,0.08), transparent 65%),
    radial-gradient(900px 650px at 95% 0%, rgba(2,6,23,0.06), transparent 60%),
    repeating-linear-gradient(0deg, rgba(2,6,23,0.05) 0, rgba(2,6,23,0.05) 1px, transparent 1px, transparent 18px);
  mix-blend-mode: multiply;
}

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

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--font-mono); }

/* layout */
.shell {
  position: relative;
  display: grid;
  grid-template-columns: 296px 1fr;
  min-height: 100vh;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,0.52);
  backdrop-filter: blur(6px);
  z-index: var(--z-overlay);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.0));
  padding: 18px 16px;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow: auto;
  z-index: var(--z-sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text);
}

.brand__icon {
  width: 30px;
  height: 30px;
  border-radius: 12px;
  background: radial-gradient(140% 120% at 0% 0%, rgba(56,189,248,0.30), transparent 55%),
              radial-gradient(120% 140% at 100% 0%, rgba(148,163,184,0.18), transparent 50%),
              rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}

.nav {
  margin-top: 18px;
  display: grid;
  gap: 6px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  color: var(--muted);
}

.nav a:hover {
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
  text-decoration: none;
}

.nav a.active {
  background: rgba(56,189,248,0.14);
  border: 1px solid rgba(56,189,248,0.20);
  color: var(--text);
}

.sidebar__section { margin-top: 18px; }

.sidebar__section-title {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.main { padding: 18px 22px 36px; }

.container { max-width: 1240px; margin: 0 auto; }

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 14px;
}

.topbar__title {
  font-family: var(--font-serif);
  font-weight: 650;
  letter-spacing: 0.2px;
  font-size: 16px;
}

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  color: var(--text);
}

.iconbtn:hover { background: rgba(255,255,255,0.07); }

.pagehead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0.1px;
}

.subhead { margin-top: 6px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* cards & tables */
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.card__title {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.card__body { padding: 12px 14px; }

.mt { margin-top: 16px; }

.tablewrap { overflow: auto; }

.table { width: 100%; border-collapse: collapse; }

.table th,
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  vertical-align: middle;
}

.table th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  font-weight: 700;
}

.table tr:hover td { background: rgba(148, 163, 184, 0.05); }

.right { text-align: right; }

/* badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--badgeBg);
  border: 1px solid var(--badgeBorder);
  color: var(--muted);
  font-size: 11px;
  margin-left: 10px;
}

.badge--dir { color: var(--text); }

.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.7);
}

/* buttons & inputs */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--btn);
  color: var(--btnText);
  border: 1px solid rgba(255,255,255,0.10);
  text-decoration: none;
  font-weight: 650;
  font-size: 13px;
  cursor: pointer;
}

.btn:hover { background: var(--btnHover); text-decoration: none; }

.btn--ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn--ghost:hover { background: rgba(148, 163, 184, 0.08); color: var(--text); }

.btn--sm { padding: 7px 9px; font-size: 12px; border-radius: var(--radius-sm); }

.input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  color: var(--text);
  outline: none;
}

.input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(56,189,248,0.18);
}

/* breadcrumbs */
.breadcrumbs { margin: 10px 0 14px; color: var(--muted); }
.breadcrumbs .sep { margin: 0 6px; opacity: 0.6; }

/* content */
.code {
  background: var(--codeBg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  overflow: auto;
  line-height: 1.35;
}

.markdown { padding: 14px; }
.markdown h1, .markdown h2, .markdown h3 {
  font-family: var(--font-serif);
  margin-top: 18px;
}

.image { max-width: 100%; height: auto; display: block; }

/* youtube-style cards (outliers tab) */
.grid--cards {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

a.ytcard { color: var(--text); text-decoration: none; }
a.ytcard:hover { text-decoration: none; }

.ytcard {
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  box-shadow: var(--shadow);
  transition: transform 120ms ease, border-color 120ms ease;
}

.ytcard:hover {
  transform: translateY(-1px);
  border-color: rgba(56,189,248,0.28);
}

.ytcard__thumb { aspect-ratio: 16/9; background: rgba(148,163,184,0.08); }
.ytcard__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.ytcard__thumb-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}

.ytcard__body { padding: 12px; display: grid; gap: 8px; }

.ytcard__title {
  font-weight: 650;
  font-size: 14px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ytcard__meta .sep { margin: 0 6px; opacity: 0.7; }

/* Discover */
.discover__toolbar { display: grid; gap: 10px; }

.discover__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(148, 163, 184, 0.06);
  font-weight: 650;
  font-size: 12px;
  text-decoration: none;
}

.chip:hover { background: rgba(148, 163, 184, 0.10); color: var(--text); text-decoration: none; }

.chip.active {
  background: rgba(56,189,248,0.14);
  border-color: rgba(56,189,248,0.22);
  color: var(--text);
}

.chip--toggle input { accent-color: var(--focus); }
.chip--field { gap: 10px; }

.chip__input {
  width: 110px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  color: var(--text);
}

.sectionhead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.sectionhead__title {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.sectionhead__link { color: var(--muted); font-size: 12px; }

.row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(280px, 1fr);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x mandatory;
}

.row > * { scroll-snap-align: start; }

.vcard {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr;
}

.vcard--new {
  border-color: rgba(34, 197, 94, 0.65);
  box-shadow:
    0 0 0 1px rgba(34, 197, 94, 0.18),
    0 18px 55px rgba(34, 197, 94, 0.10),
    var(--shadow);
  animation: vcardPulse 900ms ease-out 1;
}

@keyframes vcardPulse {
  0% { transform: translateY(-6px); filter: saturate(1.15); }
  100% { transform: translateY(0); filter: saturate(1); }
}

.vcard__thumb { display: block; aspect-ratio: 16/9; background: rgba(148,163,184,0.08); }
.vcard__thumb img { width: 100%; height: 100%; object-fit: cover; display:block; }

.vcard__thumb-placeholder {
  width:100%;
  height:100%;
  display:grid;
  place-items:center;
  color: var(--muted);
  font-size: 12px;
}

.vcard__body { padding: 12px; display: grid; gap: 8px; }

.vcard__title {
  color: var(--text);
  font-weight: 650;
  font-size: 14px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-decoration: none;
}

.vcard__title:hover { text-decoration: underline; }

.vcard__meta .sep { margin: 0 6px; opacity: 0.7; }

.vcard__badges { display: flex; flex-wrap: wrap; gap: 6px; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--badgeBorder);
  background: var(--badgeBg);
  color: var(--text);
  font-size: 11px;
}

.pill--muted { color: var(--muted); }
.pill--ok { background: rgba(34,197,94,0.12); border-color: rgba(34,197,94,0.22); color: var(--text); }

.vcard__actions { display: flex; gap: 8px; }

.discovergrid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.discovergrid__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.footer { margin-top: 22px; color: var(--muted); font-size: 12px; }

.icon { width: 16px; height: 16px; opacity: 0.9; }

/* Responsive */
@media (max-width: 1024px) {
  .grid--cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .discovergrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 920px) {
  .shell { grid-template-columns: 1fr; }
  .topbar { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 88vw;
    max-width: 360px;
    transform: translateX(-110%);
    transition: transform 160ms ease;
    border-right: 1px solid var(--border);
  }

  html.nav-open .sidebar { transform: translateX(0); }
  html.nav-open .sidebar-overlay { display: block; }

  .main { padding: 14px 14px 26px; }
}

@media (max-width: 640px) {
  .grid--cards { grid-template-columns: 1fr; }
  .discovergrid { grid-template-columns: 1fr; }
  .pagehead { flex-direction: column; }
}

@media (max-width: 680px) {
  .table th:nth-child(2), .table td:nth-child(2) { display: none; }
}
