/* ═══════════════════════════════════════════════════════════════
   GLSW Documents Modal
   Module standalone — identique au système action-panel
   ═══════════════════════════════════════════════════════════════ */

/* ── Overlay ─────────────────────────────────────────────────── */

.glsw-docs-modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.glsw-docs-modal[hidden] { display: none; }

.glsw-docs-modal__backdrop {
    position: absolute;
    inset: 0;
    background: hsl(220 14% 10% / 0.5);
    backdrop-filter: blur(2px);
    animation: glsw-backdrop-in 0.2s ease forwards;
}

.glsw-docs-modal__panel {
    position: relative;
    width: 100%;
    max-width: 640px;
    max-height: 85vh;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--card);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 32px 64px -16px hsl(220 20% 10% / 0.3),
                0 0 0 1px hsl(0 0% 100% / 0.08);
    animation: glsw-panel-in 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ── Header ──────────────────────────────────────────────────── */

.glsw-docs-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.glsw-docs-modal__title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--foreground);
    margin: 0;
}

.glsw-docs-modal__close {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.glsw-docs-modal__close:hover {
    background: hsl(0 84% 60% / 0.08);
    border-color: hsl(0 84% 60% / 0.2);
    color: hsl(0 84% 60%);
}

/* ── Body ────────────────────────────────────────────────────── */

.glsw-docs-modal__body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    font-size: 0.875rem;
    color: var(--foreground);
}

/* En mode viewer, le body laisse le viewer prendre toute la hauteur */
.glsw-docs-modal__body:has(.glsw-docs-viewer) {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Toolbar ─────────────────────────────────────────────────── */

.glsw-docs-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

/* ── Viewer ──────────────────────────────────────────────────── */

.glsw-docs-viewer {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.glsw-docs-viewer__toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
    flex-shrink: 0;
}

.glsw-docs-viewer__name {
    flex: 1 1 0;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--muted-foreground);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.glsw-docs-viewer__content {
    flex: 1;
    min-height: 0;
    border-radius: var(--radius);
    overflow: hidden;
    background: hsl(214 40% 97%);
    display: flex;
    align-items: stretch;
}

/* PDF iframe */
.glsw-docs-viewer__pdf {
    width: 100%;
    height: 100%;
    min-height: 420px;
    border: none;
    display: block;
}

/* Image */
.glsw-docs-viewer__img-wrap {
    width: 100%;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1rem;
}

.glsw-docs-viewer__img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

/* Text / CSV */
.glsw-docs-viewer__text {
    width: 100%;
    margin: 0;
    padding: 1rem;
    font-size: 0.8125rem;
    font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', monospace;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-y: auto;
    color: var(--foreground);
}

/* Unsupported format */
.glsw-docs-viewer__unsupported {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--muted-foreground);
    width: 100%;
}

.glsw-docs-viewer__unsupported p {
    margin: 0;
    font-size: 0.875rem;
}

.glsw-docs-viewer__unsupported svg {
    opacity: 0.4;
}

/* ── Category sections ───────────────────────────────────────── */

.glsw-docs-section {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.9rem;
}

.glsw-docs-section:last-child {
    margin-bottom: 0;
}

.glsw-docs-section__header {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.42rem 0.7rem;
    border-radius: var(--radius-sm);
    background: hsl(217 91% 96%);
    border-left: 3px solid hsl(217 91% 50%);
}

.glsw-docs-section__header svg {
    color: hsl(217 91% 45%);
    flex-shrink: 0;
}

.glsw-docs-section__title {
    flex: 1;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: hsl(217 60% 32%);
}

.glsw-docs-section__count {
    font-size: 0.7rem;
    font-weight: 600;
    color: hsl(217 91% 42%);
    background: hsl(217 91% 88%);
    border-radius: 10px;
    padding: 0.1em 0.55em;
    min-width: 1.5em;
    text-align: center;
}

.glsw-docs-section--uncategorized .glsw-docs-section__header {
    background: hsl(220 14% 96%);
    border-left-color: hsl(220 9% 62%);
}

.glsw-docs-section--uncategorized .glsw-docs-section__header svg {
    color: hsl(220 9% 52%);
}

.glsw-docs-section--uncategorized .glsw-docs-section__title {
    color: hsl(220 9% 42%);
}

.glsw-docs-section--uncategorized .glsw-docs-section__count {
    color: hsl(220 9% 42%);
    background: hsl(220 9% 88%);
}

/* ── Document list ───────────────────────────────────────────── */

.glsw-docs-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.glsw-docs-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    animation: glsw-docs-item-in 0.15s ease forwards;
}

.glsw-docs-item__icon {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    background: hsl(214 40% 96%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: hsl(217 91% 50%);
}

.glsw-docs-item__icon svg {
    width: 14px;
    height: 14px;
}

.glsw-docs-item__name {
    flex: 1 1 0;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--foreground);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: none;
    border: none;
    padding: 0;
    text-align: left;
    cursor: pointer;
    transition: color 0.15s ease;
}

.glsw-docs-item__name:hover {
    color: hsl(217 91% 50%);
    text-decoration: underline;
}

.glsw-docs-item__actions {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
}

/* ── Extra button sizes ──────────────────────────────────────── */

.glsw-btn--xs {
    height: 26px;
    padding: 0 0.5rem;
    font-size: 0.75rem;
    gap: 0.25rem;
}

.glsw-btn--destructive {
    color: hsl(0 84% 60%);
    border-color: hsl(0 84% 60% / 0.3);
    background: hsl(0 84% 60% / 0.05);
}

.glsw-btn--destructive:hover {
    background: hsl(0 84% 60% / 0.12);
    border-color: hsl(0 84% 60% / 0.5);
}

/* ── Add document form ───────────────────────────────────────── */

.glsw-docs-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.glsw-docs-form__title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--foreground);
    margin: 0;
}

.glsw-docs-form__field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.glsw-docs-form__label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--muted-foreground);
}

.glsw-docs-form__file-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.glsw-docs-form__file-hidden {
    display: none;
}

.glsw-docs-form__file-name {
    font-size: 0.8125rem;
    color: var(--muted-foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.glsw-docs-form__actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.glsw-docs-form__error {
    font-size: 0.8125rem;
    color: hsl(0 84% 50%);
    background: hsl(0 84% 50% / 0.08);
    border: 1px solid hsl(0 84% 50% / 0.2);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
}

/* ── Cropper overlay ─────────────────────────────────────────── */

.glsw-cropper-overlay {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: hsl(220 14% 8% / 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.glsw-cropper-overlay[hidden] { display: none; }

.glsw-cropper-box {
    background: var(--card);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 24px 48px -12px hsl(220 20% 5% / 0.5);
}

.glsw-cropper-header {
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--foreground);
    flex-shrink: 0;
}

.glsw-cropper-wrap {
    flex: 1;
    min-height: 0;
    max-height: 65vh;
    overflow: hidden;
    background: hsl(214 40% 10%);
}

.glsw-cropper-wrap img {
    display: block;
    max-width: 100%;
}

.glsw-cropper-actions {
    padding: 0.75rem 1rem;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ── Animations ──────────────────────────────────────────────── */

@keyframes glsw-docs-item-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes glsw-docs-item-out {
    from { opacity: 1; transform: scaleY(1); max-height: 60px; }
    to   { opacity: 0; transform: scaleY(0); max-height: 0; padding: 0; margin: 0; }
}

@keyframes glsw-docs-out {
    from { transform: translateY(0); }
    to   { transform: translateY(100%); }
}

/* ── Responsive ──────────────────────────────────────────────── */

@media (min-width: 600px) {
    .glsw-docs-modal {
        align-items: center;
        padding: 1rem;
    }

    .glsw-docs-modal__panel {
        border-radius: var(--radius-lg);
        max-height: 80vh;
    }
}
