:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #e4e6eb;
    --text: #1c1e21;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #15161a;
        --surface: #1e2025;
        --border: #2c2e33;
        --text: #e5e7eb;
        --muted: #9aa0a6;
        --primary: #3b82f6;
        --primary-hover: #60a5fa;
        --shadow: 0 1px 3px rgba(0,0,0,0.3);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: inherit; text-decoration: none; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }

/* --- Layout principal --- */
.app { min-height: 100vh; display: flex; flex-direction: column; position: relative; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }

.content { padding: 24px 28px 60px; max-width: 1100px; margin: 0 auto; width: 100%; }

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 14px; flex-wrap: wrap; }
.breadcrumb .crumb { color: var(--muted); }
.breadcrumb .crumb:last-child { color: var(--text); font-weight: 600; }
.breadcrumb .sep { color: var(--muted); }
.toolbar-actions { display: flex; gap: 10px; }

.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--muted);
}

/* --- Grid de carpetas --- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.item-folder {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    transition: box-shadow 0.15s;
}
.item-folder:hover { box-shadow: var(--shadow); }
.item-open { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.item-icon { font-size: 22px; }
.item-name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Lista de archivos --- */
.list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.list-head, .row {
    display: grid;
    grid-template-columns: 1fr 110px 160px 140px;
    align-items: center;
    padding: 12px 16px;
    gap: 10px;
}
.list-head {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
}
.row { border-bottom: 1px solid var(--border); font-size: 14px; }
.row:last-child { border-bottom: none; }
.row:hover { background: var(--bg); }
.row-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row-icon { font-size: 18px; }
.row-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.item-actions { display: flex; gap: 4px; justify-content: flex-end; opacity: 0; transition: opacity 0.15s; }
.item-folder:hover .item-actions, .row:hover .item-actions { opacity: 1; }

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 15px;
    padding: 6px;
    border-radius: 6px;
    line-height: 1;
}
.icon-btn:hover { background: var(--border); }

/* --- Drag & drop --- */
.drop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(37, 99, 235, 0.12);
    border: 3px dashed var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    color: var(--primary);
    z-index: 50;
    pointer-events: none;
}
.hidden { display: none !important; }

/* --- Panel de subidas --- */
.upload-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    padding: 4px 0;
}
.upload-item { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.upload-item:last-child { border-bottom: none; }
.upload-item-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; gap: 10px; }
.upload-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item-status { color: var(--muted); flex-shrink: 0; }
.progress-track { background: var(--border); border-radius: 6px; height: 6px; overflow: hidden; }
.progress-fill { background: var(--primary); height: 100%; width: 0%; transition: width 0.15s; }
.upload-item.error .progress-fill { background: var(--danger); }
.upload-item.done .progress-fill { background: #16a34a; }

/* --- Modal --- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    width: 380px;
    max-width: 90vw;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal h3 { margin: 0 0 16px; font-size: 16px; }
.modal input[type=text], .modal input[type=password], .modal input[type=number] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    margin-bottom: 12px;
}
.modal label { display: block; font-size: 13px; margin-bottom: 4px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.share-link-box {
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    margin-bottom: 12px;
    word-break: break-all;
}

/* --- Auth pages --- */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 36px 32px;
    width: 360px;
    max-width: 90vw;
    box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.auth-form label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.auth-form input {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}
.auth-form .btn { margin-top: 4px; justify-content: center; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin: 14px 0; }
.alert-error { background: rgba(220,38,38,0.1); color: var(--danger); }
.alert-ok { background: rgba(22,163,74,0.1); color: #16a34a; }

.share-file { display: flex; align-items: center; gap: 12px; margin: 18px 0; }
.share-file-name { font-weight: 600; font-size: 14px; }

@media (max-width: 640px) {
    .list-head, .row { grid-template-columns: 1fr 80px; }
    .list-head span:nth-child(3), .row span:nth-child(3) { display: none; }
    .topbar { padding: 12px 16px; }
    .content { padding: 18px 16px 60px; }
}
