/* ==========================================================================
   Agents (AI-1825): master-detail inside the one settings card, the agents as
   a quiet list on the left, a hairline, the editor with its tabs on the right;
   the routing per organisation below.
   ========================================================================== */

.agents-notice {
    margin-bottom: 16px;
}

.agents-layout {
    display: grid;
    grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
    align-items: start;
}

.agents-left {
    position: sticky;
    top: 88px;
    max-height: calc(100vh - 120px);
    overflow: auto;
    min-width: 0;
    padding-right: 20px;
    border-right: 1px solid var(--ui-divider);
}

.agents-right {
    min-width: 0;
    padding-left: 28px;
}

/* ---------- Agent list --------------------------------------------------- */

.agents-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.agents-list__item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    border-radius: var(--ui-radius-sm);
    background: transparent;
    color: var(--ui-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color 140ms var(--ui-ease);
}

.agents-list__item:hover {
    background: var(--ui-bg-hover);
}

.agents-list__item:focus-visible {
    outline: none;
    box-shadow: var(--ui-focus-ring);
}

.agents-list__item.is-selected {
    background: var(--ui-bg-active);
}

.agents-list__row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.agents-list__name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    font-size: 0.875rem;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agents-list__item.is-selected .agents-list__name {
    color: var(--ui-accent);
    font-weight: 600;
}

.agents-list__meta {
    color: var(--ui-text-2);
    font-size: 0.75rem;
}

.agents-list__meta--clip {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Editor ------------------------------------------------------- */

.agent-detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
}

.agent-detail-header__identity {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.agent-detail-header__identity > * {
    margin: 0;
}

.agent-detail-tabs {
    min-width: 0;
}

/* A section directly under the tab strip needs no second divider. */
.agent-detail-tabs .ui-tabs__panel > .ui-section:first-child {
    border-top: 0;
    padding-top: 0;
}

.agent-instructions textarea {
    min-height: 360px;
    line-height: 1.55;
    resize: vertical;
}

.agent-form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--ui-divider);
}

.agent-form-actions__start,
.agent-form-actions__end {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.agent-form-actions__end {
    margin-left: auto;
}

/* ---------- Tools -------------------------------------------------------- */

.agent-tools {
    display: flex;
    flex-direction: column;
}

.agent-tools__head {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 6px;
}

.agent-tools__head > * {
    margin: 0;
}

.agent-tool {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    align-items: center;
    gap: 8px 24px;
    padding: 12px 0;
    border-top: 1px solid var(--ui-divider);
}

.agent-tool--compact {
    padding: 8px 0;
}

.agent-tool__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.agent-tool__title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.agent-tool__name {
    font-size: 0.875rem;
    font-weight: 500;
}

.agent-tool__name--small {
    font-size: 0.8125rem;
}

.agent-tool__desc {
    display: -webkit-box;
    max-width: 62ch;
    overflow: hidden;
    color: var(--ui-text-2);
    font-size: 0.8125rem;
    line-height: 1.4;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.agent-tool__desc--one {
    -webkit-line-clamp: 1;
}

.agent-tool__control {
    min-width: 0;
}

.agent-tool__control--row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.agent-tool__days {
    width: 150px;
}

.agent-tools__plugins {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--ui-divider);
}

.agent-tools__group {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 18px 0 4px;
}

/* ---------- Snapshots ---------------------------------------------------- */

.agents-snapshots {
    margin: 0;
    padding: 0;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
    list-style: none;
}

.agents-snapshots__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 8px 10px 16px;
}

.agents-snapshots__item + .agents-snapshots__item {
    border-top: 1px solid var(--ui-divider);
}

.agents-snapshots__text {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
}

.agents-snapshots__title {
    max-width: 100%;
    overflow: hidden;
    font-size: 0.875rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agents-snapshots__meta {
    color: var(--ui-text-2);
    font-size: 0.8125rem;
}

/* ---------- Routing ------------------------------------------------------ */

.agents-routing {
    margin-top: 32px;
}

.agents-routing__select {
    min-width: 220px;
}

@media (max-width: 959px) {
    .agents-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .agents-left {
        position: static;
        max-height: 360px;
        padding: 0 0 16px;
        border-right: 0;
        border-bottom: 1px solid var(--ui-divider);
    }

    .agents-right {
        padding: 20px 0 0;
    }
}

@media (max-width: 760px) {
    .agent-tool {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 600px) {
    .agent-detail-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .agent-instructions textarea {
        min-height: 300px;
    }
}
