.knowledge-app {
  height: 100vh;
  min-height: 700px;
  overflow: hidden;
  background: #f4f7fb;
}

.knowledge-main {
  display: flex;
  min-width: 0;
  height: 100vh;
  max-width: none;
  flex-direction: column;
  padding: 24px 28px 22px;
}

.knowledge-topbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  align-items: start;
  gap: 24px;
  margin: 0 0 16px;
}

.knowledge-heading { min-width: 0; }
.knowledge-heading h1 { margin: 6px 0 2px; font-size: clamp(24px, 2.2vw, 31px); letter-spacing: -.025em; }
.knowledge-heading .muted { max-width: 620px; font-size: 13px; }
.knowledge-topbar .top-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.knowledge-topbar .top-actions button { min-height: 42px; white-space: nowrap; }
.knowledge-topbar .primary { padding-inline: 18px; box-shadow: 0 8px 18px #246bfe2b; }
.knowledge-topbar .logout-button { color: #66758a; }

.knowledge-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 11px;
  margin-bottom: 14px;
}

.knowledge-stats button {
  position: relative;
  display: grid;
  min-height: 78px;
  align-content: center;
  gap: 2px;
  padding: 12px 16px 12px 19px;
  overflow: hidden;
  border: 1px solid #dfe6ef;
  border-radius: 15px;
  background: linear-gradient(145deg, #fff, #fbfcff);
  text-align: left;
  box-shadow: 0 3px 12px #1b315008;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.knowledge-stats button::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: transparent;
}

.knowledge-stats button:hover { border-color: #9ab7ec; box-shadow: 0 8px 20px #246bfe12; transform: translateY(-1px); }
.knowledge-stats button.active { border-color: #8aabeb; background: #f5f8ff; box-shadow: 0 0 0 3px #246bfe0d; }
.knowledge-stats button.active::before { background: var(--blue); }
.knowledge-stats span { color: var(--blue); font-size: 24px; font-weight: 900; line-height: 1.1; }
.knowledge-stats small { color: #69788b; font-size: 11px; font-weight: 700; }

.knowledge-layout {
  display: grid;
  grid-template-columns: minmax(320px, 36%) minmax(0, 1fr);
  min-height: 0;
  flex: 1;
  overflow: hidden;
  border: 1px solid #dce4ee;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 12px 34px #1b31500e;
}

.knowledge-list-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid #dfe6ef;
  background: #fbfcfe;
}

.knowledge-list-head {
  z-index: 2;
  display: grid;
  gap: 12px;
  padding: 15px;
  border-bottom: 1px solid #e5eaf1;
  background: #fff;
}

.knowledge-list-head .inbox-search { min-height: 42px; border-color: #d5dfec; background: #fbfdff; }
.knowledge-tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.knowledge-tabs::-webkit-scrollbar { display: none; }
.knowledge-tabs button { min-height: 32px; padding: 7px 10px; border-radius: 9px; background: transparent; color: #68778a; font-size: 10px; white-space: nowrap; }
.knowledge-tabs button:hover { background: #f1f5fb; color: #315b9c; }
.knowledge-tabs button.active { background: var(--blue-soft); color: var(--blue); font-weight: 900; }
.knowledge-list { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-color: #aab4c0 transparent; scrollbar-width: thin; }

.knowledge-item {
  position: relative;
  display: grid;
  width: 100%;
  gap: 7px;
  padding: 15px 16px;
  border-bottom: 1px solid #e9edf3;
  background: transparent;
  text-align: left;
  transition: background .16s ease;
}

.knowledge-item::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: transparent; }
.knowledge-item:hover { background: #f3f7fd; }
.knowledge-item.selected { background: linear-gradient(90deg, #eaf2ff, #f2f7ff); }
.knowledge-item.selected::before { background: var(--blue); }
.knowledge-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.knowledge-item-top time { color: #8a96a6; font-size: 9px; white-space: nowrap; }
.knowledge-item > b { overflow: hidden; color: #182536; font-size: 13px; line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }
.knowledge-item > span:not(.knowledge-item-top) { display: -webkit-box; overflow: hidden; color: #657487; font-size: 11px; line-height: 1.5; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.knowledge-item > small { overflow: hidden; color: #356cc7; font-size: 10px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }

.knowledge-status { display: inline-flex; width: max-content; padding: 5px 9px; border-radius: 999px; font-size: 10px; font-weight: 900; }
.status-waiting_answer { background: #fff3dc; color: #8a5b00; }
.status-ready_review { background: #eaf1ff; color: #1859ce; }
.status-approved { background: #e8faef; color: #13764e; }
.status-rejected { background: #f1f3f5; color: #657384; }

.knowledge-editor-panel {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  background: linear-gradient(155deg, #fbfcfe 0%, #f6f9fd 100%);
  scrollbar-gutter: stable;
}

.knowledge-editor {
  display: grid;
  min-height: 100%;
  align-content: start;
  gap: 16px;
  padding: 22px 24px 0;
}

.knowledge-editor > header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.knowledge-editor h2 { margin: 7px 0 0; font-size: 20px; letter-spacing: -.015em; }
.knowledge-editor > header .ghost { flex: 0 0 auto; font-size: 11px; text-decoration: none; }

.knowledge-source {
  position: relative;
  padding: 10px 13px 10px 34px;
  overflow: hidden;
  border: 1px solid #e0e8f2;
  border-radius: 11px;
  background: #edf3f9;
  color: #546579;
  font-size: 10px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.knowledge-source::before { content: "↳"; position: absolute; top: 8px; left: 13px; color: #2d6bd2; font-size: 14px; font-weight: 900; }
.knowledge-editor label { display: grid; align-content: start; gap: 7px; color: #2d3b4d; font-size: 12px; font-weight: 900; }
.knowledge-editor label small { color: #7a8797; font-size: 10px; font-weight: 400; line-height: 1.45; }
.knowledge-editor textarea,
.knowledge-editor input { width: 100%; min-width: 0; padding: 11px 12px; border: 1px solid #cad7e7; border-radius: 11px; background: #fff; color: var(--ink); line-height: 1.55; box-shadow: inset 0 1px 2px #17212b05; }
.knowledge-editor input { min-height: 44px; height: 44px; }
.knowledge-editor textarea { min-height: 82px; resize: vertical; }
.knowledge-editor #knowledge-question { min-height: 82px; }
.knowledge-editor #knowledge-variants { min-height: 92px; }
.knowledge-editor #knowledge-answer { min-height: 132px; }
.knowledge-meta-grid { display: grid; grid-template-columns: minmax(150px, .32fr) minmax(0, 1fr); align-items: start; gap: 14px; }
.knowledge-meta-grid > label:first-child { align-self: start; }

.knowledge-warning {
  display: grid;
  grid-template-columns: 28px auto;
  column-gap: 10px;
  padding: 12px 14px;
  border: 1px solid #efcf82;
  border-radius: 12px;
  background: #fff9e9;
  color: #765309;
  font-size: 10px;
  line-height: 1.5;
}

.knowledge-warning::before { content: "!"; grid-row: 1 / span 2; display: grid; width: 26px; height: 26px; place-items: center; border-radius: 8px; background: #ffe9ac; color: #8a5b00; font-size: 13px; font-weight: 900; }
.knowledge-warning b { align-self: end; }
.knowledge-warning span { color: #88671f; }
.knowledge-editor .auth-message { min-height: 18px; margin: -2px 0 0; }

.knowledge-actions {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  margin: 0 -24px;
  padding: 14px 24px 16px;
  border-top: 1px solid #e1e8f0;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 -10px 24px #1b31500a;
  backdrop-filter: blur(10px);
}

.knowledge-actions button { min-height: 42px; }
.knowledge-actions .primary { padding-inline: 18px; box-shadow: 0 7px 16px #246bfe28; }
.danger-ghost { margin-right: auto; padding: 10px 14px; border: 1px solid #efc6c3; border-radius: 10px; background: #fff; color: #b42318; }
.knowledge-actions button:disabled { cursor: not-allowed; opacity: .55; box-shadow: none; }

.profile-dialog { width: min(820px, calc(100% - 28px)); max-height: 90vh; padding: 0; overflow: auto; border: 0; border-radius: 20px; box-shadow: 0 26px 80px #17212b38; }
.profile-dialog::backdrop { background: #17212b80; backdrop-filter: blur(3px); }
.profile-dialog form { display: grid; gap: 18px; padding: 25px; }
.profile-dialog header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.profile-dialog h2 { margin: 5px 0; }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.profile-grid label { display: grid; gap: 7px; color: #334155; font-size: 12px; font-weight: 800; }
.profile-grid .wide { grid-column: 1 / -1; }
.profile-grid textarea,
.profile-grid input { width: 100%; padding: 11px 12px; border: 1px solid #cfd9e7; border-radius: 10px; background: #fff; color: var(--ink); line-height: 1.55; }
.profile-grid textarea { min-height: 78px; resize: vertical; }
.dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; }

.knowledge-app button:focus-visible,
.knowledge-app a:focus-visible { outline: 3px solid #246bfe2e; outline-offset: 2px; }

@media (max-width: 1180px) {
  .knowledge-topbar { grid-template-columns: 1fr; gap: 13px; }
  .knowledge-topbar .top-actions { justify-content: flex-start; }
  .knowledge-layout { grid-template-columns: 330px minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .knowledge-app { height: auto; min-height: 100vh; overflow: visible; }
  .knowledge-main { height: calc(100vh - 70px); min-height: 680px; padding: 20px; }
  .knowledge-layout { grid-template-columns: minmax(310px, 36%) minmax(0, 1fr); }
}

@media (max-width: 720px) {
  .knowledge-main { height: auto; min-height: calc(100vh - 70px); padding: 18px; }
  .knowledge-topbar .top-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .knowledge-topbar .top-actions button { width: 100%; }
  .knowledge-topbar .top-actions .primary { grid-column: 1 / -1; }
  .knowledge-stats { grid-template-columns: repeat(2, 1fr); }
  .knowledge-layout { grid-template-columns: 1fr; overflow: visible; }
  .knowledge-list-panel { max-height: 390px; border-right: 0; border-bottom: 1px solid var(--line); }
  .knowledge-editor-panel { min-height: 610px; overflow: visible; }
  .knowledge-editor { padding: 19px 17px 0; }
  .knowledge-editor > header { align-items: flex-start; flex-direction: column; }
  .knowledge-meta-grid,
  .profile-grid { grid-template-columns: 1fr; }
  .profile-grid .wide { grid-column: auto; }
  .knowledge-warning { grid-template-columns: 28px minmax(0, 1fr); }
  .knowledge-actions { display: grid; grid-template-columns: 1fr 1fr; margin-inline: -17px; padding-inline: 17px; }
  .knowledge-actions .danger-ghost { grid-column: 1 / -1; width: 100%; }
  .dialog-actions { align-items: stretch; flex-direction: column; }
  .dialog-actions button { width: 100%; }
}

@media (max-width: 430px) {
  .knowledge-heading h1 { font-size: 25px; }
  .knowledge-stats button { min-height: 72px; }
  .knowledge-list-head { padding: 13px; }
  .knowledge-item { padding: 14px; }
  .knowledge-actions { grid-template-columns: 1fr; }
  .knowledge-actions .danger-ghost { grid-column: auto; }
}
