:root {
    --blue: #3b6dff;
    --blue-dark: #2c52d1;
    --bg: #f6f7fb;
    --surface: #ffffff;
    --border: #e3e6ee;
    --text: #1d2129;
    --text-muted: #6b7280;
    --danger: #e0453f;
    --radius: 10px;
    --shadow: 0 2px 10px rgba(20, 25, 40, 0.06);
    --shadow-lg: 0 12px 40px rgba(20, 25, 40, 0.18);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14161c;
        --surface: #1d2029;
        --border: #2c303c;
        --text: #edeef2;
        --text-muted: #9aa0ad;
        --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
        --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    }
}

* { box-sizing: border-box; }

/* L'attribut hidden doit toujours l'emporter, même sur des éléments dont la
   classe définit display:flex/grid (sinon l'overlay reste visible et bloque
   tous les clics de la page). */
[hidden] { display: none !important; }

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

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

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, box-shadow .15s, transform .05s;
    white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); text-decoration: none; }
.btn-block { width: 100%; }
.btn-danger { background: var(--danger); color: #fff; }

.icon-btn {
    background: transparent;
    border: none;
    font-size: 18px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
}
.icon-btn:hover { background: var(--border); }

/* ---------- Auth pages ---------- */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #eef1fb, #f7f9ff);
}
@media (prefers-color-scheme: dark) {
    .auth-body { background: linear-gradient(135deg, #14161c, #1b1e28); }
}
.auth-wrap { width: 100%; max-width: 420px; }
.auth-card {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 40px 32px;
    border: 1px solid var(--border);
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.logo-icon { font-size: 26px; }
.logo-text { font-size: 20px; font-weight: 700; }
.auth-card h1 { margin: 0 0 6px; font-size: 24px; }
.auth-sub { color: var(--text-muted); margin: 0 0 24px; font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label { font-size: 13px; font-weight: 600; margin-top: 10px; }
.auth-form input {
    padding: 11px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}
.auth-form input:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.auth-form .btn { margin-top: 20px; }
.auth-switch { text-align: center; margin-top: 22px; font-size: 14px; color: var(--text-muted); }
.alert { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; }
.alert-error { background: #fdeceb; color: #a3231e; border: 1px solid #f5c6c3; }
@media (prefers-color-scheme: dark) {
    .alert-error { background: #3a1f1e; color: #ff8f8a; border-color: #5c2e2b; }
}

/* ---------- App shell ---------- */
.app-body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 20;
}
.menu-toggle { display: none; }
.topbar-logo { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.topbar-search { flex: 1; max-width: 700px; }
.topbar-search input {
    width: 100%;
    padding: 10px 16px;
    border-radius: 24px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}
.topbar-search input:focus { outline: 2px solid var(--blue); }
.topbar-user { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.user-name { font-size: 14px; font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.app-layout { display: flex; flex: 1; min-height: 0; position: relative; }

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    z-index: 25;
}
.btn-new { padding: 12px 20px; border-radius: 24px; box-shadow: var(--shadow); font-size: 15px; }
.new-menu {
    position: absolute;
    top: 80px;
    left: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 30;
    display: flex;
    flex-direction: column;
    min-width: 220px;
}
.new-menu button {
    background: none;
    border: none;
    text-align: left;
    padding: 12px 16px;
    font-size: 14px;
    cursor: pointer;
    color: var(--text);
}
.new-menu button:hover { background: var(--bg); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
    padding: 10px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.sidebar-link:hover { background: var(--bg); text-decoration: none; }
.sidebar-link.active { background: #e8edff; color: var(--blue-dark); }
@media (prefers-color-scheme: dark) {
    .sidebar-link.active { background: #24304f; color: #9db4ff; }
}

.storage-meter { margin-top: auto; padding: 10px 4px; }
.storage-bar { height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; }
.storage-bar-fill { height: 100%; background: var(--blue); width: 0%; transition: width .3s; }
.storage-text { font-size: 12px; color: var(--text-muted); margin: 8px 0 0; }

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 24;
}

.main {
    flex: 1;
    overflow-y: auto;
    padding: 18px 24px 60px;
    position: relative;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}
.breadcrumb { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb .sep { color: var(--text-muted); }
.breadcrumb .current { color: var(--text); }

.empty-state { text-align: center; padding: 80px 20px; color: var(--text-muted); }
.empty-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.empty-sub { font-size: 13px; }

/* ---------- File grid ---------- */
.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
}
.file-grid.list-view { grid-template-columns: 1fr; gap: 0; }

.file-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: box-shadow .12s, border-color .12s;
}
.file-card:hover { box-shadow: var(--shadow); border-color: #c7cfe6; }
.file-card .icon { font-size: 40px; margin-bottom: 8px; }
.file-card .name {
    font-size: 13px;
    font-weight: 500;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-card .meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.file-card .card-menu-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    opacity: 0;
}
.file-card:hover .card-menu-btn, .file-card .card-menu-btn.active { opacity: 1; }

.list-view .file-card {
    flex-direction: row;
    text-align: left;
    align-items: center;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    padding: 10px 8px;
    gap: 12px;
}
.list-view .file-card .icon { font-size: 22px; margin-bottom: 0; }
.list-view .file-card .name { flex: 1; }
.list-view .file-card .meta { margin-top: 0; width: 120px; text-align: right; }
.list-view .file-card .card-menu-btn { position: static; opacity: 1; margin-left: 8px; }

/* ---------- Context menu / dropdown ---------- */
.dropdown-menu {
    position: absolute;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    z-index: 60;
    overflow: hidden;
}
.dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 11px 14px;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
}
.dropdown-menu button:hover { background: var(--bg); }
.dropdown-menu button.danger { color: var(--danger); }

/* ---------- Modal ---------- */
.modal-root {
    position: fixed;
    inset: 0;
    background: rgba(15, 18, 30, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal-box {
    background: var(--surface);
    border-radius: 14px;
    padding: 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}
.modal-box h2 { margin: 0 0 14px; font-size: 18px; }
.modal-box input[type=text] {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    margin-bottom: 18px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-box p { font-size: 14px; color: var(--text-muted); }

/* ---------- Toasts ---------- */
.toast-root {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
    width: 100%;
    max-width: 420px;
    padding: 0 16px;
}
.toast {
    background: #1d2129;
    color: #fff;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    animation: toast-in .2s ease;
}
.toast.error { background: var(--danger); }
.toast.success { background: #1c8a4b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Drag & drop overlay ---------- */
.drop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(59, 109, 255, 0.15);
    border: 3px dashed var(--blue);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}
.drop-overlay-inner { text-align: center; background: var(--surface); padding: 30px 40px; border-radius: 14px; box-shadow: var(--shadow-lg); }
.drop-icon { font-size: 40px; display: block; margin-bottom: 10px; }

/* ---------- Progress ---------- */
.upload-progress {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 300px;
    max-width: calc(100vw - 32px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    padding: 14px 16px;
    z-index: 150;
}
.upload-progress h3 { margin: 0 0 8px; font-size: 13px; }
.progress-bar { height: 6px; border-radius: 4px; background: var(--border); overflow: hidden; margin-top: 6px; }
.progress-bar-fill { height: 100%; background: var(--blue); width: 0%; transition: width .2s; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .topbar-logo .logo-text { display: none; }
    .sidebar {
        position: fixed;
        top: 56px;
        bottom: 0;
        left: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        width: 260px;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .menu-toggle { display: inline-flex; }
    .main { padding: 14px; }
}

@media (max-width: 600px) {
    .topbar { gap: 8px; padding: 8px; }
    .topbar-search { order: 3; width: 100%; max-width: none; flex-basis: 100%; }
    .user-name { display: none; }
    .file-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
    .file-card .icon { font-size: 32px; }
    .auth-card { padding: 28px 20px; }
}

@media (max-width: 420px) {
    .file-grid { grid-template-columns: repeat(2, 1fr); }
}
