/*
 * Main navigation rail (every page).
 * Geometry (76px rail, sticky/fixed position, mobile off-canvas) still comes from
 * app.css via the .sidebar class; this file only restyles the rail and its content.
 * Legacy rules target .sidebar with !important, hence the !important on the box.
 */
.crm-rail {
    --rail-bg: #101013;
    --rail-bg-2: #17171b;
    --rail-ink: #f4f4f6;
    --rail-ink-2: rgba(244, 244, 246, .56);
    --rail-hover: rgba(255, 255, 255, .07);
    --rail-line: rgba(255, 255, 255, .08);
    --rail-accent: #2a78d6;
    --rail-accent-2: #5b8cff;
}

html body.route-clients aside.sidebar.crm-rail {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0 !important;
    padding: 16px 0 14px !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: linear-gradient(180deg, var(--rail-bg-2), var(--rail-bg) 45%) !important;
    box-shadow: inset -1px 0 0 var(--rail-line) !important;
    color: var(--rail-ink) !important;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}
html body.route-clients aside.sidebar.crm-rail::before,
html body.route-clients aside.sidebar.crm-rail::after { display: none !important; }
.crm-rail *,
.crm-rail *::before,
.crm-rail *::after { box-sizing: border-box; }
.crm-rail svg { display: block; width: 20px; height: 20px; }

/* Brand */
.crm-rail-brand { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 0 0 14px; }
.crm-rail-toggle {
    position: relative;
    display: grid;
    width: 46px;
    height: 44px;
    flex: 0 0 46px;
    place-items: center;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: var(--rail-hover);
    box-shadow: inset 0 0 0 1px var(--rail-line);
    color: var(--rail-ink);
    cursor: pointer;
    transition: background .15s ease;
}
.crm-rail-toggle:hover { background: rgba(255, 255, 255, .12); }
.crm-rail-toggle:focus-visible { outline: 2px solid var(--rail-accent-2); outline-offset: 2px; }
.crm-rail-toggle svg { width: 20px; height: 20px; transition: transform .22s ease; }
body.sidebar-expanded .crm-rail-toggle svg { transform: scaleX(.8); }
body:not(.rail-animate) .crm-rail-toggle svg { transition: none; }
.crm-rail-brand-text,
.crm-rail-close,
.crm-rail-label,
.crm-rail-text,
.crm-rail-user-meta { display: none; }

/* Links */
.crm-rail-nav {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-height: 0;
    padding: 6px 0;
}
/* Visible divider between groups (the old one was almost transparent and read as an empty gap). */
.crm-rail-sep { display: block; flex: 0 0 1px; width: 32px; height: 1px; margin: 5px 0; background: rgba(255, 255, 255, .16); }

.crm-rail-link {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 46px;
    height: 44px;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: transparent;
    box-shadow: none;
    color: var(--rail-ink-2);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, transform .15s ease;
}
.crm-rail-link:hover { background: var(--rail-hover); color: var(--rail-ink); }
.crm-rail-link:active { transform: scale(.96); }
.crm-rail-link:focus-visible { outline: 2px solid var(--rail-accent-2); outline-offset: 2px; }
.crm-rail-icon { display: grid; place-items: center; }

.crm-rail-link.is-active {
    background: linear-gradient(180deg, #fff, #eceef2);
    box-shadow: 0 6px 16px -8px rgba(0, 0, 0, .6), inset 0 -1px 0 rgba(0, 0, 0, .06);
    color: #101013;
}
/* Accent tick on the rail edge next to the active item. */
.crm-rail-link.is-active::before {
    content: "";
    position: absolute;
    top: 50%;
    left: -15px;
    width: 4px;
    height: 20px;
    border-radius: 0 4px 4px 0;
    background: linear-gradient(180deg, var(--rail-accent-2), var(--rail-accent));
    transform: translateY(-50%);
}

/* Tooltip labels on the collapsed rail */
.crm-rail [data-nav-label]::after {
    content: attr(data-nav-label);
    position: absolute;
    top: 50%;
    left: calc(100% + 14px);
    z-index: 50;
    padding: 6px 10px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 10px 28px -10px rgba(0, 0, 0, .35), 0 0 0 1px rgba(0, 0, 0, .06);
    color: #17171a;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translate(-4px, -50%);
    transition: opacity .12s ease, transform .12s ease;
}
.crm-rail [data-nav-label]:hover::after,
.crm-rail [data-nav-label]:focus-visible::after { opacity: 1; transform: translate(0, -50%); }

/* Footer */
.crm-rail-footer { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 0 0; box-shadow: 0 -1px 0 var(--rail-line); margin: 0 14px; }
.crm-rail-user { position: relative; display: flex; align-items: center; gap: 10px; padding: 4px; border-radius: 50%; color: inherit; text-decoration: none; cursor: pointer; transition: transform .15s ease; }
.crm-rail-user:hover { transform: scale(1.06); }
.crm-rail-user:focus-visible { outline: 2px solid var(--rail-accent-2); outline-offset: 2px; }
.crm-rail-user:hover .crm-rail-avatar { box-shadow: 0 0 0 2px var(--rail-bg), 0 0 0 3.5px var(--rail-accent-2); }
/* On the account page the avatar is the active item. */
.crm-rail-user.is-active .crm-rail-avatar { background: linear-gradient(180deg, #fff, #eceef2); color: #101013; box-shadow: 0 0 0 2px var(--rail-bg), 0 0 0 3.5px var(--rail-accent-2); }
.crm-rail-user.is-active::before {
    content: "";
    position: absolute;
    top: 50%;
    left: -17px;
    width: 4px;
    height: 20px;
    border-radius: 0 4px 4px 0;
    background: linear-gradient(180deg, var(--rail-accent-2), var(--rail-accent));
    transform: translateY(-50%);
}
.crm-rail-avatar {
    display: grid;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(140deg, #3a3a42, #232328);
    box-shadow: 0 0 0 2px var(--rail-bg), 0 0 0 3.5px rgba(91, 140, 255, .55);
    color: #fff;
    font-size: 12.5px;
    font-weight: 600;
}
.crm-rail-logout { margin: 0; }
.crm-rail-link.is-quiet { width: 40px; height: 40px; }
.crm-rail-link.is-quiet svg { width: 18px; height: 18px; }
.crm-rail-link.is-quiet:hover { background: rgba(217, 45, 32, .16); color: #ff8a80; }

/* Mobile: the rail becomes a labelled off-canvas drawer */
@media (max-width: 860px) {
    html body.route-clients aside.sidebar.crm-rail {
        width: min(82vw, 288px) !important;
        padding: 14px 12px 14px !important;
        border-radius: 0 18px 18px 0 !important;
        box-shadow: 0 24px 60px rgba(0, 0, 0, .35) !important;
    }

    .crm-rail-brand { justify-content: flex-start; padding: 0 4px 12px; }
    .crm-rail-brand-text { display: grid; line-height: 1.15; }
    .crm-rail-brand-text strong { color: var(--rail-ink); font-size: 15px; font-weight: 600; }
    .crm-rail-brand-text small { color: var(--rail-ink-2); font-size: 12px; }
    .crm-rail-close {
        display: grid;
        width: 34px;
        height: 34px;
        margin-left: auto;
        place-items: center;
        border: 0;
        border-radius: 10px;
        background: var(--rail-hover);
        color: var(--rail-ink);
        cursor: pointer;
    }
    .crm-rail-close svg { width: 18px; height: 18px; }

    .crm-rail-label { display: block; margin: 4px 8px 6px; color: var(--rail-ink-2); font-size: 11.5px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; }
    .crm-rail-nav { align-items: stretch; gap: 2px; overflow-y: auto; }
    .crm-rail-sep { width: auto; margin: 5px 10px; }
    .crm-rail-link { justify-content: flex-start; width: 100%; height: 46px; padding: 0 12px; }
    .crm-rail-text { display: inline; font-size: 14px; font-weight: 500; }
    .crm-rail-link.is-active::before { left: -12px; }
    .crm-rail [data-nav-label]::after { display: none; }

    .crm-rail-footer { align-items: stretch; margin: 0; padding-top: 12px; }
    .crm-rail-user { padding: 6px 8px; border-radius: 12px; }
    .crm-rail-user:hover { transform: none; background: var(--rail-hover); }
    .crm-rail-user.is-active { background: var(--rail-hover); }
    .crm-rail-user.is-active::before { left: -12px; }
    .crm-rail-user-meta { display: grid; min-width: 0; line-height: 1.2; text-align: left; }
    .crm-rail-user-meta strong { overflow: hidden; color: var(--rail-ink); font-size: 13.5px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
    .crm-rail-user-meta small { color: var(--rail-ink-2); font-size: 12px; }
    .crm-rail-link.is-quiet { width: 100%; height: 44px; }
}

/* Scripts and manager plan embed full-width pages; drop the side gutters around them. */
body.route-clients:is(.page-scripts, .page-manager_plan) .content-wrap {
    padding-left: 0;
    padding-right: 0;
}

/* Expandable rail (desktop): the toggle widens it to show labels; app.js remembers the choice.
 * Icons keep the same x position in both states, so nothing jumps while it animates. */
@media (min-width: 861px) {
    html body.route-clients aside.sidebar.crm-rail { width: 76px !important; min-width: 76px !important; }
    html body.route-clients.rail-animate .app-layout { transition: grid-template-columns .22s ease; }
    html body.route-clients.rail-animate aside.sidebar.crm-rail { transition: width .22s ease, min-width .22s ease; }
    html body.route-clients.rail-animate.route-dashboard.role-manager .content-wrap { transition: margin-left .22s ease; }

    html body.route-clients.sidebar-expanded .app-layout { grid-template-columns: 220px minmax(0, 1fr) !important; }
    html body.route-clients.sidebar-expanded aside.sidebar.crm-rail {
        width: 220px !important;
        min-width: 220px !important;
        padding-right: 12px !important;
        padding-left: 12px !important;
        overflow: hidden !important;
    }
    html body.route-clients.route-dashboard.role-manager.sidebar-expanded .content-wrap { margin-left: 220px !important; }

    body.sidebar-expanded .crm-rail-brand { justify-content: flex-start; padding-left: 3px; }
    body.sidebar-expanded .crm-rail-brand-text { display: grid; min-width: 0; line-height: 1.15; white-space: nowrap; }
    body.sidebar-expanded .crm-rail-brand-text strong { color: var(--rail-ink); font-size: 14px; font-weight: 600; }
    body.sidebar-expanded .crm-rail-brand-text small { color: var(--rail-ink-2); font-size: 11.5px; }

    body.sidebar-expanded .crm-rail-nav { align-items: stretch; }
    body.sidebar-expanded .crm-rail-link { width: 100%; justify-content: flex-start; padding: 0 0 0 16px; }
    body.sidebar-expanded .crm-rail-text { display: inline; overflow: hidden; font-size: 13.5px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
    body.sidebar-expanded .crm-rail-sep { width: auto; margin: 5px 10px; }
    body.sidebar-expanded .crm-rail-link.is-active::before { left: -12px; }
    body.sidebar-expanded .crm-rail [data-nav-label]::after { display: none; }

    body.sidebar-expanded .crm-rail-footer { align-items: stretch; margin: 0; }
    body.sidebar-expanded .crm-rail-user { padding: 6px 8px 6px 10px; border-radius: 12px; }
    body.sidebar-expanded .crm-rail-user:hover { transform: none; background: var(--rail-hover); }
    body.sidebar-expanded .crm-rail-user.is-active { background: var(--rail-hover); }
    body.sidebar-expanded .crm-rail-user.is-active::before { left: -12px; }
    body.sidebar-expanded .crm-rail-user-meta { display: grid; min-width: 0; line-height: 1.2; white-space: nowrap; }
    body.sidebar-expanded .crm-rail-user-meta strong { overflow: hidden; color: var(--rail-ink); font-size: 13px; font-weight: 600; text-overflow: ellipsis; }
    body.sidebar-expanded .crm-rail-user-meta small { color: var(--rail-ink-2); font-size: 11.5px; }
    body.sidebar-expanded .crm-rail-link.is-quiet { width: 100%; height: 42px; padding-left: 17px; }
}

@media (max-width: 860px) {
    .crm-rail-toggle { display: none; }
}

/* "Фокус дня" block, identical on the dashboard and in the page header of every section. */
.crm-focus {
    position: relative;
    display: flex;
    flex: 0 1 auto;
    align-items: center;
    gap: 10px;
    min-width: 0;
    max-width: 520px;
    margin: 0;
    padding: 11px 16px;
    overflow: hidden;
    border: 1px solid #f3e6c3;
    border-radius: 12px;
    background: linear-gradient(90deg, #fffaf0, #fffdf8 60%, #fff);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}
.crm-focus::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 3px; background: #eda100; }
.crm-focus-icon { display: grid; width: 26px; height: 26px; flex: 0 0 26px; place-items: center; border-radius: 8px; background: #fdf5dd; color: #9a6a00; }
.crm-focus-icon svg { display: block; width: 14px; height: 14px; }
.crm-focus p { margin: 0; color: #4b4b53; font-size: 13px; font-weight: 400; line-height: 1.4; }
.crm-focus strong { color: #17171a; font-weight: 600; }

@media (max-width: 860px) {
    .crm-focus { flex: 1 1 100%; max-width: none; }
}

/* Global link hover underline (app.css) must not reach the navigation rail. */
.crm-rail a,
.crm-rail a:hover,
.crm-rail a:focus,
.crm-rail a:hover .crm-rail-text,
.crm-rail a:hover strong,
.crm-rail a:hover small { text-decoration: none; }
