/* ------------------------------------------------------------------------
 * Carried over verbatim from template.html — the design original.
 * Tailwind 2.2.19 comes from the CDN; these hand-written rules extend its
 * namespace with the brand colors, and win because they load afterwards.
 * ---------------------------------------------------------------------- */

/* ------------------------------------------------------------------------
 * Design tokens.
 *
 * The colours are unchanged — every value here already existed as a literal
 * further down this file. They are named because the admin page draws charts
 * with createElementNS, and an SVG element cannot inherit a Tailwind class:
 * chart.js reads these with getComputedStyle instead of carrying the fourth
 * copy of #4f46e5.
 * ---------------------------------------------------------------------- */

:root {
    --color-primary: #4f46e5;
    --color-primary-light: #6366f1;
    --color-primary-soft: #eef2ff;
    --color-secondary: #eab308;
    --color-secondary-soft: #fefce8;
    --color-tertiary: #f0fdfa;
    --color-danger: #b91c1c;
    --color-danger-soft: rgba(220, 38, 38, 0.08);
    --color-warn: #a16207;
    --color-text: #1f2937;
    --color-muted: #6b7280;
    --color-faint: #9ca3af;
    --color-border: #e5e7eb;
    --color-border-strong: #d1d5db;
    --color-surface: #ffffff;
    --color-surface-alt: #f9fafb;
}

body {
    font-family: 'Poppins', sans-serif;
}

.bg-gradient-custom {
    background: linear-gradient(to right, #f0fdfa, #fef3c7);
}

.text-primary {
    color: #4f46e5;
}

.bg-primary {
    background-color: #4f46e5;
}

/* Hover lightens rather than darkens — that is the template's convention. */
.hover\:bg-primary:hover {
    background-color: #6366f1;
}

.focus\:ring-primary:focus {
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.5);
}

.text-secondary {
    color: #eab308;
}

.bg-secondary {
    background-color: #eab308;
}

.bg-tertiary {
    background-color: #f0fdfa;
}

.btn-shadow {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card-shadow {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.more {
    position: relative;
    display: inline-block;
    padding-bottom: 2px;
}

.more:after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 2px;
    background-color: currentColor;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s ease;
}

.more:hover:after {
    transform: scaleX(1);
}

.sticky-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.1), 0 4px 6px -1px rgba(0, 0, 0, 0.06);
}

.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ------------------------------------------------------------------------
 * App UI pieces the template does not provide.
 * template.html has no text inputs, textareas, checkboxes or chat surfaces,
 * so these are derived from its <select> pattern and its radius/shadow scale.
 * ---------------------------------------------------------------------- */

.field-input,
.field-textarea {
    display: block;
    width: 100%;
    background-color: #fff;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    padding: 0.5rem 0.75rem;
    line-height: 1.375;
    color: #1f2937;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.field-input:hover,
.field-textarea:hover {
    border-color: #6b7280;
}

.field-input:focus,
.field-textarea:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.5);
}

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

.field-label {
    display: block;
    color: #374151;
    font-size: 0.875rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.field-hint {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 0.375rem;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: #374151;
    cursor: pointer;
}

.check-row input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: #4f46e5;
    cursor: pointer;
}

/* Status pills — header badges and the retrieval-mode indicator. */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.pill-on {
    background-color: rgba(79, 70, 229, 0.1);
    color: #4f46e5;
}

.pill-off {
    background-color: #f3f4f6;
    color: #6b7280;
}

.pill-warn {
    background-color: rgba(234, 179, 8, 0.15);
    color: #a16207;
}

.pill-error {
    background-color: rgba(220, 38, 38, 0.1);
    color: #b91c1c;
}

/* Chat transcript */
.messages {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 220px;
    max-height: 46vh;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.message {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    animation: rise 320ms ease;
}

.message.user {
    align-self: flex-end;
    max-width: 80%;
    background-color: #eef2ff;
    color: #1f2937;
}

.message.assistant {
    align-self: flex-start;
    max-width: 88%;
    background-color: #f0fdfa;
    color: #1f2937;
}

/* A summary is a different kind of reply — the whole document rather than an
   answer to a question — so it gets the secondary amber rather than the teal. */
.message.summary {
    align-self: flex-start;
    max-width: 92%;
    background-color: #fefce8;
    border-left: 3px solid #eab308;
    color: #1f2937;
}

/* Not a reply at all: a status line that appears while a long summary runs and
   is removed when it finishes. Centred and muted so it reads as the system
   speaking, not the model. */
.message.notice {
    align-self: center;
    max-width: 90%;
    background-color: transparent;
    border: 1px dashed #d1d5db;
    color: #6b7280;
    font-size: 0.8125rem;
    text-align: center;
}

/* 답변을 기다리는 동안의 한 줄 — 검색 중 / 생성 중. 답변이 아니므로 답변처럼
   보이지 않게 두되, .notice 처럼 가운데로 보내지는 않는다: 곧 이 자리에 답변이
   나타나므로 말풍선이 서는 위치가 같아야 바뀌는 것이 글자뿐이다. */
.message.thinking {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    align-self: flex-start;
    max-width: 88%;
    background-color: transparent;
    border: 1px dashed #d1d5db;
    color: #6b7280;
    font-size: 0.875rem;
}

.message.thinking .spinner {
    width: 0.875rem;
    height: 0.875rem;
    flex-shrink: 0;
}

.message.error {
    align-self: stretch;
    background-color: rgba(220, 38, 38, 0.08);
    color: #b91c1c;
}

.message-empty {
    color: #9ca3af;
    font-size: 0.875rem;
    text-align: center;
    padding: 2rem 0;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
}

/* Suggested queries — offered when there is nothing to answer with. */
.suggestions {
    margin-bottom: 1rem;
    padding: 0.875rem 1rem;
    border: 1px dashed #c7d2fe;
    border-radius: 0.5rem;
    background-color: #eef2ff;
}

.suggestions-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #4338ca;
    margin-bottom: 0.625rem;
}

.suggestion-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.suggestion-btn {
    padding: 0.4375rem 0.875rem;
    border: 1px solid #c7d2fe;
    border-radius: 9999px;
    background-color: #fff;
    color: #4338ca;
    font-size: 0.8125rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.suggestion-btn:hover {
    background-color: #4f46e5;
    border-color: #4f46e5;
    color: #fff;
}

.suggestion-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.5);
}

/* 가이드북이 없는 나라 — 질문이 만들어지지 않는다는 안내. 눌리지 않는다. */
.suggestion-btn.is-disabled,
.suggestion-btn.is-disabled:hover {
    border-color: #d1d5db;
    background-color: #f3f4f6;
    color: #6b7280;
    cursor: not-allowed;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* 흰 모달 안의 버튼. 하단 남색 바의 .ipn-btn 은 흰 글씨라 여기서는 보이지 않는다. */
.modal-btn {
    padding: 0.4375rem 1rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.25rem;
    background: #fff;
    color: #1f2937;
    font-size: 0.875rem;
    cursor: pointer;
}

.modal-btn-primary {
    border-color: #064f8b;
    background: #064f8b;
    color: #fff;
}

.modal-btn:hover,
.modal-btn:focus-visible {
    border-color: #064f8b;
}

.suggestion-empty {
    font-size: 0.8125rem;
    color: #6b7280;
}

.pane-scroll {
    max-height: 320px;
    overflow-y: auto;
}

.pane-scroll::-webkit-scrollbar,
.messages::-webkit-scrollbar {
    width: 8px;
}

.pane-scroll::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
    background-color: #d1d5db;
    border-radius: 9999px;
}

/* Retrieval score bar — the point of the search panel is comparing scores. */
.score-track {
    height: 6px;
    border-radius: 9999px;
    background-color: #e5e7eb;
    overflow: hidden;
}

.score-bar {
    height: 100%;
    border-radius: 9999px;
    background-color: #4f46e5;
    transition: width 0.3s ease;
}

.result-row {
    padding: 0.75rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.25rem;
    background-color: #fff;
}

.result-snippet {
    font-size: 0.8125rem;
    color: #4b5563;
    line-height: 1.55;
    margin-top: 0.5rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.attachment-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.25rem;
    background-color: #fff;
}

.attachment-row + .attachment-row {
    margin-top: 0.5rem;
}

.attachment-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: #1f2937;
    word-break: break-all;
}

.attachment-detail {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 0.125rem;
}

.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(79, 70, 229, 0.25);
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

/* ------------------------------------------------------------------------
 * Feedback (2.2.3) — both chat screens.
 * ---------------------------------------------------------------------- */

.feedback-row {
    align-self: flex-start;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.25rem 0.25rem 0.25rem 1rem;
    font-size: 0.8125rem;
    color: var(--color-muted);
}

.feedback-label {
    margin-right: 0.125rem;
}

.feedback-btn {
    padding: 0.25rem 0.625rem;
    border: 1px solid var(--color-border-strong);
    border-radius: 9999px;
    background-color: var(--color-surface);
    font-size: 0.9375rem;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}

.feedback-btn:hover:not(:disabled) {
    border-color: var(--color-primary);
    background-color: var(--color-primary-soft);
}

.feedback-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.feedback-note {
    font-size: 0.75rem;
    color: var(--color-primary);
}

/* The reason chips wrap onto their own line — they arrive after the 👎 is
   already recorded, so they must not shift the buttons under the cursor. */
.feedback-reasons {
    flex-basis: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.25rem;
}

.feedback-reason {
    padding: 0.25rem 0.625rem;
    border: 1px solid var(--color-border-strong);
    border-radius: 9999px;
    background-color: var(--color-surface);
    color: var(--color-muted);
    font-size: 0.75rem;
    cursor: pointer;
}

.feedback-reason:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* ------------------------------------------------------------------------
 * Corpus service — document rows.
 * ---------------------------------------------------------------------- */

/* The document the answer was actually written from. Heavier than the others
   on purpose: it is a different thing, not the first item of the same list. */
.doc-primary {
    border-color: var(--color-primary);
    border-left-width: 3px;
    background-color: var(--color-primary-soft);
}

.doc-meta {
    font-size: 0.75rem;
    color: var(--color-muted);
    margin-top: 0.25rem;
    word-break: break-word;
}

/* ------------------------------------------------------------------------
 * Matching passages.
 *
 * A document used to show one paragraph under the words "일치 구절 5개". These
 * are the other four — every passage the search matched, in reading order.
 * ---------------------------------------------------------------------- */

.chunk-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.625rem;
}

.chunk-list.is-scroll {
    max-height: 460px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.chunk-item {
    padding: 0.5rem 0.625rem;
    border-left: 2px solid var(--color-primary);
    border-radius: 0.25rem;
    background-color: var(--color-surface);
}

/* Matched, but the context cap or the length budget kept it out of the prompt.
   Dimmed rather than hidden: "the answer had more to draw on than it used" is
   a CORPUS_CONTEXT_CHUNKS conversation, and it cannot be had if the evidence
   for it is not on screen. */
.chunk-item.is-unused {
    border-left-color: var(--color-border-strong);
    background-color: var(--color-surface-alt);
    opacity: 0.72;
}

.chunk-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.chunk-where {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-muted);
    word-break: break-word;
}

.chunk-badge {
    font-size: 0.6875rem;
    padding: 0.0625rem 0.375rem;
    border: 1px solid var(--color-border-strong);
    border-radius: 9999px;
    color: var(--color-muted);
    white-space: nowrap;
}

/* The passage text sits tighter here than in a standalone result row: there
   are several of them stacked and the default top margin doubles the gap. */
.chunk-item .result-snippet {
    margin-top: 0.25rem;
}

/* 관련 문서 — the title is the control that opens the passages. Styled as text
   because it reads as a heading; it is a <button> because it is one. */
.doc-title-button {
    background: none;
    border: none;
    padding: 0;
    text-align: left;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: var(--color-border-strong);
}

.doc-title-button:hover,
.doc-title-button:focus-visible {
    color: var(--color-primary);
    text-decoration-color: var(--color-primary);
}

.doc-hint {
    font-size: 0.75rem;
    color: var(--color-faint);
    margin-top: 0.5rem;
}

/* ------------------------------------------------------------------------
 * Service-page dialog. Distinct from `.admin-modal-*` in admin.css on
 * purpose — different job, and the names must not collide if a page ever
 * loads both stylesheets.
 * ---------------------------------------------------------------------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background-color: rgba(17, 24, 39, 0.55);
}

.modal {
    position: relative;
    width: min(720px, 100%);
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    border-radius: 0.5rem;
    background-color: var(--color-surface);
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.25);
}

.modal-head {
    padding: 1.125rem 3rem 0.75rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--color-text);
    word-break: break-word;
}

.modal-subtitle {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--color-muted);
}

.modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.625rem;
    width: 2rem;
    height: 2rem;
    border: none;
    background: none;
    font-size: 1.375rem;
    line-height: 1;
    color: var(--color-muted);
    cursor: pointer;
}

.modal-close:hover,
.modal-close:focus-visible {
    color: var(--color-text);
}

/* The passages scroll, not the dialog: the header has to stay visible or the
   reader loses track of which document they opened. */
.modal-body {
    padding: 1rem 1.25rem 1.25rem;
    overflow-y: auto;
}

/* ------------------------------------------------------------------------
 * 채팅 대기열 모달 (js/queue.js) — 「k명 대기중」.
 *
 * 퍼져 나가는 고리 셋은 «살아 있다» 는 신호다. 숫자가 1초마다 갱신되지 않으면
 * 사람은 멈췄다고 읽는다. 숫자가 바뀔 때는 굴러가고 한 번 튄다(is-bumped).
 * ---------------------------------------------------------------------- */

.modal:has(.queue) {
    width: min(420px, 100%);
}

.queue {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.queue-pulse {
    position: relative;
    width: 4.5rem;
    height: 4.5rem;
    margin: 0.5rem 0 1rem;
}

.queue-pulse span {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid #064f8b;
    opacity: 0;
    animation: queue-ripple 2.4s ease-out infinite;
}

.queue-pulse span:nth-child(2) { animation-delay: 0.8s; }
.queue-pulse span:nth-child(3) { animation-delay: 1.6s; }

.queue-pulse::after {
    content: '';
    position: absolute;
    inset: 1.5rem;
    border-radius: 50%;
    background: #064f8b;
    animation: queue-breathe 1.2s ease-in-out infinite alternate;
}

@keyframes queue-ripple {
    from { transform: scale(0.35); opacity: 0.85; }
    to   { transform: scale(1);    opacity: 0; }
}

@keyframes queue-breathe {
    from { transform: scale(0.85); }
    to   { transform: scale(1.05); }
}

.queue-count {
    font-size: 1rem;
    color: var(--color-text);
}

.queue-number {
    display: inline-block;
    min-width: 1.5ch;
    margin-right: 0.125rem;
    font-size: 2.25rem;
    font-weight: 800;
    line-height: 1.1;
    color: #064f8b;
    font-variant-numeric: tabular-nums;
}

.queue-number.is-bumped {
    animation: queue-bump 0.45s ease-out;
}

@keyframes queue-bump {
    40% { transform: scale(1.25); }
}

/* «대기중» 뒤의 점 셋이 차례로 찍힌다. */
.queue-count-unit::after {
    content: '';
    display: inline-block;
    width: 1.25em;
    text-align: left;
    animation: queue-dots 1.5s steps(4, end) infinite;
}

@keyframes queue-dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
}

.queue-meta {
    margin-top: 0.375rem;
    font-size: 0.875rem;
    color: var(--color-muted);
}

.queue-notice {
    margin-top: 0.75rem;
    font-size: 0.8125rem;
    color: var(--color-text);
}

.queue-warning {
    width: 100%;
    margin-top: 1rem;
    padding: 0.625rem 0.75rem;
    border: 1px solid #f3d38a;
    border-radius: 0.25rem;
    background: #fff8e6;
    font-size: 0.8125rem;
    color: #8a5a00;
    text-align: left;
    word-break: keep-all;
}

.queue-warning::before {
    content: '⚠ ';
}

.queue-warning:empty {
    display: none;
}

.queue .modal-actions {
    width: 100%;
}

/* 더 기다릴 것이 없다(가득 참 · 연결 끊김) — 움직임을 멈춘다. */
.queue.is-final .queue-pulse span,
.queue.is-final .queue-pulse::after {
    animation: none;
    opacity: 0.35;
}

@media (prefers-reduced-motion: reduce) {
    .queue-pulse span,
    .queue-pulse::after,
    .queue-number.is-bumped,
    .queue-count-unit::after {
        animation: none;
    }
    .queue-count-unit::after { content: '...'; }
}

/* ------------------------------------------------------------------------
 * 근거 문서 drawer — slides in from the right.
 *
 * Not a modal. A modal takes the screen and says "deal with me"; the evidence
 * is reference material read *beside* an answer, and the reader goes back and
 * forth. Sliding off the edge leaves the transcript where it was.
 * ---------------------------------------------------------------------- */

.drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    justify-content: flex-end;
    background-color: rgba(17, 24, 39, 0);
    transition: background-color 220ms ease;
}

.drawer-overlay.is-open {
    background-color: rgba(17, 24, 39, 0.45);
}

.drawer {
    position: relative;
    width: min(560px, 100%);
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: var(--color-surface);
    box-shadow: -12px 0 40px rgba(15, 23, 42, 0.22);
    /* Off-screen until `.is-open`; `drawer.js` adds that class two frames
       later so the browser has laid this out first and actually animates. */
    transform: translateX(100%);
    transition: transform 220ms ease;
}

.drawer-overlay.is-open .drawer {
    transform: translateX(0);
}

/* Motion is decoration here; the panel still has to arrive. */
@media (prefers-reduced-motion: reduce) {
    .drawer-overlay,
    .drawer {
        transition: none;
    }
}

.drawer-head {
    padding: 1.125rem 3rem 0.75rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
}

.drawer-title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--color-text);
    word-break: break-word;
}

.drawer-subtitle {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--color-muted);
}

.drawer-close {
    position: absolute;
    top: 0.5rem;
    right: 0.625rem;
    width: 2rem;
    height: 2rem;
    border: none;
    background: none;
    font-size: 1.375rem;
    line-height: 1;
    color: var(--color-muted);
    cursor: pointer;
}

.drawer-close:hover,
.drawer-close:focus-visible {
    color: var(--color-text);
}

/* The passages scroll, not the panel: the header has to stay visible or the
   reader loses track of which answer they opened it from. */
.drawer-body {
    padding: 1rem 1.25rem 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.drawer-body mark {
    background-color: #fef08a;
    color: inherit;
    padding: 0 0.0625rem;
    border-radius: 0.125rem;
}

/* The button under an answer that opens the panel. Only rendered when that
   turn actually has evidence, so its presence is itself information. */
.evidence-open {
    margin-top: 0.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface);
    font-size: 0.75rem;
    color: var(--color-text);
    cursor: pointer;
}

.evidence-open:hover,
.evidence-open:focus-visible {
    border-color: var(--color-accent, #064f8b);
    color: var(--color-accent, #064f8b);
}

/* 답변 문장 끝의 근거 번호 — 누르면 그 문장의 근거 구절이 바로 열린다. */
.answer-anchor {
    margin-left: 0.125rem;
    padding: 0 0.125rem;
    border: none;
    background: none;
    font-size: 0.7rem;
    font-weight: 700;
    vertical-align: super;
    line-height: 1;
    color: var(--color-accent, #064f8b);
    cursor: pointer;
}

.answer-anchor:hover,
.answer-anchor:focus-visible {
    text-decoration: underline;
}

.answer-anchor-line {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--color-muted);
}

/* Query terms, marked wherever they appear in a passage.
 *
 * **A different colour from the attribution mark above, deliberately.** That
 * one means "this sentence is where the answer came from"; this one means
 * "your words are here". Painting both #fef08a would merge two different
 * claims into one highlight and the reader could not tell them apart — and
 * they nest, because a query term routinely falls inside the sourced sentence.
 */
:root {
    --ipn-term-hit: #d9f34b;
}

mark.term-hit {
    background-color: var(--ipn-term-hit);
    color: inherit;
    padding: 0 0.0625rem;
    border-radius: 0.125rem;
    box-shadow: inset 0 -0.5em 0 rgba(0, 0, 0, 0.03);
}

/* ------------------------------------------------------------------------
 * Rendered Markdown — a reply, or a passage in the 근거 문서 panel.
 *
 * Keyed on `.is-markdown` alone rather than on `.is-markdown`, because
 * a guidebook passage is Markdown for the same reason a reply is: the loaders
 * write the books' tables as Markdown tables. The typography is the same
 * typography, and restating forty rules for the second caller is how the two
 * drift apart.
 *
 * Both callers set `white-space: pre-wrap` — right for plain text and wrong
 * here, because the parser has already turned the newlines into elements, so
 * keeping it would double every paragraph break.
 * ---------------------------------------------------------------------- */

.is-markdown {
    white-space: normal;
}

.is-markdown > *:first-child { margin-top: 0; }
.is-markdown > *:last-child  { margin-bottom: 0; }

.is-markdown p,
.is-markdown ul,
.is-markdown ol,
.is-markdown blockquote,
.is-markdown pre,
.is-markdown table {
    margin: 0.5rem 0;
}

.is-markdown h1,
.is-markdown h2,
.is-markdown h3,
.is-markdown h4 {
    margin: 0.875rem 0 0.375rem;
    font-weight: 700;
    line-height: 1.35;
}

.is-markdown h1 { font-size: 1.0625rem; }
.is-markdown h2 { font-size: 1rem; }
.is-markdown h3 { font-size: 0.9375rem; }
.is-markdown h4 { font-size: 0.875rem; }

.is-markdown ul,
.is-markdown ol {
    padding-left: 1.25rem;
}

.is-markdown ul { list-style: disc; }
.is-markdown ol { list-style: decimal; }
.is-markdown li { margin: 0.1875rem 0; }
.is-markdown li > ul,
.is-markdown li > ol { margin: 0.1875rem 0; }

.is-markdown strong { font-weight: 700; }
.is-markdown em { font-style: italic; }

.is-markdown a {
    color: var(--color-primary);
    text-decoration: underline;
}

.is-markdown code {
    padding: 0.0625rem 0.25rem;
    border-radius: 0.1875rem;
    background-color: rgba(15, 23, 42, 0.07);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.8125em;
}

.is-markdown pre {
    padding: 0.625rem 0.75rem;
    border-radius: 0.25rem;
    background-color: rgba(15, 23, 42, 0.07);
    overflow-x: auto;
}

.is-markdown pre code {
    padding: 0;
    background: none;
}

.is-markdown blockquote {
    padding-left: 0.75rem;
    border-left: 3px solid var(--color-border-strong);
    color: var(--color-muted);
}

/* A guidebook answer is very often a fee or deadline table, and a table that
   overflows its bubble takes the page's horizontal scroll with it. */
.is-markdown .table-scroll,
.is-markdown table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

.is-markdown table {
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.is-markdown th,
.is-markdown td {
    padding: 0.3125rem 0.5rem;
    border: 1px solid var(--color-border-strong);
    text-align: left;
    vertical-align: top;
    /* 한 칸이 이웃 칸에 눌려 한 글자씩 세로로 쌓이는 것을 막는다. hwp 가이드북의
       국가 기본정보 표가 그렇다 — `일반사항` 옆 칸에 400자가 들어 있어서, 자동
       배분이 첫 열을 글자 하나 폭으로 줄여 버린다. 표는 이미 자기 안에서 가로로
       스크롤되므로(위 .is-markdown table) 넓어지는 쪽은 화면을 밀지 않는다. */
    min-width: 3.5rem;
}

.is-markdown th {
    background-color: var(--color-surface-alt);
    font-weight: 600;
}

/* 표 이름. 옛 로더가 `[표 6] …` 을 표의 첫 행으로 넣어 머리 행 자리에 앉혀 놓았고,
   뷰어가 그것을 여기로 꺼낸다(mdview.js:liftCaptions). 가운데 정렬은 <caption> 의
   기본값인데, 이 페이지의 다른 무엇도 가운데 정렬이 아니다. */
.is-markdown caption {
    caption-side: top;
    text-align: left;
    padding: 0 0 0.3125rem;
    font-weight: 600;
    color: var(--color-muted);
}

.is-markdown hr {
    margin: 0.75rem 0;
    border: 0;
    border-top: 1px solid var(--color-border);
}

/* ------------------------------------------------------------------------
 * Answer sentence ↔ source sentence.
 *
 * This replaced a list of every passage the model received. Those were all
 * labelled evidence, and on a measured turn that put a 상표법 article — 0.115
 * overlap with the answer — at the top of the evidence for a question about
 * examination deadlines. Retrieval scores could not tell them apart.
 * ---------------------------------------------------------------------- */

.evidence-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.625rem;
}

.evidence-item {
    padding: 0.5rem 0 0.5rem 0.625rem;
    border-left: 2px solid var(--color-primary);
}

/* The sentence the model wrote. Set apart from the source below it, because
   the whole point of the pair is that they are two different texts. */
.evidence-claim {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.55;
    word-break: break-word;
}

.evidence-source {
    margin-top: 0.3125rem;
    padding-left: 0.625rem;
    border-left: 1px dashed var(--color-border-strong);
}

.evidence-cite {
    display: block;
    padding: 0;
    border: none;
    background: none;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-muted);
    text-align: left;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: var(--color-border-strong);
    cursor: pointer;
    word-break: break-word;
}

.evidence-cite:hover,
.evidence-cite:focus-visible {
    color: var(--color-primary);
    text-decoration-color: var(--color-primary);
}

.evidence-source .result-snippet {
    margin-top: 0.25rem;
}

/* A pairing draws the block its sentence sits in, and that block can be a fee
   table filling the whole 1,200-character passage. Four of those stacked is the
   length the old ±120-character window existed to avoid, so the box scrolls
   instead. The citation's popup is not inside .evidence-source and does not
   scroll: there the passage is the point. */
.evidence-source .result-snippet.is-markdown {
    max-height: 18rem;
    overflow-y: auto;
}

/* Only part of the passage is on screen. The citation opens the rest. */
.result-snippet.is-partial::after {
    content: '…';
    display: block;
    color: var(--color-faint);
}

/* `:not(.term-hit)` because the two marks nest and mean different things — this
   one is "the answer came from here", the lime one below is "your words are
   here". Without it this rule wins on source order and paints both the same
   colour, which is what it was doing: the nesting was built and then flattened
   by a selector. */
.evidence-item mark:not(.term-hit),
.modal-body mark:not(.term-hit) {
    background-color: #fef08a;
    color: inherit;
    padding: 0 0.0625rem;
    border-radius: 0.125rem;
}

/* Sentences with nothing behind them: counted, not listed. Listing them beside
   the sourced ones would invite reading them as equally sourced; saying
   nothing would let the whole reply look attributed. */
.evidence-note {
    margin-top: 0.625rem;
    font-size: 0.75rem;
    color: var(--color-faint);
}

.evidence-details {
    margin-top: 0.75rem;
}

.evidence-details > summary {
    font-size: 0.75rem;
    color: var(--color-muted);
    cursor: pointer;
}

.evidence-details > summary:hover,
.evidence-details > summary:focus-visible {
    color: var(--color-primary);
}
