/* =====================================================================
   Aximetra — APP SHELL
   Barre latérale (source, navigation, filtres) + espace résultats.
   Chargé après styles.css : surcharge les anciennes règles d'en-tête
   et de panneaux empilés.
   ===================================================================== */
:root {
  --sidebar-w: 304px;
  --topbar-h: 60px;
}

body {
  display: block;
  min-height: 100vh;
  min-height: 100dvh;
}

.ico {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- Barre latérale ---------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 60;
  outline: none;
}

.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  height: var(--topbar-h);
  padding: 0 1.1rem;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand {
  gap: 0.7rem;
  min-width: 0;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  box-shadow: inset 0 -2px 0 var(--gold);
  flex: 0 0 auto;
}

.brand__text h1 {
  font-size: 1.08rem;
  line-height: 1.15;
}

.brand__text .subtitle {
  margin: 0;
  font-size: 0.74rem;
  line-height: 1.3;
  white-space: nowrap;
}

.sidebar__scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.4rem 0 1.25rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.side-section {
  padding: 0.9rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.side-section + .side-section {
  border-top: 1px solid var(--border);
}

.side-section__title {
  margin: 0;
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.side-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.side-block {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.side-block + .side-block {
  padding-top: 0.15rem;
}

.side-block.is-offscope,
.side-block.is-empty {
  display: none !important;
}

.side-empty {
  margin: 0;
  padding: 0.75rem 0.85rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  font-size: 0.8rem;
  color: var(--ink-muted);
  background: var(--surface-2);
}

.side-empty[hidden] {
  display: none;
}

/* Source / import, version compacte */
.upload-panel {
  padding: 0.9rem 1.1rem;
  overflow: visible;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.import-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.2rem;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-3);
}

.import-tab {
  margin: 0;
  padding: 0.42rem 0.5rem;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
}

.import-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}

.import-method {
  padding: 0;
}

.dropzone {
  flex-direction: column;
  align-items: stretch;
  gap: 0.7rem;
  padding: 0.95rem;
  border-style: dashed;
  border-radius: var(--r-md);
  text-align: center;
}

.dropzone__icon {
  width: 26px;
  height: 26px;
  margin: 0 auto;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dropzone__copy {
  margin: 0;
  align-items: center;
}

.dropzone__title {
  font-size: 0.86rem;
}

.dropzone__hint {
  font-size: 0.72rem;
}

.upload-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
}

.file-input,
.upload-controls .ghost-button,
.url-input-group .primary-button {
  justify-content: center;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  border-radius: var(--r-sm);
}

.upload-controls .ghost-button {
  padding-inline: 0.65rem;
}

.file-input:hover,
.primary-button:hover,
.ghost-button:hover {
  transform: none;
}

.url-input-group {
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
}

.sheets-url-input {
  min-width: 0;
  padding: 0.55rem 0.7rem;
  font-size: 0.84rem;
  border-radius: var(--r-sm);
}

.sheets-help {
  font-size: 0.74rem;
}

.feedback {
  margin: 0;
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-picker {
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}

.sheet-picker select,
.year-filter-select {
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  font-size: 0.84rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
}

/* Navigation verticale */
.view-tabs {
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 0.15rem;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.tab-button {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.58rem 0.7rem;
  border-radius: var(--r-sm);
  text-align: left;
  font-size: 0.87rem;
  color: var(--ink-soft);
}

.tab-button .ico {
  color: var(--ink-faint);
}

.tab-button:hover .ico {
  color: var(--accent);
}

.tab-button.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: inset 3px 0 0 var(--accent);
}

.tab-button.active .ico {
  color: var(--accent);
}

/* Filtres en colonne */
.year-filter-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
  border-radius: 0;
}

.filter-panel {
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  box-shadow: none;
  border-radius: 0;
  gap: 0.45rem;
}

.filter-header {
  flex-wrap: nowrap;
  gap: 0.5rem;
}

.filter-actions {
  gap: 0.15rem;
  margin-left: auto;
}

.link-button {
  border: none;
  background: none;
  padding: 0.15rem 0.35rem;
  border-radius: var(--r-xs);
  font: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--accent-bright);
  cursor: pointer;
}

.link-button:hover {
  background: var(--accent-softer);
  color: var(--accent-strong);
}

.filter-list {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  max-height: 260px;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}

.filter-option {
  align-items: flex-start;
  padding: 0.38rem 0.45rem;
  background: none;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--ink-muted);
}

.filter-option:hover {
  background: var(--surface);
  border-color: transparent;
}

.filter-option input {
  width: 15px;
  height: 15px;
  margin: 0.08rem 0 0;
  flex: 0 0 auto;
}

.filter-option:has(input:checked) {
  color: var(--ink);
}

.filters-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border-radius: var(--r-sm);
  font-size: 0.8rem;
}

.filters-toggle__chev {
  width: 16px;
  height: 16px;
  transition: transform 0.18s ease;
}

.filters-toggle.is-open .filters-toggle__chev {
  transform: rotate(180deg);
}

.display-limit {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
}

.display-limit__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.display-limit__range {
  width: 100%;
}

.display-limit__value {
  min-width: 2.4rem;
  font-size: 0.78rem;
  padding: 0.12rem 0.45rem;
}

.display-limit__all {
  padding-left: 0;
  border-left: none;
  font-size: 0.8rem;
}

/* Pied de barre latérale : compte */
.sidebar__foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  padding: 0.7rem 1.1rem;
}

.sidebar__foot:not(:has(.user-chip:not([hidden]))) {
  display: none;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
}

.user-chip__avatar {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  flex: 0 0 auto;
}

.user-chip__avatar::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: var(--r-pill);
  background: var(--accent);
  opacity: 0.55;
}

.user-chip__info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  min-width: 0;
  flex: 1 1 auto;
}

.user-chip__email {
  max-width: 100%;
  font-size: 0.78rem;
  color: var(--ink);
}

.user-chip__actions {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.user-chip__admin,
.user-chip__logout {
  text-align: center;
  font-size: 0.7rem;
  padding: 0.22rem 0.5rem;
}

/* ---------- Espace de travail ---------- */
.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.app-header {
  height: var(--topbar-h);
  background: rgba(245, 243, 236, 0.86);
}

.app-header__inner {
  width: 100%;
  max-width: none;
  height: 100%;
  margin: 0;
  padding: 0 clamp(1rem, 2.4vw, 2rem);
  flex-wrap: nowrap;
  gap: 0.75rem;
}

.topbar-title {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0;
  margin-right: auto;
}

.topbar-title__brand {
  display: none;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
}

.topbar-title__view {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-right {
  flex-wrap: nowrap;
  min-width: 0;
}

.header-status {
  gap: 0.45rem;
  max-width: 340px;
  border-radius: var(--r-pill);
  padding: 0.35rem 0.8rem;
  font-size: 0.76rem;
  overflow: hidden;
}

.header-status #header-status-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-status__dot {
  width: 7px;
  height: 7px;
  border-radius: var(--r-pill);
  background: var(--border-strong);
  flex: 0 0 auto;
}

.header-status.is-live .header-status__dot {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.menu-button,
.icon-button {
  display: none;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--r-sm);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.menu-button {
  position: relative;
  padding: 0.45rem 0.7rem;
  flex: 0 0 auto;
}

.menu-button__badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  line-height: 18px;
  text-align: center;
}

.icon-button {
  width: 36px;
  height: 36px;
  justify-content: center;
  padding: 0;
  flex: 0 0 auto;
}

main {
  width: 100%;
  max-width: 1600px;
  margin: 0;
  padding: clamp(1rem, 2.4vw, 1.75rem) clamp(1rem, 2.4vw, 2rem) 3rem;
  gap: 1rem;
}

.status-area {
  margin: 0;
}

/* En-tête de vue : titre + export sur une ligne */
.view-toolbar {
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 1.1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.view-heading {
  min-width: 0;
}

.view-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2vw, 1.55rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.view-sub {
  margin: 0.2rem 0 0;
  font-size: 0.86rem;
  color: var(--ink-muted);
}

.export-button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.9rem;
  border-radius: var(--r-sm);
  font-size: 0.84rem;
  background: var(--accent);
  color: #fff;
}

.export-button:hover {
  background: var(--accent-strong);
  transform: none;
}

.export-button .ico {
  width: 16px;
  height: 16px;
}

.cards-grid {
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
}

.card {
  border-radius: var(--r-md);
  padding: 1.15rem 1.2rem;
}

.insertion-compare-note summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
}

.insertion-compare-note p {
  margin: 0.5rem 0 0.2rem;
}

.app-footer {
  display: none;
}

/* ---------- État vide ---------- */
.empty-hero {
  display: grid;
  place-items: center;
  min-height: calc(100vh - var(--topbar-h) - 6rem);
  min-height: calc(100dvh - var(--topbar-h) - 6rem);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-xl);
  background:
    radial-gradient(circle at 50% 0%, var(--accent-softer), transparent 60%),
    var(--surface-2);
  padding: 2rem 1.25rem;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.empty-hero__card {
  max-width: 520px;
  text-align: center;
}

.empty-hero__icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 1.1rem;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.empty-hero__icon svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
  stroke-linejoin: round;
}

.empty-hero h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 2.6vw, 1.7rem);
  font-weight: 600;
  letter-spacing: -0.015em;
}

.empty-hero p {
  margin: 0.6rem 0 0;
  color: var(--ink-muted);
  font-size: 0.93rem;
  line-height: 1.6;
}

.empty-hero__actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.4rem;
}

.empty-hero__cta {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.empty-hero .empty-hero__hint {
  margin-top: 1rem;
  font-size: 0.78rem;
  color: var(--ink-faint);
}

body.has-data .empty-hero {
  display: none;
}

body:not(.has-data) .view {
  display: none !important;
}

body.is-dragging .empty-hero,
body.is-dragging.has-data main {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
  background-color: var(--accent-softer);
}

.sidebar-backdrop {
  display: none;
}

/* ---------- Tablette & mobile : tiroir ---------- */
@media (max-width: 1023px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    transform: translateX(-102%);
    transition: transform 0.24s ease;
    box-shadow: var(--shadow-lg);
    z-index: 80;
  }

  body.sidebar-open .sidebar {
    transform: none;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(15, 20, 32, 0.38);
    backdrop-filter: blur(2px);
  }

  .sidebar-backdrop[hidden] {
    display: none;
  }

  .menu-button,
  .icon-button {
    display: inline-flex;
  }

  .topbar-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    line-height: 1.15;
  }

  .topbar-title__brand {
    display: block;
    font-size: 0.66rem;
    color: var(--ink-faint);
    font-family: var(--font-body);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .topbar-title__view {
    max-width: 100%;
    font-size: 0.95rem;
  }
}

@media (max-width: 640px) {
  :root {
    --topbar-h: 56px;
  }

  .header-status {
    display: inline-flex;
    max-width: 36vw;
    padding: 0.3rem 0.6rem;
  }

  .view-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.7rem;
  }

  .export-button {
    justify-content: center;
  }

  .view-sub {
    font-size: 0.8rem;
  }

  .card {
    padding: 1rem;
  }

  .empty-hero {
    min-height: calc(100dvh - var(--topbar-h) - 4rem);
  }

  .empty-hero__actions > * {
    width: 100%;
    justify-content: center;
  }

  .empty-hero .empty-hero__hint {
    display: none;
  }

  .menu-button > span:not(.menu-button__badge) {
    display: none;
  }

  .menu-button {
    padding: 0.45rem 0.55rem;
  }
}

@media (max-width: 380px) {
  .header-status {
    display: none;
  }
}

/* PDF : la capture ne doit pas embarquer l'en-tête de vue */
.pdf-capture-root .view-toolbar {
  display: none;
}

/* Une fois le fichier chargé, l'import se réduit à une ligne de boutons
   pour laisser la place aux filtres. */
.file-input span {
  white-space: nowrap;
}

body.has-data .dropzone {
  padding: 0.5rem;
  border-style: solid;
  border-color: var(--border);
}

body.has-data .dropzone__icon,
body.has-data .dropzone__copy {
  display: none;
}

body.has-data .file-input span {
  font-size: 0;
}

body.has-data .file-input span::before {
  content: "Changer de fichier";
  font-size: 0.82rem;
}

@media (max-width: 640px) {
  .summary-banner {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .summary-banner::-webkit-scrollbar {
    display: none;
  }

  .summary-banner .chip {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}

/* Bouton « Rapport complet » (barre supérieure) */
.report-button {
  white-space: nowrap;
  box-shadow: inset 0 -2px 0 var(--gold);
}

body:not(.has-data) .report-button {
  display: none;
}

@media (max-width: 640px) {
  .report-button {
    padding: 0.45rem 0.55rem;
  }

  .report-button span {
    display: none;
  }
}
