/* ========== Responsive utilities ========== */
.hidden-mobile { display: block; }
.hidden-desktop { display: none; }

@media (max-width: 640px) {
  .hidden-mobile { display: none !important; }
  .hidden-desktop { display: block; }
}

/* ========== Mobile layout ========== */
@media (max-width: 640px) {
  .sidebar {
    display: none !important;
  }

  .page-wrapper {
    margin-left: 0;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  .page-wrapper--dashboard {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  .main {
    padding: var(--space-4) var(--space-4) var(--space-6);
  }

  .main__header {
    margin-bottom: var(--space-6);
  }

  .main__actions .btn--primary:not(.btn--block) {
    display: none;
  }

  /* Touch targets 44px minimum */
  .btn,
  .bottom-nav-item,
  .table-action,
  .table-action-icon,
  .client-tab,
  .segmented-control__btn,
  .filter-bar .btn {
    min-height: 44px;
    min-width: 44px;
  }

  .input,
  .select,
  .textarea {
    font-size: 16px;
    padding: 14px var(--space-4);
  }

  .radio-group label {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: var(--space-2) 0;
  }
}

/* ========== Bottom navigation ========== */
.bottom-nav {
  display: none;
}

@media (max-width: 640px) {
  .bottom-nav {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--bg-card);
    border-top: 1px solid var(--border-subtle);
    padding: var(--space-2) var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25);
  }

  body.page-wizard .bottom-nav,
  body.no-bottom-nav .bottom-nav {
    display: none;
  }

  body.page-wizard .page-wrapper,
  body.no-bottom-nav .page-wrapper {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  max-width: 72px;
  padding: var(--space-2) var(--space-1);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  min-height: 44px;
}

.bottom-nav-item svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.5;
}

.bottom-nav-item.active,
.bottom-nav-item--active {
  color: var(--accent);
}

.bottom-nav-fab {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  max-width: none;
  margin-top: -20px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--text-inverse);
  box-shadow: 0 4px 16px var(--accent-glow), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.bottom-nav-fab svg {
  width: 28px;
  height: 28px;
  stroke: var(--text-inverse);
}

.bottom-nav-fab span {
  display: none;
}

/* Bottom sheet */
.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
}

.bottom-sheet-content {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-4) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-accent);
}

.bottom-sheet-content a,
.bottom-sheet-content button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: var(--space-3) var(--space-4);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  text-align: left;
}

.bottom-sheet-content a:last-child,
.bottom-sheet-content button:last-child {
  border-bottom: none;
}

.bottom-sheet-content a.danger,
.bottom-sheet-content button.danger {
  color: var(--danger);
}

.bottom-sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 0 auto var(--space-4);
}

/* ========== List cards (mobile) ========== */
.list-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.list-card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}

.list-card:active {
  border-color: var(--accent);
}

.list-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.list-card-header strong {
  font-size: 15px;
  color: var(--text-primary);
}

.list-card-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: 13px;
  color: var(--text-secondary);
}

.list-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
  font-size: 12px;
  color: var(--text-muted);
}

.list-card-footer strong {
  color: var(--accent);
  font-size: 14px;
}

/* ========== Wizard mobile ========== */
@media (max-width: 640px) {
  body.page-wizard .sidebar {
    display: none;
  }

  body.page-wizard .page-wrapper {
    margin-left: 0;
  }

  body.page-wizard .main {
    padding-top: calc(56px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  .wizard-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 150;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-subtle);
    padding: var(--space-3) var(--space-4);
    padding-top: calc(var(--space-3) + env(safe-area-inset-top, 0px));
  }

  .wizard-progress__steps {
    display: flex;
    gap: var(--space-1);
    margin-bottom: var(--space-2);
  }

  .wizard-progress__step {
    flex: 1;
    height: 3px;
    background: var(--border-subtle);
    border-radius: 2px;
    transition: background 0.2s;
  }

  .wizard-progress__step--active,
  .wizard-progress__step--done {
    background: var(--accent);
  }

  .wizard-progress__label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
  }

  .wizard-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 160;
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
    background: var(--bg-card);
    border-top: 1px solid var(--border-subtle);
  }

  .wizard-nav .btn {
    flex: 1;
  }

  .wizard-step-panel {
    min-height: calc(100vh - 140px);
  }
}

/* ========== Devis detail mobile ========== */
@media (max-width: 640px) {
  body.page-devis-detail .page-wrapper {
    flex-direction: column;
  }

  body.page-devis-detail .panel-aside {
    display: block;
    position: static;
    width: 100%;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    order: 2;
    padding: var(--space-5) var(--space-4);
  }

  body.page-devis-detail .main {
    order: 1;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  .mobile-fab-save {
    display: flex;
    position: fixed;
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    left: var(--space-4);
    right: var(--space-4);
    z-index: 140;
  }

  .mobile-fab-save .btn {
    flex: 1;
    min-height: 48px;
  }
}

@media (min-width: 641px) {
  .mobile-fab-save,
  .wizard-progress,
  .wizard-nav {
    display: none !important;
  }
}

/* ========== Client detail mobile ========== */
@media (max-width: 640px) {
  .client-detail-grid {
    grid-template-columns: 1fr;
  }

  .client-detail-aside {
    order: -1;
    flex-direction: row;
    overflow-x: auto;
    gap: var(--space-3);
    padding-bottom: var(--space-2);
    -webkit-overflow-scrolling: touch;
  }

  .client-detail-aside .client-stat-card {
    flex: 0 0 160px;
    min-width: 160px;
  }

  .client-detail-sidebar-cta {
    display: none;
  }

  .client-mobile-cta {
    display: flex;
    position: fixed;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    left: var(--space-4);
    right: var(--space-4);
    z-index: 140;
  }

  .client-mobile-cta .btn {
    flex: 1;
    min-height: 48px;
  }

  .client-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .client-tab {
    flex-shrink: 0;
    white-space: nowrap;
  }
}

@media (min-width: 641px) {
  .client-mobile-cta {
    display: none;
  }
}

/* ========== Dashboard mobile ========== */
@media (max-width: 640px) {
  .dashboard-kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
  }

  .dashboard-kpi-card {
    min-height: 110px;
    padding: var(--space-4);
  }

  .dashboard-kpi-card__value {
    font-size: 24px;
  }

  .dashboard-charts-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-funnel__bar {
    height: 36px;
  }

  .dashboard-funnel__legend {
    grid-template-columns: repeat(2, 1fr);
  }

  .dashboard-section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .dashboard-relances-table {
    font-size: 12px;
  }
}

/* ========== Install prompt ========== */
.install-prompt {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  left: var(--space-4);
  right: var(--space-4);
  z-index: 190;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-card);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

body.page-wizard .install-prompt,
body.no-bottom-nav .install-prompt {
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
}

.install-prompt-icon img,
.install-prompt-icon svg {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.install-prompt-text {
  flex: 1;
  min-width: 0;
}

.install-prompt-text strong {
  display: block;
  font-size: 13px;
  color: var(--text-primary);
}

.install-prompt-text span {
  font-size: 11px;
  color: var(--text-muted);
}

.install-prompt-ios {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  padding: var(--space-2);
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

@media (min-width: 641px) {
  .install-prompt {
    bottom: var(--space-4);
    max-width: 420px;
    left: auto;
    right: var(--space-4);
  }
}
