html[data-knowledge-media] .km-original-hidden {
  display: none !important;
}

.km-tabs {
  display: flex;
  gap: 4px;
  max-width: 1180px;
  margin: 0 auto 20px;
  padding: 0 0 12px;
  border-bottom: 1px solid #dbe2ea;
}

.km-tab {
  min-height: 38px;
  padding: 8px 14px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #64748b;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.km-tab:hover {
  color: #0f172a;
  background: #f1f5f9;
}

.km-tab.is-active {
  color: #1d4ed8;
  background: #eaf1ff;
}

.km-root {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  color: #172033;
}

.km-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.km-header h1 {
  margin: 0;
  color: #172033;
  font-size: 24px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: 0;
}

.km-header p {
  max-width: 720px;
  margin: 6px 0 0;
  color: #64748b;
  font-size: 14px;
  line-height: 1.5;
}

.km-primary,
.km-form .km-primary {
  border: 1px solid #2563eb;
  border-radius: 6px;
  background: #2563eb;
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}

.km-header .km-primary {
  min-height: 40px;
  padding: 9px 15px;
  white-space: nowrap;
}

.km-primary:hover {
  border-color: #1d4ed8;
  background: #1d4ed8;
}

.km-primary:disabled {
  opacity: .55;
  cursor: wait;
}

.km-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 190px auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid #dbe2ea;
  border-radius: 8px;
  background: #fff;
}

.km-toolbar input,
.km-toolbar select,
.km-form input,
.km-form textarea,
.km-form select {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  outline: 0;
  background: #fff;
  color: #172033;
  font: inherit;
  font-size: 14px;
  letter-spacing: 0;
}

.km-form textarea {
  min-height: 104px;
  resize: vertical;
}

.km-toolbar input:focus,
.km-toolbar select:focus,
.km-form input:focus,
.km-form textarea:focus,
.km-form select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.km-result-count {
  color: #64748b;
  font-size: 13px;
  white-space: nowrap;
}

.km-layout {
  display: grid;
  grid-template-columns: 214px minmax(0, 1fr);
  align-items: start;
  gap: 16px;
}

.km-folders {
  position: sticky;
  top: 16px;
  padding: 12px;
  border: 1px solid #dbe2ea;
  border-radius: 8px;
  background: #fff;
}

.km-folders-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.km-folders-title button,
.km-folder-actions button,
.km-card-footer button {
  padding: 5px 7px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #2563eb;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.km-folders-title button:hover,
.km-folder-actions button:hover,
.km-card-footer button:hover {
  background: #eff6ff;
}

.km-folder {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  margin: 2px 0;
  padding: 8px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #475569;
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.km-folder span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.km-folder b {
  color: #94a3b8;
  font-size: 12px;
}

.km-folder:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.km-folder.is-active {
  background: #eaf1ff;
  color: #1d4ed8;
}

.km-folder.is-active b {
  color: #2563eb;
}

.km-folder-actions {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e2e8f0;
}

.km-folder-actions .is-danger,
.km-card-footer .is-danger {
  color: #b42318;
}

.km-folder-actions .is-danger:hover,
.km-card-footer .is-danger:hover {
  background: #fff1f0;
}

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

.km-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid #dbe2ea;
  border-radius: 8px;
  background: #fff;
}

.km-card:hover {
  border-color: #b8c5d6;
  box-shadow: 0 6px 18px rgba(15, 23, 42, .07);
}

.km-preview {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-bottom: 1px solid #e2e8f0;
  background: #eef2f7;
}

.km-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.km-file-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: #334155;
}

.km-file-marker b {
  font-size: 18px;
  letter-spacing: 0;
}

.km-file-marker span {
  margin-top: 4px;
  color: #64748b;
  font-size: 11px;
}

.km-card-body {
  padding: 12px;
}

.km-card-heading,
.km-card-footer,
.km-ai-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.km-card-heading span {
  color: #1d4ed8;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.km-card-heading small,
.km-card-footer > span {
  color: #94a3b8;
  font-size: 11px;
}

.km-card h3 {
  min-height: 42px;
  margin: 8px 0 4px;
  overflow: hidden;
  color: #172033;
  font-size: 15px;
  line-height: 1.4;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.km-card p {
  min-height: 54px;
  margin: 0;
  overflow: hidden;
  color: #64748b;
  font-size: 12px;
  line-height: 1.5;
}

.km-tags {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  min-height: 42px;
  margin-top: 9px;
}

.km-tags span {
  max-width: 100%;
  overflow: hidden;
  padding: 3px 6px;
  border-radius: 5px;
  background: #f1f5f9;
  color: #475569;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.km-ai-row {
  min-height: 42px;
  margin: 10px -12px 0;
  padding: 9px 12px;
  border-top: 1px solid #e2e8f0;
  border-bottom: 1px solid #e2e8f0;
  background: #f7fbf8;
}

.km-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #166534;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.km-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.km-switch i {
  position: relative;
  width: 34px;
  height: 20px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: #cbd5e1;
  transition: background .15s ease;
}

.km-switch i::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .25);
  content: '';
  transition: transform .15s ease;
}

.km-switch input:checked + i {
  background: #16a34a;
}

.km-switch input:checked + i::after {
  transform: translateX(14px);
}

.km-switch input:focus-visible + i {
  outline: 3px solid rgba(37, 99, 235, .2);
}

.km-card-footer {
  min-height: 36px;
  padding-top: 8px;
}

.km-card-footer > div {
  display: flex;
  gap: 2px;
}

.km-empty,
.km-loading {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  padding: 28px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  color: #64748b;
  text-align: center;
}

.km-empty b {
  margin-bottom: 5px;
  color: #334155;
  font-size: 15px;
}

.km-empty span,
.km-loading {
  font-size: 13px;
}

.km-modal-layer {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.km-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .52);
}

.km-modal {
  position: relative;
  z-index: 1;
  width: min(620px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
}

.km-modal > header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 14px 18px;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
}

.km-modal h2 {
  margin: 0;
  color: #172033;
  font-size: 18px;
  letter-spacing: 0;
}

.km-modal > header button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #64748b;
  font-size: 24px;
  cursor: pointer;
}

.km-modal > header button:hover {
  background: #f1f5f9;
  color: #172033;
}

.km-modal-body {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.km-form label:not(.km-checkbox) {
  display: grid;
  gap: 6px;
}

.km-form label > span {
  color: #334155;
  font-size: 13px;
  font-weight: 650;
}

.km-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px;
  border: 1px solid #bbdfc7;
  border-radius: 6px;
  background: #f0f9f2;
  cursor: pointer;
}

.km-checkbox input {
  width: 17px;
  min-height: 17px;
  margin-top: 1px;
}

.km-form-error {
  padding: 10px 11px;
  border: 1px solid #fecaca;
  border-radius: 6px;
  background: #fff1f2;
  color: #b42318;
  font-size: 13px;
}

.km-form-error[hidden] {
  display: none;
}

.km-form footer {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 18px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}

.km-form footer button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #475569;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.km-form footer button:hover {
  background: #f8fafc;
}

.km-form footer .km-primary {
  border-color: #2563eb;
  background: #2563eb;
  color: #fff;
}

.km-toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10020;
  max-width: min(420px, calc(100vw - 44px));
  padding: 11px 14px;
  border: 1px solid #bbdfc7;
  border-radius: 7px;
  background: #f0f9f2;
  color: #166534;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .14);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .15s ease, transform .15s ease;
}

.km-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.km-toast.is-error {
  border-color: #fecaca;
  background: #fff1f2;
  color: #b42318;
}

@media (max-width: 1120px) {
  .km-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .km-tabs {
    overflow-x: auto;
    margin-bottom: 16px;
  }

  .km-header {
    align-items: stretch;
    flex-direction: column;
  }

  .km-header .km-primary {
    width: 100%;
  }

  .km-toolbar {
    grid-template-columns: 1fr;
  }

  .km-layout {
    grid-template-columns: 1fr;
  }

  .km-folders {
    position: static;
  }

  .km-grid {
    grid-template-columns: 1fr;
  }

  .km-card h3,
  .km-card p,
  .km-tags {
    min-height: 0;
  }

  .km-modal-layer {
    align-items: flex-end;
    padding: 0;
  }

  .km-modal {
    width: 100%;
    max-height: 92vh;
    border-radius: 8px 8px 0 0;
  }
}
