/* vault/public/app/css/theme.css
 *
 * Sistema de diseño de Vault v2 (Etapa 7).
 *
 * Tokens de color en variables CSS, con modo claro/oscuro via
 * [data-theme="light"|"dark"] en <html> (alternado por theme.js,
 * persistido en localStorage). Acento violeta distintivo (#7c6ef2) en
 * ambos modos — no es el azul/verde típico de Drive/Dropbox.
 *
 * Tipografía: Inter (UI), JetBrains Mono (editor/código) — cargadas desde
 * Google Fonts en index.html.
 */

:root {
    /* Acento — igual en ambos modos, es la firma de marca */
    --accent: #7c6ef2;
    --accent-strong: #6657e8;
    --accent-soft: rgba(124, 110, 242, 0.14);
    --accent-contrast: #ffffff;

    /* Tipos de archivo — usados en iconos/gauge de almacenamiento */
    --type-image: #34b3a4;
    --type-video: #e87f5e;
    --type-audio: #d6a64a;
    --type-document: #5b8def;
    --type-archive: #9a7bd6;
    --type-other: #8a8f9c;

    /* Radios y transiciones */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: 150ms ease;

    /* Layout */
    --sidebar-w: 248px;
    --topbar-h: 64px;
    --mobile-nav-h: 60px;

    --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

/* ============ MODO OSCURO (por defecto) ============ */
:root,
[data-theme="dark"] {
    --bg: #16171c;
    --surface: #1e2027;
    --surface-elevated: #262932;
    --surface-hover: #2c2f3a;
    --border: #34384a;
    --border-soft: #2a2d38;
    --text: #eef0f3;
    --text-muted: #9099a8;
    --text-faint: #5b6270;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --overlay: rgba(10, 11, 14, 0.6);
    --scrollbar: #383c4a;
}

/* ============ MODO CLARO ============ */
[data-theme="light"] {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-elevated: #f0f2f8;
    --surface-hover: #e9ebf3;
    --border: #e2e5ee;
    --border-soft: #edeff5;
    --text: #1b1d27;
    --text-muted: #6b7180;
    --text-faint: #a3a8b5;
    --shadow: 0 8px 24px rgba(30, 34, 60, 0.10);
    --shadow-sm: 0 2px 8px rgba(30, 34, 60, 0.06);
    --overlay: rgba(20, 22, 35, 0.35);
    --scrollbar: #d8dae3;
}

* {
    box-sizing: border-box;
}

/* Tamaño por defecto para CUALQUIER icono SVG de ICONS (icons.js genera
 * <svg> sueltos, sin clase propia — el tamaño real depende de las reglas
 * más específicas de cada componente más abajo en este archivo). Esta
 * regla es la red de seguridad: sin ella, un <svg> insertado en un
 * contenedor que aún no tiene una regla `X svg { width; height; }`
 * específica se renderiza a su tamaño intrínseco (~300x150px) en vez de
 * heredar nada, rompiendo el layout. Cualquier selector más específico
 * definido después en este archivo gana por especificidad CSS normal. */
svg {
    width: 1.1em;
    height: 1.1em;
    flex-shrink: 0;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

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

button {
    font-family: inherit;
}

/* Scrollbars */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar) transparent;
}
*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
*::-webkit-scrollbar-thumb {
    background: var(--scrollbar);
    border-radius: 4px;
}
*::-webkit-scrollbar-track {
    background: transparent;
}

/* Focus visible (accesibilidad) */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============ LAYOUT RAÍZ ============ */

#app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    height: 100vh;
}

.topbar {
    grid-area: topbar;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-soft);
    background: var(--bg);
    z-index: 10;
}

.sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border-soft);
    padding: 1rem;
    overflow-y: auto;
}

.main {
    grid-area: main;
    overflow-y: auto;
    padding: 1.5rem 2rem 2rem;
    position: relative;
}

/* ============ SIDEBAR ============ */

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.6rem 1.25rem;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}

.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), #b9a9ff);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 1rem;
    flex-shrink: 0;
}

.btn-new {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    justify-content: center;
    background: var(--accent);
    color: var(--accent-contrast);
    border: none;
    border-radius: var(--radius-lg);
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), background var(--transition);
    margin-bottom: 1.25rem;
}
.btn-new:hover {
    background: var(--accent-strong);
    transform: translateY(-1px);
}
.btn-new:active {
    transform: translateY(0);
}

.nav-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 1rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    border: none;
    background: none;
    text-align: left;
    width: 100%;
}
.nav-item:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.nav-item.active {
    background: var(--accent-soft);
    color: var(--accent);
}
.nav-item .icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}
.nav-item .count {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-faint);
}

.sidebar-spacer {
    flex: 1;
}

/* Gauge de almacenamiento (elemento "firma" del diseño) */
.storage-card {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.storage-gauge-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}
.storage-ring {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
}
.storage-ring circle {
    fill: none;
    stroke-width: 4;
}
.storage-ring .track {
    stroke: var(--border);
}
.storage-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}
.storage-info .pct {
    font-size: 1rem;
    font-weight: 700;
}
.storage-info .label {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.storage-breakdown {
    display: flex;
    gap: 3px;
    height: 6px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--border-soft);
}
.storage-breakdown span {
    display: block;
    height: 100%;
}
.storage-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}
.storage-legend .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.3rem;
    vertical-align: middle;
}

/* ============ TOPBAR ============ */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.95rem;
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
}
.breadcrumb .crumb {
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 0.2rem 0.4rem;
    transition: background var(--transition), color var(--transition);
}
.breadcrumb .crumb:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.breadcrumb .crumb.current {
    color: var(--text);
    cursor: default;
}
.breadcrumb .crumb.current:hover {
    background: none;
}
.breadcrumb .sep {
    color: var(--text-faint);
}

.search-box {
    flex: 1;
    max-width: 480px;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--surface-elevated);
    border: 1px solid transparent;
    border-radius: var(--radius-lg);
    padding: 0.55rem 0.9rem;
    color: var(--text-muted);
    transition: border-color var(--transition), background var(--transition);
}
.search-box:focus-within {
    border-color: var(--accent);
    background: var(--surface);
}
.search-box input {
    border: none;
    background: none;
    outline: none;
    color: var(--text);
    font-size: 0.9rem;
    width: 100%;
    font-family: inherit;
}
.search-box svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.topbar-spacer {
    flex: 1;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    flex-shrink: 0;
}
.icon-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.icon-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
}
.icon-btn svg {
    width: 19px;
    height: 19px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    flex-shrink: 0;
    border: none;
}

/* ============ MAIN: header de vista ============ */

.view-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.view-title {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.view-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.filter-chips {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.chip {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 0.35rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.chip:hover {
    border-color: var(--accent);
    color: var(--text);
}
.chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ============ GRID DE ARCHIVOS ============ */

.drop-zone {
    position: absolute;
    inset: 0;
    z-index: 50;
    background: var(--accent-soft);
    border: 2px dashed var(--accent);
    border-radius: var(--radius-lg);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent);
    margin: 1rem;
    pointer-events: none;
}
.drop-zone.active {
    display: flex;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
}

.card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
    user-select: none;
}
.card:hover {
    border-color: var(--border);
    box-shadow: var(--shadow-sm);
}
.card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.card-thumb {
    aspect-ratio: 1.2;
    background: var(--surface-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}
.card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.card-thumb .file-icon {
    width: 42px;
    height: 42px;
}
.card-body {
    padding: 0.6rem 0.7rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}
.card-body .file-icon-sm {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 0.15rem;
}
.card-name {
    font-size: 0.83rem;
    font-weight: 500;
    line-height: 1.3;
    word-break: break-word;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    flex: 1;
    min-width: 0;
}
.card-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}
.card-fav {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition);
}
.card:hover .card-fav, .card-fav.active {
    opacity: 1;
}
.card-fav.active {
    color: #ffc83d;
}
.card-fav svg { width: 15px; height: 15px; }

.card-menu-btn {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition);
}
.card:hover .card-menu-btn {
    opacity: 1;
}
.card-menu-btn svg { width: 16px; height: 16px; }

.card.folder .card-thumb {
    background: var(--surface);
}

/* Lista (vista alternativa) */
.list {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.list-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border-soft);
    cursor: pointer;
    transition: background var(--transition);
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface-hover); }
.list-row.selected { background: var(--accent-soft); }
.list-row .file-icon { width: 22px; height: 22px; flex-shrink: 0; }
.list-row .name { flex: 1; font-size: 0.88rem; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .meta { font-size: 0.78rem; color: var(--text-muted); flex-shrink: 0; width: 90px; text-align: right; }
.list-row .date { font-size: 0.78rem; color: var(--text-muted); flex-shrink: 0; width: 130px; text-align: right; }
.list-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.6rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border-soft);
}
.list-header .name { flex: 1; }
.list-header .meta { width: 90px; text-align: right; }
.list-header .date { width: 130px; text-align: right; }

/* ============ EMPTY STATES ============ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}
.empty-state svg {
    width: 64px;
    height: 64px;
    color: var(--text-faint);
    margin-bottom: 1rem;
}
.empty-state h3 {
    font-size: 1.05rem;
    color: var(--text);
    margin: 0 0 0.35rem;
}
.empty-state p {
    font-size: 0.88rem;
    margin: 0;
    max-width: 320px;
}

/* ============ BOTONES GENÉRICOS ============ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}
.btn:hover {
    background: var(--surface-hover);
    border-color: var(--text-faint);
}
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}
.btn-danger {
    background: transparent;
    border-color: #e5544c40;
    color: #e5544c;
}
.btn-danger:hover {
    background: #e5544c14;
    border-color: #e5544c;
}
.btn-block {
    width: 100%;
    justify-content: center;
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn svg { width: 16px; height: 16px; }

/* ============ MODALES ============ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
    animation: fadeIn 150ms ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 180ms ease;
}
.modal.modal-lg { max-width: 640px; }
@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-soft);
}
.modal-header h2 {
    font-size: 1.05rem;
    margin: 0;
    font-weight: 700;
}
.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    padding: 1.1rem 1.5rem;
    border-top: 1px solid var(--border-soft);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}
.form-group input,
.form-group select,
.form-group textarea {
    border: 1px solid var(--border);
    background: var(--surface-elevated);
    border-radius: var(--radius-md);
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
    color: var(--text);
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--accent);
}
.form-error {
    color: #e5544c;
    font-size: 0.8rem;
}
.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.color-options, .icon-options {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.color-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform var(--transition);
}
.color-dot.selected {
    border-color: var(--text);
    transform: scale(1.1);
}
.icon-option {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface-elevated);
    transition: all var(--transition);
}
.icon-option.selected {
    border-color: var(--accent);
    background: var(--accent-soft);
}

/* ============ CONTEXT MENU ============ */

.context-menu {
    position: fixed;
    z-index: 200;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    padding: 0.4rem;
    min-width: 190px;
    animation: fadeIn 100ms ease;
}
.context-menu-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text);
    transition: background var(--transition);
}
.context-menu-item:hover {
    background: var(--surface-hover);
}
.context-menu-item.danger {
    color: #e5544c;
}
.context-menu-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.context-menu-sep {
    height: 1px;
    background: var(--border-soft);
    margin: 0.35rem 0;
}

/* ============ TOASTS ============ */

.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    z-index: 300;
}
.toast {
    background: var(--surface-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.75rem 1.1rem;
    font-size: 0.85rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    animation: slideUp 180ms ease;
    max-width: 320px;
}
.toast.error { border-color: #e5544c60; }
.toast.success { border-color: #34b3a460; }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ============ UPLOAD QUEUE ============ */

.upload-panel {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 320px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    z-index: 250;
    overflow: hidden;
}
.upload-panel-header {
    padding: 0.8rem 1rem;
    font-size: 0.85rem;
    font-weight: 700;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.upload-item {
    padding: 0.6rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border-soft);
}
.upload-item:last-child { border-bottom: none; }
.upload-item .name { display: flex; justify-content: space-between; gap: 0.5rem; }
.upload-item .name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-bar {
    height: 4px;
    border-radius: 2px;
    background: var(--border-soft);
    overflow: hidden;
}
.upload-bar > div {
    height: 100%;
    background: var(--accent);
    transition: width 120ms ease;
}
.upload-item.error .upload-bar > div { background: #e5544c; }
.upload-item.done .upload-bar > div { background: var(--type-image); }

/* ============ LOADING ============ */

.spinner {
    width: 22px;
    height: 22px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

/* ============ SELECTION BAR ============ */

.selection-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--accent-soft);
    border-radius: var(--radius-lg);
    padding: 0.6rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    flex-wrap: wrap;
}
.selection-bar .spacer { flex: 1; }
.selection-bar .icon-btn { color: var(--accent); }
.selection-bar .icon-btn:hover { background: rgba(124,110,242,0.18); }

/* ============ RESPONSIVE ============ */

@media (max-width: 900px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-rows: var(--topbar-h) 1fr;
        grid-template-areas:
            "topbar"
            "main";
    }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        z-index: 90;
        transform: translateX(-100%);
        transition: transform 220ms ease;
        box-shadow: var(--shadow);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: var(--overlay);
        z-index: 85;
        display: none;
    }
    .sidebar-overlay.open { display: block; }

    /* Barra de navegación inferior fija — NO forma parte del grid
     * (que causaba que los archivos quedaran tapados al hacer scroll):
     * es position:fixed, y el .main tiene padding-bottom suficiente
     * para que el contenido nunca quede detrás de ella. */
    .mobile-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 80;
        display: flex;
        align-items: center;
        justify-content: space-around;
        background: var(--surface);
        border-top: 1px solid var(--border-soft);
        padding: 0.4rem 0;
        /* Safe area para teléfonos con notch/barra de gestos */
        padding-bottom: calc(0.4rem + env(safe-area-inset-bottom, 0px));
        height: auto;
    }
    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.2rem;
        font-size: 0.68rem;
        color: var(--text-muted);
        background: none;
        border: none;
        padding: 0.4rem 1rem;
        cursor: pointer;
        font-family: inherit;
        min-width: 44px;  /* objetivo táctil mínimo */
        min-height: 44px;
        justify-content: center;
    }
    .mobile-nav-item.active { color: var(--accent); }
    .mobile-nav-item svg { width: 24px; height: 24px; }

    /* Padding del main: suficiente para la barra inferior + safe area */
    .main {
        padding: 1rem 0.85rem;
        padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px) + 1rem);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .topbar {
        padding: 0 0.85rem;
        gap: 0.5rem;
        position: sticky;
        top: 0;
        z-index: 10;
    }
    .search-box { display: none; }

    /* Breadcrumb en móvil: scroll horizontal si es largo */
    .breadcrumb {
        font-size: 0.82rem;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        scrollbar-width: none;
    }
    .breadcrumb::-webkit-scrollbar { display: none; }

    /* Grid más grande en móvil para tarjetas más cómodas */
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 0.75rem;
    }

    /* Lista en móvil: tamaño de fuente ligeramente mayor */
    .list-row { padding: 0.75rem 0.85rem; }
    .list-row .name { font-size: 0.92rem; }

    .upload-panel {
        width: calc(100% - 1.7rem);
        right: 0.85rem;
        left: 0.85rem;
        bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px) + 0.75rem);
    }
    .toast-container {
        right: 0.85rem;
        bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px) + 0.75rem);
        left: 0.85rem;
    }
    .toast { max-width: none; }
    .list-row .date { display: none; }

    /* View header en móvil: stack vertical en pantallas muy pequeñas */
    .view-header { gap: 0.5rem; }

    /* Chips de filtro: scroll horizontal en vez de wrap */
    .filter-chips {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 2px;
    }
    .filter-chips::-webkit-scrollbar { display: none; }
    .chip { flex-shrink: 0; }
}

@media (max-width: 400px) {
    .grid { grid-template-columns: repeat(2, 1fr); }
    .view-title { font-size: 1.2rem; }
}

@media (min-width: 901px) {
    .mobile-nav, .sidebar-overlay { display: none; }
    .hamburger { display: none; }
}

/* ============ MISC ============ */

.hidden { display: none !important; }

.preview-modal {
    position: fixed;
    inset: 0;
    background: rgba(10,11,14,0.92);
    z-index: 400;
    display: flex;
    flex-direction: column;
}
.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    color: #fff;
}
.preview-header .name { font-size: 0.95rem; font-weight: 600; }
.preview-header .actions { display: flex; gap: 0.4rem; }
.preview-header .icon-btn { color: #fff; }
.preview-header .icon-btn:hover { background: rgba(255,255,255,0.12); }
.preview-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 1rem;
    min-height: 0;
}
.preview-body img, .preview-body video { max-width: 100%; max-height: 100%; border-radius: 8px; }
.preview-body audio { width: 100%; max-width: 500px; }
.preview-body iframe { width: 100%; height: 100%; border: none; border-radius: 8px; background: #fff; }
.preview-body textarea {
    width: 100%; height: 100%; resize: none; border: none; outline: none;
    background: #1e2027; color: #eef0f3; font-family: var(--font-mono);
    font-size: 0.85rem; padding: 1.25rem; border-radius: 8px; line-height: 1.6;
}
.preview-body .generic {
    color: #fff; text-align: center;
}
.preview-body .generic .file-icon { width: 72px; height: 72px; margin-bottom: 1rem; }

/* ============ PLAYER (panel superior audio/video, no overlay) ============ */

#player-panel {
    display: none;
}
#player-panel.open {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
    animation: playerSlideIn 220ms ease;
}
@keyframes playerSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.player-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem 0.6rem 1rem;
    border-bottom: 1px solid var(--border-soft);
}
.player-bar-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 0;
}
.player-bar-title svg { width: 17px; height: 17px; flex-shrink: 0; color: var(--accent); }
.player-bar-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.player-bar-actions {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex-shrink: 0;
}
.player-bar-actions [data-action="prev-track"]:disabled,
.player-bar-actions [data-action="next-track"]:disabled {
    opacity: 0.3;
    cursor: default;
}

/* --- Video --- */
.player-video-wrap {
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: 65vh;
}
.player-video-wrap video {
    width: 100%;
    max-height: 65vh;
    display: block;
}

/* --- Audio --- */
.player-audio {
    display: flex;
    gap: 1.5rem;
    padding: 1.5rem;
    align-items: center;
}
.player-cover {
    width: 96px;
    height: 96px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--accent), #b9a9ff);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}
.player-cover img { width: 100%; height: 100%; object-fit: cover; }
.player-cover-fallback { color: #fff; opacity: 0.9; }
.player-cover-fallback svg { width: 38px; height: 38px; }

.player-audio-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.player-track-name {
    font-size: 0.95rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.player-track-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

.player-progress-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.player-time {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    width: 34px;
}
.player-time:last-child { text-align: right; }

.player-seek {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--border-soft);
    cursor: pointer;
    accent-color: var(--accent);
}
.player-seek::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px; height: 13px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.player-seek::-moz-range-thumb {
    width: 13px; height: 13px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.player-controls-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.player-control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--text);
    cursor: pointer;
    transition: background var(--transition);
    flex-shrink: 0;
}
.player-control-btn:hover { background: var(--surface-hover); }
.player-control-btn svg { width: 19px; height: 19px; }
.player-control-play {
    width: 42px; height: 42px;
    background: var(--accent);
    color: #fff;
}
.player-control-play:hover { background: var(--accent-strong); }
.player-control-play svg { width: 18px; height: 18px; }

.player-volume {
    display: none;
    align-items: center;
    gap: 0.3rem;
    margin-left: auto;
}
.player-volume-range {
    width: 80px;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--border-soft);
    cursor: pointer;
    accent-color: var(--accent);
}

@media (min-width: 560px) {
    .player-volume { display: flex; }
}

/* Responsive: audio pasa a columna, controles más grandes (objetivo táctil) */
@media (max-width: 640px) {
    .player-audio {
        flex-direction: column;
        align-items: stretch;
        padding: 1.25rem 1rem;
        gap: 1rem;
    }
    .player-cover {
        width: 100%;
        height: 160px;
        align-self: center;
        max-width: 220px;
    }
    .player-controls-row { justify-content: center; }
    .player-control-btn { width: 44px; height: 44px; }
    .player-control-play { width: 52px; height: 52px; }
    .player-bar-title span { max-width: 140px; }
}

.share-link-box {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.share-link-box input {
    flex: 1;
    border: 1px solid var(--border);
    background: var(--surface-elevated);
    border-radius: var(--radius-md);
    padding: 0.6rem 0.8rem;
    font-size: 0.85rem;
    color: var(--text);
    font-family: var(--font-mono);
}
.share-existing {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.share-existing-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.8rem;
    background: var(--surface-elevated);
    border-radius: var(--radius-md);
    font-size: 0.8rem;
}
.share-existing-item .meta { flex: 1; color: var(--text-muted); }
.share-existing-item code { color: var(--text); font-family: var(--font-mono); }

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.switch {
    position: relative;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; inset: 0; background: var(--border);
    border-radius: 999px; cursor: pointer; transition: background var(--transition);
}
.switch .slider::before {
    content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
    background: #fff; border-radius: 50%; transition: transform var(--transition);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.5rem;
}
.calendar-day-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-align: center;
    text-transform: uppercase;
    padding-bottom: 0.4rem;
}
.calendar-cell {
    aspect-ratio: 1;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
    overflow: hidden;
}
.calendar-cell:hover { border-color: var(--accent); }
.calendar-cell.empty { border: none; cursor: default; }
.calendar-cell.empty:hover { border: none; }
.calendar-cell .day-num { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); }
.calendar-cell .day-thumbs { display: flex; gap: 2px; flex-wrap: wrap; overflow: hidden; flex: 1; }
.calendar-cell .day-thumbs img { width: 18px; height: 18px; object-fit: cover; border-radius: 3px; }
.calendar-cell .day-count { font-size: 0.65rem; color: var(--text-faint); }

@media (max-width: 600px) {
    .calendar-cell .day-thumbs img { width: 12px; height: 12px; }
}