:root {
  color-scheme: dark light;
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --border: #2d3a4f;
  --chip-active-bg: #1e3355;
  --overlay: rgba(0, 0, 0, 0.55);
  --fab-shadow: rgba(0, 0, 0, 0.35);
  --a: #ff5c5c;
  --b: #ffb020;
  --c: #f0d030;
  --ok: #3dd68c;
  --prio-a-bg: #4a1520;
  --prio-b-bg: #3d2a10;
  --prio-c-bg: #3a3410;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #eef1f6;
  --text: #1a2332;
  --muted: #5c6b80;
  --accent: #2563eb;
  --border: #d8dee8;
  --chip-active-bg: #dbeafe;
  --overlay: rgba(15, 20, 25, 0.4);
  --fab-shadow: rgba(0, 0, 0, 0.18);
  --prio-a-bg: #fde8e8;
  --prio-b-bg: #fff3e0;
  --prio-c-bg: #fff9e0;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f0f2f5;
    --surface: #ffffff;
    --surface2: #eef1f6;
    --text: #1a2332;
    --muted: #5c6b80;
    --accent: #2563eb;
    --border: #d8dee8;
    --chip-active-bg: #dbeafe;
    --overlay: rgba(15, 20, 25, 0.4);
    --fab-shadow: rgba(0, 0, 0, 0.18);
    --prio-a-bg: #fde8e8;
    --prio-b-bg: #fff3e0;
    --prio-c-bg: #fff9e0;
  }
}

[data-theme="dark"] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

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

.login-card h1 {
  margin: 0;
}

#app-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ИИ: экран ровно во viewport — скролл только внутри колонок */
body:has(#ai-view:not(.hidden)) {
  overflow: hidden;
}
#app-screen:has(#ai-view:not(.hidden)) {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.app-content {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.app-views {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

/* Полноэкранные панели (ИИ): скролл только внутри колонок, не у .app-views */
.app-views:has(#ai-view:not(.hidden)) {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.task-detail-sidebar {
  width: 0;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  transition: width 0.18s ease;
}

.task-detail-sidebar.open {
  width: min(440px, 46vw);
  border-left: 1px solid var(--border);
}

.task-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.task-detail-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.detail-save-status {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.detail-save-status.ok {
  color: var(--ok);
}

.detail-save-status.error {
  color: var(--a);
}

.detail-panel-actions {
  justify-content: flex-start;
}

.task-detail-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  min-width: 0;
  line-height: 1.35;
  word-break: break-word;
  white-space: normal;
}

.detail-close-btn {
  flex-shrink: 0;
  font-size: 1.1rem;
  line-height: 1;
}

.task-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 20px;
}

.detail-meta-block {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 0.85rem;
}

.detail-meta-dl {
  margin: 0;
}

.detail-meta-row {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}

.detail-meta-row:last-child {
  border-bottom: none;
}

.detail-meta-row dt {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
}

.detail-meta-row dd {
  margin: 0;
  word-break: break-word;
}

.task-item.selected {
  border-color: var(--accent);
  background: var(--chip-active-bg);
}

@media (max-width: 768px) {
  .app-content {
    position: relative;
  }

  .task-detail-sidebar.open {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(100%, 420px);
    z-index: 15;
    box-shadow: -6px 0 24px var(--fab-shadow);
  }
}

.top-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.header-left h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.link-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
}

.link-btn:hover {
  color: var(--text);
  background: var(--surface2);
}
.link-btn.disabled {
  cursor: default;
  opacity: 0.6;
}
.link-btn.disabled:hover {
  color: var(--muted);
  background: transparent;
}
.link-btn.active {
  color: var(--text);
  background: var(--surface2);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  padding: 0;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.settings-layout {
  display: flex;
  min-height: calc(100vh - 52px);
}

.settings-main {
  display: flex;
  flex: 1;
  min-width: 0;
}

.settings-projects-content {
  max-width: 720px;
}

.settings-hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.92rem;
}

.project-access-project-label {
  display: block;
  margin-bottom: 16px;
  font-size: 0.92rem;
}

.project-access-project-label select {
  display: block;
  margin-top: 6px;
  width: 100%;
  max-width: 360px;
}

.project-access-table-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
}

.project-access-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.project-access-table th,
.project-access-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.project-access-table th:not(:first-child),
.project-access-table td.project-access-check {
  text-align: center;
  width: 120px;
}

.project-access-table tbody tr:hover {
  background: var(--surface2);
}

.project-access-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 0;
}

.settings-nav-item {
  display: block;
  padding: 10px 16px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}

.settings-nav-item:hover,
.settings-nav-item.active {
  color: var(--text);
  background: var(--surface2);
}

.settings-list-pane {
  flex: 1;
  min-width: 0;
  padding: 16px;
  overflow-y: auto;
}

.settings-detail-pane {
  width: 34%;
  min-width: 260px;
  max-width: 400px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--surface);
  padding: 16px;
  overflow-y: auto;
}

.settings-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.settings-list-header h2 {
  margin: 0;
  font-size: 1rem;
}

.settings-users-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-user-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: inherit;
  font: inherit;
}

.settings-user-item:hover {
  border-color: var(--accent);
}

.settings-user-item.selected {
  border-color: var(--accent);
  background: var(--chip-active-bg);
}

.settings-user-item strong {
  font-size: 0.95rem;
}

.settings-user-item span {
  font-size: 0.8rem;
  color: var(--muted);
}

.settings-form label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 10px 0 4px;
}

.settings-form input,
.settings-form select {
  width: 100%;
}

.settings-form h3 {
  margin: 0 0 12px;
  font-size: 0.95rem;
}

.user-danger-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.user-danger-actions button {
  width: auto;
  margin: 0;
}

.settings-user-item.is-inactive {
  opacity: 0.65;
}

.settings-user-item .user-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.72rem;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
  vertical-align: middle;
}

.settings-user-item .user-badge.off {
  color: #c0392b;
  border-color: color-mix(in srgb, #c0392b 40%, var(--border));
}

.muted-field {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 12px 0;
}

#tasks-view .toolbar {
  padding: 10px 16px 0;
}

#tasks-view .status-bar {
  padding: 0 16px;
}

#tasks-view main {
  max-width: none;
  margin: 0;
  padding: 8px 16px 80px;
}

.app-content.task-detail-open #tasks-view main {
  max-width: 900px;
  margin: 0 auto;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 4px;
  transition: border-color 0.15s;
}

.task-item:hover {
  border-color: var(--accent);
}

.task-done-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.task-done-btn:hover {
  border-color: var(--a);
  color: var(--a);
  background: var(--prio-a-bg);
}

.task-line {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.35;
}

.task-id {
  flex-shrink: 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.task-prio {
  flex-shrink: 0;
  font-size: 0.78rem;
  font-weight: 600;
}

.task-prio.prio-A { color: var(--a); }
.task-prio.prio-B { color: var(--b); }
.task-prio.prio-C { color: var(--c); }
.task-prio.prio-D { color: var(--muted); }

.task-est {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.task-title {
  flex: 1 1 120px;
  min-width: 0;
  word-break: break-word;
}

.task-tail {
  flex: 1 1 100%;
  font-size: 0.75rem;
  color: var(--muted);
}

@media (min-width: 480px) {
  .task-tail {
    flex: 0 1 auto;
    margin-left: auto;
    text-align: right;
    max-width: 45%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.login-card .hint {
  color: var(--muted);
  margin: 0 0 16px;
  font-size: 0.9rem;
}

.login-card label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 10px 0 4px;
}

.login-card input {
  width: 100%;
}

.password-field {
  position: relative;
  display: flex;
  align-items: center;
}

.password-field input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.password-toggle:hover {
  color: var(--text);
  background: var(--surface2);
}

.password-toggle svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.remember-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin: 12px 0 0 !important;
  font-size: 0.9rem !important;
  color: var(--text) !important;
  cursor: pointer;
  user-select: none;
}

.remember-row input {
  width: auto !important;
  margin: 0;
  accent-color: var(--accent);
}

.login-card button[type="submit"] {
  width: 100%;
  margin-top: 16px;
}

.admin-user-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.admin-user-row .tag {
  color: var(--accent);
}

.admin-user-row .muted {
  color: var(--muted);
  font-size: 0.8rem;
}

.admin-create label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 8px 0 4px;
}

.admin-create input,
.admin-create select {
  width: 100%;
}

.admin-card {
  max-width: 520px;
}

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

select,
input,
textarea,
button {
  font: inherit;
}

select,
input,
textarea {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 500;
}

button.secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

button.danger {
  background: #c0392b;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.85rem;
  cursor: pointer;
}

.chip.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--chip-active-bg);
}

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 16px 0 8px;
}

.task-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 32px 16px;
}

.panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* legacy panel — удалён, оставлены общие panel-actions */

.events {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.event {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.create-form {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 16px;
}

.create-form.open {
  display: block;
}

.create-form label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 8px 0 4px;
}

.create-form input,
.create-form select,
.create-form textarea {
  width: 100%;
}

.detail-form label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 10px 0 4px;
}

.detail-form input,
.detail-form select,
.detail-form textarea {
  width: 100%;
}

.detail-form textarea {
  resize: vertical;
  min-height: 120px;
  font-family: inherit;
  line-height: 1.45;
}

.tag-field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  position: relative;
}

.tag-field:focus-within {
  border-color: var(--accent);
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--chip-active-bg);
  font-size: 0.85rem;
  max-width: 100%;
}

.tag-chip.phantom {
  border: 1px dashed var(--muted);
}

.tag-chip button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0 2px;
  font-size: 1rem;
  line-height: 1;
}

.tag-field-input {
  flex: 1;
  min-width: 120px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  padding: 2px 0;
}

.tag-suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px var(--fab-shadow);
  max-height: 180px;
  overflow-y: auto;
}

.tag-suggest-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

.tag-suggest-item:hover,
.tag-suggest-item.active {
  background: var(--surface2);
}

.tag-suggest-item .muted {
  color: var(--muted);
  font-size: 0.82rem;
}

.detail-form .panel-actions {
  margin-top: 16px;
}

.detail-form .panel-actions button[type="submit"] {
  flex: 1;
  min-width: 120px;
}

.status-bar {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
}

.status-bar.error {
  color: var(--a);
}

.gamification-badge {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--chip-bg, rgba(0, 0, 0, 0.06));
  white-space: nowrap;
}

.xp-toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  padding: 10px 16px;
  border-radius: 10px;
  background: #1a7f37;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  max-width: min(92vw, 420px);
  text-align: center;
}

.xp-toast.level-up {
  background: linear-gradient(135deg, #7c3aed, #2563eb);
}

.xp-toast.hidden {
  display: none;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 1.6rem;
  line-height: 1;
  box-shadow: 0 4px 16px var(--fab-shadow);
}

.boot-loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.95rem;
}

@media (max-width: 480px) {
  header { padding: 10px 12px; }
  main { padding: 10px 12px 72px; }
}

/* OKR */
.okr-block {
  margin: 0 16px 8px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 20vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.okr-compact-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.okr-compact-head h2 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
}

.okr-filter-hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.75rem;
}

.okr-compact-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.okr-obj-compact {
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.okr-obj-compact:last-child {
  border-bottom: none;
}

.okr-obj-compact-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}

.okr-o-title {
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
}

.okr-kr-lines {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.okr-kr-line {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  line-height: 1.3;
  color: var(--muted);
}

.tasks-status {
  margin: 0 0 8px;
  min-height: 1.2em;
}

main .tasks-status:empty {
  display: none;
}

.okr-kr-code {
  font-weight: 600;
  color: var(--text);
  min-width: 22px;
}

.okr-kr-pct {
  min-width: 28px;
  text-align: right;
  font-size: 0.68rem;
}

.okr-kr-mini-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.okr-progress-mini {
  width: 48px;
  min-width: 48px;
  max-width: 48px;
  height: 4px;
  flex: none;
}

.okr-proj-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  font-size: 0.9rem;
  flex-shrink: 0;
  line-height: 1;
}

.okr-proj-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--chip-active-bg);
  color: var(--accent);
  white-space: nowrap;
}

.okr-proj-personal {
  color: var(--muted);
  background: var(--surface2);
}

.okr-owner-badge {
  font-size: 0.72rem;
  color: var(--muted);
}

.okr-obj-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.okr-obj-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.okr-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn.danger-icon:hover {
  color: var(--a);
}

.okr-objective {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.okr-objective h3 {
  margin: 0 0 6px;
  font-size: 0.92rem;
  font-weight: 600;
}

.okr-hint {
  margin: 0 0 10px;
  font-size: 0.8rem;
}

.okr-layers-hint {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

.okr-layers-hint summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
}

.okr-edit-card {
  max-width: 420px;
}

.okr-kr-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.okr-kr {
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.okr-kr-child {
  margin-left: 16px;
  padding-left: 8px;
  border-left: 2px solid var(--accent);
}

.okr-kr-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.85rem;
}

.okr-kr-title {
  font-size: 0.9rem;
  margin: 2px 0;
}

.okr-target {
  font-size: 0.8rem;
  color: var(--muted);
}

.okr-owner {
  font-size: 0.75rem;
  color: var(--muted);
}

.okr-progress {
  position: relative;
  flex: 1;
  min-width: 80px;
  max-width: 140px;
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}

.okr-progress-fill {
  height: 100%;
  background: var(--ok);
  border-radius: 4px;
  transition: width 0.2s;
}

.okr-progress span {
  position: absolute;
  right: 0;
  top: -16px;
  font-size: 0.7rem;
  color: var(--muted);
}

.okr-warn {
  font-size: 0.8rem;
  color: var(--b);
  margin: 4px 0;
}

.okr-page {
  display: grid;
  gap: 16px;
  padding: 12px 16px 80px;
}

@media (min-width: 900px) {
  .okr-page {
    grid-template-columns: 1fr 1.2fr;
    align-items: start;
  }
}

.okr-guidelines {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.okr-rules {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
  margin: 0;
}

.okr-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.okr-toolbar {
  display: flex;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.okr-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.okr-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
}

.okr-create-panel {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.okr-create-panel summary {
  cursor: pointer;
  font-weight: 600;
}

.okr-slider {
  width: 100%;
  max-width: 200px;
  margin-top: 4px;
}

/* ── Шаблонные поля (PHASE8) ── */
.tpl-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.tpl-field label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
}

.tpl-field input,
.tpl-field select,
.tpl-field textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  padding: 5px 8px;
}

.tpl-field textarea {
  resize: vertical;
  min-height: 56px;
}

#detail-template-fields,
#create-template-fields {
  margin-top: 4px;
}

/* ── Планировщик дня (PHASE10) ── */
.plan-container {
  max-width: 700px;
  margin: 0 auto;
  padding: 16px 20px;
}

.plan-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.plan-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
}

.plan-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.plan-controls input[type="number"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 3px 6px;
  font-size: 0.85rem;
}

.plan-wip-warning {
  background: rgba(255, 176, 32, 0.12);
  border: 1px solid rgba(255, 176, 32, 0.4);
  border-radius: 8px;
  color: var(--b);
  padding: 8px 12px;
  font-size: 0.88rem;
  margin-bottom: 12px;
}

.plan-section {
  margin-bottom: 16px;
}

.okr-suggest-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 4px 0 8px;
  line-height: 1.4;
}

.plan-section-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.plan-kr-tag {
  font-size: 0.75rem;
  background: rgba(61, 139, 253, 0.15);
  color: var(--accent);
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 4px;
}

.plan-badge {
  display: inline-block;
  font-size: 0.72rem;
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 4px;
  font-weight: 600;
}

.plan-badge.overdue {
  background: rgba(255, 92, 92, 0.2);
  color: var(--a);
}

.plan-badge.due-today {
  background: rgba(255, 176, 32, 0.2);
  color: var(--b);
}

.plan-badge.due-tomorrow {
  background: rgba(240, 208, 48, 0.15);
  color: var(--c);
}

/* ── Поля дат и OKR KR в детали задачи ── */
.detail-dates-row {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  align-items: center;
  gap: 6px 8px;
  margin: 6px 0 2px;
}
.detail-dates-row label { font-size: 0.78rem; color: var(--text-muted, #888); white-space: nowrap; margin: 0; }
.detail-dates-row input { padding: 4px 6px; border-radius: 6px; font-size: 0.85rem; }
.detail-tags-row {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  align-items: center;
  gap: 6px 8px;
  margin: 6px 0 2px;
}
.detail-tags-row label { font-size: 0.78rem; color: var(--text-muted, #888); white-space: nowrap; margin: 0; }
.detail-tags-row select { padding: 4px 6px; border-radius: 6px; font-size: 0.85rem; }
.muted-label { font-size: 0.78rem; color: var(--text-muted, #888); }

/* ── Блокеры (PHASE11) ── */
.blocker-info {
  font-size: 0.85rem;
  padding: 5px 8px;
  border-radius: 6px;
  margin-top: 6px;
  background: rgba(255, 92, 92, 0.08);
  border: 1px solid rgba(255, 92, 92, 0.2);
  color: var(--text);
}

.blocker-info a.blocker-link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.blocker-info a.blocker-link:hover {
  opacity: 0.8;
}


/* --- Аудио с диктофона --- */
.audio-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

/* --- Документы / текст (на странице Аудио) --- */
.docs-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.docs-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.88rem;
}
.docs-tab:hover { border-color: var(--accent); }
.docs-tab.active {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.docs-pane { margin-bottom: 12px; }
.docs-url-input { width: 100%; box-sizing: border-box; }
.docs-textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  line-height: 1.45;
  resize: vertical;
  min-height: 140px;
}
.docs-textarea:focus { outline: none; border-color: var(--accent); }
.docs-kind-badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  margin-right: 6px;
}
.docs-content-preview {
  white-space: pre-wrap;
  font-size: 0.88rem;
  line-height: 1.45;
  max-height: 50vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
}
.audio-header h2 { margin: 0 0 4px; }
.audio-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 16px;
}
.audio-form { margin-bottom: 24px; }
/* Ряд «загрузка файла + запись с микрофона» */
.audio-source-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
}
.audio-drop {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.audio-drop:hover,
.audio-drop.dragover {
  border-color: var(--accent);
  background: var(--surface2);
}
.audio-drop-icon { font-size: 1.6rem; }
.audio-drop-text { margin-top: 4px; font-weight: 600; }
.audio-drop-sub { margin-top: 3px; color: var(--muted); font-size: 0.8rem; }
.audio-picked {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  word-break: break-all;
}

/* Блок записи СЛЕВА от зоны загрузки — кнопка-иконка микрофона */
.audio-record {
  flex: 0 0 104px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 6px;
}
.audio-record-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  min-height: 100%;
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.audio-record-btn:hover { border-color: var(--accent); color: var(--accent); }
.audio-mic-icon { display: block; }
.audio-record-label { font-size: 0.8rem; font-weight: 600; }
.audio-record-btn.recording {
  border-color: #e5484d;
  background: rgba(229, 72, 77, 0.10);
  color: #e5484d;
}
.audio-record-btn.recording .audio-mic-icon {
  animation: audio-rec-pulse 1.1s ease-in-out infinite;
}
@keyframes audio-rec-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.9); }
}
.audio-record-time {
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.95rem;
  color: #e5484d;
  flex: 0 0 auto;
}
.audio-record-cancel {
  flex: 0 0 auto;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
}
.audio-record-cancel:hover { border-color: #e5484d; color: #e5484d; }

/* Эквалайзер уровня микрофона — вертикальные полоски */
.audio-record-eq {
  flex: 1 1 auto;
  min-width: 60px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 34px;
}
.audio-record-eq > span {
  flex: 1 1 0;
  min-width: 2px;
  height: 8%;
  border-radius: 2px 2px 0 0;
  background: linear-gradient(180deg, #e5484d 0%, #d29922 45%, #3fb950 100%);
  transition: height .07s linear;
}

/* Во время записи строка становится горизонтальной, зона загрузки прячется */
.audio-source-row.recording .audio-drop { display: none; }
.audio-source-row.recording .audio-record {
  flex: 1 1 100%;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid #e5484d;
  border-radius: 12px;
  background: rgba(229, 72, 77, 0.06);
}
.audio-source-row.recording .audio-record-btn {
  flex: 0 0 auto;
  flex-direction: row;
  width: auto;
  min-height: 0;
  gap: 8px;
  padding: 9px 16px;
  border-color: #e5484d;
  background: #e5484d;
  color: #fff;
}
.audio-source-row.recording .audio-record-btn:hover { color: #fff; }

/* Проект + тип записи + заметка в одну строку */
.audio-meta-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.audio-input {
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  font-size: 0.88rem;
  height: 38px;
}
.audio-input:focus { outline: none; border-color: var(--accent); }
.audio-input:hover { border-color: var(--accent); }
/* селекты: убираем нативный вид, рисуем свою стрелку — видно, что кликабельно */
select.audio-input {
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238b9cb3' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}
#audio-project, #audio-type { flex: 1 1 0; }
#audio-note { flex: 1.6 1 0; }
/* пустой селект выглядит как placeholder */
select.audio-input.is-placeholder { color: var(--muted); }
@media (max-width: 640px) {
  .audio-source-row { flex-direction: column; }
  .audio-record { flex-basis: auto; }
  .audio-meta-row { flex-wrap: wrap; }
  #audio-note { flex-basis: 100%; }
}
/* Подробность FollowUp: 1-5, по умолчанию 4 */
.audio-detail-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.audio-detail-label {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}
.audio-detail-levels {
  display: flex;
  gap: 4px;
}
.audio-detail-btn {
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.audio-detail-btn:hover { border-color: var(--accent); color: inherit; }
.audio-detail-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.audio-d-comment { margin-top: 12px; }
.audio-comment-input {
  width: 100%;
  resize: vertical;
  font: inherit;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: inherit;
  box-sizing: border-box;
}
.audio-d-classify { margin-top: 12px; }
.audio-tasks-accordion { margin-top: 12px; }
.audio-tasks-accordion > summary {
  cursor: pointer;
  list-style: none;
}
.audio-tasks-accordion > summary::-webkit-details-marker { display: none; }
.audio-tasks-accordion > summary::before { content: "▸ "; }
.audio-tasks-accordion[open] > summary::before { content: "▾ "; }
@media (max-width: 640px) {
  .audio-detail-row { flex-wrap: wrap; }
}

.audio-list { list-style: none; margin: 8px 0 0; padding: 0; }
.audio-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 8px;
}
.audio-item-name { font-weight: 600; word-break: break-all; }
.audio-item-meta { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.audio-empty { color: var(--muted); padding: 12px 0; }

/* --- Zoom: модалка со списком облачных записей --- */
.zoom-modal-card { width: min(640px, 100%); }
.zoom-list { max-height: 50vh; overflow-y: auto; }
.zoom-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.zoom-item .audio-item-main { min-width: 0; }
.zoom-item .audio-item-title { font-weight: 600; }
.zoom-item .audio-item-sub { font-size: 0.82rem; margin-top: 2px; }
.zoom-item.zoom-item-done { opacity: 0.65; }

.audio-progress { margin-top: 12px; }
.audio-progress-track {
  height: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.audio-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width .12s linear;
}
.audio-progress-text {
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--muted);
}

/* --- Аудио: статусы обработки и транскрипт --- */
.audio-item-row { display: flex; align-items: flex-start; gap: 10px; justify-content: space-between; }
.audio-item-left { min-width: 0; }
.audio-badge {
  flex: none;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.audio-badge-pending    { color: var(--muted); }
.audio-badge-processing { color: var(--accent); border-color: var(--accent); }
.audio-badge-done       { color: #1a7f37; border-color: #1a7f3766; }
.audio-badge-failed     { color: #b3261e; border-color: #b3261e66; }
.audio-item-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.audio-item-progress { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.audio-item-progress-track {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.audio-item-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width .3s ease;
}
.audio-item-progress-text { flex: none; font-size: 0.78rem; color: var(--muted); }
.audio-item-error { margin-top: 4px; font-size: 0.82rem; color: #b3261e; word-break: break-word; }
.audio-transcript {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 340px;
  overflow-y: auto;
  font-family: inherit;
}
@media (prefers-color-scheme: dark) {
  .audio-badge-done { color: #4ac26b; }
  .audio-badge-failed { color: #ff7b72; }
}

/* --- Аудио: классификация (тип/проект) --- */
.audio-item-class { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.audio-chip {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.audio-item-summary { margin-top: 4px; font-size: 0.85rem; color: var(--text); }

/* --- Аудио: шаг 4 (FollowUp) и содержание --- */
.audio-item-file { font-size: 0.78rem; color: var(--muted); margin-top: 2px; word-break: break-all; }
.audio-followup {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 420px;
  overflow-y: auto;
}
.audio-fu-download { display: inline-block; margin-bottom: 8px; }
.audio-fu-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.5;
}

/* --- Аудио v2: сжатый аплоад, кликабельная карточка, сайдбар --- */
.audio-container { padding: 12px 16px; }
.audio-drop { padding: 12px 16px; }
.audio-drop-icon { font-size: 1.3rem; }
.audio-drop-text { margin-top: 2px; font-size: 0.9rem; }
.audio-drop-sub { margin-top: 2px; }
.audio-form { margin-bottom: 16px; }

.audio-item-clickable { cursor: pointer; transition: border-color .12s; }
.audio-item-clickable:hover { border-color: var(--accent); }

.audio-detail-sidebar .task-detail-body { padding: 12px 14px; overflow-y: auto; }
.audio-d-summary { font-size: 0.95rem; color: var(--text); margin: 0 0 8px; font-weight: 600; }
.audio-d-actions { margin: 10px 0; display: flex; flex-wrap: wrap; gap: 8px 14px; }
.audio-d-followup { font-size: 0.9rem; line-height: 1.55; }
.audio-d-followup h3 { font-size: 1.05rem; margin: 10px 0 4px; }
.audio-d-followup h4 { font-size: 0.95rem; margin: 12px 0 4px; color: var(--accent); }
.audio-d-followup h5 { font-size: 0.9rem; margin: 8px 0 3px; }
.audio-d-followup p { margin: 4px 0; }
.audio-d-followup ul { margin: 4px 0 8px; padding-left: 20px; }
.audio-d-followup ul.md-tasks { list-style: none; padding-left: 0; }
.audio-d-followup ul.md-tasks li { margin: 3px 0; }

/* --- Аудио: утверждение задач --- */
.audio-tasks { margin-top: 14px; }
.audio-tasks-rows { display: flex; flex-direction: column; gap: 6px; }
.audio-task-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px; align-items: center; }
.audio-task-title { min-width: 0; }
.audio-task-assignee, .audio-task-priority { max-width: 130px; }
.audio-tasks-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.audio-tasks-submit { padding: 5px 12px; }

/* --- Аудио: ресайз сайдбара --- */
.audio-detail-sidebar { position: relative; }
.audio-detail-sidebar.open { width: var(--audio-sidebar-w, min(460px, 46vw)); }
.audio-resize-handle { position: absolute; left: 0; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 6; }
.audio-resize-handle:hover { background: var(--accent); opacity: 0.5; }
body.resizing-x { cursor: col-resize; user-select: none; }

/* --- База знаний: навигация --- */
.knowledge-container { max-width: 820px; margin: 0 auto; padding: 12px 16px; }
.knowledge-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.knowledge-tabs { display: flex; gap: 6px; }
.knowledge-content {
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  padding: 16px 20px; line-height: 1.6; font-size: 0.95rem; overflow-x: auto;
}
.knowledge-content h2 { font-size: 1.08rem; margin: 14px 0 5px; color: var(--accent); font-weight: 650; }
.knowledge-content h3 { font-size: 0.98rem; margin: 10px 0 4px; font-weight: 600; }
.knowledge-content h4 { font-size: 0.92rem; margin: 10px 0 4px; color: var(--muted); }
.knowledge-content p { margin: 6px 0 8px; line-height: 1.55; }
.knowledge-content ul, .knowledge-content ol { margin: 5px 0 10px; padding-left: 22px; }
.knowledge-content ul.md-tasks { list-style: none; padding-left: 0; }
.knowledge-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.knowledge-content code { background: var(--surface2); padding: 1px 5px; border-radius: 4px; font-size: 0.88em; }
.knowledge-content pre.md-code { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.knowledge-content pre.md-code code { background: none; padding: 0; }
.knowledge-content a { color: var(--accent); text-decoration: none; }
.knowledge-content a:hover { text-decoration: underline; }
.knowledge-content blockquote {
  margin: 8px 0 12px;
  padding: 6px 10px;
  border-left: 3px solid var(--accent);
  background: var(--surface2);
  color: var(--muted);
  border-radius: 0 6px 6px 0;
  font-size: 0.84rem;
  line-height: 1.45;
}
.knowledge-content blockquote p { margin: 3px 0; font-size: inherit; }
.knowledge-content table.md-table { width: 100%; border-collapse: collapse; margin: 10px 0 14px; font-size: 0.88rem; display: block; overflow-x: auto; }
.knowledge-content table.md-table th, .knowledge-content table.md-table td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.knowledge-content table.md-table th { background: var(--surface2); font-weight: 600; white-space: nowrap; }
.knowledge-content table.md-table tr:nth-child(even) td { background: color-mix(in srgb, var(--surface2) 40%, transparent); }

/* Встроенное видео: компактный 16:9 ≈ 7 строк текста */
.wiki-video {
  display: inline-block;
  vertical-align: top;
  margin: 8px 12px 10px 0;
  max-width: 100%;
}
.wiki-video-shell {
  position: relative;
  height: calc(1.55em * 7);
  width: calc(1.55em * 7 * 16 / 9);
  max-width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: #14181f;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.wiki-video-poster {
  position: absolute;
  inset: 0;
  background: center / cover no-repeat #1b2230;
  transition: opacity .2s ease;
}
.wiki-video-el {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.wiki-video-embed {
  border: 0;
  object-fit: unset;
}
.wiki-video-gdrive .wiki-video-poster { opacity: 0; }
.wiki-video-bar .wiki-video-open {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--accent);
  text-decoration: none;
  line-height: 1.3;
}
.wiki-video-bar .wiki-video-open:hover { text-decoration: underline; }
.wiki-video-play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 2.2rem;
  height: 2.2rem;
  border: none;
  border-radius: 999px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 2px;
}
.wiki-video-play:hover { background: rgba(0,0,0,.72); }
.wiki-video-status {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 4px 6px;
  font-size: 0.68rem;
  line-height: 1.2;
  color: rgba(255,255,255,.88);
  background: linear-gradient(transparent, rgba(0,0,0,.55));
  z-index: 1;
  pointer-events: none;
  text-align: center;
}
.wiki-video-playing .wiki-video-poster { opacity: 0; }
.wiki-video-playing .wiki-video-status { display: none; }
.wiki-video-bar {
  display: flex;
  gap: 4px;
  margin-top: 5px;
  flex-wrap: wrap;
}
.wiki-video-bar button {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  line-height: 1.3;
}
.wiki-video-bar button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.wiki-video-bar .wiki-video-fs { margin-left: auto; }
.wiki-video-error .wiki-video-shell { outline: 1px solid #c45; }
.wiki-visual-editor .wiki-video-shell { cursor: default; opacity: 0.92; }
.wiki-visual-editor .wiki-video-play { display: none; }

/* --- Issue reports (модерация репортов об ошибках) --- */
.issues-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.issues-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.issue-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.issue-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.issue-card-head .issue-id { font-weight: 600; color: var(--muted); }
.issue-card-head select { font-size: 0.82rem; padding: 2px 6px; border-radius: 5px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.issue-card-head .issue-author { font-size: 0.82rem; }
.issue-card-head .issue-date { font-size: 0.76rem; margin-left: auto; }
.issue-body { margin: 8px 0; white-space: pre-wrap; word-break: break-word; }
.issue-ctx { font-size: 0.76rem; word-break: break-all; margin-bottom: 8px; }
.issue-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.issue-foot .issue-note { flex: 1; min-width: 160px; padding: 4px 8px; border-radius: 5px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); font-size: 0.82rem; }

/* --- База знаний v2: вкладки проектов/страниц, редактор --- */
.knowledge-projects { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.knowledge-proj-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.knowledge-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.knowledge-pages { display: flex; flex-wrap: wrap; gap: 6px; }
.knowledge-page-tab.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.knowledge-actions { display: flex; gap: 4px; }
.knowledge-editor { display: flex; flex-direction: column; gap: 8px; }
#knowledge-textarea { width: 100%; min-height: 55vh; resize: vertical; font-family: ui-monospace, monospace; font-size: 0.88rem; line-height: 1.5; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.knowledge-editor-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.wiki-archive-btn { margin-left: auto; }

/* --- База знаний: вики (Obsidian-lite) --- */
.knowledge-container.wiki { max-width: none; width: 100%; margin: 0; padding: 12px 20px 24px; box-sizing: border-box; }
.wiki-layout { display: flex; gap: 16px; align-items: flex-start; }
.wiki-notes { flex: 0 0 280px; max-height: calc(100vh - 120px); overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); padding: 8px; position: sticky; top: 8px; }
.wiki-notes-head { display: flex; gap: 6px; margin-bottom: 6px; position: sticky; top: 0; background: var(--surface); z-index: 1; padding-bottom: 4px; }
#wiki-search { flex: 1; min-width: 0; }
.wiki-note-list { list-style: none; margin: 0; padding: 0; }
.wiki-note-group { margin: 0 0 6px; }
.wiki-note-group-label { cursor: pointer; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); padding: 4px 6px; user-select: none; list-style: none; }
.wiki-note-group-label::-webkit-details-marker { display: none; }
.wiki-note-group-list { list-style: none; margin: 0; padding: 0 0 4px; }
.wiki-note-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 0.88rem; line-height: 1.25; }
.wiki-note-item.wiki-note-draft { font-style: italic; color: var(--muted); }
.wiki-note-item.wiki-note-deleted { text-decoration: line-through; opacity: 0.55; font-style: normal; }
.wiki-note-item.wiki-note-deprecated { opacity: 0.55; font-style: italic; }
.wiki-note-item:hover { background: var(--surface2); }
.wiki-note-item.active { background: var(--accent); color: #fff; }
.wiki-note-item.active.wiki-note-draft { color: #fff; font-style: italic; }
.wiki-note-item.active.wiki-note-deleted { color: #fff; text-decoration: line-through; opacity: 0.9; }
.wiki-tree-folder { list-style: none; margin: 2px 0; }
.wiki-folder-head { display: flex; align-items: center; gap: 2px; width: 100%; padding: 2px 4px; border-radius: 6px; color: var(--muted); font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; text-align: left; }
.wiki-folder-head:hover { background: var(--surface2); color: var(--text); }
.wiki-folder-head.active { background: var(--accent); color: #fff; }
.wiki-folder-head.active .wiki-folder-name,
.wiki-folder-head.active .wiki-folder-toggle { color: #fff; }
.wiki-folder-toggle { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 22px; height: 22px; padding: 0; border: none; border-radius: 4px; background: transparent; color: inherit; font-size: 0.7rem; cursor: pointer; transition: transform 0.15s; }
.wiki-folder-toggle:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.wiki-folder-collapsed .wiki-folder-toggle { transform: rotate(-90deg); }
.wiki-folder-name { flex: 1; min-width: 0; padding: 4px 6px; border: none; border-radius: 4px; background: transparent; color: inherit; font: inherit; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; cursor: pointer; text-align: left; }
.wiki-folder-name:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.wiki-folder-collapsed .wiki-tree-children { display: none; }
.wiki-tree-children { padding-left: 8px; border-left: 1px solid var(--border); margin-left: 6px; }
.wiki-tree-children .wiki-note-item { font-size: 0.84rem; padding: 5px 8px; }
.wiki-note-snippet { font-size: 0.78rem; color: var(--muted); }
.wiki-note-item.active .wiki-note-snippet { color: rgba(255,255,255,0.85); }
.wiki-main { flex: 1; min-width: 0; }
.wiki-main-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.wiki-title-row { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; }
.wiki-title-block { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.wiki-main-head h2 { margin: 0; font-size: 1.2rem; line-height: 1.3; }
.wiki-back-btn { flex-shrink: 0; font-size: 1.1rem; font-weight: 600; line-height: 1; }
.wiki-status-badge {
  display: inline-block; flex-shrink: 0;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--muted); text-transform: none;
}
.wiki-status-draft { color: #a67c00; border-color: color-mix(in srgb, #e6b800 45%, var(--border)); background: color-mix(in srgb, #e6b800 12%, var(--surface)); }
.wiki-status-published { color: #1f7a3f; border-color: color-mix(in srgb, #2ecc71 40%, var(--border)); background: color-mix(in srgb, #2ecc71 12%, var(--surface)); }
.wiki-status-review { color: #1a5fb4; border-color: color-mix(in srgb, #3584e4 40%, var(--border)); background: color-mix(in srgb, #3584e4 12%, var(--surface)); }
.wiki-status-deleted { color: #a51d2a; border-color: color-mix(in srgb, #c01c28 40%, var(--border)); background: color-mix(in srgb, #c01c28 12%, var(--surface)); text-decoration: line-through; }
.wiki-main-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.wiki-main-actions .icon-btn.active { background: var(--accent); color: #fff; }
.wiki-history-panel {
  flex: 0 0 300px;
  max-height: calc(100vh - 120px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 8px;
  position: sticky;
  top: 8px;
}
.wiki-history-panel.hidden { display: none; }
.wiki-ai-panel {
  flex: 0 0 390px;
  min-width: 0;    /* не давать содержимому (длинным репликам чата) раздвигать панель шире базовой */
  overflow: hidden;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: 0;
  max-height: calc(100vh - 24px);
  position: sticky;
  top: 8px;
  z-index: 4;
  border-left: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, var(--accent) 8%);
  box-shadow: -6px 0 18px color-mix(in srgb, var(--text) 10%, transparent);
  transition: flex-basis .18s ease, box-shadow .18s ease, margin .18s ease;
}
.wiki-ai-panel:not(.is-collapsed) {
  flex-direction: column;
}
.wiki-ai-panel.is-collapsed {
  flex: 0 0 28px;
  margin-left: -16px;   /* съесть gap у .wiki-layout */
  margin-right: -20px;  /* съесть padding у .knowledge-container.wiki */
  border-left: none;
  background: transparent;
  box-shadow: none;
}
.wiki-ai-panel.hidden { display: none; }
.wiki-ai-panel.is-collapsed .wiki-ai-panel-body { display: none; }
.wiki-ai-rail-tab {
  flex: 0 0 28px;
  width: 28px;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 8px 0 0 8px;
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  padding: 10px 0;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  letter-spacing: .06em;
  font-size: 0.78rem;
  font-weight: 600;
  align-self: center;
  min-height: 7.5rem;
  box-shadow: -2px 0 8px color-mix(in srgb, var(--text) 8%, transparent);
}
.wiki-ai-rail-tab:hover {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  color: var(--text);
}
.wiki-ai-panel.is-collapsed .wiki-ai-rail-tab {
  border-radius: 8px 0 0 8px;
  height: auto;
  align-self: center;
}
.wiki-ai-panel:not(.is-collapsed) .wiki-ai-rail-tab {
  /* в открытом виде — не боковой рельс, а горизонтальная подпись сверху, над «Чаты · Знания» */
  flex: 0 0 auto;
  width: 100%;
  writing-mode: horizontal-tb;
  transform: none;
  align-self: stretch;
  min-height: 0;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  box-shadow: none;
  text-align: left;
  padding: 5px 10px;
  background: color-mix(in srgb, var(--surface) 88%, var(--bg));
  color: var(--muted);
}
.wiki-ai-panel-body {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}
.wiki-ai-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); gap: 8px; }
.wiki-ai-chat-list { list-style: none; margin: 0; padding: 0; border-bottom: 1px solid var(--border); max-height: 9.5rem; overflow: auto; }
.wiki-ai-chat-list li { padding: 6px 10px; cursor: pointer; border-left: 3px solid transparent; font-size: 0.85rem; }
.wiki-ai-chat-list li:hover { background: var(--surface2); }
.wiki-ai-chat-list li.active { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); border-left-color: var(--muted); font-weight: 600; }
.wiki-ai-main-host { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.wiki-ai-main-host .ai-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.wiki-history-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.wiki-history-list {
  flex: 1;
  overflow-y: auto;
  font-size: 0.82rem;
  min-height: 80px;
}
.wiki-history-item {
  display: block; width: 100%;
  text-align: left;
  border: none; border-radius: 6px;
  background: transparent; color: var(--text);
  padding: 7px 8px; margin: 0 0 4px; cursor: pointer;
}
.wiki-history-item:hover { background: var(--surface2); }
.wiki-history-item.active { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); }
.wiki-history-msg { display: block; font-size: 0.84rem; line-height: 1.3; margin-bottom: 2px; }
.wiki-history-meta { display: block; font-size: 0.72rem; color: var(--muted); }
.wiki-history-preview {
  margin-top: 8px;
  max-height: 42vh;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  font-size: 0.86rem;
}
.wiki-history-rev-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin-bottom: 8px;
}
@media (max-width: 1100px) {
  .wiki-history-panel { flex-basis: 260px; }
}
@media (max-width: 900px) {
  .wiki-history-panel {
    position: fixed; right: 8px; top: 60px; bottom: 8px;
    width: min(92vw, 340px); z-index: 40;
    box-shadow: 0 8px 28px rgba(0,0,0,.18);
  }
}
.wiki-meta-fields {
  display: grid;
  grid-template-columns: 110px 160px 1fr;
  gap: 10px;
  margin-bottom: 4px;
}
.wiki-template-banner {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent, #5b7cfa);
  background: color-mix(in srgb, var(--accent, #5b7cfa) 10%, transparent);
}
.wiki-meta-field {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.78rem; color: var(--muted);
}
.wiki-meta-field input,
.wiki-meta-field select {
  width: 100%;
  font-size: 0.9rem;
  color: var(--text);
}
.wiki-edit-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 4px 0 8px;
}
.wiki-mode-tabs {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface2);
}
.wiki-mode-tab {
  border: none;
  margin: 0;
  padding: 6px 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.84rem;
  width: auto;
}
.wiki-mode-tab.active {
  background: var(--accent);
  color: #fff;
}
.wiki-visual-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.wiki-visual-tools button {
  width: auto;
  margin: 0;
  min-width: 32px;
  padding: 4px 8px;
  font-size: 0.78rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
}
.wiki-visual-tools button:hover { border-color: var(--accent); }
.wiki-visual-tools button[data-cmd="bold"] { font-weight: 700; }
.wiki-visual-editor {
  min-height: 42vh;
  max-height: 70vh;
  overflow-y: auto;
  outline: none;
  cursor: text;
}
.wiki-visual-editor:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}
.wiki-visual-editor .wikilink { cursor: text; }
#wiki-textarea.hidden,
.wiki-visual-editor.hidden,
.wiki-visual-tools.hidden { display: none !important; }
@media (max-width: 720px) {
  .wiki-meta-fields { grid-template-columns: 1fr 1fr; }
  .wiki-meta-title { grid-column: 1 / -1; }
}
.wiki-content { min-height: 38vh; }
a.wikilink { color: var(--accent); cursor: pointer; text-decoration: none; border-bottom: 1px dashed var(--accent); }
a.wikilink:hover { border-bottom-style: solid; }
.wiki-backlinks { margin-top: 16px; }
.wiki-backlink-list { list-style: none; padding-left: 0; }
.wiki-backlink-list li { margin: 3px 0; }
#wiki-textarea { width: 100%; min-height: 55vh; resize: vertical; font-family: ui-monospace, monospace; font-size: 0.88rem; line-height: 1.5; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
@media (max-width: 720px) { .wiki-layout { flex-direction: column; } .wiki-notes { flex-basis: auto; width: 100%; } }

.groups-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
  max-height: 240px;
  overflow-y: auto;
}
.group-detail {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.group-detail h4 { margin: 16px 0 8px; font-size: 0.95rem; }

.wiki-ctx-menu {
  position: fixed;
  z-index: 1200;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 4px;
}
.wiki-ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
.wiki-ctx-item:hover { background: var(--surface2); }

.wiki-modal {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.wiki-modal.hidden { display: none !important; }
.wiki-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}
.wiki-modal-card {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: min(80vh, 640px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
}
.wiki-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.wiki-modal-header h3 { margin: 0; font-size: 1.05rem; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  font-size: 0.92rem;
}

.academy-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 16px 40px;
}
.academy-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.academy-header h2 { margin: 0; }
.academy-header-actions { display: flex; gap: 8px; }
.academy-course-cards {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}
.academy-course-card {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--text);
}
.academy-course-card:hover { border-color: var(--accent); }
.academy-course-card-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.academy-progress {
  position: relative;
  height: 18px;
  background: var(--surface2);
  border-radius: 9px;
  overflow: hidden;
  margin-bottom: 6px;
}
.academy-progress-fill {
  height: 100%;
  background: color-mix(in srgb, var(--accent) 70%, transparent);
}
.academy-progress span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}
.academy-back-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}
.academy-lesson-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.academy-lesson-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.academy-lesson-row:hover:not(:disabled) { border-color: var(--accent); }
.academy-lesson-row:disabled,
.academy-lesson-locked { opacity: 0.55; cursor: not-allowed; }
.academy-lesson-pos {
  font-weight: 600;
  color: var(--muted);
}
.academy-lesson-body { margin: 14px 0; min-height: 20vh; }
.academy-lesson-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}
.academy-error-report {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  max-width: 560px;
}
.academy-error-report-label {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.academy-error-report textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 3.2em;
  resize: vertical;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.academy-error-report-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}
.academy-errors-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 16px;
}
.academy-errors-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.academy-error-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--surface);
}
.academy-error-card-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.academy-error-card-meta { margin: 6px 0 8px; line-height: 1.35; }
.academy-error-quote {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  background: var(--surface2);
  font-size: 0.92rem;
  white-space: pre-wrap;
}
.academy-error-card label {
  display: block;
  margin: 8px 0;
  font-size: 0.88rem;
}
.academy-error-card select,
.academy-error-card textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  box-sizing: border-box;
}
#wiki-error-modal textarea {
  width: 100%;
  box-sizing: border-box;
  margin: 8px 0 12px;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}
.academy-relearn-banner {
  background: color-mix(in srgb, #c47a00 18%, var(--surface));
  border: 1px solid color-mix(in srgb, #c47a00 40%, var(--border));
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.academy-show-changes-btn {
  background: color-mix(in srgb, var(--accent) 22%, var(--surface));
  border: 1px solid var(--accent);
  color: var(--text);
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
}
.academy-show-changes-btn:hover {
  background: color-mix(in srgb, var(--accent) 32%, var(--surface));
}
.academy-diff-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  max-height: 55vh;
  overflow: auto;
  background: var(--surface);
}
.academy-diff-box.academy-diff-rich {
  font-family: inherit;
  font-size: inherit;
  white-space: normal;
}
.academy-diff-view { display: flex; flex-direction: column; gap: 16px; }
.academy-diff-heading {
  margin: 0 0 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.academy-diff-section.academy-diff-added {
  border-left: 3px solid #0a6b3c;
  padding-left: 12px;
}
.academy-diff-section.academy-diff-removed {
  border-left: 3px solid #b33;
  padding-left: 12px;
}
.academy-diff-section.academy-diff-removed .academy-diff-body {
  opacity: 0.88;
}
.academy-diff-section.academy-diff-removed .academy-diff-body :is(p, li, h1, h2, h3, td, th) {
  text-decoration: line-through;
  color: color-mix(in srgb, #b33 55%, var(--text));
}
.academy-diff-del {
  text-decoration: line-through;
  color: #b33;
  background: color-mix(in srgb, #b33 12%, transparent);
}
.academy-diff-ins {
  color: #0a6b3c;
  background: color-mix(in srgb, #0a6b3c 12%, transparent);
  text-decoration: none;
}
.academy-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.academy-tabs .active {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
}
.academy-relearn-list,
.academy-updates-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.academy-relearn-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 12px;
}
.academy-relearn-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 6px;
}
.academy-relearn-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.academy-relearn-toggle {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 10px 0;
}
.academy-q {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--surface);
}
.academy-q-stem { margin-bottom: 10px; }
.academy-choices { display: flex; flex-direction: column; gap: 6px; }
.academy-choice {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
}
.academy-choice:hover { background: var(--surface2); }
.academy-manage-form { max-width: 560px; }
.academy-groups-fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 12px 0;
}
.academy-draft-warn {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #c4a35a;
  background: rgba(196, 163, 90, 0.12);
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.35;
}
.academy-lesson-builder { margin: 12px 0; }
.academy-lesson-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.academy-lesson-add-row input { flex: 1; }
.academy-suggest {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  max-height: 320px;
  overflow: auto;
  margin-top: 4px;
  font-size: 0.8rem;
}
.academy-suggest-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 5px 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.8rem;
  line-height: 1.25;
}
.academy-suggest-item strong { font-size: 0.8rem; font-weight: 600; }
.academy-suggest-item .muted-field { font-size: 0.72rem; }
.academy-suggest-item:hover { background: var(--surface2); }
.academy-suggest-empty { padding: 8px; color: var(--muted); font-size: 0.8rem; }

.academy-manage-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.academy-manage-list-head h4 { margin: 0; }
.academy-plus-btn {
  font-size: 1.25rem;
  line-height: 1;
  width: 36px;
  height: 36px;
}
.academy-manage-list { list-style: none; padding: 0; margin: 8px 0 16px; }
.academy-manage-course { margin: 0 0 6px; }
.academy-manage-course-btn {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  cursor: pointer;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}
.academy-manage-course.active .academy-manage-course-btn,
.academy-manage-course-btn:hover {
  border-color: var(--accent);
}
.academy-manage-course-title {
  display: block;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.academy-manage-course-meta {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}
#academy-next-quiz:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.academy-picked-lessons { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.academy-picked-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
}
.academy-picked-main { display: flex; gap: 10px; align-items: flex-start; }
.academy-picked-actions { display: flex; gap: 2px; }
.academy-q-badge {
  font-size: 0.8rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.academy-q-badge.off { opacity: 0.45; background: var(--surface2); }
.academy-q-edit {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: var(--surface);
}
.danger-icon { color: #b33; }
.wiki-img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 8px 0;
  display: block;
}
.wiki-subscribers {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.wiki-subs-head { font-weight: 600; margin-bottom: 8px; }
.wiki-subs-list { list-style: none; padding: 0; margin: 0; }
.wiki-subs-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.wiki-history-rev-actions { display: flex; gap: 8px; margin: 8px 0; }

/* Аккордеоны markdown: `##> Заголовок` → <details class="md-fold"> */
.md-fold {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 10px 0;
  background: transparent;
}
.md-fold > summary {
  cursor: pointer;
  font-weight: 650;
  color: var(--accent);
  padding: 8px 12px;
  list-style: none;
  user-select: none;
}
.md-fold > summary::-webkit-details-marker { display: none; }
.md-fold > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  color: var(--muted);
  transition: transform 0.15s ease;
}
.md-fold[open] > summary::before { transform: rotate(90deg); }
.md-fold > .md-fold-body { padding: 0 12px 10px; }
.md-fold .md-fold { margin: 8px 0; }

/* Публичная страница шаринга (public.html) */
body.public-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.public-container {
  min-height: 40vh;
}

.public-password-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 320px;
  margin: 60px auto 0;
  text-align: center;
}

.public-password-form input[type="password"] {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.md-video-note {
  padding: 8px 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
}

/* --- Модуль «ИИ-задачи» --- */
/* Независимый скролл: левый список и лента сообщений — каждый свой overflow */
#ai-view:not(.hidden) {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.ai-layout {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  gap: 12px;
  overflow: hidden;
}
.ai-chats {
  width: 280px;
  flex: 0 0 280px;
  align-self: stretch;
  border-right: 1px solid var(--border, #ddd);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  padding: 8px;
}
.ai-chats-toolbar { display: flex; gap: 6px; flex-wrap: wrap; }
.ai-chats-toolbar .btn { flex: 1; min-width: 0; font-size: 13px; padding: 6px 8px; }
.ai-chat-tree { margin-top: 6px; }
.ai-chat-list { list-style: none; padding: 0; margin: 4px 0; }
.ai-folder { margin: 4px 0 8px; border-radius: 8px; }
.ai-folder-summary {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  position: relative;
  user-select: none;
}
.ai-folder-summary::-webkit-details-marker { display: none; }
.ai-folder-summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 11px;
  width: 12px;
}
.ai-folder[open] > .ai-folder-summary::before { content: "▾"; }
.ai-folder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-folder-count { flex: none; font-size: 11px; font-weight: 500; color: var(--muted); }
.ai-folder .ai-chat-list { margin-left: 8px; }
.ai-folder-empty { padding: 4px 8px; font-size: 12px; color: var(--muted); }
.ai-chat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: default;
  font-size: 14px;
  position: relative;
}
.ai-chat-item:hover { background: var(--hover, #eef); }
.ai-chat-item.active { background: var(--accent-soft, #e5ecff); font-weight: 600; }
.ai-chat-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.ai-chat-rel {
  flex: none;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.ai-chat-more {
  flex: none;
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0 4px;
  font-size: 16px;
  line-height: 1;
  border-radius: 4px;
  cursor: pointer;
}
.ai-chat-more:hover { color: var(--text); background: var(--surface2, #eee); }
.ai-chat-menu {
  display: none;
  position: absolute;
  right: 4px;
  top: 100%;
  z-index: 5;
  min-width: 140px;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface, #fff);
  box-shadow: 0 4px 16px var(--fab-shadow, rgba(0,0,0,.15));
}
.ai-chat-menu.open {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 60vh;
  overflow-y: auto;
}
.ai-chat-menu button {
  background: transparent;
  color: var(--text);
  border: none;
  text-align: left;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
}
.ai-chat-menu button:hover { background: var(--surface2, #eee); }
/* Секция-список внутри меню (выбор папки) — вместо prompt «введите номер». */
.ai-menu-sep {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 6px 8px 2px;
  border-top: 1px solid var(--border);
  margin-top: 2px;
}
.ai-menu-sep:empty { padding: 0; margin-top: 4px; }
.ai-chat-menu .ai-menu-opt {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-chat-menu .ai-menu-opt.active { color: var(--accent, #36c); font-weight: 500; }
/* Галочка слева: справа её съедает ellipsis у длинных «Папка · проект». */
.ai-chat-menu .ai-menu-opt.active::before { content: "✓ "; }
.ai-folder-badge {
  flex: none;
  max-width: 7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 6px;
  color: var(--accent, #36c);
  background: color-mix(in srgb, var(--accent, #36c) 14%, transparent);
}
.ai-modal-back {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .35);
}
.ai-modal {
  width: min(440px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface, #fff);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.ai-modal-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.ai-modal label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted);
}
.ai-modal input,
.ai-modal select,
.ai-modal textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg, #fff);
  border: 1px solid var(--border, #ccc);
  border-radius: 8px;
  padding: 7px 8px;
}
.ai-modal textarea { resize: vertical; min-height: 72px; }
.ai-modal-hint { font-size: 11px; color: var(--muted); line-height: 1.35; }
.ai-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.ai-archive-wrap { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 6px; }
.ai-archive-wrap.empty { display: none; }
.ai-archive-summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 8px;
  user-select: none;
}
.ai-context-ring {
  flex: none;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  line-height: 0;
  border-radius: 50%;
}
.ai-context-ring .ai-ring-track { stroke: var(--border, #ccc); }
.ai-context-ring .ai-ring-primary {
  stroke: hsl(var(--ai-ring-hue, 120) 45% 55%);
  stroke-dasharray: 0 88;
  transition: stroke-dasharray .25s ease, stroke .25s ease;
}
.ai-context-ring .ai-ring-overflow {
  stroke: #c0392b;
  stroke-dasharray: 0 88;
  opacity: 0.95;
  transition: stroke-dasharray .25s ease;
}
.ai-context-ring.warn { box-shadow: 0 0 0 2px color-mix(in srgb, #e6b800 45%, transparent); }
.ai-context-ring.overflow .ai-ring-primary { opacity: 0.85; }
.ai-model-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
  text-align: left;
  max-width: 8.5rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 8px;
  cursor: pointer;
}
.ai-model-label:hover { border-color: var(--border, #ccc); background: var(--surface2, #f2f2f2); }
.ai-model-label-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.ai-model-caret {
  flex: none;
  font-size: 9px;
  line-height: 1;
  color: var(--muted);
  opacity: 0.9;
}
.ai-model-label:hover .ai-model-label-text,
.ai-model-label:hover .ai-model-caret {
  color: var(--text);
}
/* Меню якорится к .ai-compose (не к кнопке): кнопка модели теперь в середине
   нижней панели, и от неё меню вылезало бы за узкий рельс «Знаний». */
.ai-model-wrap { position: static; max-width: 8.5rem; display: inline-flex; }
.ai-model-menu {
  position: absolute;
  left: 10px;
  bottom: calc(100% + 6px);
  min-width: min(17rem, calc(100% - 20px));
  max-width: min(24rem, calc(100% - 20px));
  max-height: 20rem;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px var(--fab-shadow, rgba(0,0,0,.25));
  z-index: 40;
  padding: 6px;
}
.ai-model-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}
.ai-model-item-name {
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-model-item:hover:not(:disabled) { background: var(--surface2); }
.ai-model-item.active .ai-model-item-name { color: var(--accent); }
.ai-model-item.disabled, .ai-model-item:disabled { opacity: .45; cursor: not-allowed; }
.ai-model-item-meta {
  color: var(--muted);
  white-space: nowrap;
  font-size: 11px;
  flex: none;
}
.ai-model-sep {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 8px 8px 4px;
}
.ai-limit-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 12px 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, #e6b800 18%, var(--surface));
  border: 1px solid color-mix(in srgb, #e6b800 40%, transparent);
  color: var(--text);
  font-size: 12px;
}
.ai-limit-banner.hidden { display: none; }
.ai-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  align-self: stretch;
  overflow: hidden;
}
.ai-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
}
.ai-status,
.ai-compose {
  flex-shrink: 0;
}
.ai-msg { margin: 10px 0; padding: 10px 12px; border-radius: 12px; max-width: 85%; }
.ai-msg-body { white-space: pre-wrap; word-wrap: break-word; }
.ai-msg-user { background: var(--accent-soft, #e5ecff); margin-left: auto; }
.ai-msg-assistant { background: var(--panel, #f6f6f6); }
/* Узкая панель «Знания» — экономим горизонталь: меньше отступов, реплики шире,
   расстояние между «моей» и «ИИ» стороной уменьшено. */
.wiki-ai-panel .ai-messages { padding: 8px; }
.wiki-ai-panel .ai-msg { margin: 8px 0; padding: 8px 10px; max-width: 94%; }
.ai-sources {
  font-size: 12px;
  opacity: .85;
  margin-top: 6px;
  display: flex;
  align-items: baseline;
  gap: 0;
  max-width: 100%;
  line-height: 1.35;
}
.ai-sources:not(.expanded) {
  white-space: nowrap;
  overflow: hidden;
}
.ai-sources.expanded {
  flex-wrap: wrap;
  white-space: normal;
}
.ai-sources-label { flex: none; opacity: .75; }
.ai-sources-body {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-sources.expanded .ai-sources-body { overflow: visible; }
.ai-sources a.ai-source-link { color: var(--accent); }
.ai-sources-toggle {
  display: inline;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 0 0 0 2px;
  cursor: pointer;
  font-weight: 500;
  vertical-align: baseline;
}
.ai-sources-toggle:hover { color: var(--accent); }
.ai-plan { margin-top: 10px; padding: 10px; border: 1px dashed var(--border, #bbb); border-radius: 10px; }
.ai-plan-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.ai-step { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; font-size: 14px; cursor: pointer; }
.ai-step-num {
  flex: 0 0 auto;
  min-width: 1.4em;
  color: var(--muted, #888);
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}
.ai-step-text { white-space: pre-wrap; flex: 1; min-width: 0; }
.ai-step-error { color: #b00020; }
.ai-step-done { color: #0a7a2f; }
.ai-plan-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center; }
.ai-exec-btn { margin-top: 0; }
.ai-cancel-btn {
  margin-top: 0;
  background: transparent;
  color: var(--text, #222);
  border: 1px solid var(--border, #bbb);
}
.ai-cancel-btn:hover { border-color: var(--muted, #888); }
.ai-plan-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted, #888);
  line-height: 1.35;
}
.ai-clarify {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--border, #bbb);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface2, #f4f4f4) 70%, transparent);
}
.ai-clarify-done { opacity: 0.75; }
.ai-clarify-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.ai-clarify-q { margin-bottom: 12px; }
.ai-clarify-prompt { font-size: 14px; margin-bottom: 6px; }
.ai-clarify-options { display: flex; flex-direction: column; gap: 4px; }
.ai-clarify-opt {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 14px;
  cursor: pointer;
}
.ai-clarify-text {
  width: 100%;
  margin-top: 6px;
  box-sizing: border-box;
  resize: vertical;
  font: inherit;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border, #bbb);
  background: var(--surface, #fff);
  color: inherit;
}
.ai-clarify-submit { margin-top: 4px; }
.ai-status { padding: 4px 12px; font-size: 13px; opacity: .8; min-height: 20px; }
.ai-status.error { color: #b00020; opacity: 1; }
.ai-status-thinking {
  opacity: 1;
  color: var(--muted, #666);
  font-variant-numeric: tabular-nums;
}
.ai-msg-pending { opacity: .92; }
.ai-msg-assistant { position: relative; }
.ai-msg-body :is(p, ul, ol) { margin: 0.35em 0; }
.ai-msg-body :is(ul, ol) { padding-left: 1.25em; }
.ai-msg-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.ai-msg-body code {
  font-size: 0.9em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--surface2, #eee) 80%, transparent);
}
.ai-msg-body pre.md-code {
  overflow-x: auto;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface2, #eee);
  font-size: 0.85em;
}
.ai-msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  opacity: 0.55;
  transition: opacity .15s ease;
}
.ai-msg-assistant:hover .ai-msg-actions,
.ai-msg-actions:focus-within { opacity: 1; }
.ai-copy-btn {
  background: transparent;
  color: var(--muted, #666);
  border: 1px solid var(--border, #ccc);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
}
.ai-copy-btn:hover { color: var(--text); border-color: var(--accent); }
.ai-copy-btn.copied { color: var(--ok, #0a7a2f); border-color: var(--ok, #0a7a2f); }
.ai-compose {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--border, #ddd);
  align-items: stretch;
  position: relative;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.ai-compose.ai-compose-drag {
  background: color-mix(in srgb, var(--accent, #3366aa) 8%, var(--bg, #fff));
  box-shadow: inset 0 0 0 2px var(--accent, #3366aa);
  border-radius: 8px;
}
.ai-compose.ai-compose-drag::after {
  content: "Отпустите файл, чтобы прикрепить";
  position: absolute;
  inset: 6px;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  border-radius: 6px;
  border: 2px dashed var(--accent, #3366aa);
  background: color-mix(in srgb, var(--bg, #fff) 82%, transparent);
  color: var(--text, #222);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  padding: 12px;
}
.ai-main.ai-main-drag .ai-compose:not(.ai-compose-drag) {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent, #3366aa) 50%, transparent);
}
/* Раскладка «как в VS Code»: поле ввода сверху, панель инструментов снизу внутри
   той же рамки; отправка — справа в той же строке. */
.ai-compose-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border, #ccc);
  border-radius: 12px;
  background: var(--bg, #fff);
  transition: border-color .12s ease;
}
.ai-compose-field:focus-within { border-color: var(--accent, #888); }
.ai-compose-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-compose-tools {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
}
.ai-tool-btn {
  height: 30px;
  min-width: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted, #666);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ai-tool-btn:hover { color: var(--text); border-color: var(--border, #ccc); background: var(--surface2, #f2f2f2); }
.ai-mode-btn {
  gap: 5px;
  padding: 0 8px;
  font: inherit;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}
.ai-mode-icon {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.ai-mode-icon svg { display: block; }
.ai-mode-btn.is-auto {
  color: var(--accent, #3366aa);
  border-color: color-mix(in srgb, var(--accent, #3366aa) 45%, transparent);
  background: color-mix(in srgb, var(--accent, #3366aa) 12%, transparent);
}
.ai-mode-btn.is-auto:hover {
  color: var(--accent, #3366aa);
  background: color-mix(in srgb, var(--accent, #3366aa) 20%, transparent);
}
.ai-tool-btn.recording {
  color: #c0392b;
  border-color: #c0392b;
  animation: ai-mic-pulse 1.2s ease-in-out infinite;
}
@keyframes ai-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(192, 57, 43, 0); }
}
.ai-compose-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 2px;
}
.ai-compose-chips[hidden] { display: none !important; }
.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border, #ccc);
  background: var(--bg-soft, #f6f6f6);
  font-size: 12px;
  line-height: 1.3;
}
.ai-chip-preview {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.ai-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}
.ai-chip-mode {
  border: none;
  background: transparent;
  color: var(--accent, #336);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
  white-space: nowrap;
}
.ai-chip-x {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted, #888);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.ai-chip-x:hover { color: var(--text); }
.ai-chip-context { background: var(--accent-soft, #eaf2ff); border-color: var(--accent, #336); }
.ai-chip-patch { background: #fff3d6; border-color: #d9a441; }
/* Тема переключается и вручную ([data-theme]), не только системно — иначе
   светлый фон чипа остаётся под тёмной темой и текст почти не читается. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ai-chip-context { background: rgba(80, 130, 220, 0.18); color: var(--text); }
  :root:not([data-theme="light"]) .ai-chip-patch { background: rgba(217, 164, 65, 0.18); color: var(--text); }
}
[data-theme="dark"] .ai-chip-context { background: rgba(80, 130, 220, 0.18); color: var(--text); }
[data-theme="dark"] .ai-chip-patch { background: rgba(217, 164, 65, 0.18); color: var(--text); }
.ai-chip-pasted .ai-chip-label, .ai-chip-patch .ai-chip-label { cursor: pointer; }
.ai-paste-preview {
  width: 100%;
  max-height: 160px;
  overflow: auto;
  margin-top: 4px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border, #ddd);
  background: var(--bg, #fff);
  font-size: 12px;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.ai-msg-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.ai-msg-chip {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border, #ccc);
  background: var(--bg-soft, #f6f6f6);
  color: var(--muted, #555);
}
.ai-compose textarea {
  flex: 1;
  resize: none;
  font: inherit;
  padding: 4px 2px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: inherit;
  min-height: 0;
}
.ai-compose textarea:focus { outline: none; }
.ai-send-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  flex: none;
  margin-left: auto;
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}
.ai-send-btn .ai-send-icon,
.ai-send-btn .ai-stop-icon {
  display: block;
  pointer-events: none;
}
.ai-send-btn.ai-send-btn-stop {
  background: var(--text, #222);
  color: var(--surface, #fff);
  border-color: var(--text, #222);
}
.ai-send-btn.ai-send-btn-stop:hover {
  filter: brightness(1.1);
}
.ai-model-whisper {
  padding: 8px 10px;
  border-top: 1px solid var(--border, #ddd);
  font-size: 12px;
  color: var(--muted, #666);
}
.ai-model-whisper label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ai-model-whisper select {
  font: inherit;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border, #ccc);
}

.ai-chat-item.ai-chat-busy .ai-chat-title::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent, #3b6ef5);
  vertical-align: middle;
  animation: ai-busy-pulse 1.1s ease-in-out infinite;
}
@keyframes ai-busy-pulse {
  0%, 100% { opacity: .35; transform: scale(.85); }
  50% { opacity: 1; transform: scale(1); }
}
.ai-progress {
  opacity: .9;
  border: 1px dashed var(--border, #ccc);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 6px 0 10px;
  background: color-mix(in srgb, var(--surface2, #f4f4f4) 70%, transparent);
}
.ai-progress-body {
  font-size: 13px;
  color: var(--muted, #666);
  font-variant-numeric: tabular-nums;
}
.ai-progress-body.ai-progress-stalled {
  color: #9a5b00;
}
.ai-progress-error .ai-progress-body { color: #b00020; }
.ai-progress-trail {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
/* Одна строка на шаг: пишем до конца строки, дальше — многоточие (полный текст в title). */
.ai-progress-line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  max-width: 100%;
}
.ai-progress-line-done {
  opacity: .55;
}
.ai-progress-line-live {
  opacity: 1;
  font-weight: 500;
}
.ai-progress-toggle {
  align-self: flex-start;
  display: inline;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 0 0 2px;
  cursor: pointer;
  font-weight: 500;
}
.ai-progress-toggle:hover { color: var(--accent); }

.wiki-selection-fix-btn {
  position: fixed;
  z-index: 500;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border, #ccc);
  background: var(--bg, #fff);
  color: var(--text, #222);
  font-size: 12px;
  font-family: inherit;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}
.wiki-selection-fix-btn:hover { border-color: var(--accent, #336); }
.wiki-selection-fix-btn.hidden { display: none; }


/* Profile / Telegram link */
.profile-page { max-width: 520px; margin: 24px auto; padding: 0 16px; }
.profile-card { border: 1px solid var(--border, #ddd); border-radius: 10px; padding: 16px 18px; }
.profile-card h3 { margin: 0 0 8px; }
.profile-muted { color: var(--muted, #888); font-size: 0.9rem; }
.profile-code {
  font-size: 2rem; letter-spacing: 0.35em; font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 12px 0;
}
.profile-code-label { margin-bottom: 4px; }


.profile-dl { margin: 0; display: grid; gap: 10px; }
.profile-dl > div { display: grid; grid-template-columns: 140px 1fr; gap: 8px; align-items: baseline; }
.profile-dl dt { margin: 0; color: var(--muted, #888); font-size: 0.9rem; }
.profile-dl dd { margin: 0; word-break: break-word; }
.profile-steps { margin: 10px 0 16px; padding-left: 1.25rem; line-height: 1.45; }
.profile-steps li { margin: 0.4rem 0; }
.profile-action-link {
  display: inline-block; text-decoration: none; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--border, #ddd);
}
