/* ===== Темы ===== */
:root {
    /* Светлая тема (базовая) */
    --bg-dark: #f4f4f6;
    --bg-panel: #ffffff;
    --bg-card: #ffffff;
    --bg-inner: #ececef;
    --bg-input: #e9e9ef;
    --bg-hover: #dcdce4;
    --text-main: #1c1c1e;
    --text-secondary: #6b6b70;
    --border-color: #d5d5dc;
    --accent: #3866ff;
    --btn-gradient-start: #ff3838;
    --btn-gradient-end: #3838ff;
}

:root[data-theme="dark"] {
    --bg-dark: #121212;
    --bg-panel: #1e1e1e;
    --bg-card: #222;
    --bg-inner: #181818;
    --bg-input: #2a2a2a;
    --bg-hover: #333;
    --text-main: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #333;
    --accent: #6fa8ff;
}

/* «Как в системе»: атрибут не задан — слушаем настройку ОС */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg-dark: #121212;
        --bg-panel: #1e1e1e;
        --bg-card: #222;
        --bg-inner: #181818;
        --bg-input: #2a2a2a;
        --bg-hover: #333;
        --text-main: #e0e0e0;
        --text-secondary: #a0a0a0;
        --border-color: #333;
        --accent: #6fa8ff;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    display: flex;
    min-height: 100vh;
}

/* ===== Боковая панель ===== */
#sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.logo {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 16px;
}

#sidebar input {
    width: 100%;
    padding: 9px 10px;
    margin-bottom: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
}

.profile-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.username { font-weight: 600; }

.btn-upload {
    width: 100%;
    padding: 12px;
    border-radius: 24px;
    border: none;
    background: linear-gradient(45deg,
        var(--btn-gradient-start), var(--btn-gradient-end),
        var(--btn-gradient-start), var(--btn-gradient-end));
    background-size: 400% 400%;
    animation: gradient-flow 4s ease infinite;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
}

.file-label {
    font-size: .8rem;
    color: var(--text-secondary);
    word-break: break-all;
}

.btn-small {
    width: 100%;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-main);
    cursor: pointer;
    animation: none;
}

/* ===== Индикатор хранилища ===== */
#storage-block {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.storage-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-inner);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.storage-fill {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--btn-gradient-start), var(--btn-gradient-end));
    transition: width .5s ease;
}

.storage-fill.warning {
    background: linear-gradient(90deg, #ffa500, #ff6a00);
}

.storage-fill.danger {
    background: linear-gradient(90deg, #ff3838, #ff0000);
    animation: pulse 1.2s ease infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .55; }
}

.storage-text {
    font-size: .8rem;
    color: var(--text-secondary);
}

/* ===== Основная область ===== */
#content-area {
    flex: 1;
    padding: 24px 32px;
    overflow-y: auto;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.content-header h1 {
    margin: 0;
    font-size: 1.4rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.actions-bar {
    display: flex;
    gap: 10px;
    align-items: center;
}

.actions-bar button {
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-main);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    animation: none;
}

.actions-bar button:hover { background: var(--bg-hover); }

.btn-delete { color: #ff6b6b !important; }

.muted { color: var(--text-secondary); font-size: .9rem; }

/* ===== Шестерёнка ===== */
.icon-btn {
    width: 42px;
    height: 42px;
    font-size: 1.3rem;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .3s ease;
}

.icon-btn:hover {
    background: var(--bg-hover);
    transform: rotate(45deg);
}

.icon-btn.open {
    transform: rotate(90deg);
    border-color: var(--accent);
}

/* ===== Сетка карточек ===== */
.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.file-card {
    background: var(--bg-card);
    border: 2px solid transparent;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: transform .15s, border-color .15s;
    position: relative;
}

.file-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-color);
}

.file-card.selected {
    border-color: var(--accent);
}

.file-preview {
    height: 140px;
    background: var(--bg-inner);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.file-preview img,
.file-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.file-icon {
    font-size: 48px;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
}

.file-name {
    flex: 1;
    font-size: .88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: .75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.file-card input[type="checkbox"] {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
    cursor: pointer;
    z-index: 2;
}

.empty-message {
    color: var(--text-secondary);
    padding: 40px;
    text-align: center;
    grid-column: 1 / -1;
}

/* ===== Кнопки ===== */
button {
    font-family: inherit;
}

#login-block button {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 6px;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    background: linear-gradient(45deg,
        var(--btn-gradient-start), var(--btn-gradient-end),
        var(--btn-gradient-start), var(--btn-gradient-end));
    background-size: 400% 400%;
    animation: gradient-flow 4s ease infinite;
}

@keyframes gradient-flow {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ===== Предпросмотр файла ===== */
#preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .75);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#preview-box {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-inner);
}

#preview-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.preview-btn {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    animation: none;
}

.preview-btn:hover {
    background: var(--bg-hover);
}

#preview-content {
    padding: 16px;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 200px;
}

#preview-content img {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 8px;
    object-fit: contain;
}

#preview-content video,
#preview-content audio {
    max-width: 100%;
}

#preview-content video {
    max-height: 65vh;
    border-radius: 8px;
}

#preview-content iframe {
    width: 100%;
    height: 70vh;
    border: none;
    border-radius: 8px;
    background: #fff;
}

#preview-content pre {
    white-space: pre-wrap;
    word-break: break-word;
    width: 100%;
    font-size: .9rem;
    color: var(--text-main);
    margin: 0;
}

#preview-content .preview-unsupported {
    color: var(--text-secondary);
    text-align: center;
}

#preview-content .preview-loading {
    color: var(--text-secondary);
}

.select-btn {
    padding: 2px 8px;
    font-size: 1rem;
    line-height: 1;
    flex-shrink: 0;
}

/* ===== Окно настроек ===== */
#settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    z-index: 1500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#settings-box {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 100%;
    max-width: 420px;
    padding: 0 0 16px;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-inner);
    font-weight: 600;
    border-radius: 12px 12px 0 0;
}

.settings-row {
    padding: 14px 16px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: .92rem;
}

.settings-row select {
    background: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
}

.settings-row.muted.small {
    font-size: .78rem;
    display: block;
    padding-top: 14px;
}

/* ===== Корзина ===== */
.btn-trash {
    margin-bottom: 4px;
}

#trash-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    z-index: 1400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#trash-box {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 100%;
    max-width: 560px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#trash-list {
    overflow-y: auto;
    padding: 8px 0;
}

.trash-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
}

.trash-item:last-child { border-bottom: none; }

.trash-name {
    flex: 1;
    font-size: .88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.trash-size {
    font-size: .75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.trash-empty {
    color: var(--text-secondary);
    text-align: center;
    padding: 40px 16px;
}

/* ===== Меню карточки (⋮) ===== */
.menu-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    padding: 2px 6px;
    border-radius: 6px;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 1;
}

.menu-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

#card-menu {
    position: fixed;
    z-index: 1600;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.5);
    min-width: 200px;
    padding: 6px 0;
    display: none;
}

#card-menu .menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 16px;
    border: none;
    background: transparent;
    color: var(--text-main);
    font-size: .9rem;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}

#card-menu .menu-item:hover {
    background: var(--bg-hover);
}

#card-menu .menu-item.danger {
    color: #ff6b6b;
}

#card-menu .menu-sep {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* ===== Чекбоксы ===== */
input[type="checkbox"] {
    accent-color: var(--accent);
}

/* ===== Всплывающие уведомления ===== */
#toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 320px;
}

.toast {
    padding: 12px 16px;
    border-radius: 8px;
    color: #fff;
    font-size: .9rem;
    box-shadow: 0 4px 12px rgba(0,0,0,.4);
    opacity: 0;
    transform: translateX(30px);
    transition: opacity .25s ease, transform .25s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.success { background: #2e7d32; }
.toast.error   { background: #c62828; }
.toast.info    { background: #1565c0; }

.toast.hide {
    opacity: 0;
    transform: translateX(30px);
}

/* ===== Скроллбар ===== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-hover); }

.btn-install {
    border-color: var(--accent) !important;
    color: var(--accent) !important;
}

/* ===== Мобильная версия ===== */
@media (max-width: 700px) {
    body { flex-direction: column; }
    #sidebar { width: 100%; min-width: 0; }
    #content-area { padding: 16px; }
}
