/* ── ВКЛАДКИ ── */
#tabs {
    display: flex;
    align-items: flex-end;
    flex-wrap: nowrap;
    gap: 2px;
    padding: 6px 8px 0;
    background: var(--window);
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
}

.tab {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 13px;
    color: var(--dim);
    background: transparent;
    border-radius: var(--r) var(--r) 0 0;
    cursor: pointer;
    user-select: none;
}

.tab.active {
    color: var(--text);
    background: var(--tab);
}

.tab .tclose {
    color: var(--dim);
    margin-left: 6px;
    font-size: 11px;
}

.tab .tclose:hover,
#tab-add:hover {
    color: var(--text);
}

#tab-add {
    flex: 0 0 auto;
    background: none;
    color: var(--dim);
    font-size: 18px;
    padding: 4px 8px;
    margin-bottom: 2px;
}

/* ── НАВБАР ── */
#navbar {
    display: flex;
    align-items: center;
    background: var(--tab);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
    height: 38px;
}

#nav-left {
    width: 148px;
    min-width: 148px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 6px;
    flex-shrink: 0;
    border-right: 1px solid var(--line);
}

.nav-btn {
    height: 26px;
    min-width: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    background: transparent;
    border: none;
    color: var(--dim);
    font-size: 14px;
    border-radius: var(--r);
}

.nav-btn:hover {
    color: var(--text);
    background: var(--field);
}

/* Тонкая подстройка пиксельных символов навигации */
#btn-up {
    transform: translateY(1px);
}

#btn-refresh {
    transform: translateY(2px);
}

#path-bar {
    flex: 1;
    height: 26px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 12px;
    font-size: 13px;
    color: var(--dim);
    background: var(--field);
    border-radius: var(--r);
    margin: 0 8px;
    min-width: 100px;
    overflow: hidden;
}
#path-crumbs { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; overflow: auto; scrollbar-width: none; white-space: nowrap; }
#path-bar #btn-refresh { flex: 0 0 auto; margin-left: 8px; transform: none; }

#path-bar span {
    cursor: pointer;
}

#path-bar span:hover {
    color: var(--text);
    text-decoration: underline;
}

#path-bar .sep {
    color: var(--dim);
}


#nav-right {
    position: relative;
    display: flex;
    align-items: center;
    width: 180px;
    min-width: 0;
    flex: 0 1 180px;
    padding-right: 8px;
    flex-shrink: 1;
}

#search-box {
    width: 100%;
    max-width: 180px;
    height: 26px;
    padding: 0 10px;
    font-size: 12px;
    background: var(--field);
    border-radius: var(--r);
    border: none;
}

.search-panel {
    position: absolute;
    top: calc(100% + 14px);
    right: 8px;
    z-index: 130;
    width: min(360px, calc(100vw - 24px));
    max-height: min(440px, calc(100dvh - 90px));
    overflow-y: auto;
    display: none;
    padding: 8px;
    background: var(--tab);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.search-panel.open { display: block; }

.search-scopes {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}

.search-scopes button {
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: var(--r);
    color: var(--dim);
    font-size: 11px;
}

.search-scopes button.active {
    color: var(--text);
    border-color: var(--accent);
}

.search-result {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 6px;
    border-radius: var(--r);
    cursor: pointer;
}

.search-result:hover {
    background: var(--field);
}

.search-result.selected {
    background: rgba(255, 62, 62, 0.16);
    outline: 1px solid var(--accent);
}

.search-result-icon { flex: 0 0 auto; }
.search-result-text { min-width: 0; display: flex; flex-direction: column; }
.search-result-text strong,
.search-result-text small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.search-result-text strong { color: var(--text); font-size: 12px; }
.search-result-text small { color: var(--dim); font-size: 10px; }

/* ── РАБОЧЕЕ ПРОСТРАНСТВО ── */
#workspace {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    overflow: hidden;
    background: var(--bg);
}

/* ── СУЖЕННЫЙ САЙДБАР И НАВБАР ── */
#sidebar {
    width: 148px;
    min-width: 148px;
    height: 100%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--line);
    background: var(--bg);
    flex-shrink: 0;
    position: relative;
}

#tree-wrap {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
    box-sizing: border-box;
    padding: 10px 4px 140px 6px;
    user-select: none;
    -webkit-user-select: none;
}

/* ── КОМПАКТНЫЙ ПРОФИЛЬ / ВХОД В ОДНУ ЛИНИЮ С АВАТАРОМ ── */
#profile {
    box-sizing: border-box;
    position: fixed;
    left: 0;
    bottom: 38px;
    z-index: 111;
    width: 148px;
    max-height: calc(100dvh - 110px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    padding: 8px;
    border: 1px solid var(--line);
    border-bottom: 0;
    background: var(--window);
}

#auth-compact-row {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 48px;
}

/* Аватарка встает ровно слева на высоту двух полей */
#avatar {
    width: 46px;
    height: 46px;
    min-width: 46px;
    min-height: 46px;
    border-radius: var(--r);
    background: var(--field);
    object-fit: cover;
    margin: 0;
    flex-shrink: 0;
}

/* Поля ввода справа от аватарки */
#login-fields {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

#login-fields input {
    width: 100%;
    height: 21px;
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 2px 6px;
    font-size: 11px;
    color: var(--text);
    text-align: right;
}

#login-fields input::placeholder {
    text-align: right;
    color: var(--dim);
}

/* Блок инфо юзера вместо полей (когда авторизован) */
#user-info-fields {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-width: 0;
}

#p-name {
    text-align: right;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.15;
}

#quota-txt {
    text-align: right;
    font-size: 10px;
    color: var(--dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.15;
}

/* Кнопка "запомнить сессию" со строчной буквы */
.custom-remember {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 5px 0 4px;
    cursor: pointer;
    user-select: none;
}

.chk-text {
    font-size: 10px;
    color: var(--dim);
}

/* Кнопки профиля имеют ту же высоту, что и кнопки файлов */
#auth-btns {
    display: flex;
    gap: 4px;
}

#auth-status {
    display: none;
    margin-top: 4px;
    color: var(--dim);
    font-size: 9px;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.auth-btn {
    flex: 1;
    height: 24px;
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1;
    font-size: 11px;
    color: var(--dim);
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 0 2px;
    cursor: pointer;
    user-select: none;
}

.auth-btn:hover {
    color: var(--text);
    background: var(--tab);
}



#user-controls {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    width: 100%;
    max-width: 100%;
    margin-top: 6px;
}

.profile-actions-column {
    display: flex;
    flex-direction: column;
    gap: 4px;
}


.auth-exit-btn {
    width: 62px;
    min-width: 62px;
    max-width: 62px;
    height: 23px;
    min-height: 23px;
    border: 1px solid var(--line);
    font-size: 10px;
    color: var(--dim);
    margin-top: 0;
    padding: 0 3px;
    text-transform: lowercase;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.auth-exit-btn:hover {
    color: var(--text);
    background: var(--tab);
}

.system-stats-window {
    left: auto;
    top: auto;
    right: 18px;
    bottom: 86px;
    width: 190px;
    height: auto;
    min-width: 170px;
    max-width: calc(100vw - 24px);
    min-height: 0;
    max-height: none;
    transform: none;
    resize: none;
    background: rgba(18, 18, 18, 0.42) !important;
    background-image: none !important;
    backdrop-filter: blur(18px) saturate(135%);
    -webkit-backdrop-filter: blur(18px) saturate(135%);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28) !important;
}

.system-stats-window::after {
    display: none;
}

.system-stats-window.system-stats-expanded {
    width: min(560px, calc(100vw - 24px)) !important;
    height: auto !important;
    max-height: min(760px, calc(100vh - 100px)) !important;
}

.system-stats-window.system-stats-expanded .system-stats-body {
    overflow-y: auto;
}

.system-stats-body {
    padding: 9px 11px 10px;
    color: var(--dim);
    font-size: 11px;
}

.system-stat-row {
    display: flex;
    justify-content: space-between;
    gap: 4px;
    line-height: 1.5;
    white-space: nowrap;
}

.system-stat-row strong {
    min-width: 0;
    overflow: hidden;
    color: var(--text);
    font-weight: 500;
    text-overflow: ellipsis;
}

.system-stats-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    margin-left: auto;
}

.system-stats-toggle,
.system-stats-reboot {
    width: auto;
    min-width: 62px;
    height: 24px;
    padding: 0 7px;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: var(--field);
    color: var(--dim);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
}

.system-stats-toggle:hover,
.system-stats-reboot:hover {
    color: var(--text);
    border-color: var(--accent);
}

.system-stats-reboot.armed {
    border-color: var(--accent);
    color: var(--accent);
}

.system-stats-reboot:disabled {
    opacity: .65;
    cursor: wait;
}

.system-stats-admin {
    margin-top: 9px;
    padding-top: 9px;
    border-top: 1px solid var(--line);
}

.system-stats-admin .admin-panel {
    margin: 0;
}

.system-stats-admin .admin-panel h1 {
    display: none;
}

.system-stats-admin .admin-user-card-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.system-stats-admin .admin-user-danger {
    display: flex;
}

.system-stats-time {
    margin-top: 4px;
    color: var(--dim);
    font-size: 9px;
    opacity: 0.8;
}

#admin-view {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px;
    margin-bottom: 76px;
    box-sizing: border-box;
    border-radius: 12px;
    scrollbar-gutter: stable;
}

.admin-panel {
    max-width: 1000px;
    margin: 0 auto;
}

.admin-panel h1,
.admin-panel h2 {
    margin: 0 0 12px;
    font-size: 16px;
    font-weight: 500;
}

.admin-section {
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: rgba(20, 20, 20, 0.68);
    backdrop-filter: blur(14px) saturate(120%);
    -webkit-backdrop-filter: blur(14px) saturate(120%);
    overflow: hidden;
}

.admin-section > summary {
    padding: 11px 12px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}

.admin-section > summary:hover {
    background: rgba(255, 255, 255, 0.04);
}

.admin-section-body {
    padding: 10px;
}

.admin-section-body > :last-child {
    margin-bottom: 0;
}

.admin-settings,
.admin-user-card {
    padding: 12px;
    background: rgba(20, 20, 20, 0.68);
    backdrop-filter: blur(14px) saturate(120%);
    -webkit-backdrop-filter: blur(14px) saturate(120%);
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: var(--r);
}

.admin-settings-grid,
.admin-user-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.admin-user-card {
    display: block;
    padding: 0;
    border-radius: 8px;
    overflow: hidden;
}

.admin-user-summary {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 10px 12px;
    cursor: pointer;
    list-style: none;
}

.admin-user-summary::-webkit-details-marker {
    display: none;
}

.admin-user-summary::before {
    content: "›";
    color: var(--dim);
    font-size: 16px;
    transition: transform 0.15s ease;
}

.admin-user-card[open] .admin-user-summary::before {
    transform: rotate(90deg);
}

.admin-user-summary:hover {
    background: rgba(255, 255, 255, 0.04);
}

.admin-user-card-body {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 8px 10px 10px;
    align-items: start;
}

.admin-user-card .admin-user-editor {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 7px;
    min-width: 0;
}

.admin-user-editor > .admin-user-tags {
    grid-column: 1 / -1;
}

.admin-user-editor > .admin-input,
.admin-user-editor > .btn-vpn {
    width: 100%;
}

.admin-user-danger {
    align-self: stretch;
    width: 100%;
}

.admin-user-name {
    display: block;
    margin: 0;
    min-width: 0;
    text-align: left;
    overflow-wrap: anywhere;
}

.admin-user-name.admin-role {
    color: #f87171;
}

.admin-user-editor,
.admin-user-controls,
.admin-user-danger {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.admin-user-controls {
    min-width: 0;
    align-content: flex-start;
}

.admin-user-controls label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    flex: 1 1 100%;
    color: var(--dim);
    font-size: 10px;
}

.admin-user-controls select {
    width: 100%;
}

.admin-user-controls select[multiple] {
    min-height: 64px;
    padding: 4px;
}

.admin-user-danger {
    justify-content: stretch;
}

.admin-user-danger .btn-vpn {
    flex: 1 1 0;
}

.admin-user-tags {
    flex: 1 1 100%;
    min-width: 0;
}

.admin-user-card select,
.admin-user-card input {
    min-width: 0;
}

.admin-user-meta {
    margin-left: auto;
    min-width: 0;
    max-width: 45%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--dim);
    font-size: 11px;
}

.admin-user-actions input,
.admin-settings input,
.admin-user-editor input,
.admin-user-editor select {
    width: 100px;
    min-width: 0;
    box-sizing: border-box;
}

.admin-user-editor .admin-user-tags {
    width: 100%;
}

.admin-user-editor select {
    color: var(--text);
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 4px 6px;
}

.admin-user-danger .btn-vpn {
    min-height: 26px;
    padding: 5px;
    font-size: 10px;
    overflow-wrap: anywhere;
}

.admin-panel .admin-input {
    height: 26px;
    padding: 4px 7px;
    font-family: inherit;
    font-size: 10px;
    line-height: 16px;
    border-radius: 5px;
    background: rgba(196, 196, 196, 0.08);
    border: 1px solid rgba(196, 196, 196, 0.24);
    color: #c4c4c4;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.admin-settings-grid > .admin-input {
    flex: 1 1 110px;
    width: 110px;
}

.admin-panel .admin-input::placeholder {
    color: #858585;
}

.admin-panel .admin-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(255, 62, 62, 0.12);
    outline: none;
}

.admin-tag-picker {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 6px;
}

.admin-tag-picker > summary {
    cursor: pointer;
    color: var(--dim);
    font-size: 10px;
}

.admin-tag-picker .admin-input {
    height: 70px;
    margin-top: 6px;
}

@media (min-width: 900px) {
    #admin-view {
        margin-bottom: 96px;
    }
}

.admin-danger {
    color: #f87171 !important;
}

#quota-wrap {
    width: 100%;
    height: 2px;
    background: var(--field);
    border-radius: var(--r);
    margin-top: 2px;
}

#quota-fill {
    height: 2px;
    background: var(--accent);
    width: 0%;
}

/* ── ИДЕАЛЬНО ВЫРОВНЕННОЕ ДЕРЕВО WINDOWS ── */
.win-node {
    display: flex;
    flex-direction: column;
    user-select: none;
    -webkit-user-select: none;
}

.win-row {
    display: flex;
    align-items: center;
    height: 24px;
    padding-right: 8px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    font-size: 12px;
    color: var(--text);
    border-radius: var(--r);
}

.win-row:hover {
    background: rgba(255, 255, 255, 0.06);
}

.win-row.selected {
    background: rgba(196, 196, 196, 0.14);
    color: var(--text);
}

/* Слот для шеврона: ВСЕГДА 16px, чтобы иконки стояли ровно */
.win-chevron {
    width: 16px;
    height: 16px;
    min-width: 16px;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.win-chevron.empty {
    visibility: hidden; /* Место зарезервировано, но шеврон пустой */
}

/* Сам шеврон Windows */
.win-arrow {
    display: block;
    width: 9px !important;
    height: 9px !important;
    max-width: 9px;
    max-height: 9px;
    color: var(--dim);
    transition: transform 0.15s ease;
}

.win-chevron:hover .win-arrow {
    color: var(--text);
}

/* Поворот стрелки при раскрытии (без смещений по высоте!) */
.win-arrow.open {
    transform: rotate(90deg);
}

.win-icon {
    margin-right: 6px;
    font-size: 14px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.win-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
    -webkit-user-select: none;
}

.win-sub {
    padding-left: 16px; /* Ровный шаг вложенности для подпапок */
}

.auth-btn.err {
    background: var(--accent);
    color: var(--bg);
}

/* Кастомный чекбокс */
.custom-remember input {
    display: none;
}

.custom-chk-box {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid var(--line);
    background: var(--field);
    display: flex;
    align-items: center;
    justify-content: center;
}

.custom-remember input:checked + .custom-chk-box {
    background: var(--accent);
    border-color: var(--accent);
}

.custom-remember input:checked + .custom-chk-box::after {
    content: "✓";
    font-size: 10px;
    color: var(--bg);
    font-weight: bold;
}
