/* Knowledge app. Uses the shell tokens only; RTL/LTR follows the document direction.
   Navigation lives in the single top context bar, so no in-page sidebar is drawn. */
.km-page { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ------------------------------------------------------------- toolbar */
.km-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.km-search-box { flex: 1 1 340px; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 6px 0 12px; min-width: 0; }
.km-search-box > svg { color: var(--muted); flex: 0 0 auto; }
.km-search-box input { flex: 1 1 auto; min-width: 0; border: 0; background: transparent; color: var(--ink); font: inherit; padding: 10px 0; outline: none; }
.km-search-box input::placeholder { color: var(--muted-2); }
.km-search-box:focus-within { border-color: var(--brand-200); box-shadow: 0 0 0 3px var(--brand-50); }

/* --------------------------------------------------------------- KPIs */
.km-kpi { grid-template-columns: repeat(auto-fit, minmax(162px, 1fr)); }
.km-kpi .stat { text-decoration: none; }
.km-kpi .stat-value { font-size: clamp(21px, 1.9vw, 26px); }

/* ---------------------------------------------------------- dashboard */
.km-dash { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.km-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.km-dash .card-title { justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
.km-link { margin-inline-start: auto; font-size: 12px; font-weight: 600; color: var(--brand); text-decoration: none; }
.km-link:hover { text-decoration: underline; }
.km-list-tight { margin-top: 10px; }

.km-mini-list { display: flex; flex-direction: column; margin-top: 8px; }
.km-mini { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 2px; border-bottom: 1px dashed var(--line); color: inherit; text-decoration: none; font-size: 13px; }
.km-mini:last-child { border-bottom: 0; }
.km-mini span { color: var(--ink-2); }
.km-mini b { font-variant-numeric: tabular-nums; color: var(--ink); }
.km-mini:hover span { color: var(--brand); }

.km-doc { display: flex; align-items: center; gap: 9px; padding: 8px 2px; border-bottom: 1px dashed var(--line); color: inherit; text-decoration: none; min-width: 0; }
.km-doc:last-child { border-bottom: 0; }
.km-doc > svg { color: var(--brand); flex: 0 0 auto; }
.km-doc > span { display: flex; flex-direction: column; min-width: 0; }
.km-doc strong { font-size: 13px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.km-doc span span { color: var(--muted); font-size: 11.5px; }
.km-doc:hover strong { color: var(--brand); }

.km-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.km-section-head h2 { margin: 0; font-size: 17px; }

.km-libs { display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 10px; }
.km-lib { display: flex; flex-direction: column; gap: 6px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: inherit; text-decoration: none; transition: border-color 0.15s ease, box-shadow 0.15s ease; }
.km-lib:hover { border-color: var(--brand-200); box-shadow: var(--shadow-xs); }
.km-lib-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); }
.km-lib-title { font-weight: 700; font-size: 14px; }
.km-lib-sub { color: var(--muted); font-size: 12px; line-height: 1.5; }
.km-lib-foot { margin-top: auto; font-size: 11.5px; color: var(--muted-2); border-top: 1px solid var(--line); padding-top: 8px; }
.km-gap { border-inline-start: 3px solid var(--brand); }

/* --------------------------------------------------------------- rows */
.km-list { display: flex; flex-direction: column; gap: 8px; }
.km-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; text-align: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 13px; cursor: pointer; color: inherit; font: inherit; text-decoration: none; }
.km-row:hover { border-color: var(--brand-200); background: var(--surface-2); }
.km-row-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); }
.km-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.km-row-main strong { font-size: 13.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.km-row-sub { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.km-row-end { display: flex; align-items: center; gap: 10px; }
.km-row-date { color: var(--muted-2); font-size: 11px; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.km-snippet { margin: -2px 0 4px; padding-inline-start: 54px; color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------- groups */
.km-group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; display: flex; flex-direction: column; gap: 10px; }
.km-group-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.km-group-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); flex: 0 0 auto; }
.km-group-head > div { display: flex; flex-direction: column; min-width: 0; }
.km-group-head strong { font-size: 14px; }
.km-group-head div span { color: var(--muted); font-size: 11.5px; }
.km-group-head > .small { margin-inline-start: auto; }
.km-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.km-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); border-radius: 999px; padding: 5px 11px; font: inherit; font-size: 12px; cursor: pointer; }
.km-chip:hover { border-color: var(--brand-200); color: var(--brand-3); }
.km-chip.active { background: var(--brand-50); border-color: var(--brand-200); color: var(--brand-3); font-weight: 650; }
.km-chip-n { background: var(--surface); border-radius: 999px; padding: 0 6px; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.km-chips-status { padding: 2px 0; }

/* -------------------------------------------------------------- empty */
.km-empty { display: flex; flex-direction: column; align-items: center; gap: 7px; text-align: center; padding: 30px 18px; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--muted); }
.km-empty > svg { color: var(--brand); opacity: 0.75; }
.km-empty strong { color: var(--ink); font-size: 14.5px; }
.km-empty p { margin: 0; max-width: 54ch; font-size: 12.5px; line-height: 1.6; }
.km-empty .km-actions { margin-top: 4px; justify-content: center; }

/* ------------------------------------------------------------ article */
.km-article { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.km-article > h1 { margin-top: 4px; }
.km-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 12px; margin: 8px 0 16px; }
.km-meta span { display: inline-flex; align-items: center; gap: 4px; }
.km-body { line-height: 1.8; font-size: 14px; }
.km-body h2, .km-body h3 { margin: 16px 0 6px; }
.km-body ul, .km-body ol { padding-inline-start: 22px; }
.km-callout { border-inline-start: 3px solid var(--brand); background: var(--brand-50); padding: 9px 12px; border-radius: 8px; margin: 8px 0; }
.km-callout.warn { border-color: var(--amber); background: var(--amber-soft); }
.km-callout.danger { border-color: var(--red); background: var(--red-soft); }
.km-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ------------------------------------------------------------- editor */
.km-editor { display: flex; flex-direction: column; gap: 10px; }
.km-editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.km-block { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 11px; background: var(--surface-2); }
.km-block [contenteditable] { min-height: 1.7em; outline: none; font-size: 13.5px; line-height: 1.7; }
.km-block:focus-within { border-color: var(--brand-200); }
.km-save { color: var(--muted); font-size: 11.5px; min-height: 1em; margin: 0; }

/* ---------------------------------------------------------------- training */
.km-course { text-align: start; font: inherit; cursor: pointer; }
.km-course .km-lib-foot { display: flex; align-items: center; gap: 6px; }
.km-course-detail { display: flex; flex-direction: column; gap: 10px; }
.km-lessons { display: flex; flex-direction: column; gap: 10px; }
.km-lesson { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--surface-2); }
.km-lesson h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 14px; flex-wrap: wrap; }
.km-lesson-n { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); font-size: 11.5px; font-weight: 700; flex: 0 0 auto; }
.km-lesson p { margin: 0 0 8px; color: var(--ink-2); font-size: 13px; line-height: 1.7; }
.km-exam { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.km-exam h3 { margin: 0; font-size: 15px; }
.km-exam fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; margin: 0; }
.km-exam legend { font-size: 13px; font-weight: 650; padding: 0 4px; }
.km-exam label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; padding: 3px 0; color: var(--ink-2); }

/* -------------------------------------------------────────────── article rhythm */
.km-article h2 { margin: 20px 0 8px; font-size: 17px; }
.km-article > h2:first-of-type { margin-top: 10px; }
.km-body p { margin: 0 0 10px; }
.km-body > :first-child { margin-top: 0; }
.km-sub { margin-top: 22px; }
.km-sub > h2 { display: flex; align-items: center; gap: 6px; margin-top: 0; }
.km-sub > h2 svg { color: var(--brand); flex: 0 0 auto; }
.km-file-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.km-file-list li { display: flex; align-items: center; gap: 7px; color: var(--ink-2); }
.km-file-list svg { color: var(--muted); flex: 0 0 auto; }
.km-file-list a { color: var(--brand-3); text-decoration: none; }
.km-file-list a:hover { text-decoration: underline; }
.km-file-list .muted { color: var(--muted-2); }
.km-upload { cursor: pointer; margin: 2px 0 4px; }
.km-link-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 10px 12px; align-items: end; margin-top: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; }
.km-link-form .field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.km-link-form .btn { margin-bottom: 1px; }

/* --------------------------------------------------------------- misc */
.km-tree { margin: 0; padding-inline-start: 18px; }
.km-note { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; color: var(--ink-2); font-size: 12.5px; line-height: 1.6; }

@media (max-width: 900px) {
  .km-dash { grid-template-columns: 1fr; }
  .km-editor-grid { grid-template-columns: 1fr; }
  .km-row-date { display: none; }
  .km-link-form { grid-template-columns: 1fr 1fr; }
  .km-link-form .btn { grid-column: 1 / -1; justify-self: start; }
}
@media (max-width: 620px) {
  .km-libs { grid-template-columns: 1fr 1fr; }
  .km-search-box { flex-basis: 100%; }
  .km-row { grid-template-columns: auto minmax(0, 1fr); }
  .km-row-end { grid-column: 2; justify-content: flex-start; }
  .km-snippet { padding-inline-start: 0; }
}
