/*
 * Shell: top bar, left navigation (full >= 1280px, icon rail 768-1279px, drawer < 768px) and footer.
 * The body is a grid (ms-base.css): topbar spans both columns, nav is column 1 (auto width),
 * <main> and .ms-footer are column 2. Pages without the nav (auth, access denied) simply have an empty column 1.
 * html.ms-js (set by ms-theme.js) turns the phone nav into an off-canvas drawer; without JS it stays a visible block.
 */

/* ---------- top bar ---------- */
.ms-topbar {
    grid-column: 1 / -1;
    grid-row: 1;
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--ms-top-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 16px;
    background: var(--ms-surface);
    border-bottom: 1px solid var(--ms-line);
}

.ms-topbar-left,
.ms-topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.ms-burger {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 40px;
    height: 40px;
    margin-left: -8px;
    padding: 0;
    border: 0;
    border-radius: var(--ms-radius);
    background: transparent;
    cursor: pointer;
}

.ms-burger:hover { background: var(--ms-nav-hover); }

.ms-burger span {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 2px;
    background: var(--ms-muted);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.ms-burger.is-open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.ms-burger.is-open span:nth-child(2) { opacity: 0; }
.ms-burger.is-open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.ms-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    color: var(--ms-text);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.ms-body a.ms-brand:hover { text-decoration: none; color: var(--ms-text); }

.ms-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid var(--ms-line);
    border-radius: 8px;
    /* the Sedona logo is navy with a transparent S: a white tile in both themes, like the auth card */
    background: #fff;
}

.ms-brand-mark img { display: block; width: 22px; height: 22px; }

.ms-company {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    max-width: 340px;
    color: var(--ms-muted);
    font-size: 0.875rem;
}

.ms-company::before {
    content: "";
    flex: 0 0 1px;
    height: 20px;
    background: var(--ms-line-strong);
}

.ms-company span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- account menu ---------- */
.ms-account { position: relative; }

.ms-account > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 38px;
    padding: 0 10px 0 4px;
    border-radius: var(--ms-radius);
    color: var(--ms-text);
    font-weight: 500;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.ms-account > summary::-webkit-details-marker { display: none; }
.ms-account > summary:hover,
.ms-account[open] > summary { background: var(--ms-nav-hover); }

.ms-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border-radius: 50%;
    background: var(--ms-accent-subtle);
    color: var(--ms-accent-text);
    font-size: 1rem;
}

.ms-account-chevron { color: var(--ms-faint); font-size: 0.75rem; }

.ms-popover {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 1200;
    width: 300px;
    max-width: calc(100vw - 24px);
    padding: 14px;
    background: var(--ms-surface);
    border: 1px solid var(--ms-line);
    border-radius: var(--ms-radius-card);
    box-shadow: var(--ms-shadow-pop);
    display: grid;
    gap: 14px;
}

.ms-popover-id small {
    display: block;
    color: var(--ms-faint);
    font-size: 0.75rem;
}

.ms-popover-id strong {
    display: block;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.ms-popover-label {
    display: block;
    margin-bottom: 6px;
    color: var(--ms-muted);
    font-size: 0.75rem;
    font-weight: 500;
}

.ms-seg {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding: 2px;
    background: var(--ms-sunk);
    border: 1px solid var(--ms-line);
    border-radius: var(--ms-radius);
}

.ms-seg button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 32px;
    padding: 0 6px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--ms-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
}

.ms-seg button:hover { color: var(--ms-text); }

.ms-seg button[aria-pressed="true"] {
    background: var(--ms-surface);
    border-color: var(--ms-line-strong);
    color: var(--ms-text);
    font-weight: 600;
    box-shadow: var(--ms-shadow);
}

.ms-menu-actions {
    display: grid;
    gap: 6px;
    margin: 0;
    padding-top: 12px;
    border-top: 1px solid var(--ms-grid);
}

.ms-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 38px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--ms-radius);
    background: transparent;
    color: var(--ms-text);
    font-size: 0.875rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
}

.ms-menu-item:hover { background: var(--ms-nav-hover); }
.ms-menu-item i { color: var(--ms-muted); }
.ms-menu-item.is-quiet { color: var(--ms-muted); font-weight: 400; }

/* ---------- navigation ---------- */
.ms-nav {
    grid-column: 1;
    grid-row: 2 / 4;
    position: sticky;
    top: var(--ms-top-h);
    align-self: start;
    z-index: 900;
    width: var(--ms-nav-w);
    height: calc(100vh - var(--ms-top-h));
    height: calc(100dvh - var(--ms-top-h));
    overflow-y: auto;
    padding: 12px;
    background: var(--ms-surface);
    border-right: 1px solid var(--ms-line);
}

.ms-nav-head { display: none; }

.ms-nav-group + .ms-nav-group {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--ms-grid);
}

.ms-nav-title {
    margin: 6px 12px 4px;
    color: var(--ms-faint);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.ms-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 40px;
    padding: 0 12px;
    border-radius: var(--ms-radius);
    color: var(--ms-muted);
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
}

.ms-nav-link i {
    flex: 0 0 20px;
    width: 20px;
    font-size: 1.0625rem;
    line-height: 1;
    text-align: center;
}

.ms-body a.ms-nav-link:hover {
    background: var(--ms-nav-hover);
    color: var(--ms-text);
    text-decoration: none;
}

.ms-body a.ms-nav-link.is-active {
    background: var(--ms-nav-sel-bg);
    color: var(--ms-nav-sel-text);
    font-weight: 600;
}

.ms-overlay {
    position: fixed;
    inset: 0;
    z-index: 1090;
    background: var(--ms-scrim);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.ms-overlay.is-open { opacity: 1; visibility: visible; }

/* ---------- page frame ---------- */
.ms-body > main {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
}

.ms-footer {
    grid-column: 2;
    grid-row: 3;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 16px;
    padding: 16px var(--ms-page-pad) 20px;
    border-top: 1px solid var(--ms-line);
    color: var(--ms-faint);
    font-size: 0.75rem;
}

/* ---------- icon rail: 768-1279px ---------- */
@media (min-width: 768px) and (max-width: 1279.98px) {
    .ms-nav {
        width: var(--ms-rail-w);
        padding: 12px 10px;
    }

    .ms-nav-title { display: none; }

    .ms-nav-link {
        justify-content: center;
        padding: 0;
        width: 44px;
    }

    .ms-nav-text {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
}

/* ---------- phone: drawer ---------- */
@media (max-width: 767.98px) {
    .ms-topbar { padding: 0 12px; gap: 8px; }
    .ms-company { display: none; }
    .ms-account-label,
    .ms-account-chevron { display: none; }
    .ms-account > summary { padding: 0 4px; }
    .ms-popover { position: fixed; left: 12px; right: 12px; top: calc(var(--ms-top-h) + 6px); width: auto; max-width: none; }

    /* without JS there is no drawer: the nav stays out of the way (every page keeps its own links) */
    .ms-nav { display: none; }

    .ms-js .ms-burger { display: inline-flex; }

    .ms-js .ms-nav {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 1100;
        width: min(300px, 86vw);
        height: 100vh;
        height: 100dvh;
        padding: 0 12px 16px;
        border-right: 1px solid var(--ms-line);
        border-bottom: 0;
        box-shadow: var(--ms-shadow-pop);
        transform: translateX(-104%);
        visibility: hidden;
        transition: transform 0.22s ease, visibility 0.22s;
    }

    .ms-js .ms-nav.is-open {
        transform: none;
        visibility: visible;
    }

    .ms-js .ms-nav-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        min-height: var(--ms-top-h);
        margin: 0 -12px 8px;
        padding: 0 12px 0 16px;
        border-bottom: 1px solid var(--ms-line);
    }

    .ms-nav-company {
        min-width: 0;
        color: var(--ms-muted);
        font-size: 0.8125rem;
        line-height: 1.3;
    }

    .ms-nav-company strong {
        display: block;
        color: var(--ms-text);
        font-size: 0.9375rem;
        overflow-wrap: anywhere;
    }

    .ms-nav-close {
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
        border: 0;
        border-radius: var(--ms-radius);
        background: transparent;
        color: var(--ms-muted);
        font-size: 1.125rem;
        cursor: pointer;
    }

    .ms-nav-close:hover { background: var(--ms-nav-hover); color: var(--ms-text); }

    .ms-nav-link { min-height: 44px; }
    .ms-footer { padding-bottom: 24px; }
}

@media (min-width: 768px) {
    .ms-overlay { display: none; }
}

/* page behind the open phone drawer does not scroll */
html.ms-nav-open { overflow: hidden; }
