/**
 * S-Cloud — Vues universelles (style SharePoint)
 *
 * Pattern : <div class="sc-view sc-view--list" data-sc-view>
 *              <a class="sc-view-item" ...>
 *                  <span class="sc-view-item-icon">...</span>
 *                  <span class="sc-view-item-name">...</span>
 *                  <span class="sc-view-item-meta">...</span>
 *                  <span class="sc-view-item-aside">...</span>  (modified by / date)
 *              </a>
 *          </div>
 *
 * Modes : --list (default), --compact, --tiles, --autofit
 *
 * Le toggle (sc-view-toggle) change la classe sur le container
 * et persiste le choix dans localStorage.
 */

/* ════════════════════════════════════════════════════════════════════
 *  Toggle button + menu (replique le bouton "Switch view options"
 *  de SharePoint, top-right)
 * ════════════════════════════════════════════════════════════════════ */
.sc-view-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 12px;
}
.sc-view-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--r, 6px);
    color: var(--c-text-muted, #64748B);
    cursor: pointer;
    font-size: .85rem;
    transition: all .12s;
}
.sc-view-toggle-btn:hover {
    background: var(--c-bg-subtle, #F1F5F9);
    color: var(--c-text, #1F2937);
    border-color: var(--c-border-soft, #E2E8F0);
}
.sc-view-toggle-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 1050;
    min-width: 220px;
    background: var(--c-bg-surface, #fff);
    border: 1px solid var(--c-border-soft, #E2E8F0);
    border-radius: var(--r-lg, 10px);
    box-shadow: var(--sh, 0 6px 18px rgb(15 23 42 / .12));
    padding: 4px;
    display: none;
}
.sc-view-toggle-wrap.is-open .sc-view-toggle-menu { display: block; }
.sc-view-toggle-wrap { position: relative; }
.sc-view-toggle-opt {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--r, 6px);
    cursor: pointer;
    color: var(--c-text, #1F2937);
    font-size: .9rem;
    border: 1px solid transparent;
    background: transparent;
    width: 100%;
    text-align: left;
}
.sc-view-toggle-opt:hover { background: var(--c-bg-subtle, #F1F5F9); }
.sc-view-toggle-opt.is-active {
    background: var(--c-brand-50, #EEF2FF);
    color: var(--c-brand-700, #4338CA);
    font-weight: 600;
    border-color: var(--c-brand-200, #C7D2FE);
}
.sc-view-toggle-opt .sc-view-toggle-ic {
    width: 18px; height: 18px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--c-text-muted, #64748B);
}
.sc-view-toggle-opt.is-active .sc-view-toggle-ic { color: var(--c-brand-600, #4338CA); }
.sc-view-toggle-divider {
    height: 1px; background: var(--c-border-soft, #E2E8F0); margin: 4px 0;
}

/* ════════════════════════════════════════════════════════════════════
 *  Mode LIST — defaut, type SharePoint
 * ════════════════════════════════════════════════════════════════════ */
.sc-view {
    border: 1px solid var(--c-border-soft, #E2E8F0);
    border-radius: var(--r-lg, 10px);
    background: var(--c-bg-surface, #fff);
    overflow: hidden;
}
.sc-view--list {
    display: flex;
    flex-direction: column;
}
.sc-view--list .sc-view-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--c-bg-subtle, #F8FAFC);
    border-bottom: 1px solid var(--c-border-soft, #E2E8F0);
    font-size: .75rem;
    font-weight: 600;
    color: var(--c-text-muted, #64748B);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.sc-view--list .sc-view-header-name { flex: 1; min-width: 0; }
.sc-view--list .sc-view-header-aside { flex-shrink: 0; min-width: 180px; }
.sc-view--list .sc-view-header-meta { flex-shrink: 0; min-width: 160px; }

.sc-view--list .sc-view-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    text-decoration: none;
    color: var(--c-text, #1F2937);
    border-bottom: 1px solid var(--c-border-soft, #E2E8F0);
    transition: background .12s;
    cursor: pointer;
}
.sc-view--list .sc-view-item:last-child { border-bottom: none; }
.sc-view--list .sc-view-item:hover { background: var(--c-bg-subtle, #F8FAFC); }
.sc-view--list .sc-view-item-icon {
    width: 28px; height: 28px;
    flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--c-brand-500, #6366F1);
}
.sc-view--list .sc-view-item-main {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column;
    gap: 2px;
}
.sc-view--list .sc-view-item-name {
    font-weight: 600;
    font-size: .9rem;
    color: var(--c-text, #1F2937);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sc-view--list .sc-view-item-sub {
    font-size: .75rem;
    color: var(--c-text-muted, #64748B);
}
.sc-view--list .sc-view-item-meta {
    flex-shrink: 0;
    min-width: 160px;
    font-size: .82rem;
    color: var(--c-text-muted, #64748B);
}
.sc-view--list .sc-view-item-aside {
    flex-shrink: 0;
    min-width: 180px;
    display: flex; align-items: center; gap: 6px;
    font-size: .82rem;
}
.sc-view--list .sc-view-item-actions {
    flex-shrink: 0;
    opacity: 0;
    transition: opacity .12s;
}
.sc-view--list .sc-view-item:hover .sc-view-item-actions { opacity: 1; }

/* ════════════════════════════════════════════════════════════════════
 *  Mode COMPACT — lignes plus serrees
 * ════════════════════════════════════════════════════════════════════ */
.sc-view--compact .sc-view-item {
    padding: 6px 12px;
    gap: 8px;
}
.sc-view--compact .sc-view-item-icon {
    width: 20px; height: 20px;
}
.sc-view--compact .sc-view-item-name { font-size: .85rem; }
.sc-view--compact .sc-view-item-sub { display: none; }
.sc-view--compact .sc-view-item-meta,
.sc-view--compact .sc-view-item-aside { font-size: .78rem; }
.sc-view--compact .sc-view-header { padding: 6px 12px; }

/* ════════════════════════════════════════════════════════════════════
 *  Mode AUTOFIT — wrap text, multiline names
 * ════════════════════════════════════════════════════════════════════ */
.sc-view--autofit .sc-view-item {
    align-items: flex-start;
    padding: 12px 16px;
}
.sc-view--autofit .sc-view-item-name {
    white-space: normal;
    word-break: break-word;
    line-height: 1.35;
}
.sc-view--autofit .sc-view-item-icon { margin-top: 2px; }

/* ════════════════════════════════════════════════════════════════════
 *  Mode TILES — grille de cartes (style SharePoint Tiles)
 * ════════════════════════════════════════════════════════════════════ */
.sc-view--tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
    padding: 16px;
    border: none;
    background: transparent;
}
.sc-view--tiles .sc-view-header,
.sc-view--tiles .sc-view-header-name,
.sc-view--tiles .sc-view-header-aside,
.sc-view--tiles .sc-view-header-meta { display: none; }

.sc-view--tiles .sc-view-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 16px 14px;
    background: var(--c-bg-surface, #fff);
    border: 1px solid var(--c-border-soft, #E2E8F0);
    border-radius: var(--r-lg, 10px);
    text-decoration: none;
    color: var(--c-text, #1F2937);
    transition: all .15s;
    min-height: 160px;
}
.sc-view--tiles .sc-view-item:hover {
    border-color: var(--c-brand-300, #A5B4FC);
    box-shadow: 0 6px 18px rgb(79 70 229 / .12);
    transform: translateY(-2px);
    background: var(--c-bg-surface, #fff);
}
.sc-view--tiles .sc-view-item-icon {
    width: 48px; height: 48px;
    border-radius: 10px;
    background: var(--c-bg-subtle, #F1F5F9);
    color: var(--c-brand-500, #6366F1);
    align-self: flex-start;
}
.sc-view--tiles .sc-view-item-main {
    flex: 1;
    min-width: 0;
    display: flex; flex-direction: column; gap: 4px;
}
.sc-view--tiles .sc-view-item-name {
    font-weight: 700;
    font-size: .92rem;
    color: var(--c-text, #1F2937);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: normal;
}
.sc-view--tiles .sc-view-item-sub {
    font-size: .78rem;
    color: var(--c-text-muted, #64748B);
    line-height: 1.4;
}
.sc-view--tiles .sc-view-item-meta,
.sc-view--tiles .sc-view-item-aside {
    margin-top: auto;
    border-top: 1px solid var(--c-border-soft, #E2E8F0);
    padding-top: 8px;
    min-width: 0;
    font-size: .72rem;
    color: var(--c-text-muted, #64748B);
}
.sc-view--tiles .sc-view-item-actions { display: none; }

/* ════════════════════════════════════════════════════════════════════
 *  ICONES DE TYPE DE FICHIER colorees (style SharePoint)
 *  → .sc-ft-pdf, .sc-ft-word, .sc-ft-excel, .sc-ft-ppt, etc.
 * ════════════════════════════════════════════════════════════════════ */
.sc-ft {
    width: 28px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 6px;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}
.sc-ft-pdf      { background: #DC2626; }   /* rouge */
.sc-ft-word     { background: #2563EB; }   /* bleu Word */
.sc-ft-excel    { background: #16A34A; }   /* vert Excel */
.sc-ft-ppt      { background: #EA580C; }   /* orange PPT */
.sc-ft-image    { background: #DB2777; }   /* rose */
.sc-ft-archive  { background: #6B7280; }   /* gris archive */
.sc-ft-video    { background: #7C3AED; }   /* violet video */
.sc-ft-audio    { background: #0891B2; }   /* cyan audio */
.sc-ft-text     { background: #475569; }   /* slate text */
.sc-ft-folder   { background: #F59E0B; }   /* ambre dossier */
.sc-ft-default  { background: #64748B; }   /* slate par defaut */

/* En mode tiles, icones plus grandes */
.sc-view--tiles .sc-ft { width: 48px; height: 48px; font-size: 14px; border-radius: 10px; }

/* ════════════════════════════════════════════════════════════════════
 *  AVATAR CHIP (style SharePoint "Modified By")
 * ════════════════════════════════════════════════════════════════════ */
.sc-avatar-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px 2px 2px;
    border-radius: 999px;
    background: var(--c-bg-subtle, #F1F5F9);
    color: var(--c-text, #1F2937);
    font-size: .78rem;
    border: 1px solid var(--c-border-soft, #E2E8F0);
}
.sc-avatar-chip-ic {
    width: 22px; height: 22px; border-radius: 50%;
    background: linear-gradient(135deg, #6366F1, #8B5CF6);
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 700;
    flex-shrink: 0;
}

/* ════════════════════════════════════════════════════════════════════
 *  DATE RELATIVE
 * ════════════════════════════════════════════════════════════════════ */
.sc-date-rel { color: var(--c-text-muted, #64748B); }
.sc-date-rel--fresh { color: var(--c-brand-600, #4338CA); font-weight: 500; }

/* ════════════════════════════════════════════════════════════════════
 *  EMPTY STATE dans une sc-view
 * ════════════════════════════════════════════════════════════════════ */
.sc-view-empty {
    padding: 48px 24px;
    text-align: center;
    color: var(--c-text-muted, #64748B);
}
.sc-view-empty-icon {
    width: 64px; height: 64px;
    margin: 0 auto 12px;
    background: var(--c-bg-subtle, #F1F5F9);
    color: var(--c-text-subtle, #94A3B8);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}

/* ════════════════════════════════════════════════════════════════════
 *  MOBILE — adapte les modes
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
    .sc-view--list .sc-view-item-meta,
    .sc-view--list .sc-view-item-aside { display: none; }
    .sc-view--list .sc-view-header-meta,
    .sc-view--list .sc-view-header-aside { display: none; }
    .sc-view--tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); padding: 8px; gap: 10px; }
    .sc-view--tiles .sc-view-item { min-height: 130px; padding: 12px 10px; }
}
