:root {
    /* --- Dark Theme Palette --- */
    --primary-color: #0d6efd;
    --primary-hover: #338bff;
    --danger-color: #e54848;
    --danger-hover: #fa5252;
    --text-color: #e9ecef;
    --text-color-muted: #adb5bd;
    --bg-color: #212529;
    --bg-color-light: #343a40;
    --item-bg: #2b3035;
    --border-color: #495057;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    
    /* Icon Colors */
    --folder-color: #868e96;
}

body {
    font-family: var(--font-family);
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    scrollbar-color: var(--border-color) var(--bg-color);
    scrollbar-width: thin;
}

/* --- Страница входа --- */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}
.login-form {
    padding: 2rem;
    background: var(--item-bg);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 360px;
    border: 1px solid var(--border-color);
}
.login-form h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-color);
}
.login-form .form-group {
    margin-bottom: 1rem;
}
.login-form label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-color-muted);
}
.login-form input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    background-color: var(--bg-color-light);
    color: var(--text-color);
    border-radius: 4px;
    box-sizing: border-box;
}
.login-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25);
}
.login-form button {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}
.login-form button:hover {
    background: var(--primary-hover);
}
.login-form .error {
    color: var(--danger-color);
    text-align: center;
    margin-bottom: 1rem;
}

/* --- Основной интерфейс --- */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--item-bg);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    border-bottom: 1px solid var(--border-color);
}
.logo { font-size: 1.5rem; font-weight: bold; color: var(--text-color); }
.search-bar { flex-grow: 1; margin: 0 2rem; }
.search-bar input {
    width: 100%;
    max-width: 500px;
    padding: 0.6rem 1rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-color-light);
    color: var(--text-color);
    font-size: 1rem;
}
.search-bar input:focus {
    outline: none;
    border-color: var(--primary-color);
}
.header-controls { display: flex; align-items: center; gap: 1rem; }

.view-switcher {
    display: flex;
    border-radius: 6px;
    background-color: var(--bg-color-light);
    padding: 2px;
}
.view-switcher button {
    background-color: transparent;
    border: none;
    color: var(--text-color-muted);
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
}
.view-switcher button:hover:not(.active) {
    color: var(--text-color);
}
.view-switcher button.active {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.logout-btn {
    text-decoration: none;
    color: var(--primary-color);
    font-weight: 500;
}
.logout-btn:hover {
    color: var(--primary-hover);
}

.container {
    padding: 2rem;
    position: relative;
}
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap; /* Позволяет переноситься на мобильных */
    gap: 1rem;
}

/* ИЗМЕНЕНИЕ: Полностью новые стили для хлебных крошек */
.breadcrumbs {
    flex: 1;
    min-width: 0; /* Важно для сжатия flex-элемента */
}
.breadcrumbs ol {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    flex-wrap: nowrap; /* Запрещаем стандартный перенос */
    overflow: hidden; /* Скрываем то, что не помещается */
}
.breadcrumbs li {
    display: flex;
    align-items: center;
    white-space: nowrap; /* Текст внутри элемента не переносится */
}
.breadcrumbs li:not(:first-child)::before {
    content: '';
    display: inline-block;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23adb5bd' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='9 18 15 12 9 6'%3E%3C/polyline%3E%3C/svg%3E");
    background-size: 16px 16px;
    width: 16px;
    height: 16px;
    margin: 0 0.25rem;
    flex-shrink: 0;
}
.breadcrumbs a, .breadcrumbs span {
    display: block;
    text-decoration: none;
    color: var(--text-color-muted);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s;
    overflow: hidden;
    text-overflow: ellipsis;
}
.breadcrumbs a:hover {
    background-color: var(--bg-color-light);
    color: var(--text-color);
}
.breadcrumbs span {
    color: var(--text-color);
    font-weight: 500;
}
.breadcrumbs .home-icon {
    color: var(--text-color);
}
.breadcrumbs .breadcrumb-ellipsis {
    color: var(--text-color-muted);
    padding: 0 0.5rem;
    cursor: default;
}

.actions {
    flex-shrink: 0; /* Кнопки не должны сжиматься */
}
.actions button {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background: var(--primary-color);
    color: white;
    font-size: 0.9rem;
    margin-left: 0.5rem;
}
.actions button:hover {
    background-color: var(--primary-hover);
}

#file-manager-content {
    display: grid;
    gap: 1.5rem;
}
/* Сетка */
#file-manager-content.grid-view {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.grid-view .item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1rem;
    border-radius: 8px;
    background: var(--item-bg);
    border: 1px solid var(--border-color);
    transition: box-shadow 0.2s, border-color 0.2s;
    overflow: hidden;
}
.grid-view .item:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.grid-view .item .item-link {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}
.grid-view .item .icon {
    width: 64px;
    height: 64px;
    margin-bottom: 0.75rem;
}
.grid-view .item .icon svg {
    width: 100%;
    height: 100%;
}
.grid-view .folder-item .icon svg { color: var(--folder-color); }
.grid-view .item .icon .custom-icon {
    width: 100%; height: 100%; object-fit: cover; border-radius: 8px;
}
.grid-view .item .name {
    overflow-wrap: break-word;
    font-weight: 500;
}
.grid-view .doc-meta { display: none; }
.grid-view .grid-meta-date {
    font-size: 0.8rem;
    color: var(--text-color-muted);
    margin-top: 0.5rem;
    white-space: nowrap;
}
.grid-view .grid-meta-tags {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    line-height: 1.2;
    padding: 0 4px;
}
.grid-view .grid-meta-tags .tag {
    font-size: 0.75rem;
    padding: 2px 6px;
    background-color: var(--bg-color-light);
    border-radius: 10px;
    color: var(--text-color-muted);
}

/* Список */
#file-manager-content.list-view {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.list-view .grid-meta-date,
.list-view .grid-meta-tags {
    display: none;
}
.list-view .item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--item-bg);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    position: relative;
    overflow: hidden;
}
.list-view .item:hover { background-color: var(--bg-color-light); }
.list-view .item-link {
    flex-grow: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
    color: inherit;
    min-width: 0;
}
.list-view .item .icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}
.list-view .item .icon svg {
    width: 100%;
    height: 100%;
}
.list-view .folder-item .icon svg { color: var(--folder-color); }
.list-view .item .icon .custom-icon {
    width: 100%; height: 100%; object-fit: cover; border-radius: 4px;
}
.list-view .item .name {
    font-weight: 500;
    text-align: left;
    word-break: break-all;
}
.list-view .doc-meta {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-left: auto;
    margin-right: 150px;
    color: var(--text-color-muted);
    flex-shrink: 0;
}
.list-view .meta-date { min-width: 80px; }
.list-view .meta-tags .tag {
    background: var(--bg-color-light);
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
    font-size: 0.8rem;
    color: var(--text-color);
}

/* Действия с элементами */
.item .item-actions {
    position: absolute;
    top: 5px;
    right: 5px;
    display: none;
    gap: 2px;
}
.item:hover .item-actions { display: flex; }
.list-view .item-actions { top: 50%; transform: translateY(-50%); }

.action-btn {
    background: var(--bg-color-light);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-color);
}
.action-btn:hover { background: var(--border-color); }
.delete-folder-btn, .delete-doc-btn { color: var(--danger-color); }


/* Модальные окна */
.hidden { display: none !important; }
#modal-backdrop {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 99;
}
.modal {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: var(--item-bg);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    z-index: 100;
    width: 90%;
    max-width: 500px;
    border: 1px solid var(--border-color);
}
.modal h3 { margin-top: 0; color: var(--text-color); }
.modal .form-group { margin-bottom: 1rem; }
.modal label { display: block; margin-bottom: 0.5rem; color: var(--text-color-muted);}
.modal input[type="text"],
.modal input[type="date"],
.modal input[type="file"],
.modal textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    background-color: var(--bg-color-light);
    color: var(--text-color);
    border-radius: 4px;
    box-sizing: border-box;
}
.modal .modal-actions {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}
.modal button {
    padding: 0.6rem 1.2rem;
    border: 1px solid transparent;
    border-radius: 5px;
    cursor: pointer;
}
.modal .cancel-btn {
    background: #6c757d;
    color: white;
}
.modal .cancel-btn:hover {
    background: #5a6268;
}
.modal button[type="submit"], .modal .danger-btn {
    background: var(--primary-color);
    color: white;
}
.modal button[type="submit"]:hover {
    background: var(--primary-hover);
}
.modal .danger-btn { background: var(--danger-color); }
.modal .danger-btn:hover { background: var(--danger-hover); }

/* Стилизация папки */
.color-palette { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.color-swatch {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: border-color 0.2s;
}
.color-swatch.selected, .color-swatch:hover { border-color: var(--primary-color); }

/* Загрузка файлов */
.drop-area {
    border: 2px dashed var(--border-color);
    border-radius: 5px;
    padding: 2rem;
    text-align: center;
    color: var(--text-color-muted);
    cursor: pointer;
    position: relative;
    transition: border-color 0.2s, background-color 0.2s;
}
.drop-area.dragover {
    border-color: var(--primary-color);
    background: rgba(13, 110, 253, 0.1);
}
.drop-area input[type="file"] {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    opacity: 0;
    cursor: pointer;
}
#file-preview-list .file-preview-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: var(--bg-color-light);
    margin-top: 0.5rem;
    border-radius: 4px;
}
.upload-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 101;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    color: var(--text-color);
    display: none; /* Скрыт по умолчанию */
}
.upload-overlay.active { display: flex; }

/* Поиск */
#search-results-container {
    padding: 1rem;
    background: var(--item-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
#search-results-list {
    list-style: none;
    padding: 0;
}
#search-results-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}
#search-results-list li:last-child { border-bottom: none; }
#search-results-list a {
    text-decoration: none;
    color: var(--primary-color);
}
#search-results-list .path {
    font-size: 0.85rem;
    color: var(--text-color-muted);
    margin-left: 0.5rem;
}


/* Адаптивность */
@media (max-width: 768px) {
    .main-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    .search-bar { margin: 0; }
    .container { padding: 1rem; }

    .actions { width: 100%; display: flex; justify-content: space-around; }
    .actions button { flex-grow: 1; }

    #file-manager-content.grid-view {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .list-view .doc-meta {
        display: none;
    }
    .list-view .item .item-actions {
        position: relative;
        transform: none;
        top: 0; right: 0;
        margin-left: auto;
    }
}