:root {
  --bg: #f6f7f9;
  --surface: #fff;
  --line: #d9dee7;
  --line-strong: #c6ceda;
  --text: #172033;
  --muted: #657085;
  --muted-strong: #465168;
  --accent: #176b87;
  --accent-2: #c2410c;
  --focus: #2563eb;
  --code-bg: #101828;
  --shadow: 0 10px 28px rgba(29, 42, 68, .08);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}
a { color: var(--accent); }
button, input, select { font: inherit; letter-spacing: 0; }
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: 72px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; min-width: 0; }
.brand-mark {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  background: #172033;
  color: #fff;
  border-radius: 8px;
  font-weight: 800;
  font-size: 14px;
}
.brand strong, .brand small { display: block; white-space: nowrap; }
.brand strong { font-size: 18px; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.source-meta { display: flex; align-items: center; justify-content: flex-end; gap: 14px; color: var(--muted); font-size: 13px; min-width: 0; }
.source-meta a {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
}
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 250px minmax(340px, 520px) minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}
.rail {
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  padding: 16px 12px;
  overflow: auto;
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
}
#divisionList { display: grid; gap: 4px; }
.division-button {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted-strong);
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
}
.division-button:hover, .division-button:focus-visible { background: #eef3f8; outline: none; }
.division-button.active { background: #e7eef6; color: var(--text); font-weight: 700; }
.division-button span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.division-button strong { color: var(--muted); font-size: 12px; }
.division-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--division-color, #9aa4b2); }
.division-dot.all { background: linear-gradient(135deg, #176b87, #c2410c); }
.catalog-panel {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 18px;
  overflow: auto;
  height: calc(100vh - 72px);
  position: sticky;
  top: 72px;
}
.tools { display: grid; grid-template-columns: minmax(0,1fr) 150px; gap: 10px; align-items: end; }
.search-field { display: grid; gap: 6px; }
.search-field span, .result-summary { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  padding: 9px 11px;
}
input:focus, select:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.result-summary { margin: 16px 0 10px; }
.agent-grid { display: grid; gap: 10px; }
.agent-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  cursor: pointer;
  text-align: left;
  display: grid;
  gap: 8px;
  box-shadow: 0 1px 0 rgba(20,31,49,.02);
}
.agent-card:hover, .agent-card:focus-visible, .agent-card.active {
  border-color: color-mix(in srgb, var(--division-color, #176b87), #000 10%);
  box-shadow: var(--shadow);
  outline: none;
}
.agent-card.active { background: color-mix(in srgb, var(--division-color, #176b87) 7%, #fff); }
.agent-card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.agent-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.agent-emoji {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: #eef3f8;
  border-radius: 8px;
  flex: 0 0 auto;
}
.agent-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.division-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 160px;
  color: var(--muted-strong);
  background: #f3f5f8;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}
.division-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-description { margin: 0; color: var(--muted-strong); font-size: 13px; line-height: 1.5; }
.agent-vibe { color: var(--accent-2); font-size: 12px; line-height: 1.4; font-weight: 700; }
.reader-panel { padding: 24px clamp(18px, 3vw, 44px); overflow: auto; height: calc(100vh - 72px); }
.empty-state {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  color: var(--muted-strong);
  padding: 40px 0;
}
.empty-state h1 { margin: 18px 0 8px; color: var(--text); font-size: clamp(26px, 4vw, 44px); }
.empty-state p { max-width: 460px; margin: 0; line-height: 1.6; }
.empty-visual {
  width: min(360px, 78vw);
  aspect-ratio: 16 / 9;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  box-shadow: var(--shadow);
}
.empty-visual span { border-radius: 8px; background: #edf1f6; border-left: 8px solid #176b87; }
.empty-visual span:nth-child(2) { border-left-color: #c2410c; }
.empty-visual span:nth-child(3) { border-left-color: #15803d; }
.empty-visual span:nth-child(4) { border-left-color: #b45309; }
.reader.hidden, .empty-state.hidden { display: none; }
.reader { max-width: 920px; margin: 0 auto; }
.reader-header { border-bottom: 1px solid var(--line); padding-bottom: 18px; margin-bottom: 22px; }
.reader-kicker { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--muted); font-size: 13px; font-weight: 700; }
.reader h1 { margin: 0 0 10px; font-size: clamp(28px, 4vw, 48px); line-height: 1.04; }
.reader-header p { color: var(--muted-strong); line-height: 1.6; max-width: 760px; margin: 0; }
.reader-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.reader-actions a, .reader-actions button {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  padding: 9px 11px;
  font-weight: 800;
  cursor: pointer;
}
.reader-actions a.primary { background: var(--text); color: #fff; border-color: var(--text); }
.markdown { color: #202a3d; line-height: 1.7; }
.markdown h1, .markdown h2, .markdown h3 { color: var(--text); line-height: 1.18; }
.markdown h1 { font-size: 30px; margin: 28px 0 12px; }
.markdown h2 { font-size: 24px; margin: 28px 0 10px; border-top: 1px solid var(--line); padding-top: 18px; }
.markdown h3 { font-size: 18px; margin: 20px 0 8px; }
.markdown p, .markdown ul, .markdown ol, .markdown pre { margin: 0 0 14px; }
.markdown ul, .markdown ol { padding-left: 22px; }
.markdown li { margin: 5px 0; }
.markdown code { background: #eef2f6; color: #111827; border-radius: 5px; padding: 2px 5px; font-size: .92em; }
.markdown pre { overflow: auto; border-radius: 8px; background: var(--code-bg); color: #eef2ff; padding: 16px; }
.markdown pre code { background: transparent; color: inherit; padding: 0; }
.markdown blockquote { margin: 0 0 14px; padding: 12px 14px; border-left: 4px solid var(--accent); background: #eef5f7; color: var(--muted-strong); }
@media (max-width: 1120px) { .workspace { grid-template-columns: 220px minmax(300px,420px) minmax(0,1fr); } }
@media (max-width: 920px) {
  .topbar { height: auto; min-height: 68px; padding: 12px 14px; align-items: flex-start; flex-direction: column; }
  .source-meta { width: 100%; justify-content: space-between; }
  .workspace { display: block; min-height: auto; }
  .rail, .catalog-panel, .reader-panel { position: static; height: auto; overflow: visible; border-right: 0; }
  .rail { border-bottom: 1px solid var(--line); padding: 10px; }
  #divisionList { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
  .division-button { width: auto; min-width: 150px; }
  .catalog-panel { border-bottom: 1px solid var(--line); }
  .agent-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
@media (max-width: 560px) {
  .brand small { white-space: normal; }
  .tools { grid-template-columns: 1fr; }
  .agent-card-top { align-items: flex-start; flex-direction: column; }
  .division-pill { max-width: 100%; }
}
