/* IKC V1 — Responsive Interface */

:root {
    --navy: #17324d;
    --navy-light: #244866;
    --accent: #3b82a0;
    --page-bg: #f3f6f9;
    --surface: #ffffff;
    --border: #e1e7ed;
    --text: #253446;
    --muted: #718096;
    --hover: #edf4f8;
    --selected: #e3eef5;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
        "Microsoft YaHei", sans-serif;
    color: var(--text);
    background: var(--page-bg);
    line-height: 1.6;
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

/* Top header */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 18px 28px;
    background: var(--navy);
    color: #ffffff;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand-icon {
    display: grid;
    place-items: center;
    flex: 0 0 46px;
    width: 46px;
    height: 46px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 12px;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 1px;
}

.brand h1 {
    margin: 0;
    font-size: 21px;
    line-height: 1.35;
    font-weight: 650;
}

.brand p {
    margin: 3px 0 0;
    color: #c8d7e5;
    font-size: 13px;
}

#search-input {
    width: min(390px, 40%);
    min-width: 220px;
    min-height: 44px;
    padding: 10px 15px;
    border: 1px solid transparent;
    border-radius: 9px;
    outline: none;
    background: #ffffff;
    color: var(--text);
}

#search-input:focus {
    border-color: #91c5df;
    box-shadow: 0 0 0 3px rgba(145, 197, 223, 0.25);
}

/* Main workspace */

.workspace {
    display: grid;
    grid-template-columns: 290px minmax(0, 1fr);
    gap: 20px;
    width: 100%;
    max-width: 1800px;
    min-height: calc(100vh - 82px);
    margin: 0 auto;
    padding: 20px;
}

.sidebar,
.reader {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.sidebar {
    align-self: start;
    padding: 16px 12px;
    overflow-wrap: anywhere;
}

.section-heading {
    padding: 4px 9px 13px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 1.2px;
}

.reader {
    padding: 28px 34px;
    overflow-wrap: anywhere;
}

.breadcrumb {
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
}

/* Knowledge tree */

.tree-item {
    min-width: 0;
}

.tree-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 38px;
    padding: 7px 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.tree-row:hover {
    background: var(--hover);
}

.tree-row.selected {
    background: var(--selected);
    color: var(--navy);
    font-weight: 650;
}

.tree-row span:last-child {
    min-width: 0;
    overflow-wrap: anywhere;
}

.tree-arrow {
    flex: 0 0 12px;
    color: var(--muted);
}

.tree-icon {
    flex: 0 0 20px;
    text-align: center;
}

.tree-children {
    margin-left: 13px;
    padding-left: 7px;
    border-left: 1px solid var(--border);
}

.tree-children[hidden] {
    display: none;
}

/* Search results */

.search-result {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin: 4px 0;
    padding: 11px;
    border-radius: 8px;
    cursor: pointer;
    overflow-wrap: anywhere;
}

.search-result:hover {
    background: var(--hover);
}

.search-result strong {
    color: var(--navy);
}

.search-result small {
    color: var(--muted);
    overflow-wrap: anywhere;
}

/* Article reading */

.article {
    max-width: 900px;
    font-size: 16px;
    line-height: 1.8;
}

.article h1,
.article h2,
.article h3 {
    color: var(--navy);
    line-height: 1.4;
}

.article h1 {
    font-size: 30px;
}

.article h2 {
    margin-top: 30px;
    font-size: 23px;
}

.article h3 {
    margin-top: 24px;
    font-size: 18px;
}

.article p,
.article li {
    overflow-wrap: anywhere;
}

.article a {
    color: var(--accent);
}

.article pre {
    max-width: 100%;
    padding: 14px;
    overflow-x: auto;
    border-radius: 8px;
    background: #f0f3f6;
}

.article code {
    overflow-wrap: anywhere;
}

.article table {
    display: block;
    width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
}

.article th,
.article td {
    padding: 9px 12px;
    border: 1px solid var(--border);
    text-align: left;
}

.article th {
    background: var(--hover);
}

/* Tablet */

@media (max-width: 900px) {
    .topbar {
        gap: 16px;
        padding: 16px 20px;
    }

    .workspace {
        grid-template-columns: 245px minmax(0, 1fr);
        gap: 14px;
        padding: 14px;
    }

    .reader {
        padding: 24px;
    }

    .brand h1 {
        font-size: 18px;
    }
}

/* Mobile */

@media (max-width: 680px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
        padding: 16px;
    }

    .brand {
        gap: 11px;
    }

    .brand-icon {
        flex-basis: 40px;
        width: 40px;
        height: 40px;
        border-radius: 10px;
    }

    .brand h1 {
        font-size: 18px;
    }

    .brand p {
        font-size: 12px;
    }

    #search-input {
        width: 100%;
        min-width: 0;
        min-height: 46px;
    }

    .workspace {
        display: flex;
        flex-direction: column;
        gap: 12px;
        min-height: auto;
        padding: 12px;
    }

    .sidebar {
        width: 100%;
        padding: 12px 10px;
    }

    .reader {
        width: 100%;
        padding: 20px 16px;
    }

    .breadcrumb {
        margin-bottom: 18px;
        overflow-wrap: anywhere;
    }

    .article {
        font-size: 15px;
        line-height: 1.75;
    }

    .article h1 {
        font-size: 25px;
    }

    .article h2 {
        font-size: 21px;
    }

    .article h3 {
        font-size: 17px;
    }

    .tree-row {
        min-height: 42px;
        padding-top: 9px;
        padding-bottom: 9px;
    }
}

/* Small phones */

@media (max-width: 380px) {
    .workspace {
        padding: 8px;
    }

    .reader {
        padding: 16px 12px;
    }

    .brand h1 {
        font-size: 16px;
    }
}

/* Knowledge tree header and mobile toggle */

.sidebar-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 9px 10px;
}

.sidebar-heading .section-heading {
    padding: 4px 0;
}

.tree-toggle {
    display: none;
    flex-shrink: 0;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    color: var(--navy);
    font-size: 12px;
    cursor: pointer;
}

.tree-toggle:hover {
    background: var(--hover);
}

#knowledge-tree[hidden] {
    display: none;
}

@media (max-width: 680px) {
    .tree-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 36px;
    }
}

/* Article metadata */

.article-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 12px 20px;
    margin: -10px 0 24px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.meta-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.meta-label {
    margin-right: 3px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 750;
    letter-spacing: 0.8px;
}

.meta-chip {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 3px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f7f9fb;
    color: var(--navy);
    font-size: 12px;
    overflow-wrap: anywhere;
}

.status-chip {
    background: #edf5ef;
    border-color: #d6e8da;
    color: #356746;
}

@media (max-width: 680px) {
    .article-meta {
        gap: 10px;
        margin-top: -6px;
        margin-bottom: 20px;
        padding-bottom: 15px;
    }

    .meta-group {
        gap: 5px;
    }
}


/* Related topics */

.article .related-topics-heading {
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.article .related-topic-list {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin: 12px 0 24px;
}

.article .related-topic {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 46px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--navy);
    font-size: 14px;
    line-height: 1.5;
    text-align: left;
    overflow-wrap: anywhere;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.article .related-topic::after {
    content: "›";
    flex-shrink: 0;
    margin-left: 12px;
    color: var(--muted);
    font-size: 22px;
}

.article .related-topic:hover:not(:disabled) {
    background: var(--hover);
    border-color: var(--accent);
}

.article .related-topic:disabled {
    color: var(--muted);
    background: #f7f9fb;
    cursor: default;
}

.article .related-topic:disabled::after {
    content: "";
}

@media (max-width: 680px) {
    .article .related-topic {
        min-height: 46px;
        padding: 11px 12px;
    }
}



/* Inline terminology popup */
.ikc-term-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: transparent;
}

.ikc-term-popup {

    position: fixed;
    z-index: 1001;
    width: min(340px, calc(100vw - 24px));
    width: min(340px, calc(100vw - 24px));
    max-height: min(320px, calc(100vh - 24px));
    overflow-y: auto;
    box-sizing: border-box;
    padding: 20px;
    border: 1px solid #d8dce3;
    border-radius: 12px;
    background: #ffffff;
    color: #222222;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
}

.ikc-term-popup h2 {
    margin: 0 28px 12px 0;
    font-size: 17px;
    line-height: 1.5;
}

.ikc-term-definition {
    margin: 0 0 16px;
    line-height: 1.7;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.ikc-term-close {
    float: right;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 23px;
}

.ikc-term-full-article {
    max-width: 100%;
    padding: 9px 12px;
    border: 1px solid #d8dce3;
    border-radius: 7px;
    background: #f7f8fa;
    color: #222222;
    cursor: pointer;
}

/* Private IKC session controls */
.logout-form { margin: 0; flex: 0 0 auto; }
.logout-button { min-height: 42px; padding: 8px 12px; border: 1px solid rgba(255,255,255,.45); border-radius: 8px; background: transparent; color: #fff; cursor: pointer; white-space: nowrap; }
.logout-button:hover { background: rgba(255,255,255,.12); }
@media (max-width: 680px) { .logout-form { width: 100%; } .logout-button { width: 100%; } }


/* Mobile header modes: homepage header vs. compact article actions */
.ikc-article-actions {
    display: flex;
    align-items: stretch;
    gap: 10px;
    margin: 0 0 18px;
}
.ikc-article-action-button {
    min-height: 42px;
    flex: 1 1 0;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff;
    color: var(--navy);
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
}
.ikc-article-action-button:active { background: var(--hover); }
.ikc-article-back {
    min-height: 42px; flex: 0 0 auto; margin: 0; padding: 7px 9px;
    border: 1px solid var(--border); border-radius: 9px; background: #fff;
    color: var(--navy-light); font-size: 12px; font-weight: 650; cursor: pointer;
}
.ikc-article-back[hidden] { display: none !important; }

@media (max-width: 680px) {
    .topbar {
        position: sticky;
        top: 0;
        z-index: 100;
        box-shadow: 0 2px 10px rgba(17, 35, 53, 0.12);
    }
    body.ikc-article-open .topbar {
        display: none !important;
    }
    body.ikc-article-open .workspace {
        padding-top: 66px;
    }
    body.ikc-article-open .sidebar {
        display: none;
    }
    body.ikc-article-open .reader {
        border: 0;
        border-radius: 0;
        padding-top: 10px;
    }
    body.ikc-article-open .ikc-article-actions {
        position: fixed;
        z-index: 1000;
        top: 0;
        left: 0;
        right: 0;
        margin: 0;
        padding: 8px 12px;
        gap: 8px;
        flex-wrap: wrap;
        background: #fff;
        border-bottom: 1px solid var(--border);
        box-shadow: 0 2px 8px rgba(17, 35, 53, 0.10);
    }
    body.ikc-article-open .ikc-article-action-button {
        min-width: 0; min-height: 42px; flex: 1 1 calc(50% - 4px); padding: 7px 4px;
        font-size: 11px; line-height: 1.25; white-space: normal;
    }
    body.ikc-article-open .ikc-article-back {
        display: block; width: 100%; min-width: 100%; min-height: 38px;
        flex: 0 0 100%; margin: 0; padding: 7px 10px;
        font-size: 12px; line-height: 1.25; white-space: normal;
    }
    body.ikc-article-open .breadcrumb {
        margin-bottom: 12px;
        padding-bottom: 8px;
        font-size: 11px;
    }
    body.ikc-article-open .article-meta {
        margin-top: 0;
        margin-bottom: 14px;
        padding-bottom: 10px;
    }
}




/* V6 desktop reading layout: fixed header/tree/actions, scroll article only. */
@media (min-width: 900px) {
    html, body { height: 100%; }
    body { min-height: 100vh; overflow: hidden; }
    .topbar {
        position: sticky;
        top: 0;
        z-index: 1100;
        min-height: 64px;
        padding: 10px 16px;
        box-shadow: 0 2px 8px rgba(17, 35, 53, 0.10);
    }
    .brand-icon { flex-basis: 38px; width: 38px; height: 38px; border-radius: 10px; }
    .brand { gap: 10px; }
    .brand h1 { font-size: 18px; }
    .brand p { font-size: 11px; }
    #search-input { min-height: 38px; width: min(390px, 34vw); }
    .logout-button { min-height: 36px; }
    .workspace {
        grid-template-columns: 228px minmax(0, 1fr);
        gap: 14px;
        width: 100%;
        max-width: none;
        height: calc(100vh - 64px);
        min-height: 0;
        margin: 0;
        padding: 14px 16px 16px;
        overflow: hidden;
        box-sizing: border-box;
    }
    .sidebar {
        align-self: stretch;
        height: 100%;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 12px 10px;
        box-sizing: border-box;
    }
    .reader {
        display: flex;
        flex-direction: column;
        align-self: stretch;
        height: 100%;
        min-height: 0;
        padding: 18px 26px 0;
        overflow: hidden;
        box-sizing: border-box;
    }
    .ikc-article-actions {
        position: sticky;
        top: 0;
        z-index: 20;
        flex: 0 0 auto;
        justify-content: flex-start;
        gap: 8px;
        margin: 0 0 12px;
        padding: 0 0 10px;
        background: var(--surface);
    }
    .ikc-article-action-button {
        flex: 0 0 auto;
        width: auto;
        min-width: 170px;
        min-height: 34px;
        padding: 6px 14px;
        font-size: 12px;
    }
    .ikc-article-back { flex: 0 0 auto; margin-bottom: 8px; }
    .breadcrumb {
        flex: 0 0 auto;
        margin-bottom: 12px;
        padding-bottom: 9px;
        font-size: 11px;
    }
    .article-meta {
        flex: 0 0 auto;
        gap: 6px 10px;
        margin: 0 0 14px;
        padding-bottom: 10px;
        font-size: 11px;
    }
    .meta-group { gap: 4px; }
    .meta-label { font-size: 9px; letter-spacing: .5px; }
    .meta-chip { padding: 2px 6px; font-size: 10px; border-radius: 5px; }
    #article-content {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 0 12px 28px 0;
        scrollbar-gutter: stable;
    }
}

/* Same-page article PDF printing; keeps the current IKC tab open. */
@page { size: auto; margin: 18mm 16mm; }
@media print {
  html.ikc-printing-article body, html.ikc-printing-article body * { visibility: visible !important; }
  html.ikc-printing-article body { color: #222 !important; background: #fff !important; }
  html.ikc-printing-article body > .topbar,
  html.ikc-printing-article body > .logout-form { display: none !important; }
  html.ikc-printing-article body > .workspace { display: block !important; width: 100% !important; max-width: none !important; min-height: 0 !important; margin: 0 !important; padding: 0 !important; }
  html.ikc-printing-article .workspace .sidebar,
  html.ikc-printing-article .reader > .breadcrumb,
  html.ikc-printing-article .reader > #article-meta,
  html.ikc-printing-article .reader > .ikc-article-actions,
  html.ikc-printing-article .reader > .ikc-article-back { display: none !important; }
  html.ikc-printing-article .workspace .reader { display: block !important; width: 100% !important; min-width: 0 !important; margin: 0 !important; padding: 0 !important; border: 0 !important; border-radius: 0 !important; background: #fff !important; box-shadow: none !important; overflow: visible !important; }
  html.ikc-printing-article #article-content { display: block !important; width: 100% !important; margin: 0 !important; padding: 0 !important; border: 0 !important; background: #fff !important; color: #222 !important; font: 11pt/1.65 Arial, "Microsoft YaHei", sans-serif !important; overflow: visible !important; }
  html.ikc-printing-article #article-content h1,
  html.ikc-printing-article #article-content h2,
  html.ikc-printing-article #article-content h3,
  html.ikc-printing-article #article-content h4 { color: #17324d !important; line-height: 1.35 !important; break-after: avoid-page; page-break-after: avoid; }
  html.ikc-printing-article #article-content h1 { font-size: 23pt !important; }
  html.ikc-printing-article #article-content h2 { font-size: 17pt !important; margin-top: 24px !important; }
  html.ikc-printing-article #article-content h3 { font-size: 13pt !important; margin-top: 18px !important; }
  html.ikc-printing-article #article-content p,
  html.ikc-printing-article #article-content li { overflow-wrap: anywhere; }
  html.ikc-printing-article #article-content a { color: #245d7a !important; text-decoration: underline; }
  html.ikc-printing-article #article-content table { width: 100%; border-collapse: collapse; margin: 12px 0; }
  html.ikc-printing-article #article-content th,
  html.ikc-printing-article #article-content td { border: 1px solid #cbd2d9; padding: 6px 8px; text-align: left; vertical-align: top; }
  html.ikc-printing-article #article-content th { background: #f0f3f6 !important; }
  html.ikc-printing-article #article-content pre,
  html.ikc-printing-article #article-content code { white-space: pre-wrap; overflow-wrap: anywhere; }
  html.ikc-printing-article #article-content blockquote { border-left: 3px solid #c9a96e; margin-left: 0; padding-left: 12px; color: #555 !important; }
  html.ikc-printing-article #article-content img { max-width: 100% !important; }
  html.ikc-printing-article #article-content button,
  html.ikc-printing-article #article-content .ikc-tool-trigger { display: none !important; }
  html.ikc-printing-article .ikc-article-print-footer { display: block !important; margin-top: 28px; padding-top: 8px; border-top: 1px solid #ddd; color: #666 !important; font-size: 9pt; }
}


/* Desktop layout refinement — local test only. Mobile rules remain unchanged. */
@media screen and (min-width: 900px) {
  .workspace {
    width: min(1600px, 100%);
    max-width: 1600px;
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 18px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 24px;
    padding-right: 24px;
    box-sizing: border-box;
  }

  .sidebar {
    min-width: 0;
    padding-left: 12px;
    padding-right: 12px;
    overflow-wrap: anywhere;
  }

  .tree-row {
    min-width: 0;
    gap: 9px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .tree-row span:last-child {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: normal;
  }

  .reader {
    min-width: 0;
    padding-left: 26px;
    padding-right: 26px;
  }

  /* The article previously stopped at 900px, leaving unused space on the right. */
  #article-content.article {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
    padding-right: 18px;
  }

  .ikc-article-actions {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    justify-content: flex-start;
    gap: 10px;
    margin: 0 0 6px;
    padding: 0 0 4px;
    background: var(--surface);
  }

  .ikc-article-action-button {
    flex: 0 0 auto;
    min-width: 195px;
    min-height: 42px;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 650;
    border-radius: 8px;
  }

  #article-meta.article-meta {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 9px 14px;
    margin-top: 0;
    margin-bottom: 10px;
    padding-bottom: 10px;
  }

  .meta-group {
    max-width: 100%;
    min-width: 0;
  }

  .meta-label {
    font-size: 11px;
    letter-spacing: .6px;
  }

  .meta-chip {
    max-width: 300px;
    padding: 4px 9px;
    font-size: 12px;
    overflow-wrap: anywhere;
  }

  /* Desktop already has the tree on the left; keep the back link for mobile only. */
  .ikc-article-back {
    display: none !important;
  }
}


/* The Markdown filename/path is intentionally omitted from article headers. */
#breadcrumb[hidden] {
  display: none !important;
}
