/**
 * TW Espace Documents Pro — Styles Front-end
 * @package TW_Espace_Documents
 */

/* ============================================================
   Variables CSS (overridées par les réglages du plugin)
   ============================================================ */
:root {
  --tw-ed-primary:      #2563eb;
  --tw-ed-secondary:    #64748b;
  --tw-ed-accent:       #0ea5e9;
  --tw-ed-bg:           #ffffff;
  --tw-ed-text:         #1e293b;
  --tw-ed-muted:        #94a3b8;
  --tw-ed-border:       #e8edf3;
  --tw-ed-hover-bg:     #f8fafc;
  --tw-ed-radius:       10px;
  --tw-ed-radius-sm:    6px;
  --tw-ed-font:         inherit;
  --tw-ed-font-size:    14px;
  --tw-ed-cols:         3;
  --tw-ed-shadow:       0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.04);
}

/* ============================================================
   Reset boutons (évite les styles natifs du navigateur)
   ============================================================ */
.tw-ed-browser button {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  line-height: inherit;
}

.tw-ed-browser button:focus-visible {
  outline: 2px solid var(--tw-ed-primary);
  outline-offset: 2px;
  border-radius: var(--tw-ed-radius-sm);
}

/* ============================================================
   Conteneur principal
   ============================================================ */
.tw-ed-browser {
  font-family: var(--tw-ed-font);
  font-size: var(--tw-ed-font-size);
  color: var(--tw-ed-text);
  background: var(--tw-ed-bg);
  border-radius: var(--tw-ed-radius);
  box-shadow: var(--tw-ed-shadow);
  overflow: hidden;
}

/* ============================================================
   Fil d'Ariane
   ============================================================ */
.tw-ed-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  background: var(--tw-ed-hover-bg);
  border-bottom: 1px solid var(--tw-ed-border);
  font-size: 0.8em;
  flex-wrap: wrap;
  color: var(--tw-ed-secondary);
}

.tw-ed-breadcrumb__home {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--tw-ed-radius-sm);
  color: var(--tw-ed-primary);
  font-weight: 500;
  transition: background 0.15s;
}

.tw-ed-breadcrumb__home:hover {
  background: color-mix(in srgb, var(--tw-ed-primary) 10%, transparent);
}

.tw-ed-breadcrumb__icon {
  display: inline-flex;
  align-items: center;
  opacity: 0.8;
}

.tw-ed-breadcrumb__icon svg {
  fill: var(--tw-ed-primary);
}

.tw-ed-breadcrumb__sep {
  color: var(--tw-ed-muted);
  font-weight: 300;
  user-select: none;
}

/* Crumbs intermédiaires (créés dynamiquement par JS) */
.tw-ed-breadcrumb .tw-ed-nav {
  padding: 3px 8px;
  border-radius: var(--tw-ed-radius-sm);
  color: var(--tw-ed-primary);
  font-weight: 500;
  transition: background 0.15s;
}

.tw-ed-breadcrumb .tw-ed-nav:hover {
  background: color-mix(in srgb, var(--tw-ed-primary) 10%, transparent);
}

/* ============================================================
   Bouton "dossier parent" (retour)
   ============================================================ */
.tw-ed-back-wrap {
  border-bottom: 1px solid var(--tw-ed-border);
}

.tw-ed-back-wrap[hidden] {
  display: none;
}

.tw-ed-item--back {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  color: var(--tw-ed-secondary);
  font-size: 0.875em;
  transition: background 0.15s, color 0.15s;
}

.tw-ed-item--back:hover {
  background: var(--tw-ed-hover-bg);
  color: var(--tw-ed-primary);
}

.tw-ed-item--back .tw-ed-item__icon svg {
  fill: currentColor;
  display: block;
}

.tw-ed-item--back .tw-ed-item__name {
  font-weight: normal;
}

/* ============================================================
   Zone de chargement (spinner)
   ============================================================ */
.tw-ed-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.tw-ed-loading[hidden] {
  display: none;
}

.tw-ed-spinner {
  display: block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--tw-ed-border);
  border-top-color: var(--tw-ed-primary);
  border-radius: 50%;
  animation: tw-ed-spin 0.7s linear infinite;
}

@keyframes tw-ed-spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Liste / grille d'éléments
   ============================================================ */
.tw-ed-items {
  display: flex;
  flex-direction: column;
}

/* Mode grille */
.tw-ed-browser--grid .tw-ed-items {
  display: grid;
  grid-template-columns: repeat(var(--tw-ed-cols, 3), 1fr);
  gap: 12px;
  padding: 16px;
}

/* ============================================================
   Élément générique (dossier ou document)
   ============================================================ */
.tw-ed-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--tw-ed-border);
  color: var(--tw-ed-text);
  text-decoration: none;
  transition: background 0.12s;
  width: 100%;
  position: relative;
  /* Neutralise les styles de lien hérités du thème */
  box-shadow: none;
  outline-offset: -2px;
}

.tw-ed-item:last-child {
  border-bottom: none;
}

.tw-ed-item:hover {
  background: var(--tw-ed-hover-bg);
  color: var(--tw-ed-text);
  text-decoration: none;
}

/* Effet hover sur le bouton d'action quand on survole la ligne */
.tw-ed-item--document:hover .tw-ed-btn-download {
  background: color-mix(in srgb, var(--tw-ed-primary) 82%, #000);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--tw-ed-primary) 40%, transparent);
  transform: translateY(-1px);
}

/* Mode grille */
.tw-ed-browser--grid .tw-ed-item {
  flex-direction: column;
  align-items: center;
  text-align: center;
  border: 1px solid var(--tw-ed-border);
  border-radius: var(--tw-ed-radius);
  padding: 20px 14px;
  gap: 10px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.12s;
}

.tw-ed-browser--grid .tw-ed-item:last-child {
  border-bottom: 1px solid var(--tw-ed-border);
}

.tw-ed-browser--grid .tw-ed-item:hover {
  border-color: var(--tw-ed-primary);
  box-shadow: 0 2px 12px rgba(37, 99, 235, 0.1);
}

/* ============================================================
   Dossier
   ============================================================ */
.tw-ed-item--folder {
  font-weight: 500;
  cursor: pointer;
}

.tw-ed-item--folder .tw-ed-item__icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.tw-ed-item--folder .tw-ed-item__icon svg {
  fill: #f59e0b;
  width: 28px;
  height: 28px;
  display: block;
  flex-shrink: 0;
}

.tw-ed-browser--grid .tw-ed-item--folder .tw-ed-item__icon svg {
  width: 44px;
  height: 44px;
}

.tw-ed-item--folder .tw-ed-item__chevron {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  color: var(--tw-ed-muted);
  transition: transform 0.15s, color 0.15s;
  flex-shrink: 0;
}

.tw-ed-item--folder .tw-ed-item__chevron svg {
  fill: currentColor;
  display: block;
}

.tw-ed-item--folder:hover .tw-ed-item__chevron {
  transform: translateX(3px);
  color: var(--tw-ed-primary);
}

.tw-ed-browser--grid .tw-ed-item--folder .tw-ed-item__chevron {
  display: none;
}

/* ============================================================
   Document
   ============================================================ */
.tw-ed-item--document {
  align-items: center;
}

.tw-ed-item__icon-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
}

.tw-ed-browser--grid .tw-ed-item__icon-wrap {
  width: auto;
}

.tw-ed-item__icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: block;
}

.tw-ed-browser--grid .tw-ed-item__icon {
  width: 44px;
  height: 44px;
}

.tw-ed-item__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tw-ed-browser--grid .tw-ed-item__body {
  text-align: center;
  width: 100%;
}

.tw-ed-item__title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tw-ed-browser--grid .tw-ed-item__title-row {
  justify-content: center;
}

.tw-ed-item__name {
  font-weight: 500;
  color: var(--tw-ed-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  font-size: 0.9375em;
}

.tw-ed-browser--grid .tw-ed-item__name {
  white-space: normal;
  word-break: break-word;
  font-size: 0.875em;
}

.tw-ed-item__desc {
  font-size: 0.8em;
  color: var(--tw-ed-secondary);
  margin: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.tw-ed-item__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75em;
  color: var(--tw-ed-muted);
  margin-top: 1px;
}

.tw-ed-browser--grid .tw-ed-item__meta {
  justify-content: center;
  flex-wrap: wrap;
}

.tw-ed-item__size,
.tw-ed-item__dl-count,
.tw-ed-item__date {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}

.tw-ed-item__dl-count svg,
.tw-ed-item__size svg {
  fill: currentColor;
  opacity: 0.7;
}

/* Séparateurs entre méta (·) */
.tw-ed-item__size + .tw-ed-item__date::before,
.tw-ed-item__size + .tw-ed-item__dl-count::before,
.tw-ed-item__dl-count + .tw-ed-item__date::before {
  content: '·';
  margin-right: 2px;
  opacity: 0.5;
}

/* Badge "lien externe" */
.tw-ed-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.7em;
  font-weight: 600;
  flex-shrink: 0;
}

.tw-ed-badge--link {
  background: color-mix(in srgb, var(--tw-ed-accent) 12%, transparent);
  color: var(--tw-ed-accent);
}

.tw-ed-badge--link svg {
  fill: currentColor;
}

/* ============================================================
   Bouton de téléchargement / lien externe
   ============================================================ */
.tw-ed-item__action {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  margin-left: auto;
}

.tw-ed-btn-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--tw-ed-primary);
  color: #fff;
  text-decoration: none;
  transition: background 0.18s, box-shadow 0.18s, transform 0.12s;
  flex-shrink: 0;
}

.tw-ed-btn-download:hover {
  color: #fff;
}

.tw-ed-btn-download svg {
  fill: currentColor;
  display: block;
}

.tw-ed-browser--grid .tw-ed-btn-download {
  width: 40px;
  height: 40px;
  margin-top: 4px;
}

/* ============================================================
   État vide
   ============================================================ */
.tw-ed-empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--tw-ed-muted);
  font-size: 0.9em;
}

/* ============================================================
   Messages d'état (notice / erreur)
   ============================================================ */
.tw-ed-notice,
.tw-ed-error {
  padding: 12px 16px;
  border-radius: var(--tw-ed-radius);
  font-size: var(--tw-ed-font-size);
  margin: 0;
}

.tw-ed-notice {
  background: color-mix(in srgb, var(--tw-ed-primary) 8%, transparent);
  border-left: 3px solid var(--tw-ed-primary);
  color: var(--tw-ed-primary);
}

.tw-ed-error {
  background: #fef2f2;
  border-left: 3px solid #fca5a5;
  color: #dc2626;
}

.tw-ed-notice a {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 680px) {
  .tw-ed-browser--grid .tw-ed-items {
    grid-template-columns: repeat(2, 1fr);
  }

  .tw-ed-item__meta {
    gap: 6px;
  }

  .tw-ed-breadcrumb {
    padding: 8px 12px;
  }
}

@media (max-width: 400px) {
  .tw-ed-browser--grid .tw-ed-items {
    grid-template-columns: 1fr;
  }

  .tw-ed-item {
    padding: 10px 12px;
  }
}

/* ============================================================
   Thème : Corporate
   Fond gris clair, icônes dossier bleu marine, bouton discret
   ============================================================ */

/* Redéfinition des variables de base pour le thème Corporate.
   Les valeurs exactes (couleurs, radius) viennent des réglages via :root,
   la classe ajoute les différences structurelles. */
.tw-ed-browser--theme-corporate {
  --tw-ed-shadow: 0 1px 4px rgba(0, 0, 0, 0.07), 0 2px 8px rgba(0, 0, 0, 0.04);
}

/* Dossiers : icône bleu marine (primary) au lieu de jaune */
.tw-ed-browser--theme-corporate .tw-ed-item--folder .tw-ed-item__icon svg {
  fill: var(--tw-ed-primary);
}

/* Bouton de téléchargement : contour discret au lieu du cercle plein */
.tw-ed-browser--theme-corporate .tw-ed-btn-download {
  background: transparent;
  border: 1.5px solid var(--tw-ed-border);
  color: var(--tw-ed-primary);
  border-radius: var(--tw-ed-radius-sm);
  width: 30px;
  height: 30px;
  box-shadow: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tw-ed-browser--theme-corporate .tw-ed-btn-download svg {
  fill: currentColor;
}

.tw-ed-browser--theme-corporate .tw-ed-item--document:hover .tw-ed-btn-download {
  background: var(--tw-ed-primary);
  border-color: var(--tw-ed-primary);
  color: #fff;
  box-shadow: none;
  transform: none;
}

/* Items légèrement plus compacts */
.tw-ed-browser--theme-corporate .tw-ed-item {
  padding: 9px 14px;
  gap: 10px;
}

/* Nom du document : pas de gras marqué, style plus sobre */
.tw-ed-browser--theme-corporate .tw-ed-item__name {
  font-weight: 400;
}

.tw-ed-browser--theme-corporate .tw-ed-item--folder .tw-ed-item__name {
  font-weight: 500;
}

/* Fil d'Ariane (breadcrumb) légèrement adapté */
.tw-ed-browser--theme-corporate .tw-ed-breadcrumb {
  background: var(--tw-ed-bg);
  border-bottom: 1.5px solid var(--tw-ed-border);
  font-size: 0.78em;
  letter-spacing: 0.01em;
}

/* ============================================================
   Print
   ============================================================ */
@media print {
  .tw-ed-btn-download,
  .tw-ed-breadcrumb {
    display: none;
  }

  .tw-ed-browser {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}
