/* ===== dialogue.css — namespaced replacement for eval.css ===== */
/* All rules scoped under .dlg-page to avoid global pollution. */

/* ===== Theme variables ===== */
/* Also scoped onto select.dlg-select, the opt-in used by selects outside a
   .dlg-page root — the shared select rules below consume these tokens. The
   non-token declarations (font, max-width) are harmless on a select. */
.dlg-page,
select.dlg-select {
    --dlg-font: var(--app-font-primary, "Geist", sans-serif);
    --dlg-color-text: var(--app-text-primary, rgba(17, 24, 39, 0.87));
    --dlg-color-text-secondary: var(--app-text-secondary, #919191);
    --dlg-color-bg: var(--app-bg-primary, #fff);
    --dlg-color-bg-secondary: var(--app-bg-secondary, #f9f9f9);
    --dlg-color-bg-hover: var(--app-bg-hover, #f5f5f5);
    --dlg-color-primary: var(--app-action-hover, #141b9b);
    --dlg-color-primary-hover: var(--app-action-hover, #141b9b);
    --dlg-color-border: hsla(0, 0%, 40%, 0.15);
    --dlg-color-border-light: hsla(0, 0%, 40%, 0.08);
    --dlg-color-danger: var(--app-text-alert, #dc172e);
    --dlg-radius: 8px;
    --dlg-radius-sm: 6px;
    --dlg-padding: 16px;

    font-family: var(--dlg-font);
    font-size: 14px;
    line-height: 22px;
    color: var(--dlg-color-text);

    /* Single-column reading width — the default scheme, so no admin page renders
     * full-bleed. Data-dense, two-column pages opt into the wider scheme by
     * adding `dlg-page--wide` (below) rather than restating a max-width. */
    max-width: 1000px;
}

/*
 * Double-column scheme: the wider cap for pages that lay content out in two
 * columns or show dense tables (Retrieval, Prompt list, Eval, etc.). Written as
 * two classes on one element so it beats the base `.dlg-page` cap without
 * `!important`; the page still keeps its own layout rules (flex, grid, …).
 */
.dlg-page.dlg-page--wide {
    max-width: 1800px;
}

/* ===== Forms ===== */
/* select.dlg-select is the opt-in hook for selects on pages that don't use
   the .dlg-page blanket (e.g. .am-page) — same shared look, no duplication. */
.dlg-page input,
.dlg-page select,
select.dlg-select {
    padding: 9px 12px;
    border: 1px solid var(--dlg-color-border);
    border-radius: var(--dlg-radius-sm);
    font-family: var(--dlg-font);
    font-size: 14px;
    line-height: 22px;
    color: var(--dlg-color-text);
    background: var(--dlg-color-bg);
    transition: border-color 0.15s ease;
}

.dlg-page input:hover {
    border-color: hsla(0, 0%, 40%, 0.3);
}

/* Figma "Input fields / Select input, State=Hover" (7511:30124): the box
   fills with Background/Hover, the stroke stays as is. */
.dlg-page select:hover,
select.dlg-select:hover {
    background-color: var(--dlg-color-bg-hover);
}

.dlg-page input:focus,
.dlg-page select:focus,
select.dlg-select:focus,
.dlg-page textarea:focus {
    outline: 2px solid var(--app-focus-ring, rgba(20, 27, 155, 0.6));
    outline-offset: -2px;
    border-color: var(--dlg-color-primary);
}

.dlg-page input[type=text] {
    width: 100%;
    max-width: 500px;
    box-sizing: border-box;
}

.dlg-page input[type=checkbox] {
    width: auto;
    padding: 0;
    accent-color: var(--dlg-color-primary);
}

.dlg-page textarea {
    border: 1px solid var(--dlg-color-border);
    border-radius: var(--dlg-radius-sm);
    font-family: monospace;
    font-size: 13px;
    line-height: 20px;
    color: var(--dlg-color-text);
    background: var(--dlg-color-bg);
    padding: 9px 12px;
    transition: border-color 0.15s ease;
}

.dlg-page textarea:hover {
    border-color: hsla(0, 0%, 40%, 0.3);
}

/* Native selects keep the OS appearance unless it is explicitly disabled —
   on macOS that renders the Aqua button and hides all our border/radius
   styling, so Dialogue's dropdowns look unlike the other apps. Neutralize
   it and draw central-ui's own chevron (icons.js DROPDOWN_ICON, colored
   --app-icon-primary), so the closed state matches .app-select-trigger.
   The open menu stays OS-native by design (server-HTML + local JS hybrid). */
.dlg-page select:not([multiple]),
select.dlg-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M6 8L10 12L14 8' stroke='rgba(17,24,39,0.57)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px 20px;
    padding-right: 40px;
}

/* Customizable select — the open list is ours too, where the browser
   supports it (Chromium 135+; Safari/Firefox ignore base-select and keep
   the native picker above, so nothing regresses there). Styled after the
   Figma "Dropdown/Type" component (TellusR-Admin 7511:38911): white card
   with the standard stroke, 8px radius, 2px/7px shadow, 4px padding, and
   40px rows (9px 16px) in Geist Medium with 4px between them. Hover and
   selected use the same tokens as the sidebar and header menus. */
@supports (appearance: base-select) {
    .dlg-page select:not([multiple]),
    select.dlg-select {
        appearance: base-select;
    }

    /* base-select draws its own arrow; we keep the chevron drawn above. */
    .dlg-page select:not([multiple])::picker-icon,
    select.dlg-select::picker-icon {
        display: none;
    }

    /* No `display` here: the picker is a popover, and the UA hides it with
       display:none while closed — overriding that shows every list at once. */
    .dlg-page select:not([multiple])::picker(select),
    select.dlg-select::picker(select) {
        appearance: base-select;
        margin: 4px 0 0;
        padding: 4px;
        border: 1px solid var(--dlg-color-border);
        border-radius: var(--dlg-radius);
        background: var(--dlg-color-bg);
        box-shadow: 0 2px 7px rgba(0, 0, 0, 0.11);
    }

    .dlg-page select:not([multiple]) option,
    select.dlg-select option {
        display: flex;
        align-items: center;
        box-sizing: border-box;
        min-height: 40px;
        padding: 9px 16px;
        border-radius: var(--dlg-radius);
        font-family: var(--dlg-font);
        font-size: 14px;
        font-weight: 500;
        line-height: 22px;
        color: var(--dlg-color-text);
        background: var(--dlg-color-bg);
        cursor: pointer;
    }

    /* 4px between rows, as in the design. */
    .dlg-page select:not([multiple]) option + option,
    select.dlg-select option + option {
        margin-top: 4px;
    }

    .dlg-page select:not([multiple]) option:hover,
    select.dlg-select option:hover,
    .dlg-page select:not([multiple]) option:focus-visible,
    select.dlg-select option:focus-visible {
        background: var(--dlg-color-bg-hover);
        outline: none;
    }

    /* The selected row is not tinted; it carries the design's check icon
       (Figma "Input option, State=Selected", 7511:30164) at the end. */
    .dlg-page select:not([multiple]) option::checkmark,
    select.dlg-select option::checkmark {
        order: 1;
        margin-left: auto;
        width: 20px;
        height: 20px;
        content: url("data:image/svg+xml,%3Csvg%20preserveAspectRatio=%22none%22%20overflow=%22visible%22%20style=%22display:%20block%3B%22%20width=%2220%22%20height=%2220%22%20viewBox=%220%200%2020%2020%22%20fill=%22none%22%20xmlns=%22http://www.w3.org/2000/svg%22%3E%20%3Cg%20id=%22check%22%3E%20%3Cpath%20id=%22Vector%22%20d=%22M4%2010L8%2014L16%206%22%20stroke=%22%23212121%22%20stroke-width=%221.66667%22%20stroke-linecap=%22round%22%20stroke-linejoin=%22round%22/%3E%20%3C/g%3E%20%3C/svg%3E");
    }
}

/* ===== Fieldsets ===== */
.dlg-page fieldset {
    border: 1px solid var(--dlg-color-border);
    border-radius: var(--dlg-radius);
    padding: var(--dlg-padding);
    background: var(--dlg-color-bg);
    margin: 0;
}

.dlg-page fieldset + fieldset {
    margin-top: 16px;
}

.dlg-page legend {
    font-size: 14px;
    font-weight: 600;
    line-height: 22px;
    color: var(--dlg-color-text);
    padding: 0 4px;
}

/* ===== Buttons ===== */
.dlg-page button,
.dlg-page .submit {
    padding: 9px 16px;
    border: 1px solid var(--dlg-color-border);
    border-radius: var(--dlg-radius-sm);
    background: var(--dlg-color-bg);
    color: var(--dlg-color-text);
    font-family: var(--dlg-font);
    font-size: 14px;
    font-weight: 500;
    line-height: 22px;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.dlg-page button:hover,
.dlg-page .submit:hover {
    background: var(--dlg-color-bg-hover);
    border-color: var(--dlg-color-primary);
}

.dlg-page button:active,
.dlg-page .submit:active {
    background: var(--app-bg-pressed, rgba(20, 27, 155, 0.2));
}

.dlg-page button.defaultButton,
.dlg-page .submit.defaultButton {
    background: var(--app-action-primary, #212121);
    color: #f5f5f5;
    border-color: var(--app-action-primary, #212121);
}

.dlg-page button.defaultButton:hover,
.dlg-page .submit.defaultButton:hover {
    background: var(--dlg-color-primary);
    border-color: var(--dlg-color-primary);
}

/* ===== Form layout ===== */
/* New namespaced classes; old names kept as aliases for unmigrated pages. */
.dlg-page .dlg-fields,
.dlg-page .table {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dlg-page .dlg-field,
.dlg-page .row {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin: 0;
}

.dlg-page .dlg-value,
.dlg-page .cell {
    flex: 1;
    min-width: 0;
}

.dlg-page .dlg-label,
.dlg-page .label {
    flex: 0 0 auto;
    width: 10em;
    font-weight: 500;
    font-size: 14px;
    color: var(--dlg-color-text-secondary);
}

.dlg-page .dlg-field .submit,
.dlg-page .row .submit {
    flex-shrink: 0;
}

.dlg-page .dlg-actions,
.dlg-page .buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

.dlg-page .dlg-actions .submit,
.dlg-page .buttons .submit {
    display: inline-flex;
}

/* ===== Status ===== */
.dlg-page .js-admin-status {
    min-height: 1.2em;
    font-size: 13px;
    color: var(--dlg-color-text-secondary);
}

.dlg-page .js-admin-status.is-error {
    color: var(--dlg-color-danger);
    font-weight: 600;
}

/* ===== Split layout ===== */
.dlg-page .search-config-split {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.dlg-page .search-config-left {
    min-width: 0;
}

.dlg-page .search-config-right {
    min-width: 280px;
}

@media (min-width: 1100px) {
    .dlg-page .search-config-split {
        flex-direction: row;
        align-items: flex-start;
    }
    .dlg-page .search-config-left {
        flex: 1 1 55%;
    }
    .dlg-page .search-config-right {
        flex: 1 1 40%;
        position: sticky;
        top: 0;
    }
}

/* ===== Search bar (chat-ask style) ===== */
.dlg-page .dlg-search-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--dlg-color-bg-secondary);
    border: 1px solid rgba(20, 27, 155, 0.2);
    border-radius: var(--dlg-radius);
    padding: 4px 6px 4px 12px;
    margin-top: 8px;
    transition: border-color 0.15s ease;
}

.dlg-page .dlg-search-bar:focus-within {
    border-color: rgba(20, 27, 155, 0.4);
}

.dlg-page .dlg-search-bar input[type=text] {
    flex: 1;
    width: 0;
    min-width: 0;
    max-width: none;
    border: none;
    outline: none;
    background: transparent;
    padding: 9px 0;
    font-size: 16px;
    line-height: 22px;
}

.dlg-page .dlg-search-bar input[type=text]:focus {
    outline: none;
    border-color: transparent;
}

.dlg-page .dlg-search-bar input[type=text]::placeholder {
    color: var(--app-text-placeholder, rgba(17, 24, 39, 0.35));
}

.dlg-page .dlg-search-bar button,
.dlg-page .dlg-search-bar .submit {
    flex-shrink: 0;
    background: rgba(20, 27, 155, 0.87);
    color: #fff;
    border: none;
    border-radius: var(--dlg-radius-sm);
    padding: 9px 16px;
    font-weight: 500;
}

.dlg-page .dlg-search-bar button:hover,
.dlg-page .dlg-search-bar .submit:hover {
    background: rgba(20, 27, 155, 1);
    border: none;
}

/* ===== Search results ===== */
.dlg-page .search-result-entry {
    margin: 8px 0;
    padding: 12px 16px;
    background: var(--dlg-color-bg-secondary);
    border: 1px solid var(--dlg-color-border-light);
    border-radius: var(--dlg-radius);
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 12px;
}

.dlg-page .search-result-entry dt {
    font-weight: 600;
    font-size: 12px;
    color: var(--dlg-color-text-secondary);
    padding-top: 2px;
}

.dlg-page .search-result-entry dd {
    margin: 0;
    font-size: 14px;
    word-break: break-word;
}

/* ===== Config panels ===== */
.dlg-page [data-config-panel] {
    margin-top: 16px;
}

/* ===== Config tabs (JS-created nav) ===== */
.dlg-page .dlg-config-tabs {
    margin-top: 16px;
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--dlg-color-border);
    margin-bottom: 0;
    padding: 0;
    background: none;
}

.dlg-page .dlg-config-tab {
    padding: 8px 16px;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--dlg-radius-sm) var(--dlg-radius-sm) 0 0;
    background: var(--dlg-color-bg);
    color: var(--dlg-color-text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: -2px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.dlg-page .dlg-config-tab:hover {
    background: var(--dlg-color-bg-secondary);
    color: var(--dlg-color-text);
}

.dlg-page .dlg-config-tab.active {
    border-color: var(--dlg-color-border);
    border-bottom: 2px solid var(--dlg-color-bg);
    background: var(--dlg-color-bg);
    color: var(--dlg-color-primary);
    font-weight: 600;
}

/* When tabs are present, hide panel legends and connect panel to tab bar */
.dlg-page .dlg-config-tabs ~ [data-config-panel] {
    border-top: none;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    margin-top: 0 !important;
}

.dlg-page .dlg-config-tabs ~ [data-config-panel] > legend {
    display: none;
}

/* ===== Details/summary (Advanced toggle) ===== */
.dlg-page details {
    margin-top: 12px;
}

.dlg-page details summary {
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--dlg-color-text-secondary);
    padding: 4px 0;
    user-select: none;
    /* Keep the disclosure marker inside the content box so it aligns with the
     * summary's text (and any heading above it) instead of protruding left. */
    list-style-position: inside;
}

.dlg-page details summary:hover {
    color: var(--dlg-color-text);
}

.dlg-page details[open] > summary {
    margin-bottom: 12px;
}

/* ===== Result entry (key/value pair list shared by Test Search + Kotlin
 * SearchEntrySnippet) ===== */
.dlg-result-entry {
    margin-bottom: 8px;
    padding: 10px 14px;
    background: var(--dlg-color-bg-secondary);
    border: 1px solid var(--dlg-color-border-light);
    border-radius: var(--dlg-radius);
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 12px;
}

.dlg-result-entry dt {
    font-weight: 600;
    font-size: 12px;
    color: var(--dlg-color-text-secondary);
    padding-top: 2px;
}

.dlg-result-entry dd {
    margin: 0;
    font-size: 14px;
    word-break: break-word;
}

.dlg-result-entry pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Neutralize the global .dlg-page details { margin-top: 12px } rule so the
 * disclosure triangle aligns with the <dt> label in the same grid row. */
.dlg-result-entry details {
    margin: 0;
}

/* ===== Links ===== */
.dlg-page a {
    color: var(--dlg-color-primary);
    text-decoration: none;
}

.dlg-page a:hover {
    color: var(--dlg-color-primary-hover);
    text-decoration: underline;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .dlg-page .dlg-field,
    .dlg-page .row {
        flex-direction: column;
        gap: 4px;
    }

    .dlg-page .dlg-label,
    .dlg-page .label {
        width: auto;
    }

    .dlg-page input[type=text] {
        max-width: none;
    }
}
