/* ─────────────────────────────────────────────────────────────────────────────
   KaitLab AI — visual system

   KaitLab AI — visual system

   Built from the KAITLab logo, sampled from the mark itself rather than
   guessed: Prussian blue #023047 and blue-green #219EBC. The navy carries the
   structure — it is the body text and the whole neutral ramp is tinted toward
   it — and the blue-green marks anything actionable.

   #219EBC appears at logo scale but never as an interface accent: white on it
   is 3.14:1, which fails WCAG AA. Interactive surfaces use #126982, the same
   hue darkened until it passes. A brand colour seen for a second and one stared
   at all day have different jobs, and the second job has a contrast floor.

   The product is an internal knowledge tool people open many times a day, so it
   aims for calm and legible rather than loud. Colour is spent sparingly and
   never twice on the same meaning: the accent is "you can act on this", green
   is "this worked", amber and red are the two grades of "look at this". A
   status that borrows the accent stops being a status, which is why `--ok`
   exists separately from `--accent`.

   Every foreground/background pair below is measured at >= 4.5:1 in both
   themes. Changing one means re-checking its partner.

   Both themes are defined: the palette lives on :root, and only the tokens that
   change are redefined for dark.
   ──────────────────────────────────────────────────────────────────────────── */

:root {
    /* The neutral ramp is the brand navy desaturated upward, not grey — it is
       what makes the panel read as KaitLab's rather than as stock Bootstrap */
    --ink-900: #023047;   /* brand Prussian blue, straight from the logo */
    --ink-700: #1d4d63;
    --ink-500: #537687;   /* 4.87:1 on white — muted, still readable */
    --ink-300: #b3cbd8;
    --ink-100: #d9e6ed;
    --ink-50:  #eef4f8;

    --surface:      #ffffff;
    --surface-sunk: #f5fafc;
    --surface-raise:#ffffff;

    --accent:      #126982;   /* brand blue-green, darkened to 6.23:1 */
    --accent-soft: #ddeef6;
    --accent-ink:  #0a4a5e;
    /* Text that sits *on* --accent. Split out because the two themes disagree:
       a light accent on dark needs dark text, and hardcoding #fff is how a
       button ends up at 1.7:1 against its own background. */
    --accent-on:   #ffffff;
    /* The untouched brand colour. Reserved for the logo mark, where it is
       decoration rather than something anyone has to read. */
    --brand:       #219ebc;

    --danger:      #c0392b;
    --danger-soft: #fdeaea;
    --warn:        #96590a;   /* the brand amber #FFB703, darkened for AA */
    --warn-soft:   #fff2d6;

    --ok:      #10794f;
    --ok-soft: #dcf3e8;
    --ok-ink:  #0b5c3c;

    --line: var(--ink-100);
    --radius: 10px;
    --radius-lg: 14px;
    /* Shadows tinted with the brand navy rather than neutral black, so they
       sit on the page instead of greying it */
    --shadow-sm: 0 1px 2px rgba(2, 48, 71, .07), 0 1px 3px rgba(2, 48, 71, .05);
    --shadow-md: 0 4px 12px rgba(2, 48, 71, .09), 0 1px 3px rgba(2, 48, 71, .06);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --ink-900: #e8f3f8;
        --ink-700: #bcd7e3;
        --ink-500: #85a8b8;
        --ink-300: #3d6376;
        --ink-100: #0e3446;
        --ink-50:  #0a2c3b;

        /* Dark mode is the brand navy taken further down, not neutral black */
        --surface:      #04222f;
        --surface-sunk: #021925;
        --surface-raise:#073243;

        /* #8ECAE6 — the light blue from the same brand palette. Dark mode wants
           the accent lighter than the page, so the family supplies it directly
           rather than needing an invented tint. */
        --accent:      #8ecae6;
        --accent-soft: #073a4d;
        --accent-ink:  #b9dff0;
        /* Brand navy as the label on the light accent; white would be 1.8:1 */
        --accent-on:   #023047;

        --danger:      #ff8a80;
        --danger-soft: #40120f;
        --warn:        #ffb703;   /* brand amber, readable as-is on dark */
        --warn-soft:   #3a2a05;

        --ok:      #3fa87a;
        --ok-soft: #0c3428;
        --ok-ink:  #7fc9a5;

        --line: #0e3446;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
    }
}

/* ── Base ─────────────────────────────────────────────────────────────────── */

body {
    background: var(--surface-sunk);
    color: var(--ink-900);
    font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-weight: 650; letter-spacing: -.015em; color: var(--ink-900); }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
code { color: var(--accent-ink); background: var(--accent-soft); padding: .1em .35em; border-radius: 4px; }

.text-muted { color: var(--ink-500) !important; }
.eyebrow { font-size: .72rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-500); }

/* ── Navigation ───────────────────────────────────────────────────────────── */

.navbar.kl-nav {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    padding: .6rem 0;
}
.navbar.kl-nav .navbar-brand {
    font-weight: 700; letter-spacing: -.02em; color: var(--ink-900);
    display: inline-flex; align-items: center; gap: .55rem;
}
/* The one place the untouched brand blue-green appears. It reads as the logo
   rather than as a control, and the gradient runs to --accent-ink so the glyph
   keeps its contrast at both ends in either theme. */
.navbar.kl-nav .navbar-brand .mark {
    width: 26px; height: 26px; border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), var(--accent-ink));
    display: inline-grid; place-items: center;
    color: var(--accent-on); font-size: .78rem; font-weight: 800;
    box-shadow: inset 0 0 0 1px var(--brand);
}
.navbar.kl-nav .nav-link {
    color: var(--ink-700); font-weight: 550; border-radius: 8px;
    padding: .35rem .7rem !important; margin: 0 .1rem;
}
.navbar.kl-nav .nav-link:hover { background: var(--ink-50); color: var(--ink-900); }
.navbar.kl-nav .nav-link.active { background: var(--accent-soft); color: var(--accent-ink); }
.navbar.kl-nav .dropdown-menu {
    border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-md); background: var(--surface-raise); padding: .35rem;
}
.navbar.kl-nav .dropdown-item { border-radius: 6px; color: var(--ink-700); }
.navbar.kl-nav .dropdown-item:hover { background: var(--ink-50); color: var(--ink-900); }

/* ── Surfaces ─────────────────────────────────────────────────────────────── */

.kl-card {
    background: var(--surface-raise);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.15rem 1.25rem;
}
.kl-card + .kl-card { margin-top: 1rem; }
.kl-card__title { font-size: .95rem; font-weight: 650; margin: 0 0 .75rem; }

.table { color: var(--ink-900); --bs-table-bg: transparent; }
.table > :not(caption) > * > * { border-color: var(--line); padding: .6rem .5rem; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-500); font-weight: 650; }

/* ── Controls ─────────────────────────────────────────────────────────────── */

.form-control, .form-select {
    background: var(--surface); color: var(--ink-900);
    border: 1px solid var(--ink-300); border-radius: var(--radius);
    padding: .5rem .75rem;
}
.form-control:focus, .form-select:focus {
    background: var(--surface); color: var(--ink-900);
    border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-control::placeholder { color: var(--ink-500); }
.form-label { font-weight: 600; font-size: .85rem; color: var(--ink-700); }
.form-text { color: var(--ink-500); font-size: .82rem; }

.btn { border-radius: var(--radius); font-weight: 600; padding: .45rem .95rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-on); }
.btn-primary:hover, .btn-primary:focus {
    background: var(--accent-ink); border-color: var(--accent-ink); color: var(--accent-on);
}
.btn-outline-secondary { color: var(--ink-700); border-color: var(--ink-300); }
.btn-outline-secondary:hover { background: var(--ink-50); color: var(--ink-900); border-color: var(--ink-300); }

/* ── Status ───────────────────────────────────────────────────────────────── */

.alert { border: 1px solid transparent; border-radius: var(--radius); font-size: .9rem; }
.alert-danger  { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.alert-warning { background: var(--warn-soft);   border-color: var(--warn);   color: var(--warn); }
.alert-info    { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }

.kl-pill {
    display: inline-flex; align-items: center; gap: .35rem;
    font-size: .75rem; font-weight: 650; padding: .15rem .55rem;
    border-radius: 999px; background: var(--ink-50); color: var(--ink-700);
}
/* Green, not the accent: "ready" is a status, and a status that shares the
   colour of every button and link on the page tells you nothing at a glance. */
.kl-pill--ok    { background: var(--ok-soft);     color: var(--ok-ink); }
.kl-pill--warn  { background: var(--warn-soft);   color: var(--warn); }
.kl-pill--error { background: var(--danger-soft); color: var(--danger); }
.kl-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ── Chat ─────────────────────────────────────────────────────────────────── */

.kl-chat {
    display: flex; flex-direction: column;
    height: calc(100vh - 230px); min-height: 26rem;
    background: var(--surface-raise);
    border: 1px solid var(--line); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm); overflow: hidden;
}
.kl-chat__log { flex: 1; overflow-y: auto; padding: 1.4rem 1.5rem; }
.kl-chat__composer {
    border-top: 1px solid var(--line); background: var(--surface);
    padding: .85rem 1rem; display: flex; gap: .6rem;
}

.kl-msg { margin-bottom: 1.5rem; max-width: 46rem; }
.kl-msg__who {
    font-size: .72rem; font-weight: 650; letter-spacing: .05em;
    text-transform: uppercase; color: var(--ink-500); margin-bottom: .3rem;
}
.kl-msg__body { white-space: pre-wrap; word-wrap: break-word; }

.kl-msg--user .kl-msg__body {
    background: var(--ink-50); border-radius: var(--radius);
    padding: .65rem .9rem; display: inline-block;
}
.kl-msg--ai .kl-msg__body { color: var(--ink-900); }
.kl-msg--error .kl-msg__body { color: var(--danger); }

/* A caret while tokens stream, so the pause before the first token reads as
   "thinking" rather than "broken" */
.kl-msg__body.is-streaming::after {
    content: ''; display: inline-block;
    width: .5em; height: 1.05em; margin-left: 2px;
    background: var(--accent); vertical-align: text-bottom;
    animation: kl-blink 1s steps(2, start) infinite;
}
@keyframes kl-blink { to { visibility: hidden; } }

.kl-sources { margin-top: .75rem; padding-top: .6rem; border-top: 1px dashed var(--line); }
.kl-source {
    display: inline-flex; align-items: center; gap: .4rem;
    font-size: .82rem; padding: .25rem .6rem; margin: .2rem .3rem .2rem 0;
    border: 1px solid var(--line); border-radius: 999px;
    background: var(--surface); color: var(--ink-700); text-decoration: none;
}
.kl-source:hover { border-color: var(--accent); color: var(--accent-ink); text-decoration: none; }
.kl-source__n {
    min-width: 17px; height: 17px; border-radius: 50%;
    background: var(--accent-soft); color: var(--accent-ink);
    font-size: .68rem; font-weight: 700;
    display: grid; place-items: center;
}

.kl-empty { text-align: center; color: var(--ink-500); padding: 3.5rem 1rem; }
.kl-empty h3 { font-size: 1.05rem; color: var(--ink-700); margin-bottom: .4rem; }
.kl-suggest {
    display: inline-block; margin: .25rem; padding: .45rem .85rem;
    border: 1px solid var(--line); border-radius: 999px;
    background: var(--surface); color: var(--ink-700);
    font-size: .85rem; cursor: pointer;
}
.kl-suggest:hover { border-color: var(--accent); color: var(--accent-ink); }

/* ── Conversation list ────────────────────────────────────────────────────── */

.kl-convo {
    display: block; padding: .55rem .7rem; border-radius: var(--radius);
    color: var(--ink-700); font-size: .87rem; text-decoration: none;
    border: 1px solid transparent;
}
.kl-convo:hover { background: var(--ink-50); color: var(--ink-900); text-decoration: none; }
.kl-convo.is-active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

/* ── Misc ─────────────────────────────────────────────────────────────────── */

.kl-footer { border-top: 1px solid var(--line); background: var(--surface); color: var(--ink-500); font-size: .82rem; }
.kl-drop {
    border: 2px dashed var(--ink-300); border-radius: var(--radius-lg);
    padding: 2rem; text-align: center; color: var(--ink-500);
    background: var(--surface); transition: border-color .15s, background .15s;
}
.kl-drop.is-over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }

/* ── Wizards ──────────────────────────────────────────────────────────────────
   Multi-step flows are pages, never dialogs. A modal hides the context you are
   deciding against, cannot be linked to or reloaded, traps keyboard focus, and
   on a phone covers the entire screen anyway — at which point it is a page with
   extra problems.
   ──────────────────────────────────────────────────────────────────────────── */

.kl-steps { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1.5rem; }
.kl-step {
    display: flex; align-items: center; gap: .5rem;
    padding: .4rem .8rem; border-radius: 999px;
    border: 1px solid var(--line); background: var(--surface);
    color: var(--ink-500); font-size: .84rem; font-weight: 550;
}
.kl-step__n {
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--ink-100); color: var(--ink-500);
    font-size: .72rem; font-weight: 700; display: grid; place-items: center;
}
.kl-step.is-current { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.kl-step.is-current .kl-step__n { background: var(--accent); color: var(--accent-on); }
.kl-step.is-done { color: var(--ink-700); }
.kl-step.is-done .kl-step__n { background: var(--accent-soft); color: var(--accent-ink); }

.kl-actions {
    display: flex; gap: .6rem; align-items: center;
    margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--line);
}
.kl-actions .ms-auto { margin-left: auto; }

/* Destructive and safety-critical confirmations are inline panels, so the thing
   being confirmed stays on screen while you read the consequence */
.kl-confirm {
    border: 1px solid var(--warn); background: var(--warn-soft);
    border-radius: var(--radius); padding: 1rem; margin: .75rem 0;
}
.kl-confirm--danger { border-color: var(--danger); background: var(--danger-soft); }
.kl-confirm h4 { font-size: .95rem; margin-bottom: .4rem; }

/* ── Responsive ───────────────────────────────────────────────────────────────
   Mobile-first adjustments. The chat has to work on a phone: it is the screen
   people will reach for between meetings, which is exactly when they need an
   answer from the handbook.
   ──────────────────────────────────────────────────────────────────────────── */

.kl-sidebar { margin-bottom: 1.25rem; }

@media (max-width: 767.98px) {
    body { font-size: 16px; }  /* iOS zooms inputs below 16px */

    .kl-chat {
        height: calc(100vh - 250px);
        border-radius: var(--radius);
    }
    .kl-chat__log { padding: 1rem; }
    .kl-chat__composer { padding: .7rem; }

    .kl-msg { max-width: 100%; }

    /* Conversations collapse to a scrollable strip so the chat keeps the screen */
    .kl-sidebar { position: sticky; top: .5rem; z-index: 5; background: var(--surface-sunk); }
    .kl-sidebar .list-group {
        display: flex; flex-direction: row; gap: .4rem;
        overflow-x: auto; padding-bottom: .35rem;
        scrollbar-width: none;
    }
    .kl-sidebar .list-group::-webkit-scrollbar { display: none; }
    .kl-convo { white-space: nowrap; flex: 0 0 auto; border: 1px solid var(--line); }

    .kl-steps { gap: .3rem; }
    .kl-step { padding: .3rem .6rem; font-size: .78rem; }
    .kl-step__label { display: none; }   /* numbers alone still show progress */
    .kl-step.is-current .kl-step__label { display: inline; }

    .kl-actions { flex-wrap: wrap; }
    .kl-actions .btn { flex: 1 1 auto; }

    /* Wide tables scroll inside themselves rather than the page */
    .kl-scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .kl-scroll-x > .table { min-width: 34rem; }

    .kl-card { padding: 1rem; border-radius: var(--radius); }
}

@media (min-width: 768px) {
    .kl-sidebar { position: sticky; top: 1rem; }
}

@media (max-width: 991.98px) {
    .navbar.kl-nav .navbar-collapse { padding-top: .5rem; }
    .navbar.kl-nav .nav-link { padding: .5rem .7rem !important; }
}

/* Respect a stated preference for less motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
    .kl-msg__body.is-streaming::after { animation: none; opacity: .6; }
}

/* Passages that were searched but that the answer did not draw on. Collapsed
   rather than hidden: the retrieval set is worth being able to inspect, but
   presenting it beside the citations overstates what the answer rests on. */
.kl-sources-more { margin-top: .5rem; }
.kl-sources-more > summary {
    cursor: pointer; color: var(--ink-500); font-size: .8rem;
    list-style: none; padding: .15rem 0;
}
.kl-sources-more > summary:hover { color: var(--ink-700); }
.kl-sources-more > summary::-webkit-details-marker { display: none; }
.kl-sources-more > summary::before { content: "▸ "; }
.kl-sources-more[open] > summary::before { content: "▾ "; }
.kl-sources-more .kl-source { opacity: .7; }

/* Conversation rows: the delete control stays out of the way until hover, so
   the sidebar reads as a list of conversations rather than a list of buttons. */
.kl-convo-row { display: flex; align-items: center; gap: .25rem; }
.kl-convo-row .kl-convo { flex: 1 1 auto; min-width: 0; }
.kl-convo-row form { flex: 0 0 auto; margin: 0; }
.kl-convo-del {
    border: 0; background: none; color: var(--ink-500);
    line-height: 1; padding: .25rem .4rem; border-radius: 6px;
    opacity: 0; transition: opacity .12s ease, color .12s ease;
}
.kl-convo-row:hover .kl-convo-del,
.kl-convo-del:focus-visible { opacity: 1; }
.kl-convo-del:hover { color: var(--danger); background: var(--danger-soft); }
/* Touch devices have no hover, so it is always visible there */
@media (hover: none) { .kl-convo-del { opacity: 1; } }

/* ── Cost dashboard ───────────────────────────────────────────────────────── */

/* A bar chart in CSS. One fewer dependency, no JavaScript needed, and it
   inherits the theme rather than needing a second palette configured. */
.kl-bars {
    display: flex; align-items: flex-end; gap: 3px;
    height: 140px; padding-top: .5rem; overflow-x: auto;
}
.kl-bar {
    flex: 1 0 14px; display: flex; flex-direction: column;
    justify-content: flex-end; height: 100%; min-width: 14px;
}
.kl-bar__fill {
    background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px;
    transition: background .12s ease;
}
.kl-bar:hover .kl-bar__fill { background: var(--accent-ink); }
.kl-bar__label {
    font-size: .65rem; color: var(--ink-500); text-align: center;
    padding-top: .25rem;
}

/* Proportion bars in the breakdown tables and beside each budget. */
.kl-meter {
    height: 6px; background: var(--ink-100); border-radius: 999px; overflow: hidden;
}
.kl-meter__fill { height: 100%; background: var(--accent); border-radius: 999px; }
.kl-meter__fill.is-over { background: var(--danger); }

/* Was this helpful? Quiet until the answer has finished arriving, because a
   rating control competing with the text is a rating nobody reads first. */
.kl-rate {
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
    margin-top: .6rem; font-size: .8rem; color: var(--ink-500);
}
.kl-rate.is-done { color: var(--ok); }
.kl-rate__btn {
    border: 1px solid var(--line); background: var(--surface);
    color: var(--ink-700); border-radius: 999px;
    padding: .15rem .6rem; font-size: .8rem; cursor: pointer;
}
.kl-rate__btn:hover { border-color: var(--accent); color: var(--accent-ink); }

/* The small × that removes a role. Quiet inside the pill until you want it,
   because a row of delete buttons reads as a warning rather than a list. */
.kl-role-x {
    border: 0; background: none; color: inherit; opacity: .5;
    padding: 0 0 0 .25rem; line-height: 1; cursor: pointer; font-size: .9em;
}
.kl-role-x:hover { opacity: 1; color: var(--danger); }
.kl-role-add { width: auto; min-width: 7rem; font-size: .78rem; }

/* An evaluation run takes minutes. Saying so beats a button that looks broken. */
.kl-running {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .4rem .8rem; border-radius: var(--radius);
    background: var(--accent-soft); color: var(--accent-ink); font-size: .85rem;
}
.kl-spinner {
    width: .8rem; height: .8rem; border-radius: 50%;
    border: 2px solid currentColor; border-right-color: transparent;
    animation: kl-spin .7s linear infinite;
}
@keyframes kl-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .kl-spinner { animation: none; opacity: .6; }
}
