/* DEX Admin — reset, typography and the page shell (sidebar, topbar, content, mobile bars). */

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-padding-top: 80px;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    font-size: var(--fs-15);
    font-weight: var(--w-text);
    line-height: var(--lh-text);
    letter-spacing: var(--ls-text);
    color: var(--ink);
    background-color: var(--tint);
    background-image:
        radial-gradient(circle at 8% 10%, rgba(56, 189, 248, .18), transparent 30rem),
        radial-gradient(circle at 94% 88%, rgba(124, 58, 237, .14), transparent 32rem);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img,
svg {
    display: block;
    max-width: 100%;
}

svg.icon {
    display: inline-block;
    flex: 0 0 auto;
    vertical-align: middle;
}

h1,
h2,
h3,
h4 {
    margin: 0;
    color: var(--ink);
    line-height: var(--lh-head);
}

h1 {
    font-size: var(--fs-28);
    font-weight: var(--w-head);
    letter-spacing: var(--ls-h1);
}

h2 {
    font-size: var(--fs-22);
    font-weight: var(--w-head);
    letter-spacing: var(--ls-h3);
}

h3 {
    font-size: var(--fs-18);
    font-weight: var(--w-sub);
    letter-spacing: var(--ls-h3);
}

h4 {
    font-size: var(--fs-15);
    font-weight: var(--w-sub);
}

p {
    margin: 0;
}

a {
    color: var(--link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

code,
kbd,
samp,
pre,
.mono {
    font-family: var(--font-mono);
    font-size: .92em;
    letter-spacing: 0;
}

pre {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

button,
input,
select,
textarea {
    font: inherit;
    letter-spacing: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 2px solid var(--indigo);
    outline-offset: 2px;
}

::selection {
    background: rgba(99, 102, 241, .22);
}

.num,
time,
.tabular {
    font-variant-numeric: tabular-nums;
}

.muted {
    color: var(--muted-ink);
}

.small {
    font-size: var(--fs-13);
}

.tiny {
    font-size: var(--fs-12);
}

.nowrap {
    white-space: nowrap;
}

.break {
    overflow-wrap: anywhere;
}

.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: 16px;
    top: -60px;
    z-index: 200;
    padding: 10px 16px;
    border-radius: var(--pill);
    color: #fff;
    background: var(--deep);
    font-weight: var(--w-sub);
}

.skip-link:focus {
    top: 16px;
    text-decoration: none;
}

/* ---------- shell ---------- */

.shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    gap: var(--gap);
    min-height: 100vh;
    padding: var(--gap);
}

.mobile-bar {
    display: none;
}

.bottom-nav {
    display: none;
}

.nav-backdrop {
    display: none;
}

/* ---------- sidebar (dark, LK .sidebar dialogs.html:64-83) ---------- */

.sidebar {
    position: sticky;
    top: var(--gap);
    height: calc(100vh - 2 * var(--gap));
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    border-radius: var(--r-24);
    color: var(--deep-ink);
    background: var(--deep);
    box-shadow: var(--shadow-deep);
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 18px 16px 12px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: inherit;
}

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

.brand-tile {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: grid;
    place-items: center;
    border-radius: var(--r-14);
    background: #fff;
    box-shadow: 0 10px 24px rgba(4, 16, 33, .28);
}

.brand-tile img {
    width: 28px;
    height: 30px;
}

.brand-name {
    display: grid;
    gap: 1px;
    min-width: 0;
}

.brand-word {
    font-size: 20px;
    font-weight: var(--w-brand);
    letter-spacing: -0.02em;
    line-height: 1;
    color: #fff;
}

.brand-sub {
    font-size: var(--fs-12);
    font-weight: var(--w-sub);
    color: var(--deep-muted);
    letter-spacing: 0;
}

.sidebar .sidebar-close {
    display: none;
}

.sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 12px 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--deep-3) transparent;
}

.nav-group + .nav-group {
    margin-top: 6px;
}

.nav-group-title {
    margin: 0;
    padding: 6px 12px 4px;
    font-size: 11px;
    font-weight: var(--w-sub);
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #6f86a1;
}

.nav-list {
    display: grid;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 37px;
    padding: 0 12px;
    border-radius: var(--pill);
    color: #b9cce2;
    font-size: var(--fs-15);
    font-weight: var(--w-sub);
    letter-spacing: -0.005em;
    transition: background-color .15s ease, color .15s ease;
}

.nav-link:hover {
    color: #fff;
    background: var(--deep-2);
    text-decoration: none;
}

.nav-link .icon {
    color: #7f98b5;
}

.nav-link:hover .icon {
    color: #cfe0f5;
}

.nav-link[aria-current="page"] {
    color: #fff;
    background: var(--grad);
    text-shadow: var(--on-grad-shadow);
    box-shadow: 0 10px 24px rgba(99, 102, 241, .32);
}

.nav-link[aria-current="page"] .icon {
    color: #fff;
}

.nav-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* замок у раздела — ближе к подписи: длинная подпись («Режимы и настройки») не обрезается, когда у меню появляется
   полоса прокрутки (открытое подменю на ноутбуке) */
.nav-link:has(> .nav-lock) {
    padding-right: 8px;
}

.nav-lock {
    margin-left: -4px;
    color: #6f86a1;
}

.nav-link[aria-current="page"] .nav-lock {
    color: rgba(255, 255, 255, .8);
}

.nav-sub {
    display: grid;
    gap: 1px;
    margin: 2px 0 6px 30px;
    padding: 0 0 0 10px;
    list-style: none;
    border-left: 1px solid var(--deep-3);
}

.nav-sublink {
    display: block;
    padding: 6px 10px;
    border-radius: var(--r-10);
    color: #93a7bf;
    font-size: var(--fs-13);
    font-weight: var(--w-text);
}

.nav-sublink:hover {
    color: #fff;
    background: var(--deep-2);
    text-decoration: none;
}

.nav-sublink[aria-current="page"] {
    color: #fff;
    background: var(--deep-3);
}

.sidebar-foot {
    display: grid;
    gap: 10px;
    padding: 12px 16px 16px;
    border-top: 1px solid rgba(255, 255, 255, .06);
}

.bridge-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 8px 12px;
    border-radius: var(--r-16);
    background: var(--deep-2);
    color: var(--deep-ink);
    font-size: var(--fs-13);
    font-weight: var(--w-sub);
}

.bridge-indicator .bridge-text {
    display: grid;
    min-width: 0;
}

.bridge-indicator .bridge-sub {
    color: var(--deep-muted);
    font-size: var(--fs-12);
    font-weight: var(--w-text);
}

.dot {
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
    border-radius: 50%;
    background: #94a3b8;
}

.dot.is-online {
    background: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, .18);
}

.dot.is-stale {
    background: #f59e0b;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, .18);
}

.dot.is-offline {
    background: #f43f5e;
    box-shadow: 0 0 0 4px rgba(244, 63, 94, .18);
}

.sidebar-session {
    display: none;
}

/* ---------- main column ---------- */

.main {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: var(--topbar-h);
    padding: 10px 12px 10px 22px;
    border-radius: var(--r-24);
    background: var(--surface);
    box-shadow: var(--shadow-card);
}

.topbar-crumbs {
    flex: 1 1 auto;
    min-width: 0;
}

.topbar-stats {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.topbar-session {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 12px;
    border-left: 1px solid var(--line);
}

/* слева ничего нет (ни цепочки, ни счётчиков) — разделитель не нужен */
.topbar--bare .topbar-session {
    padding-left: 0;
    border-left: 0;
}

.session-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 0 12px;
    border-radius: var(--pill);
    color: var(--ink-2);
    background: var(--surface-3);
    font-size: var(--fs-13);
    font-weight: var(--w-sub);
    white-space: nowrap;
}

.session-chip:hover {
    text-decoration: none;
    background: var(--tint);
}

.session-chip .icon {
    color: var(--muted);
}

.logout-form {
    margin: 0;
}

.banners {
    display: grid;
    gap: 10px;
}

.banners:empty {
    display: none;
}

.content {
    display: grid;
    gap: var(--gap);
    align-content: start;
    min-width: 0;
    outline: none;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 6px 4px 0;
}

.page-head-text {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.page-sub {
    color: var(--muted-ink);
    font-size: var(--fs-15);
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.page-actions:empty {
    display: none;
}

.grid {
    display: grid;
    gap: var(--gap);
}

.grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-aside {
    grid-template-columns: minmax(0, 1fr) 340px;
}

.stack {
    display: grid;
    gap: 12px;
    align-content: start;
}

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

.row-between {
    justify-content: space-between;
}

.spacer {
    flex: 1 1 auto;
}

/* ---------- 1320 ---------- */

@media (max-width: 1320px) {
    .grid-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid-aside {
        grid-template-columns: minmax(0, 1fr) 300px;
    }

    .topbar-stats .stat-label {
        display: none;
    }
}

/* ---------- 700-979: dark strip + drawer ---------- */

@media (max-width: 979.98px) {
    .shell {
        display: block;
        padding: 0;
    }

    .mobile-bar {
        position: sticky;
        top: 0;
        z-index: 40;
        display: flex;
        align-items: center;
        gap: 12px;
        min-height: 60px;
        padding: 8px 16px;
        padding-top: max(8px, env(safe-area-inset-top));
        color: #fff;
        background: var(--deep);
        box-shadow: 0 10px 30px rgba(4, 16, 33, .18);
    }

    .mobile-bar .brand-tile {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
        border-radius: var(--r-12);
    }

    .mobile-bar .brand-tile img {
        width: 22px;
        height: 24px;
    }

    .mobile-menu-btn {
        width: auto;
        padding: 0 14px 0 10px;
    }

    .mobile-title {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: var(--fs-15);
        font-weight: var(--w-sub);
    }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 70;
        width: min(320px, 86vw);
        height: 100%;
        border-radius: 0 var(--r-24) var(--r-24) 0;
        transform: translateX(-105%);
        visibility: hidden;
        transition: transform .22s ease, visibility 0s linear .22s;
    }

    .nav-open .sidebar {
        transform: none;
        visibility: visible;
        transition: transform .22s ease;
    }

    .sidebar .sidebar-close {
        display: inline-flex;
    }

    .nav-open .nav-backdrop {
        position: fixed;
        inset: 0;
        z-index: 65;
        display: block;
        background: rgba(13, 24, 38, .45);
    }

    .nav-open body {
        overflow: hidden;
    }

    .sidebar-session {
        display: grid;
        gap: 8px;
    }

    .main {
        padding: 16px;
    }

    .topbar {
        min-height: 0;
        padding: 12px 16px;
        border-radius: var(--r-20);
        flex-wrap: wrap;
    }

    .topbar-session {
        display: none;
    }

    /* ни цепочки, ни счётчиков: сеанс здесь в меню — пустую белую полосу не показываем */
    .topbar--bare {
        display: none;
    }

    .grid-2,
    .grid-3,
    .grid-aside {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ---------- < 700: bottom navigation, full-width actions ---------- */

@media (max-width: 699.98px) {
    body {
        padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
        background-attachment: scroll;
    }

    h1 {
        font-size: var(--fs-22);
    }

    h2 {
        font-size: var(--fs-18);
    }

    .mobile-bar .mobile-menu-btn {
        display: none;
    }

    .bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 50;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        min-height: var(--bottom-nav-h);
        padding: 6px 6px env(safe-area-inset-bottom);
        margin: 0;
        list-style: none;
        background: var(--deep);
        box-shadow: 0 -10px 30px rgba(4, 16, 33, .2);
    }

    .bottom-nav-item {
        display: grid;
        justify-items: center;
        align-content: center;
        gap: 3px;
        min-height: 52px;
        border: 0;
        border-radius: var(--r-14);
        color: #93a7bf;
        background: transparent;
        font-size: 11px;
        font-weight: var(--w-sub);
        letter-spacing: 0;
    }

    .bottom-nav-item:hover {
        text-decoration: none;
        color: #fff;
    }

    .bottom-nav-item[aria-current="page"] {
        color: #fff;
        background: var(--deep-2);
    }

    .bottom-nav-item[aria-current="page"] .icon {
        color: var(--sky);
    }

    .main {
        padding: 12px 16px 20px;
    }

    .topbar-crumbs {
        flex-basis: 100%;
    }

    .topbar-stats {
        justify-content: flex-start;
    }

    .page-head {
        padding: 2px 0 0;
    }

    .page-actions {
        width: 100%;
    }

    .page-actions > .btn,
    .page-actions > form,
    .page-actions > form > .btn {
        flex: 1 1 100%;
        width: 100%;
    }
}

/* ---------- 560 ---------- */

@media (max-width: 560px) {
    .topbar-stats .stat {
        padding: 0 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
