:root {
    --cm-bg: #f4f5f7;
    --cm-surface: #ffffff;
    --cm-border: #e2e4e9;
    --cm-text: #16181d;
    --cm-text-muted: #6b7280;
    --cm-primary: #e4002b;
    --cm-primary-dark: #b8001f;
    --cm-danger-bg: #fee2e2;
    --cm-danger-text: #b91c1c;
    --radius: 10px;
}

* { box-sizing: border-box; }

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

/* ---- Login ---- */
.cm-login-body {
    margin: 0;
    min-height: 100vh;
    background: #0b0b0c;
}
.cm-login-split {
    display: flex;
    min-height: 100vh;
}

/* Panneau visuel : collage de photos d'ambiance (masqué sur petit écran) */
.cm-login-visual {
    flex: 1 1 55%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    position: relative;
    overflow: hidden;
}
.cm-login-visual img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    filter: grayscale(15%);
}
.cm-login-visual::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.15) 70%, #0b0b0c 100%),
                linear-gradient(0deg, rgba(0,0,0,0.35), transparent 40%);
}

/* Panneau formulaire */
.cm-login-panel {
    flex: 1 1 45%;
    max-width: 480px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    padding: 32px;
}
.cm-login-box {
    width: 100%;
    max-width: 320px;
    text-align: center;
}
.cm-login-logo {
    display: block;
    width: 45%;
    max-width: 160px;
    height: auto;
    margin: 0 auto 22px;
}
.cm-login-box h1 { margin: 0 0 4px; font-size: 22px; }
.cm-subtitle { color: var(--cm-text-muted); margin: 0 0 24px; font-size: 14px; }

@media (max-width: 800px) {
    .cm-login-visual { display: none; }
    .cm-login-panel { max-width: none; flex: 1 1 100%; min-height: 100vh; }
}
.cm-login-box form { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.cm-login-box label { font-size: 13px; font-weight: 600; margin-top: 10px; }
.cm-login-box input {
    padding: 10px 12px;
    border: 1px solid var(--cm-border);
    border-radius: 8px;
    font-size: 14px;
}
.cm-login-box button {
    margin-top: 20px;
    padding: 11px;
    background: var(--cm-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease;
}
.cm-login-box button:hover { background: var(--cm-primary-dark); }
.cm-alert {
    background: #eef2ff;
    color: #3730a3;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 10px;
}
.cm-alert-error { background: var(--cm-danger-bg); color: var(--cm-danger-text); }

/* ---- Layout général ---- */
.cm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 24px;
    background: var(--cm-surface);
    border-bottom: 1px solid var(--cm-border);
    flex-wrap: wrap;
}
.cm-header h1 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.cm-header-logo { height: 24px; width: auto; display: block; }
.cm-header-title { color: var(--cm-text-muted); font-weight: 500; font-size: 14px; border-left: 1px solid var(--cm-border); padding-left: 12px; }

.cm-searchbar {
    display: flex;
    align-items: center;
    flex: 1 1 320px;
    max-width: 480px;
    background: var(--cm-bg);
    border: 1px solid var(--cm-border);
    border-radius: 8px;
    overflow: hidden;
}
.cm-searchbar input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 9px 12px;
    font-size: 14px;
    color: var(--cm-text);
    outline: none;
}
.cm-searchbar button {
    border: none;
    background: transparent;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 15px;
}
.cm-searchbar button:hover { background: var(--cm-border); }

.cm-search-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 14px;
    color: var(--cm-text-muted);
    margin-bottom: 18px;
}
.cm-search-clear {
    color: var(--cm-primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}
.cm-search-clear:hover { text-decoration: underline; }

.cm-card-folder-link {
    display: block;
    font-size: 11px;
    color: var(--cm-text-muted);
    text-decoration: none;
    margin-top: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}
.cm-card-folder-link:hover { color: var(--cm-primary); text-decoration: underline; }
.cm-logout {
    text-decoration: none;
    color: var(--cm-text-muted);
    font-size: 13px;
    padding: 6px 12px;
    border: 1px solid var(--cm-border);
    border-radius: 6px;
}
.cm-logout:hover { background: var(--cm-bg); }

.cm-layout {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - 57px);
}

/* ---- Sidebar / arborescence ---- */
.cm-sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--cm-surface);
    border-right: 1px solid var(--cm-border);
    padding: 16px 12px;
    height: calc(100vh - 57px);
    overflow-y: auto;
    position: sticky;
    top: 57px;
}
.cm-root-link {
    display: block;
    text-decoration: none;
    color: var(--cm-text);
    font-weight: 600;
    padding: 6px 8px;
    border-radius: 6px;
    margin-bottom: 8px;
}
.cm-root-link:hover { background: var(--cm-bg); }

ul.cm-tree { list-style: none; margin: 0; padding-left: 14px; }
.cm-sidebar > ul.cm-tree { padding-left: 0; }
.cm-tree summary {
    cursor: pointer;
    list-style: none;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 14px;
}
.cm-tree summary::-webkit-details-marker { display: none; }
.cm-tree summary:hover { background: var(--cm-bg); }
.cm-tree a { text-decoration: none; color: var(--cm-text); }
.cm-tree-active { color: var(--cm-primary); font-weight: 700; }

/* ---- Contenu principal ---- */
.cm-main { flex: 1; padding: 20px 28px; }

.cm-breadcrumb {
    font-size: 14px;
    margin-bottom: 18px;
    color: var(--cm-text-muted);
}
.cm-breadcrumb a { color: var(--cm-text); text-decoration: none; }
.cm-breadcrumb a:hover { text-decoration: underline; }
.cm-sep { margin: 0 6px; color: var(--cm-border); }

.cm-empty { color: var(--cm-text-muted); font-size: 14px; }

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

.cm-card {
    position: relative;
    background: var(--cm-surface);
    border: 1px solid var(--cm-border);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    text-decoration: none;
    color: var(--cm-text);
    transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
.cm-card:hover { box-shadow: 0 6px 18px rgba(0,0,0,0.08); transform: translateY(-2px); }
.cm-card-checked { border-color: var(--cm-primary); box-shadow: 0 0 0 2px rgba(228,0,43,0.15); }

.cm-card-select {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.9);
    border-radius: 6px;
    z-index: 2;
}
.cm-card-select input {
    width: 16px;
    height: 16px;
    accent-color: var(--cm-primary);
    cursor: pointer;
}
.cm-card-selectable { padding-top: 34px; }

.cm-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    background: var(--cm-surface);
    border: 1px solid var(--cm-border);
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 16px;
}
.cm-select-all {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
}
.cm-select-all input { width: 16px; height: 16px; accent-color: var(--cm-primary); cursor: pointer; }
.cm-download-selected {
    border: none;
    background: var(--cm-primary);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 9px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s ease, opacity .15s ease;
}
.cm-download-selected:hover:not(:disabled) { background: var(--cm-primary-dark); }
.cm-download-selected:disabled { opacity: 0.45; cursor: not-allowed; }

.cm-thumb {
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--cm-bg);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 8px;
}
.cm-thumb img { max-width: 100%; max-height: 100%; object-fit: cover; }
.cm-thumb-icon { font-size: 40px; }

.cm-card-name {
    font-size: 13px;
    font-weight: 600;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cm-card-meta {
    font-size: 11px;
    color: var(--cm-text-muted);
    margin-top: 2px;
}

.cm-download {
    margin-top: 10px;
    display: inline-block;
    font-size: 12px;
    padding: 6px 10px;
    background: var(--cm-primary);
    color: #fff;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
}
.cm-download:hover { background: var(--cm-primary-dark); }

.cm-thumb-clickable {
    cursor: zoom-in;
    position: relative;
}
.cm-thumb-clickable[data-preview-type="video"] { cursor: pointer; }
.cm-thumb-clickable[data-preview-type="video"]::after {
    content: "▶";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 20px;
    background: rgba(0,0,0,0.28);
}

.cm-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cm-lightbox[hidden] { display: none; }
.cm-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.88);
}
.cm-lightbox-close {
    position: fixed;
    top: 18px;
    right: 22px;
    z-index: 2;
    background: rgba(255,255,255,0.1);
    border: none;
    color: #fff;
    font-size: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
}
.cm-lightbox-close:hover { background: rgba(255,255,255,0.2); }
.cm-lightbox-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    max-width: 92vw;
    max-height: 92vh;
    padding: 20px;
}
.cm-lightbox-media img,
.cm-lightbox-media video {
    display: block;
    max-width: 88vw;
    max-height: 82vh;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.cm-lightbox-caption {
    color: #fff;
    font-size: 13px;
    opacity: 0.85;
    max-width: 80vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
@media (max-width: 720px) {
    .cm-layout { flex-direction: column; }
    .cm-sidebar { width: 100%; height: auto; position: relative; top: 0; border-right: none; border-bottom: 1px solid var(--cm-border); }
}
