/*
 * layout.css - Structure de la page : barre du haut, accueil, liste, fiche.
 */

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
}

/* ------------------------------------------------------------ Barre du haut */

.topbar {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr minmax(220px, 540px) 1fr;
  align-items: center;
  gap: 20px;
  padding: 0 18px 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--on-accent);
  background: linear-gradient(150deg, color-mix(in srgb, var(--accent) 82%, #fff), var(--accent));
  border-radius: 10px;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgb(255 255 255 / .18);
}

.brand-mark .icon { width: 19px; height: 19px; }

.brand-name {
  font: 600 17px/1 var(--font-display);
  letter-spacing: -.01em;
  white-space: nowrap;
}

.brand-name span { color: var(--text-3); font-weight: 500; }

.search {
  position: relative;
  display: flex;
  align-items: center;
  height: 38px;
  color: var(--text-3);
  background: var(--surface-3);
  border: 1px solid transparent;
  border-radius: 10px;
  transition: background-color .15s, border-color .15s, box-shadow .15s;
}

.search:focus-within { background: var(--surface); border-color: var(--accent); box-shadow: var(--ring); }
.search .icon { position: absolute; left: 12px; pointer-events: none; }

.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 44px 0 38px;
  background: none;
  border: 0;
  outline: none;
  color: var(--text);
}

.search input::-webkit-search-cancel-button { display: none; }
.search kbd { position: absolute; right: 10px; pointer-events: none; }
.search:focus-within kbd, .search.has-value kbd { display: none; }

.search-clear {
  position: absolute;
  right: 6px;
  width: 28px;
  height: 28px;
}

.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }

/* Separateur entre les actions et le groupe raccourcis + theme (comme Assemble Images) :
   10 px de chaque cote (6 px d'ecart + 4 px de marge). */
.topbar-sep {
  flex: none;
  width: 1px;
  height: 20px;
  margin: 0 4px;
  background: var(--border);
}

.dirty-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-right: 6px;
  padding: 4px 10px 4px 9px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: 99px;
  white-space: nowrap;
  animation: fade-in .3s;
}

.dirty-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  background: currentColor;
  border-radius: 50%;
}

/* ------------------------------------------------------------------ Accueil */

.welcome {
  display: grid;
  place-items: center;
  padding: 32px 20px 48px;
  overflow-y: auto;
  background:
    radial-gradient(1100px 520px at 50% -10%, var(--accent-softer), transparent 70%),
    var(--bg);
}

.welcome-inner {
  width: min(640px, 100%);
  text-align: center;
  animation: slide-up .5s var(--ease);
}

.welcome h1 {
  font: 500 clamp(30px, 4.4vw, 44px)/1.12 var(--font-serif);
  letter-spacing: -.015em;
}

.welcome h1 em { font-style: italic; color: var(--accent); }

.welcome .lead {
  max-width: 470px;
  margin: 14px auto 30px;
  font-size: 16px;
  color: var(--text-2);
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 38px 24px 34px;
  background: var(--surface);
  border: 1.5px dashed var(--border-strong);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  transition: border-color .2s, background-color .2s, box-shadow .2s, transform .2s var(--ease);
}

.dropzone:hover, .dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-softer);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.dropzone-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 10px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 16px;
}

.dropzone-icon .icon { width: 26px; height: 26px; }
.dropzone-title { font-size: 17px; font-weight: 600; }
.dropzone-sub { font-size: 14px; color: var(--text-3); }

.welcome-actions { display: flex; justify-content: center; gap: 10px; margin-top: 18px; }

.welcome-features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 40px;
  text-align: left;
}

.welcome-features li {
  display: flex;
  gap: 10px;
  padding: 14px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-2);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.welcome-features .icon { margin-top: 1px; color: var(--accent); }

/* ------------------------------------------------------------ Espace de travail */

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  min-height: 0;
}

/* Liste */

.list-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.list-head {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.filters { display: flex; flex-wrap: wrap; gap: 5px; }

.list-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-3);
}

.list-count { margin-right: auto; font-weight: 600; color: var(--text-2); }

.select-sm {
  height: 28px;
  padding: 0 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  background-color: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  max-width: 150px;
  text-overflow: ellipsis;
}

.select-sm:hover { background-color: var(--surface-3); }
.select-sm:focus-visible { outline: none; box-shadow: var(--ring); }

.list-body { position: relative; flex: 1; min-height: 0; overflow: hidden; }

.contact-list {
  height: 100%;
  overflow-y: auto;
  outline: none;
  overscroll-behavior: contain;
}

/* Liste virtualisée : app.js positionne chaque ligne (hauteurs fixes, voir ROW_H). */
.list-canvas { position: relative; }
.list-row { position: absolute; left: 8px; right: 8px; }
.has-rail .list-row { right: 26px; }

/* En-tête de section collé en haut de la liste */
.list-sticky {
  position: absolute;
  top: 0;
  left: 8px;
  right: 14px;
  z-index: 2;
  pointer-events: none;
}

.has-rail .list-sticky { right: 26px; }
.list-sticky .btn { pointer-events: auto; }

.list-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  color: var(--text-3);
}

.list-empty strong { color: var(--text-2); font-weight: 600; }

/* Fiche */

.detail-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
}

/* ---------------------------------------------------------------- Responsive */

@media (max-width: 1080px) {
  .brand-name { display: none; }
  .topbar { grid-template-columns: auto minmax(160px, 1fr) auto; gap: 14px; }
  .topbar-actions .btn-label { display: none; }
  .topbar-actions .btn:not(.btn-icon) { padding: 0 10px; }
}

@media (max-width: 820px) {
  .topbar { padding: 0 10px 0 12px; gap: 10px; }
  .search kbd, .dirty-badge { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .list-pane { border-right: 0; }
  .detail-pane {
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    z-index: 15;
    background: var(--bg);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform .28s var(--ease), visibility 0s .28s;
  }
  .app.show-detail .detail-pane {
    transform: none;
    visibility: visible;
    transition: transform .28s var(--ease);
  }
  .welcome-features { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; } /* recherche sans largeur minimale */
  .topbar-actions { gap: 2px; }
}

/* ---------------------------------------------- Menu Barbatools et menu etroit
   Grand ecran : icone Barbatools tout a droite de la barre (menu des autres
   outils). Ecran etroit (seuil ci-dessous, choisi par mesure) : l'icone, les
   raccourcis et le theme quittent la barre (le + de Nouveau reste, juste a
   droite de la recherche) ; un chevron a cote du logo ouvre un menu avec le
   theme et les raccourcis, puis Barbatools et les autres outils. */

.brand-menu {
  display: none;
  place-items: center;
  flex: none;
  width: 22px;
  height: 34px;
  margin-left: -8px;
  padding: 0;
  color: var(--text-3);
  background: none;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.brand-menu:hover { color: var(--text); background: var(--surface-3); }
.brand-menu .icon { width: 16px; height: 16px; }

/* .menu.app-menu : remplace la position du menu d'export par celle d'un popover
   fixe sous la barre, a gauche */
.menu.app-menu {
  position: fixed;
  inset: auto;
  top: calc(var(--topbar-h) + 4px);
  left: 8px;
  margin: 0;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - var(--topbar-h) - 16px);
  overflow: auto;
  color: var(--text);
}

.menu.app-menu::backdrop { background: transparent; }
.menu.app-menu button { min-height: 40px; color: inherit; }
.app-menu-check { margin-left: auto; visibility: hidden; }
.menu.app-menu [aria-checked="true"] .app-menu-check { visibility: visible; color: var(--accent); }

@media (max-width: 520px) {
  .barba-desktop, #btn-help, #btn-theme, .topbar-sep { display: none; }
  .brand-menu { display: grid; }
  #btn-new { order: -1; } /* le + juste a droite de la recherche, avant Ouvrir */
  /* Raccourci "/" masque : marge droite minimale ; la place du bouton d'effacement
     (28 px a 6 px du bord) n'est reservee que quand il est affiche (texte saisi) */
  .search input { padding-right: 10px; }
  .search.has-value input { padding-right: 36px; }
}

@media (min-width: 521px) {
  .menu.app-menu { display: none; }
}
