/* ==========================================================================
   AgentBroker App Shell — rail + topbar + main для /app/* страниц.
   Импортировано из design/AgentBroker/Contracts.html (2026-04-20).
   Зависит от /widget/_shared/tokens.css (--ab-* custom properties).
   ========================================================================== */

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--ab-color-bg-subtle, #f7f7f8);
    color: var(--ab-color-text, #27272a);
    font-family: var(--ab-font-sans, 'Inter', 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    font-size: var(--ab-font-size-base, 14px);
    line-height: var(--ab-line-normal, 1.5);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Shell grid --------------------------------------------------------- */

.app-shell {
    display: grid;
    grid-template-columns: 56px 1fr;
    min-height: 100vh;
}

.app-shell__main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-shell__content {
    flex: 1;
    min-width: 0;
}

/* --- Left rail (icon-only navigation) ---------------------------------- */

.rail {
    background: var(--ab-color-surface, #fff);
    border-right: 1px solid var(--ab-color-border, #e2e2e6);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 20;
}

.rail__logo {
    width: 36px;
    height: 36px;
    background: var(--ab-color-brand-500, #f91942);
    color: #fff;
    display: grid;
    place-items: center;
    border-radius: 10px;
    font-weight: 700;
    font-size: 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 6px rgba(249, 25, 66, 0.25);
    text-decoration: none;
}

.rail__logo:hover { text-decoration: none; }

.rail__btn {
    position: relative;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: var(--ab-color-text-subtle, #71717a);
    cursor: pointer;
    background: transparent;
    border: 0;
    text-decoration: none;
    transition:
        background var(--ab-duration-fast, 120ms) var(--ab-ease-standard, cubic-bezier(0.2, 0, 0, 1)),
        color var(--ab-duration-fast, 120ms) var(--ab-ease-standard, cubic-bezier(0.2, 0, 0, 1));
}

.rail__btn:hover {
    background: var(--ab-color-bg-muted, #eeeef1);
    color: var(--ab-color-text, #27272a);
    text-decoration: none;
}

.rail__btn.is-active {
    background: var(--ab-color-brand-50, #fff1f4);
    color: var(--ab-color-brand-600, #db1239);
}

.rail__btn.is-active::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--ab-color-brand-500, #f91942);
}

.rail__btn .ic {
    width: 20px;
    height: 20px;
}

/* Tooltip справа на rail-btn — чистый CSS через data-tip */
.rail__btn[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: #1a1a1f;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--ab-duration-fast, 120ms) var(--ab-ease-standard, cubic-bezier(0.2, 0, 0, 1));
    z-index: 100;
}

.rail__btn[data-tip]:hover::after { opacity: 1; }

.rail__spacer { flex: 1; }
.rail__divider { width: 24px; height: 1px; background: var(--ab-color-border, #e2e2e6); margin: 4px 0; }

/* --- Topbar ------------------------------------------------------------- */

.topbar {
    background: var(--ab-color-surface, #fff);
    border-bottom: 1px solid var(--ab-color-border, #e2e2e6);
    display: flex;
    align-items: center;
    padding: 0 24px;
    height: 60px;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 15;
}

.topnav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.topnav__item {
    background: transparent;
    border: 0;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--ab-color-text, #27272a);
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background var(--ab-duration-fast, 120ms) var(--ab-ease-standard, cubic-bezier(0.2, 0, 0, 1));
}

.topnav__item:hover,
.topnav__item.is-open {
    background: var(--ab-color-bg-muted, #eeeef1);
}

.topnav__item .chev {
    width: 12px;
    height: 12px;
    color: var(--ab-color-text-subtle, #71717a);
    transition: transform var(--ab-duration-fast, 120ms) var(--ab-ease-standard, cubic-bezier(0.2, 0, 0, 1));
}

.topnav__item.is-open .chev { transform: rotate(180deg); }

.topnav__item--legacy {
    color: var(--ab-color-brand-600, #db1239);
    font-weight: 600;
    text-decoration: none;
    margin-left: 8px;
}
.topnav__item--legacy:hover {
    color: var(--ab-color-brand-700, #b40c2e);
    background: var(--ab-color-brand-50, #fff1f4);
    text-decoration: none;
}

.topbar__spacer { flex: 1; }

/* Dropdown-wrapper — чтобы позиционировать menu-panel относительно триггера */
.dropdown {
    position: relative;
}

.dropdown__panel {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 25;
}

.dropdown__panel--right {
    left: auto;
    right: 0;
}

.dropdown__panel[hidden] {
    display: none;
}

/* --- User menu --------------------------------------------------------- */

.user-menu {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px 6px 6px;
    border-radius: 10px;
    cursor: pointer;
    transition: background var(--ab-duration-fast, 120ms) var(--ab-ease-standard, cubic-bezier(0.2, 0, 0, 1));
    border: 1px solid transparent;
    background: transparent;
    font-family: inherit;
    text-decoration: none;
    color: inherit;
}

.user-menu:hover,
.user-menu.is-open {
    background: var(--ab-color-bg-muted, #eeeef1);
    border-color: var(--ab-color-border, #e2e2e6);
    text-decoration: none;
}

.user-menu__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #a0adff 0%, #6b7cff 100%);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 600;
    flex: none;
}

.user-menu__info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.2;
}

.user-menu__name {
    font-size: 13px;
    font-weight: 500;
    color: var(--ab-color-text, #27272a);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu__id {
    font-size: 11px;
    color: var(--ab-color-text-subtle, #71717a);
    font-family: var(--ab-font-mono, ui-monospace, monospace);
}

.user-menu .chev {
    width: 12px;
    height: 12px;
    color: var(--ab-color-text-subtle, #71717a);
}

@media (max-width: 640px) {
    .user-menu__info { display: none; }
}

/* --- CTA "Новый контракт" ---------------------------------------------- */

.cta-new {
    height: 40px;
    padding: 0 18px;
    background: var(--ab-color-brand-500, #f91942);
    color: #fff;
    border: 0;
    border-radius: var(--ab-radius-full, 9999px);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(249, 25, 66, 0.25);
    transition:
        background var(--ab-duration-fast, 120ms) var(--ab-ease-standard, cubic-bezier(0.2, 0, 0, 1)),
        box-shadow var(--ab-duration-fast, 120ms) var(--ab-ease-standard, cubic-bezier(0.2, 0, 0, 1));
    text-decoration: none;
    white-space: nowrap;
}

.cta-new:hover {
    background: var(--ab-color-brand-600, #db1239);
    box-shadow: 0 4px 12px rgba(249, 25, 66, 0.35);
    color: #fff;
    text-decoration: none;
}

.cta-new__plus {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    display: grid;
    place-items: center;
    font-size: 14px;
    font-weight: 400;
    line-height: 1;
}

@media (max-width: 640px) {
    .cta-new__label { display: none; }
    .cta-new { padding: 0 12px; }
}

/* --- Crumbs ------------------------------------------------------------ */

.crumbs {
    padding: 12px 32px 0;
    font-size: 13px;
    color: var(--ab-color-text-muted, #52525b);
}

.crumbs a {
    color: inherit;
    text-decoration: none;
}

.crumbs a:hover { color: var(--ab-color-text, #27272a); }

.crumbs b {
    color: var(--ab-color-text, #27272a);
    font-weight: 500;
}

/* --- Dropdown menu panel ----------------------------------------------- */

.menu-panel {
    background: var(--ab-color-surface, #fff);
    border: 1px solid var(--ab-color-border, #e2e2e6);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    padding: 8px;
    min-width: 260px;
}

.menu-panel__group-title {
    padding: 6px 12px 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--ab-color-text-subtle, #71717a);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.menu-panel__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    color: var(--ab-color-text, #27272a);
    cursor: pointer;
    text-decoration: none;
}

.menu-panel__item:hover {
    background: var(--ab-color-bg-muted, #eeeef1);
    color: var(--ab-color-text, #27272a);
    text-decoration: none;
}

.menu-panel__item--danger { color: var(--ab-color-brand-600, #db1239); }
.menu-panel__item--danger:hover { color: var(--ab-color-brand-700, #b40c2e); }

.menu-panel__item .ic {
    width: 16px;
    height: 16px;
    color: var(--ab-color-text-subtle, #71717a);
    flex: none;
}

.menu-panel__item .meta {
    margin-left: auto;
    font-size: 11px;
    color: var(--ab-color-text-subtle, #71717a);
}

.menu-panel__sep {
    height: 1px;
    background: var(--ab-color-border, #e2e2e6);
    margin: 6px 4px;
}

/* --- Responsive --------------------------------------------------------- */

@media (max-width: 780px) {
    .topnav { display: none; }
}

@media (max-width: 520px) {
    .app-shell { grid-template-columns: 48px 1fr; }
    .topbar { padding: 0 12px; gap: 4px; }
    .crumbs { padding: 10px 16px 0; }
}
