/* Settings page — /admin/settings (utils/admin_settings_layouts.py).
   Section nav on the left, the active section's groups on the right. */

/* ── Whose settings ─────────────────────────────────────────────────── */
.settings-identity {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}
.settings-identity-mark {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #eef0ff;
    color: #4B4BCC;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.settings-identity-text { min-width: 0; }
.settings-identity-name {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    line-height: 1.3;
}
.settings-identity-sub {
    font-size: var(--fs-sm);
    color: #6b7280;
    margin-top: 2px;
}
.settings-scope-picker {
    width: 340px;
    max-width: 100%;
}
/* Menu rows are a fixed 35px, so a long name is cut to one line; the option's
   title carries the full name. */
.settings-scope-picker .VirtualizedSelectOption,
.settings-model-picker .VirtualizedSelectOption {
    display: block;
    line-height: 35px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Platform defaults, set apart from the organizations listed under it. */
.settings-scope-picker .VirtualizedSelectOption:has(.settings-scope-platform) {
    border-bottom: 1px solid #e5e7eb;
}

/* ── Two columns ────────────────────────────────────────────────────── */
/* Queried on its own width, not the window's: the app sidebar takes 260px
   of the window above 768px and none below. */
.settings-layout {
    container: settings-layout / inline-size;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 32px;
    align-items: start;
}

.settings-nav {
    position: sticky;
    top: 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.settings-nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 7px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #374151;
    font-size: var(--fs-md);
    text-align: left;
    cursor: pointer;
}
.settings-nav-item i {
    width: 16px;
    text-align: center;
    color: #6b7280;
}
.settings-nav-item:hover {
    background: #f3f4f6;
    color: #111827;
}
.settings-nav-item:focus-visible {
    outline: 2px solid #4B4BCC;
    outline-offset: 2px;
}
.settings-nav-item.is-active {
    background: #eef0ff;
    color: #3a3aa0;
    font-weight: 600;
}
.settings-nav-item.is-active i { color: #4B4BCC; }
.settings-nav-item.is-active::before {
    content: "";
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 22px;
    border-radius: 4px;
    background: #4B4BCC;
}

/* ── Right column ───────────────────────────────────────────────────── */
.settings-content { container: settings-content / inline-size; }

.settings-panel-header {
    padding-bottom: 10px;
    margin-bottom: 18px;
    border-bottom: 1px solid #e5e7eb;
}
.settings-panel-title {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    color: #111827;
}
.settings-panel-desc {
    margin: 4px 0 0;
    font-size: var(--fs-sm);
    color: #6b7280;
}

.settings-section:not(:first-child) {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid #d1d5db;
}
.settings-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 8px;
    margin-bottom: 4px;
}
.settings-section-header + .settings-box { padding-top: 12px; }
.settings-section-title {
    margin: 0;
    font-size: var(--fs-h2);
    font-weight: 600;
    color: #111827;
}

.settings-box + .settings-box {
    margin-top: 12px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}
/* A badge that doesn't fit beside the title goes under it, so the title keeps
   its one line. */
.settings-box-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 12px;
}
.settings-box-title {
    font-size: var(--fs-lg);
    font-weight: 600;
    color: #111827;
}
.settings-subsection-title {
    font-size: var(--fs-md);
    font-weight: 600;
    color: #111827;
}
.settings-box-row { padding: 12px 0; }
.settings-box-row + .settings-box-row { border-top: 1px solid #f0f1f4; }
/* Models: space rather than rules between the groups and rows of a section. */
.settings-models .settings-box + .settings-box {
    margin-top: 20px;
    padding-top: 0;
    border-top: 0;
}
.settings-models .settings-box-row + .settings-box-row { border-top: 0; }
.settings-models-source {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-bottom: 16px;
    font-size: var(--fs-sm);
    color: #6b7280;
}
.settings-models-source:empty { display: none; }
.settings-models-status:not(:empty),
.settings-models-notice:not(:empty) { margin-bottom: 16px; }
.settings-row-title {
    font-size: var(--fs-md);
    font-weight: 600;
    color: #111827;
}
.settings-row-desc {
    margin: 2px 0 12px;
    font-size: var(--fs-sm);
    color: #6b7280;
}
.settings-box-row > .settings-row-desc:last-child { margin-bottom: 0; }

.settings-field { margin-bottom: 12px; }
.settings-field-label {
    font-size: var(--fs-sm);
    font-weight: 600;
}
.settings-field-help {
    margin-top: 4px;
    font-size: var(--fs-xs);
    line-height: 1.4;
    color: #6b7280;
}
.settings-field-info {
    margin-left: 6px;
    font-size: 12px;
    color: #9ca3af;
    cursor: help;
}
/* Dropdowns as tall as the text inputs, with a long value cut off before the
   25px arrow, and the 17px clear button when there is one, rather than running
   under them. */
.settings-scope-picker .Select-control,
.settings-field .Select-control { height: 38px; }
.settings-scope-picker .Select-placeholder,
.settings-scope-picker .Select--single > .Select-control .Select-value,
.settings-field .Select-placeholder,
.settings-field .Select--single > .Select-control .Select-value {
    line-height: 36px;
    padding-right: 25px;
}
.settings-field .Select--single.is-clearable.has-value:not(.is-disabled) > .Select-control .Select-value {
    padding-right: 42px;
}
.settings-scope-picker .Select-input,
.settings-field .Select-input { height: 36px; }
/* A long model name wraps inside its chip rather than leaving the × behind. */
.settings-field .Select--multi .Select-value {
    display: inline-flex;
    max-width: calc(100% - 5px);
}

.settings-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
}

.settings-form { max-width: 640px; }
.settings-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 14px;
}
.settings-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.settings-inline .form-control { max-width: 420px; }

.settings-outcome {
    margin-top: 8px;
    font-size: var(--fs-sm);
    color: #6b7280;
}
.settings-outcome.is-ok { color: #047857; }
.settings-outcome.is-warning { color: #b45309; }
.settings-outcome.is-error { color: #b91c1c; }
/* A success line is an Alert for its timer, drawn as the plain line. */
.settings-outcome.alert {
    padding: 0;
    margin-bottom: 0;
    border: 0;
}

/* No more than three columns, however wide the panel. */
.settings-model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(max(240px, calc((100% - 16px) / 3)), 1fr));
    gap: 8px;
}
.settings-model-card {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 6px 6px 6px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: var(--fs-md);
}
.settings-model-card img {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    object-fit: contain;
}
.settings-model-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
    color: #111827;
}
.btn.settings-model-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    min-height: 24px;
    padding: 0 4px;
    color: #9ca3af;
    text-decoration: none;
}
.btn.settings-model-remove:hover { color: #b91c1c; }

.settings-add-picker { max-width: 640px; }
.settings-model-picker img {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    border-radius: 3px;
    object-fit: contain;
    vertical-align: middle;
}
.settings-model-id {
    margin-left: 8px;
    color: #9ca3af;
    font-size: 12px;
}
/* The id is for telling models apart in the menu, not for the chosen value. */
.settings-model-picker .Select-value .settings-model-id { display: none; }

.settings-auto-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.settings-auto-list > :empty { display: none; }
.settings-auto-card {
    position: relative;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}
/* Right padding keeps the chevron clear of the remove button over it. */
.settings-auto-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 44px 10px 14px;
    list-style: none;
    cursor: pointer;
}
.settings-auto-summary::-webkit-details-marker { display: none; }
.settings-auto-summary img {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    object-fit: contain;
}
.settings-auto-name,
.settings-auto-about {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.settings-auto-name {
    font-weight: 600;
    color: #111827;
}
.settings-auto-about {
    font-size: var(--fs-sm);
    color: #6b7280;
}
.settings-auto-chev {
    flex-shrink: 0;
    margin-left: auto;
    font-size: 12px;
    color: #9ca3af;
    transition: transform 0.2s;
}
.settings-auto-details[open] .settings-auto-chev { transform: rotate(180deg); }
.settings-auto-fields { padding: 4px 14px 2px; }
.settings-auto-remove {
    position: absolute;
    top: 8px;
    right: 10px;
}
.settings-auto-status:not(:empty) { padding: 0 14px 12px; }
.settings-auto-status .settings-outcome { margin-top: 0; }

.settings-soon {
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 11px;
    font-weight: 600;
    vertical-align: middle;
}
/* Disabled dropdowns take no hover, so the card gets it for its label. */
.settings-soon-wrap {
    margin-top: 20px;
    padding: 14px 14px 2px;
    background: #f9fafb;
    cursor: not-allowed;
}
.settings-soon-wrap .Select { pointer-events: none; }
/* Drawn inside the card and ignored by the pointer, so showing it adds
   nothing to the page and cannot take the hover off the card. */
.settings-soon-wrap::after {
    content: "Coming soon";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 4px 8px;
    border-radius: 6px;
    background: rgba(17, 24, 39, 0.9);
    color: #fff;
    font-size: var(--fs-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}
.settings-soon-wrap:hover::after { opacity: 1; }

/* Bootstrap takes pointer events off a disabled button or switch, which also
   hides its cursor. They are given back; a disabled control ignores the click. */
.settings-content :is(.form-control, .btn, .form-check-input):disabled,
.settings-content .form-check-input:disabled ~ .form-check-label,
.settings-content .Select.is-disabled,
.settings-content .Select.is-disabled * { cursor: not-allowed; }
.settings-content :is(.btn, .form-check-input):disabled { pointer-events: auto; }

/* ── Narrow: the nav becomes a row above the content ────────────────── */
/* A container can't restyle its own grid, so both children span it. */
@container settings-layout (max-width: 819px) {
    .settings-nav,
    .settings-content { grid-column: 1 / -1; }
    .settings-nav {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 4px;
        padding-bottom: 12px;
        border-bottom: 1px solid #e5e7eb;
    }
    .settings-nav-item { width: auto; }
    .settings-nav-item.is-active::before { display: none; }
}

/* Phone width: the page's and the card's padding would leave a 260px column. */
@media (max-width: 600px) {
    .admin-page:has(.settings-layout) {
        padding-left: 16px;
        padding-right: 16px;
    }
    .admin-body:has(> .settings-layout) { padding: 16px; }
}

@container settings-content (max-width: 599px) {
    .settings-grid-2,
    .settings-model-grid { grid-template-columns: minmax(0, 1fr); }
}
