/* =========================================================================
   AI SOLVING TOOLS

   This file is linked from index.html on every page, so everything below is
   scoped under .ai-tools-root (the panel root, also set on the tool's own
   dialogs). The deliberate exceptions are .fullscreen-dialog and the two
   toast classes, which sit outside the panel in the DOM, and the badges,
   chips and markdown rules that the build and solve views reuse.
   ========================================================================= */

/* =========================
   DIALOG SHELL
   ========================= */

.fullscreen-dialog {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    max-height: 100vh;
    margin: 0;
    border-radius: 0;
    overflow-x: hidden;
}

.fullscreen-dialog .md-dialog-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 0;
}

/* The custom element is display:block by default, which would leave .ai-tools-root
   unconstrained: the header, the rail and the whole data list would size to their
   content and the host view would scroll as one block (taking the chat's tab bar out
   of sight with it). Making the host a flex item that may shrink below its content is
   what lets the header and rail stay put while only the data list scrolls. */
ai-tools-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.ai-tools-root {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.ai-tools-root *,
.ai-tools-root *::before,
.ai-tools-root *::after {
    box-sizing: border-box;
}

.ai-workspace {
    min-height: 0;
    overflow: hidden;
}

/* Header and rail are flex="none" in the template: they keep their height and stay
   visible, so only .ai-detail below them scrolls. */
.ai-header,
.ai-rail {
    flex-shrink: 0;
}

/* =========================
   EMPTY / LOADING STATES
   ========================= */

.ai-empty-state {
    padding: 40px 24px;
    text-align: center;
}

/* The saved runs make this state as tall as the user's history, inside a root that hides
   its overflow. Scroll it, and centre with auto margins rather than layout-align: a centred
   flex column overflows at both ends, putting the title and buttons above the scroll origin,
   out of reach. */
.ai-tools-root .ai-empty-state {
    min-height: 0;
    overflow-y: auto;
    justify-content: flex-start;
}

.ai-tools-root .ai-empty-state > * {
    flex: none;
}

.ai-tools-root .ai-empty-state > :first-child {
    margin-top: auto;
}

.ai-tools-root .ai-empty-state > :last-child {
    margin-bottom: auto;
}

.ai-empty-icon {
    font-size: 64px;
    width: 64px;
    height: 64px;
    color: #c8c8c8;
    margin-bottom: 16px;
}

.ai-empty-title {
    font-size: 18px;
    font-weight: 500;
    color: #555;
}

.ai-empty-hint {
    font-size: 13px;
    color: #9e9e9e;
    margin-top: 6px;
    max-width: 460px;
}

.ai-empty-actions {
    margin-top: 20px;
    gap: 8px;
}

.ai-loading-label {
    text-align: center;
    color: #777;
}

/* =========================
   SAVED RUNS
   ========================= */

.ai-runs {
    margin-top: 28px;
    width: 100%;
    max-width: 640px;
    text-align: left;
}

.ai-runs-title {
    font-size: 13px;
    font-weight: 600;
    color: #777;
    margin-bottom: 6px;
}

.ai-run-row {
    gap: 8px;
    padding: 6px 8px;
    border: 1px solid #e4e4e4;
    border-radius: 6px;
    background: #fff;
    margin-bottom: 6px;
}

.ai-run-row .md-button {
    margin: 0;
}

.ai-tools-root .ai-runs-more {
    align-self: center;
    margin: 4px 0 0;
    color: #777;
    text-transform: none;
}

.ai-run-icon {
    color: #b0b0b0;
    flex: none;
}

.ai-run-text {
    min-width: 0;
}

.ai-run-name {
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

.ai-run-meta {
    font-size: 12px;
    color: #9e9e9e;
}

.ai-run-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 5px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background-color: #A3D039;
    color: #fff;
}

.ai-run-badge.draft {
    background-color: #77C6CB;
}

/* ---- Earlier runs of the open project, in the header ---- */

.ai-project-runs {
    margin-top: 6px;
    padding: 2px 4px 2px 10px;
    border-radius: 6px;
    background: #f7f7f7;
}

.ai-project-runs-summary {
    gap: 8px;
    font-size: 13px;
    color: #444;
}

.ai-project-runs-summary .md-button {
    margin: 0;
    flex: none;
}

/* Capped: the header is fixed, and the steps below it must stay on screen. */
.ai-project-runs-list {
    max-height: 180px;
    overflow-y: auto;
    padding: 4px 6px 0 0;
}

/* =========================
   HEADER
   ========================= */

.ai-header {
    padding: 8px 16px 12px 16px;
    border-bottom: 1px solid #e4e4e4;
    background: #fff;
    /* The panel is as wide as its host, not as the window: docked in the chat it is a narrow
       column inside a wide page, so the action bar below adapts to this box (@container
       ai-panel) rather than to the viewport. */
    container-type: inline-size;
    container-name: ai-panel;
}

.ai-header-identity {
    min-height: 44px;
}

.ai-project-icon {
    color: #77C6CB;
    margin-right: 10px;
    flex: none;
}

.ai-project-icon.virtual {
    color: #673ab7;
}

.ai-project-name-wrapper {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-project-name {
    font-size: 18px;
    font-weight: 500;
    line-height: 1.3;
    min-width: 0;
}

.ai-virtual-badge {
    flex: none;
    background-color: #673ab7;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    border-radius: 5px;
    padding: 2px 6px;
}

.ai-icon-accent { color: #A3D039; }
.ai-icon-danger { color: #c62828; }
.ai-icon-muted  { color: #9e9e9e; }

/* ---- Project description ---- */

.ai-description {
    margin-top: 2px;
    padding: 8px 10px;
    border-radius: 6px;
    background: #f7f7f7;
    gap: 8px;
}

.ai-description-icon {
    color: #b0b0b0;
    font-size: 18px;
    width: 18px;
    height: 18px;
    margin-top: 2px;
    flex: none;
}

/* Clamped, and never expanded in place: this sits in the fixed header, so its height has to
   stay the same whatever the project description contains. The full text opens in a dialog. */
.ai-description-text {
    font-size: 13px;
    line-height: 1.5;
    color: #444;
    text-align: justify;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ai-description-toggle {
    font-size: 12px;
    margin-top: 2px;
    align-self: flex-start;
}

.ai-description-missing {
    gap: 8px;
    color: #b71c1c;
    font-size: 13px;
}

.ai-description-missing md-icon {
    color: #c62828;
    font-size: 18px;
    width: 18px;
    height: 18px;
    flex: none;
}

.md-button.ai-description-cta {
    flex: none;
    margin: 0;
    min-height: 28px;
    line-height: 28px;
}

/* ---- Action bar ---- */

.ai-actions-bar {
    margin-top: 10px;
    gap: 4px;
    /* One line: this sits in the fixed header, above the only part that scrolls, so wrapping
       would take its height from the generated data. Everything below gives way instead. */
    flex-wrap: nowrap;
}

.ai-actions-bar .md-button {
    margin: 0 4px 0 0;
    display: inline-flex;
    align-items: center;
    flex: none;
}

.ai-actions-bar .md-button md-icon {
    margin-right: 8px;
}

.md-button.ai-stop-button,
.md-button.ai-stop-button:not([disabled]):hover {
    background-color: #dc3545;
    color: #fff;
}

.md-button.ai-stop-button md-icon,
.md-button.ai-stop-button md-progress-circular {
    color: #fff;
    margin-right: 8px;
}

.md-button.ai-save-button.md-raised {
    background-color: #A3D039;
    color: #F2F2F2;
}

.md-button.ai-save-button.md-raised md-icon {
    color: #fff;
}

.md-button.ai-save-button:not([disabled]):hover {
    background-color: #adce5f;
}

.md-button.ai-save-button.md-raised:disabled {
    background-color: #d8e4bb;
    color: rgba(0, 0, 0, 0.38);
}

.md-button.ai-save-button.md-raised:disabled md-icon {
    color: rgba(0, 0, 0, 0.38);
}

/* ---- Global progress ---- */

.ai-global-progress {
    gap: 8px;
    min-width: 0;
}

.ai-global-progress-label {
    font-size: 12px;
    color: #9e9e9e;
    white-space: nowrap;
    /* Without these the label cannot shrink: the row is right-aligned, so it overflowed to
       the left and only its last word stayed on screen. */
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-global-progress-track {
    width: 140px;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
    overflow: hidden;
    flex: none;
}

.ai-global-progress-fill {
    height: 100%;
    background: #A3D039;
    border-radius: 3px;
    transition: width 0.4s ease;
}

.ai-global-progress-value {
    font-size: 12px;
    font-weight: 600;
    color: #A3D039;
    min-width: 34px;
    text-align: right;
}

/* =========================
   RAIL
   ========================= */

.ai-rail {
    position: relative;
    padding: 14px 16px 10px 16px;
    background: #fafafa;
    border-bottom: 1px solid #e4e4e4;
    flex-shrink: 0;
    /* Same reason as the header: docked in the chat the rail is a narrow column inside a wide
       page, so what it can show depends on this box, not on the window. */
    container-type: inline-size;
    container-name: ai-rail;
}

/* Three widths for the step labels:
   - wide: the full title ("Génération des paramètres"), wrapping onto two lines if need be;
   - middle: five cells leave too little room for it (it wraps one word per line, or ends
     up as "Génération du…" on a short screen), so the short one ("Paramètres") on one line;
   - narrow: not even that fits, so the circle alone, whose tooltip has the full title. */
.ai-rail-title-short {
    display: none;
}

@container ai-rail (max-width: 900px) {

    .ai-rail-title-full {
        display: none;
    }

    .ai-rail-title-short {
        display: block;
        max-width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@container ai-rail (max-width: 340px) {

    .ai-rail-title-short {
        display: none;
    }
}

@container ai-rail (max-width: 380px) {

    .ai-circle {
        width: 40px;
        height: 40px;
    }

    .ai-circle md-icon {
        width: 22px;
        height: 22px;
        font-size: 22px;
    }
}

.ai-rail-track,
.ai-rail-track-fill {
    position: absolute;
    top: 42px;
    height: 4px;
    border-radius: 2px;
}

.ai-rail-track {
    left: 16px;
    right: 16px;
    background: #e0e0e0;
    z-index: 1;
}

.ai-rail-track-fill {
    left: 16px;
    max-width: calc(100% - 32px);
    background: #A3D039;
    z-index: 2;
    transition: width 0.4s ease;
}

.ai-rail-cells {
    position: relative;
    z-index: 3;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    align-items: start;
}

.ai-rail-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0 4px 6px 4px;
    cursor: pointer;
    border-radius: 8px;
    border: 2px solid transparent;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    min-width: 0;
}

.ai-rail-cell:hover {
    background-color: rgba(0, 0, 0, 0.035);
}

.ai-rail-cell.selected {
    border-color: #77C6CB;
    background-color: rgba(119, 198, 203, 0.12);
}

.ai-circle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #bdbdbd;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.ai-circle md-icon {
    width: 30px;
    height: 30px;
    font-size: 30px;
    color: #fff;
    fill: #fff;
}

.ai-rail-cell.active .ai-circle,
.ai-rail-cell.running .ai-circle {
    background: #77C6CB;
}

.ai-rail-cell.running .ai-circle {
    animation: aiStepPulse 1.6s ease-in-out infinite;
}

.ai-rail-cell.done .ai-circle     { background: #A3D039; }
.ai-rail-cell.disabled .ai-circle { background: #d4d4d4; }
.ai-rail-cell.error .ai-circle    { background: #c62828; }

.ai-rail-cell.disabled {
    opacity: 0.75;
}

@keyframes aiStepPulse {
    0%   { transform: scale(1);    box-shadow: 0 0 0 0 rgba(119, 198, 203, 0.7); }
    50%  { transform: scale(1.06); box-shadow: 0 0 0 10px rgba(119, 198, 203, 0); }
    100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(119, 198, 203, 0); }
}

.ai-rail-title {
    margin-top: 6px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.25;
    color: #444;
    overflow-wrap: break-word;
    word-break: break-word;
}

.ai-rail-meta {
    font-size: 12px;
    color: #9e9e9e;
}

.ai-rail-cell.done .ai-rail-meta  { color: #A3D039; font-weight: 600; }
.ai-rail-cell.error .ai-rail-meta { color: #c62828; font-weight: 600; }

/* =========================
   DETAIL PANE
   ========================= */

/* The single scrolling region of the panel. The project title, the pipeline actions and the
   rail sit above it and stay put; everything in here scrolls together, so there is never a
   scrollbar inside a scrollbar. */
.ai-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: #fff;
    padding: 0 16px 16px 16px;
}

.ai-detail {
    padding: 0;
}

.ai-detail-header {
    gap: 8px;
    padding: 12px 0 8px 0;
    /* Keeps the step's title and actions reachable while its data scrolls past. Sticky, which
       is a paint offset — not a second scroll container. */
    position: sticky;
    top: 0;
    z-index: 2;
    background: #fff;
}

.ai-detail-title {
    font-size: 17px;
    font-weight: 500;
    color: #333;
}

.ai-detail-sub {
    font-size: 12px;
    color: #9e9e9e;
    margin-top: 2px;
}

.ai-detail-header .md-button {
    margin: 0 0 0 6px;
    display: inline-flex;
    align-items: center;
}

.ai-detail-header .md-button md-icon {
    margin-right: 6px;
}

.md-button.ai-goto-button md-icon {
    margin-right: 0;
    margin-left: 6px;
}

.ai-running-chip {
    gap: 8px;
    font-size: 13px;
    color: #77C6CB;
    padding: 0 10px;
}

/* ---- Sub-steps ---- */

.ai-substeps {
    gap: 6px;
    padding-bottom: 10px;
}

.ai-substep {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #9e9e9e;
    background: #f2f2f2;
    border-radius: 14px;
    padding: 3px 10px 3px 6px;
}

.ai-substep md-icon {
    padding-top: 4px;
    font-size: 16px;
    width: 16px;
    height: 16px;
    color: #c4c4c4;
}

.ai-substep.running {
    background: rgba(119, 198, 203, 0.16);
    color: #4c8f94;
}

.ai-substep.done {
    background: rgba(163, 208, 57, 0.16);
    color: #6f8f27;
}

.ai-substep.done md-icon {
    color: #A3D039;
}

.ai-substep.error {
    background: rgba(198, 40, 40, 0.12);
    color: #c62828;
}

.ai-substep.error md-icon {
    color: #c62828;
}

/* ---- Error block ---- */

.ai-error-block {
    gap: 10px;
    margin-bottom: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    background: rgba(198, 40, 40, 0.08);
    border: 1px solid rgba(198, 40, 40, 0.25);
    color: #b71c1c;
    font-size: 13px;
}

.ai-error-block md-icon {
    color: #c62828;
    flex: none;
}

.ai-error-block .md-button {
    flex: none;
    margin: 0;
}

/* =========================
   DATA LIST
   ========================= */

ai-step-data-column {
    display: block;
}

.ai-data-container {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #fafafa;
    padding: 6px;
    /* The cards adapt to the list's width (docked in the chat it is a narrow column). */
    container-type: inline-size;
    container-name: ai-data;
}

.ai-no-data {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #9e9e9e;
    border: 1px dashed #e0e0e0;
    border-radius: 4px;
    background: #fafafa;
    min-height: 120px;
}

.ai-data-row {
    gap: 4px;
}

.ai-data-row .ai-data-row-body {
    min-width: 0;
}

.ai-data-row.excluded .ai-data-row-body {
    opacity: 0.45;
    filter: grayscale(1);
}

/* Steps 3 to 5: the row unfolds the card. */
.ai-data-row.selectable .ai-data-row-body {
    cursor: pointer;
}

/* No scroller of its own: everything in the pane shares .ai-scroll. */
.ai-row-detail {
    margin: 4px 0 10px 0;
    padding: 10px 12px;
    border-left: 3px solid #77C6CB;
    background: #fafafa;
    border-radius: 0 4px 4px 0;
}

.ai-row-detail-title {
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #777;
    margin-bottom: 8px;
}

.ai-row-detail-sub {
    margin-top: 8px;
    text-align: justify;
}

md-checkbox.ai-keep-checkbox {
    margin: 10px 0 0 4px;
    flex: none;
}

.ai-detail-excluded {
    font-size: 12px;
    color: #CC6600;
    margin-top: 2px;
}

.ai-detail-unsaved {
    font-size: 12px;
    color: #777;
    margin-top: 2px;
}

.ai-detail-edited {
    font-size: 12px;
    color: #77C6CB;
    margin-top: 2px;
}

.ai-detail-outdated {
    font-size: 12px;
    color: #f57c00;
    margin-top: 2px;
}

.ai-tools-root .ai-rail-edited {
    font-size: 13px;
    width: 13px;
    height: 13px;
    min-width: 13px;
    min-height: 13px;
    color: #77C6CB;
    vertical-align: middle;
}

/* Edition in place: the card keeps its footprint, the row behind keeps its scroller. */
.ai-tools-root .ai-card-edit-button {
    margin: 0;
    opacity: 0.55;
}

.ai-tools-root .ai-card-edit-button:hover {
    opacity: 1;
}

.ai-tools-root .ai-card-edit md-input-container {
    margin-top: 6px;
    margin-bottom: 0;
}

.ai-tools-root .ai-card-edit-actions {
    margin-top: 6px;
}

.ai-tools-root .ai-inline-input {
    width: 100%;
    border: none;
    border-bottom: 1px solid #77C6CB;
    background: transparent;
    font-size: inherit;
    font-family: inherit;
    padding: 2px 0;
}

/* A reference text (the evolution law of a hypothesis, the TRIZ principle of a principle)
   that reads the same on every card using it: one line until clicked. */
.ai-tools-root .ai-folded-description {
    color: #777;
    margin-top: 2px;
    cursor: pointer;
}

.ai-tools-root .ai-folded-description-text {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.ai-tools-root .ai-folded-description.expanded .ai-folded-description-text {
    white-space: normal;
    text-align: justify;
}

.ai-tools-root .ai-folded-description-icon {
    flex: none;
    margin: 0 0 0 4px;
    font-size: 18px;
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    color: #9e9e9e;
}

.ai-tools-root .selected-contradiction {
    border: #A3D039 2px solid;
}

/* =========================
   BADGES
   ========================= */

.ai-tools-root .parameters-warning {
    background-color: #c62828;
    color: #fff;
    display: inline-flex;
    justify-content: flex-start;
    gap: 4px;
    align-items: center;
    border-radius: 5px;
    padding: 1px 6px;
    font-size: 11px;
    line-height: 1.5;
}

.ai-tools-root .parameters-warning md-icon {
    color: #fff;
    margin: 0;
    width: 14px;
    height: 14px;
    min-width: 14px;
    min-height: 14px;
    font-size: 14px;
}

/* The unit after a parameter's name: part of it, but quieter. */
.ai-tools-root .ai-card-unit {
    font-weight: 400;
    color: #777;
}

/* "Generated by the AI" badges. Not scoped to .ai-tools-root: the build and solve views
   (hypotheses, laws, parameters, resolution, solutions) mark AI-generated items with them too. */
.ai-badge,
.ai-badge-inline {
    background-color: #673ab7;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    border-radius: 5px;
    text-transform: uppercase;
    pointer-events: none;
    padding: 2px 6px;
    letter-spacing: 0.5px;
}

.ai-badge {
    position: absolute;
    top: 6px;
    right: 6px;
}

.ai-badge-inline {
    display: inline-block;
    margin-left: 6px;
    line-height: 1;
    vertical-align: middle;
}

/* A parameter or a solution the model itself rated as a forced fit (param_fit / principle_fit).
   Not scoped to .ai-tools-root: the hypothesis and solutions views show it too. It carries a
   tooltip, so unlike the other badges it takes the pointer. */
.ai-badge-weak {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 6px;
    border-radius: 5px;
    background-color: #f57c00;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    vertical-align: middle;
    cursor: help;
}

.ai-badge-inline.ai-badge-weak {
    background-color: #f57c00;
    pointer-events: auto;
    cursor: help;
}

.ai-tools-root .ai-weak-icon {
    color: #f57c00;
    margin: 0 4px;
}

/* Rendered markdown: keep the paragraphs and lists as tight as the caption around them. Not
   scoped to .ai-tools-root: <picc-markdown> renders the same markup in the build and solve views. */
.ai-markdown p,
.ai-markdown ul,
.ai-markdown ol {
    margin: 0 0 6px 0;
}

.ai-markdown > :last-child {
    margin-bottom: 0;
}

.ai-tools-root .ai-parameter-measures {
    color: #666;
    margin-top: 2px;
}

/* =========================
   TABLES INSIDE CARDS
   ========================= */

.ai-tools-root .md-table-bordered {
    width: 100%;
    border-collapse: collapse;
    background-color: #fafafa;
}

.ai-tools-root .md-table-bordered th,
.ai-tools-root .md-table-bordered td {
    border: 1px solid rgba(0, 0, 0, 0.12);
    padding: 8px 12px;
}

.ai-tools-root .md-table-bordered thead tr {
    background-color: rgba(0, 0, 0, 0.04);
}

/* =========================
   TRIZ / SOLUTIONS
   ========================= */

.ai-tools-root .kpartialsolution-color,
.ai-tools-root .pe-improved {
    color: #A3D039;
}

.ai-tools-root .kproblem-color,
.ai-tools-root .pe-degraded {
    color: #CC6600;
}

.ai-tools-root .line-break {
    overflow-wrap: break-word;
    word-break: break-word;
}

.ai-tools-root .contradiction-summary-compact {
    font-size: 13px;
    line-height: 1.4;
}

/* Same box clamp as .ai-description-text in the header. */
.ai-tools-root .ai-clamp-1,
.ai-tools-root .ai-clamp-2 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: break-word;
    word-break: break-word;
}

.ai-tools-root .ai-clamp-1 {
    -webkit-line-clamp: 1;
}

.ai-tools-root .ai-clamp-2 {
    -webkit-line-clamp: 2;
}

.ai-tools-root .ai-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* Neutral on purpose: the purple .ai-badge-inline means "generated by the AI" and the run
   badges carry a status, while this is only the name of a principle. Not scoped to
   .ai-tools-root: the solutions view shows a principle's domain with it too. */
.ai-chip {
    background-color: #eef1f3;
    color: #444;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.5;
    border-radius: 5px;
    padding: 1px 6px;
}

.ai-tools-root .ai-principle-context {
    color: #777;
    font-style: italic;
    margin-top: 3px;
}

/* ---- Cards (one per generated item, steps 1 to 5) ----
   One frame for every step; what changes is the accent: the stripe on the left edge, the
   avatar's tint and its icon. The colours are the project's own: orange / green for a KMAP
   problem / partial solution, teal for a parameter, yellow for a solution (as in the
   solutions view). Hypotheses and principles have no colour of their own in the app, so they
   take a blue and an indigo, kept away from the purple of the AI badge. */

.ai-tools-root .ai-card {
    --ai-card-accent: #b0bec5;
    --ai-card-tint: #eceff1;
    --ai-card-ink: #607d8b;
    margin: 4px 8px;
    padding: 8px 10px 10px 10px;
    background: #fff;
    border: 1px solid #e6e6e6;
    border-left: 4px solid var(--ai-card-accent);
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    transition: box-shadow 0.2s ease;
}

.ai-tools-root .ai-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ai-tools-root .ai-card.kind-problem {
    --ai-card-accent: #CC6600;
    --ai-card-tint: rgba(204, 102, 0, 0.12);
    --ai-card-ink: #CC6600;
}

.ai-tools-root .ai-card.kind-partialsolution {
    --ai-card-accent: #A3D039;
    --ai-card-tint: rgba(163, 208, 57, 0.18);
    --ai-card-ink: #6f9a1a;
}

.ai-tools-root .ai-card.kind-parameter {
    --ai-card-accent: #77C6CB;
    --ai-card-tint: rgba(119, 198, 203, 0.2);
    --ai-card-ink: #3f9aa0;
}

.ai-tools-root .ai-card.kind-hypothesis {
    --ai-card-accent: #42A5F5;
    --ai-card-tint: rgba(66, 165, 245, 0.14);
    --ai-card-ink: #1e78c2;
}

.ai-tools-root .ai-card.kind-principle {
    --ai-card-accent: #5C6BC0;
    --ai-card-tint: rgba(92, 107, 192, 0.14);
    --ai-card-ink: #3f4ea0;
}

.ai-tools-root .ai-card.kind-solution {
    --ai-card-accent: #E8C547;
    --ai-card-tint: #FCF0BC;
    --ai-card-ink: #9a7b00;
}

/* A folder of solutions keeps the neutral defaults, on a grey ground. */
.ai-tools-root .ai-card.is-folder {
    --ai-card-accent: #b0bec5;
    --ai-card-tint: #eceff1;
    --ai-card-ink: #607d8b;
    background: #fafafa;
}

/* Weak fit (principle_fit / param_fit "forced"): the stripe says it before the badge does. */
.ai-tools-root .ai-card.is-weak {
    border-left-color: #f57c00;
}

/* The KMAP and parameter cards open a preview when clicked. */
.ai-tools-root .ai-card.is-selectable {
    cursor: pointer;
}

/* Inside a folder: already framed by the parent, so lighter and flush with it. */
.ai-tools-root .ai-card.is-nested {
    margin: 0;
    box-shadow: none;
}

.ai-tools-root .ai-card-header {
    gap: 8px;
    min-height: 40px;
}

/* The heading takes the free width; without flex: none the buttons would give theirs up to
   a long name and their icon would be cut in half. */
.ai-tools-root .ai-card-header > .md-button,
.ai-tools-root .ai-card-header > md-icon,
.ai-tools-root .ai-card-header > .ai-card-chevron,
.ai-tools-root .ai-card-avatar {
    flex: none;
}

.ai-tools-root .ai-card-chevron {
    display: flex;
    align-items: center;
    color: #9e9e9e;
}

.ai-tools-root .ai-card-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--ai-card-tint);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-tools-root .ai-card-avatar md-icon {
    margin: 0;
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    font-size: 20px;
    color: var(--ai-card-ink);
}

.ai-tools-root .ai-card-heading {
    min-width: 0;
}

.ai-tools-root .ai-card-name {
    font-size: 14px;
    line-height: 1.4;
    font-weight: 500;
    color: #333;
}

.ai-tools-root .ai-card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
}

/* In a row of their own, the badges line up with the gap rather than their inline margin. */
.ai-tools-root .ai-card-meta .ai-badge-inline {
    margin-left: 0;
}

.ai-tools-root .ai-card-caption {
    font-size: 12px;
    line-height: 1.4;
    color: #777;
    margin-top: 2px;
}

.ai-tools-root .ai-card-body {
    margin-top: 8px;
    padding-left: 40px;
}

/* Indented only once: a nested card is already under its parent's text, and a narrow panel
   has no width to give away. */
.ai-tools-root .ai-card.is-nested .ai-card-body {
    padding-left: 0;
}

@container ai-data (max-width: 480px) {

    .ai-tools-root .ai-card-body {
        padding-left: 0;
    }
}

.ai-tools-root .ai-card-section {
    margin-top: 10px;
}

.ai-tools-root .ai-card-section:first-child {
    margin-top: 0;
}

/* Same weight as the row detail's titles (.ai-row-detail-title). */
.ai-tools-root .ai-card-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #777;
    margin-bottom: 4px;
}

/* A heading that names something (a parameter, a principle) rather than a field. */
.ai-tools-root .ai-card-subtitle {
    font-size: 13px;
    font-weight: 500;
    color: #333;
}

.ai-tools-root .ai-card-text {
    font-size: 13px;
    line-height: 1.5;
    color: #444;
    text-align: justify;
}

.ai-tools-root .ai-card-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 8px;
    border-radius: 10px;
    background: #eef1f3;
    color: #555;
    font-size: 11px;
    text-transform: none;
    letter-spacing: 0;
}

.ai-tools-root .ai-card-pill md-icon,
.ai-tools-root .ai-card-box-title md-icon {
    margin: 0;
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    font-size: 16px;
    color: inherit;
}

/* Side by side while there is room, stacked once each would get narrower than 200px. */
.ai-tools-root .ai-card-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px;
}

.ai-tools-root .ai-card-box {
    padding: 8px 10px;
    border-radius: 0 4px 4px 0;
    border-left: 3px solid #cfd8dc;
    background: #f7f9fa;
}

/* A list of boxes under a section heading (the principle card's parameters and principles).
   A box that is a section of its own keeps the section spacing. */
.ai-tools-root .ai-card-section + .ai-card-box:not(.ai-card-section),
.ai-tools-root .ai-card-box + .ai-card-box:not(.ai-card-section) {
    margin-top: 6px;
}

.ai-tools-root .ai-card-box.positive {
    border-left-color: #A3D039;
    background: rgba(163, 208, 57, 0.1);
}

.ai-tools-root .ai-card-box.negative {
    border-left-color: #CC6600;
    background: rgba(204, 102, 0, 0.07);
}

/* In the card's own colour: what the step produced, as opposed to its context. */
.ai-tools-root .ai-card-box.accent {
    border-left-color: var(--ai-card-accent);
    background: var(--ai-card-tint);
}

.ai-tools-root .ai-card-box.principle {
    border-left-color: #77C6CB;
    background: rgba(119, 198, 203, 0.1);
}

.ai-tools-root .ai-card-box-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px;
    font-size: 12px;
    font-weight: 600;
    color: #555;
    margin-bottom: 4px;
}

.ai-tools-root .ai-card-box-title .ai-badge-inline {
    margin-left: 0;
}

.ai-tools-root .ai-card-box.positive .ai-card-box-title {
    color: #6f9a1a;
}

.ai-tools-root .ai-card-box.negative .ai-card-box-title {
    color: #CC6600;
}

.ai-tools-root .ai-card-box.accent .ai-card-box-title {
    color: var(--ai-card-ink);
}

.ai-tools-root .ai-card-box.principle .ai-card-box-title {
    color: #3f9aa0;
}

.ai-tools-root .ai-card-subsection {
    margin-top: 8px;
}

.ai-tools-root .ai-card-image img {
    max-width: 100%;
    border-radius: 4px;
}

.ai-tools-root .ai-card-children {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
}

/* =========================
   TOOL DIALOGS
   ========================= */

.ai-side-dialog .ai-dialog-intro,
.ai-save-dialog .ai-dialog-intro {
    color: #777;
    font-size: 13px;
    margin: 0 0 12px 0;
}

.ai-save-dialog .md-dialog-content {
    padding: 24px;
}

.ai-save-target {
    margin-bottom: 8px;
    padding: 10px 12px;
    border-radius: 6px;
    background: #f7f7f7;
}

.ai-save-target-title {
    font-size: 13px;
    font-weight: 600;
    color: #555;
    margin-bottom: 4px;
}

.ai-save-target md-radio-button {
    margin-bottom: 4px;
}

.ai-save-slider-wrapper {
    position: relative;
    margin: 110px 60px 10px 60px;
}

.ai-save-icons-row {
    position: absolute;
    top: -96px;
    left: 0;
    right: 0;
    height: 80px;
}

.ai-save-icon {
    position: absolute;
    transform: translateX(-50%);
    width: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.ai-save-icon .ai-circle {
    width: 48px;
    height: 48px;
    transition: 0.3s ease;
}

.ai-save-icon.active .ai-circle {
    background: #A3D039;
    transform: scale(1.1);
}

.ai-save-step-title {
    margin-top: 8px;
    font-size: 12px;
    color: #666;
    line-height: 1.25;
}

.ai-save-icon.active .ai-save-step-title {
    color: #A3D039;
    font-weight: 600;
}

/* The run dialog reuses the save dialog's markers: green for a step that keeps its data,
   the teal of a running step for one that will be generated. */
.ai-run-dialog .ai-save-icon.kept .ai-circle {
    background: #A3D039;
}

.ai-run-dialog .ai-save-icon.will-run .ai-circle {
    background: #77C6CB;
    transform: scale(1.1);
}

.ai-run-dialog .ai-save-icon.will-run .ai-save-step-title {
    color: #3f9aa0;
    font-weight: 600;
}

.ai-run-dialog .ai-save-icon.selectable {
    cursor: pointer;
}

.ai-run-dialog .ai-save-icon:not(.selectable) {
    opacity: 0.6;
}

.ai-run-shortcuts {
    gap: 8px;
    margin-top: 4px;
}

.ai-run-outdated,
.ai-tools-root .ai-rail-outdated {
    font-size: 14px;
    width: 14px;
    height: 14px;
    min-width: 14px;
    min-height: 14px;
    color: #f57c00;
    vertical-align: middle;
}

.ai-save-status {
    gap: 10px;
    margin-top: 16px;
    font-size: 13px;
    color: #777;
}

#save-range-slider .md-thumb:after,
#save-range-slider .md-track-fill {
    background-color: #A3D039 !important;
    border-color: #A3D039 !important;
}

#save-range-slider .md-focus-thumb,
#save-range-slider .md-focus-ring {
    background-color: #A3D039;
}

/* =========================
   TOASTS (appended to body, outside the panel)
   ========================= */

.ai-success-toast .md-toast-content,
.ai-error-toast .md-toast-content {
    border-radius: 10px;
}

.ai-success-toast .md-toast-content {
    background-color: #A3D039;
}

.ai-error-toast .md-toast-content {
    background-color: #c62828;
}

/* =========================
   NARROW LAYOUTS (docked in the chat side panel)
   ========================= */

/* =========================
   NARROW PANEL

   In order, as the panel gets narrower: the progress wording goes, then its bar, then the
   button labels — the icons and the rail below still say what is running and how far it is.
   ========================= */

@container ai-panel (max-width: 620px) {

    .ai-global-progress-label {
        display: none;
    }

    .ai-global-progress-track {
        width: 90px;
    }
}

@container ai-panel (max-width: 480px) {

    .ai-global-progress-track {
        width: 60px;
    }
}

@container ai-panel (max-width: 380px) {

    .ai-global-progress-track {
        display: none;
    }

    .ai-actions-bar .ai-button-label {
        display: none;
    }

    .ai-actions-bar .md-button {
        min-width: 0;
        padding: 0 10px;
    }

    .ai-actions-bar .md-button md-icon,
    .ai-actions-bar .md-button md-progress-circular {
        margin-right: 0;
    }
}

@media (max-width: 1100px) {

    .ai-rail-track,
    .ai-rail-track-fill {
        display: none;
    }

    .ai-rail-cells {
        grid-auto-flow: row;
        grid-auto-columns: auto;
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 4px;
    }

    .ai-circle {
        width: 44px;
        height: 44px;
    }

    .ai-circle md-icon {
        width: 24px;
        height: 24px;
        font-size: 24px;
    }

    .ai-rail-title {
        font-size: 12px;
    }

    .ai-global-progress-label {
        display: none;
    }

    .ai-global-progress-track {
        width: 90px;
    }
}

/* =========================
   SHORT VIEWPORTS

   Everything above .ai-scroll is fixed, so on a short screen it is the rail that gives up its
   labels — not the generated data that gives up its room.
   ========================= */

@media (max-height: 800px) {

    .ai-rail {
        padding: 10px 16px 6px 16px;
    }

    .ai-rail-track,
    .ai-rail-track-fill {
        top: 32px;
    }

    .ai-circle {
        width: 44px;
        height: 44px;
    }

    .ai-circle md-icon {
        width: 24px;
        height: 24px;
        font-size: 24px;
    }

    .ai-header {
        padding: 6px 16px 8px 16px;
    }

    .ai-actions-bar {
        margin-top: 6px;
    }
}

@media (max-height: 640px) {

    /* Down to one line rather than nothing: a title that wraps costs the data three lines of
       height, a truncated one costs sixteen pixels and still names the step. The circle's
       tooltip has it in full. */
    .ai-rail-title {
        margin-top: 3px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }

    /* One line of context is enough when the screen is this short. */
    .ai-description-text {
        -webkit-line-clamp: 1;
    }
}
