/* Контент Завод v1 — прототипы экранов
   Дизайн-токены и примитивы в стилистике shadcn/ui (neutral).
   Одноразовые макеты: без сборки, без CDN, без сети. */

:root {
  --background: 0 0% 100%;
  --foreground: 0 0% 3.9%;
  --card: 0 0% 100%;
  --muted: 0 0% 96.1%;
  --muted-foreground: 0 0% 45.1%;
  --border: 0 0% 89.8%;
  --input: 0 0% 89.8%;
  --primary: 0 0% 9%;
  --primary-foreground: 0 0% 98%;
  --accent: 0 0% 96.1%;
  --accent-foreground: 0 0% 9%;
  --destructive: 0 72% 45%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 65% 32%;
  --warning: 38 92% 40%;
  --info: 217 75% 45%;
  --ring: 0 0% 63.9%;
  --radius: 0.5rem;
  --sidebar: 0 0% 98%;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
}

:root.dark {
  --background: 0 0% 7%;
  --foreground: 0 0% 96%;
  --card: 0 0% 9.5%;
  --muted: 0 0% 15%;
  --muted-foreground: 0 0% 63.9%;
  --border: 0 0% 18%;
  --input: 0 0% 18%;
  --primary: 0 0% 96%;
  --primary-foreground: 0 0% 9%;
  --accent: 0 0% 16%;
  --accent-foreground: 0 0% 96%;
  --destructive: 0 62% 52%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 55% 48%;
  --warning: 38 88% 58%;
  --info: 217 78% 65%;
  --ring: 0 0% 45%;
  --sidebar: 0 0% 9%;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
a { color: inherit; }

.muted { color: hsl(var(--muted-foreground)); }
.small { font-size: 12px; }
.xs { font-size: 11px; }
.mono { font-family: var(--font-mono); font-size: 12px; }
.strong { font-weight: 600; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap { flex-wrap: wrap; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mt-32 { margin-top: 32px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }

/* ---------- App shell ---------- */

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.rail {
  width: 56px;
  flex: 0 0 56px;
  background: hsl(var(--sidebar));
  border-right: 1px solid hsl(var(--border));
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;
  gap: 4px;
}

.rail-logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; letter-spacing: -0.03em;
  margin-bottom: 10px;
}

.rail-item {
  position: relative;
  width: 38px; height: 38px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: hsl(var(--muted-foreground));
  text-decoration: none;
  cursor: pointer;
}
.rail-item:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.rail-item.active { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.rail-item.active::before {
  content: ""; position: absolute; left: -9px; top: 8px;
  width: 3px; height: 22px; border-radius: 0 3px 3px 0;
  background: hsl(var(--primary));
}
.rail-item svg { width: 18px; height: 18px; stroke-width: 1.75; }
.rail-item .tip {
  position: absolute; left: 46px; top: 50%; transform: translateY(-50%);
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  padding: 4px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 40;
}
.rail-item:hover .tip { opacity: 1; }
.rail-spacer { flex: 1; }

.panel {
  width: 280px;
  flex: 0 0 280px;
  background: hsl(var(--sidebar));
  border-right: 1px solid hsl(var(--border));
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.panel-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid hsl(var(--border));
}

.panel-section {
  padding: 12px 12px 4px;
}
.panel-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(var(--muted-foreground));
  padding: 0 4px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: 7px;
  color: hsl(var(--foreground));
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
}
.nav-item:hover { background: hsl(var(--accent)); }
.nav-item.active { background: hsl(var(--accent)); font-weight: 500; }
.nav-item svg { width: 15px; height: 15px; color: hsl(var(--muted-foreground)); flex: 0 0 15px; }

/* Фаза-карточка */
.phase {
  display: block;
  padding: 9px 10px;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  background: hsl(var(--card));
  margin-bottom: 6px;
  cursor: pointer;
  text-decoration: none;
}
.phase:hover { border-color: hsl(var(--ring)); }
.phase.active { border-color: hsl(var(--primary)); box-shadow: 0 0 0 1px hsl(var(--primary)); }
.phase.empty { background: transparent; border-style: dashed; }
.phase-title { font-size: 13px; font-weight: 500; }
.phase-meta { font-size: 11px; color: hsl(var(--muted-foreground)); margin-top: 2px; }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: hsl(var(--background));
}

.topbar {
  height: 52px;
  flex: 0 0 52px;
  border-bottom: 1px solid hsl(var(--border));
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: hsl(var(--card));
}

.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.crumbs .sep { color: hsl(var(--muted-foreground)); }

.content { flex: 1; overflow-y: auto; padding: 20px 24px; }
.content.flush { padding: 0; }
.workarea { flex: 1; display: flex; min-height: 0; }
.workarea > .chat { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.workarea > .doc {
  width: 46%;
  flex: 0 0 46%;
  border-left: 1px solid hsl(var(--border));
  display: flex; flex-direction: column;
  background: hsl(var(--card));
}

/* ---------- Primitives ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 13px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid transparent;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  font-size: 13px; font-weight: 500; font-family: inherit;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { opacity: .9; }
.btn svg { width: 15px; height: 15px; }
.btn.outline { background: transparent; color: hsl(var(--foreground)); border-color: hsl(var(--border)); }
.btn.outline:hover { background: hsl(var(--accent)); opacity: 1; }
.btn.ghost { background: transparent; color: hsl(var(--foreground)); }
.btn.ghost:hover { background: hsl(var(--accent)); opacity: 1; }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12px; }
.btn.icon { width: 34px; padding: 0; }
.btn.icon.sm { width: 28px; }
.btn.danger { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.input, .textarea, .select {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: inherit; font-size: 13px;
}
.textarea { height: auto; padding: 9px 10px; resize: none; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: hsl(var(--muted-foreground)); }
.input:focus, .textarea:focus, .select:focus { outline: 2px solid hsl(var(--ring)); outline-offset: -1px; }

.card {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
}
.card-head { padding: 14px 16px; border-bottom: 1px solid hsl(var(--border)); }
.card-body { padding: 16px; }
.card-foot { padding: 12px 16px; border-top: 1px solid hsl(var(--border)); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 8px;
  border-radius: 999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  font-size: 11px; font-weight: 500; white-space: nowrap;
}
.badge.solid { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: transparent; }
.badge.ok { background: hsl(var(--success) / .12); color: hsl(var(--success)); border-color: hsl(var(--success) / .3); }
.badge.warn { background: hsl(var(--warning) / .12); color: hsl(var(--warning)); border-color: hsl(var(--warning) / .3); }
.badge.err { background: hsl(var(--destructive) / .12); color: hsl(var(--destructive)); border-color: hsl(var(--destructive) / .3); }
.badge.info { background: hsl(var(--info) / .12); color: hsl(var(--info)); border-color: hsl(var(--info) / .3); }

.dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; flex: 0 0 6px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-weight: 500; font-size: 12px;
  color: hsl(var(--muted-foreground));
  padding: 9px 12px; border-bottom: 1px solid hsl(var(--border));
  white-space: nowrap;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid hsl(var(--border)); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: hsl(var(--muted) / .5); }

.avatar {
  width: 28px; height: 28px; border-radius: 999px;
  background: hsl(var(--muted)); color: hsl(var(--muted-foreground));
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; flex: 0 0 28px;
}

.sep { height: 1px; background: hsl(var(--border)); margin: 12px 0; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid hsl(var(--border)); }
.tab {
  padding: 8px 12px; font-size: 13px; cursor: pointer;
  color: hsl(var(--muted-foreground));
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: hsl(var(--foreground)); border-bottom-color: hsl(var(--primary)); font-weight: 500; }

/* ---------- Chat ---------- */

.chat-log { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 78%; }
.msg.user { align-self: flex-end; }
.msg-bubble {
  padding: 10px 13px;
  border-radius: 12px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  font-size: 13px;
}
.msg.user .msg-bubble { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: transparent; }
.msg-time { font-size: 11px; color: hsl(var(--muted-foreground)); margin-top: 4px; }
.msg.user .msg-time { text-align: right; }

.run {
  border: 1px solid hsl(var(--border));
  border-radius: 12px;
  background: hsl(var(--card));
  overflow: hidden;
  max-width: 88%;
}
.run-head { padding: 11px 13px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid hsl(var(--border)); }
.run-steps { padding: 6px 13px 10px; display: flex; flex-direction: column; gap: 1px; }
.run-step { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 12.5px; }
.run-step .ico { width: 14px; height: 14px; flex: 0 0 14px; color: hsl(var(--muted-foreground)); }
.run-step.done .ico { color: hsl(var(--success)); }
.run-step.active { font-weight: 500; }
.run-step.pending { color: hsl(var(--muted-foreground)); }
.run-foot { padding: 9px 13px; border-top: 1px solid hsl(var(--border)); background: hsl(var(--muted) / .4); }

.progress { height: 4px; border-radius: 999px; background: hsl(var(--muted)); overflow: hidden; }
.progress > i { display: block; height: 100%; background: hsl(var(--primary)); border-radius: 999px; }

.spin { animation: spin 1.1s linear infinite; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

.composer { border-top: 1px solid hsl(var(--border)); padding: 12px 16px; background: hsl(var(--card)); }
.composer-box {
  border: 1px solid hsl(var(--input)); border-radius: var(--radius);
  padding: 8px 10px; display: flex; align-items: flex-end; gap: 8px;
  background: hsl(var(--background));
}
.composer-box textarea {
  border: none; background: transparent; resize: none; outline: none;
  font-family: inherit; font-size: 13px; color: hsl(var(--foreground));
  flex: 1; height: 40px; line-height: 1.5;
}

/* ---------- Document / editor ---------- */

.doc-head { padding: 12px 16px; border-bottom: 1px solid hsl(var(--border)); }
.doc-body { flex: 1; overflow-y: auto; padding: 20px 22px; }
.doc-body h2 { margin: 0 0 10px; font-size: 17px; }
.doc-body h3 { margin: 20px 0 8px; font-size: 14px; }
.doc-body p { margin: 0 0 10px; font-size: 13.5px; line-height: 1.65; }
.doc-body ul { margin: 0 0 12px; padding-left: 18px; font-size: 13.5px; line-height: 1.65; }
.doc-body li { margin-bottom: 4px; }
.cite {
  font-size: 11px; color: hsl(var(--info));
  border-bottom: 1px dotted hsl(var(--info) / .5); cursor: pointer;
  vertical-align: super; padding: 0 1px;
}
.sel { background: hsl(var(--warning) / .22); border-radius: 3px; padding: 1px 0; box-shadow: 0 0 0 1px hsl(var(--warning) / .35); }
.diff-add { background: hsl(var(--success) / .14); text-decoration: none; }
.diff-del { background: hsl(var(--destructive) / .12); text-decoration: line-through; opacity: .75; }

.popover {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  box-shadow: 0 10px 30px -10px rgb(0 0 0 / .28), 0 2px 8px -2px rgb(0 0 0 / .12);
}

.source-row { display: flex; gap: 10px; padding: 11px 0; border-bottom: 1px solid hsl(var(--border)); }
.source-row:last-child { border-bottom: none; }
.source-num {
  width: 20px; height: 20px; border-radius: 5px; flex: 0 0 20px;
  background: hsl(var(--muted)); color: hsl(var(--muted-foreground));
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600;
}

/* ---------- Prototype chrome ---------- */

.proto {
  position: fixed; top: 0; left: 0; right: 0; height: 34px; z-index: 100;
  background: hsl(var(--foreground)); color: hsl(var(--background));
  display: flex; align-items: center; gap: 12px; padding: 0 12px;
  font-size: 12px;
}
.proto a { color: inherit; text-decoration: none; opacity: .85; }
.proto a:hover { opacity: 1; text-decoration: underline; }
.proto .pill { border: 1px solid currentColor; border-radius: 999px; padding: 1px 8px; opacity: .8; }
body.proto-on { padding-top: 34px; }
body.proto-on .app { height: calc(100vh - 34px); }

.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.c3, .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.empty {
  border: 1px dashed hsl(var(--border));
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  color: hsl(var(--muted-foreground));
}

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; font-size: 13px; }
.kv dt { color: hsl(var(--muted-foreground)); }
.kv dd { margin: 0; }

/* Панель источников внутри инспектора документа (постоянная, не прячет провенанс) */
.sources-pane {
  border-top: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / .35);
  display: flex; flex-direction: column;
  max-height: 34%;
}
.sources-head {
  padding: 9px 14px; display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid hsl(var(--border));
}
.sources-list { overflow-y: auto; padding: 4px 14px 12px; }
.src {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 6px 0; border-bottom: 1px solid hsl(var(--border) / .7);
}
.src:last-child { border-bottom: none; }

/* ---------- Single-sidebar rework (итерация 2 макетов) ---------- */

.panel { width: 264px; flex: 0 0 264px; display: flex; flex-direction: column; overflow: hidden; }
.panel-scroll { flex: 1; overflow-y: auto; }

.ws-box { position: relative; padding: 10px 10px 8px; border-bottom: 1px solid hsl(var(--border)); }
.ws-switch {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 7px 9px;
  border: 1px solid hsl(var(--border));
  border-radius: 9px;
  background: hsl(var(--card));
  font-family: inherit; color: inherit;
  cursor: pointer;
}
.ws-switch:hover { border-color: hsl(var(--ring)); }
.ws-avatar { width: 24px; height: 24px; font-size: 10px; flex: 0 0 24px; border-radius: 7px; }
.ws-chev { width: 15px; height: 15px; color: hsl(var(--muted-foreground)); flex: 0 0 15px; }

.ws-drop {
  display: none;
  position: absolute; left: 10px; right: 10px; top: calc(100% - 4px);
  z-index: 60;
  border: 1px solid hsl(var(--border));
  border-radius: 10px;
  background: hsl(var(--card));
  box-shadow: 0 12px 32px -12px rgb(0 0 0 / .3), 0 3px 10px -3px rgb(0 0 0 / .15);
  padding: 4px;
}
.ws-drop.open { display: block; }

.nav-item.stub { cursor: pointer; }
.phase.stub { cursor: pointer; }

.back-link { margin: 8px 10px 0; color: hsl(var(--muted-foreground)); }
.back-link:hover { color: hsl(var(--foreground)); }
.back-link svg { width: 14px; height: 14px; }

.panel-bottom { border-top: 1px solid hsl(var(--border)); padding: 8px 10px 10px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 7px 9px; margin-top: 2px; }
