/**
 * ProCarte — interface « application native » (PWA installée, TWA, écran d'accueil iPhone).
 * Toutes les règles sont limitées à html.is-app : le site web n'est pas affecté.
 */
[data-app-share][hidden] { display: none !important; }

html.is-app {
  --app-bar-h: 52px;
  --app-tab-h: 58px;
  --app-bg: #0b1120;
  --app-surface: rgba(15, 23, 42, 0.86);
  --app-border: rgba(148, 163, 184, 0.16);
  --app-text: #f1f5f9;
  --app-muted: #94a3b8;
  --app-accent: #3b82f6;
  --app-safe-top: env(safe-area-inset-top, 0px);
  --app-safe-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--app-bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

html.is-app[data-theme="light"] {
  --app-bg: #f1f5f9;
  --app-surface: rgba(255, 255, 255, 0.9);
  --app-border: rgba(15, 23, 42, 0.1);
  --app-text: #0f172a;
  --app-muted: #64748b;
}

html.is-app body {
  padding: 0 !important;
  overscroll-behavior-y: none;
  -webkit-touch-callout: none;
  animation: pcAppEnter 0.24s ease-out both;
}

@keyframes pcAppEnter {
  from { opacity: 0; }
  to { opacity: 1; }
}

html.is-app .web-only,
html.is-app #pcTopbar,
html.is-app #navMenuBackdrop,
html.is-app #navMenu,
html.is-app .chat-fab,
html.is-app .pwa-install-banner,
html.is-app .pwa-ios-hint,
html.is-app .pwa-open-app-bar,
html.is-app .dashboard-page .dashboard-tabs,
html.is-app .dashboard-header [data-procarte-push],
html.is-app .dashboard-actions [data-procarte-push],
html.is-app .dashboard-actions a[href$="index.php"],
html.is-app .chat-back-home {
  display: none !important;
}

html.is-app input,
html.is-app textarea,
html.is-app [contenteditable] {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

/* ——— Écran de démarrage ——— */
html.is-app.pc-splash::before,
html.is-app.pc-splash::after {
  content: "";
  position: fixed;
  z-index: 2147483000;
  pointer-events: none;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
html.is-app.pc-splash::before {
  inset: 0;
  background: radial-gradient(circle at 50% 42%, #1e3a8a 0%, #0b1120 62%);
}
html.is-app.pc-splash::after {
  top: 50%;
  left: 50%;
  width: 112px;
  height: 112px;
  margin: -76px 0 0 -56px;
  border-radius: 26px;
  background: #fff url("../../icons/icon-512.png") center / 150% no-repeat;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  animation: pcSplashPop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
html.is-app.pc-splash.pc-ready::before,
html.is-app.pc-splash.pc-ready::after {
  opacity: 0;
  visibility: hidden;
}
@keyframes pcSplashPop {
  from { transform: scale(0.82); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ——— Barre de titre ——— */
.pc-appbar { display: none; }
html.is-app .pc-appbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10040;
  display: flex;
  align-items: center;
  gap: 6px;
  height: calc(var(--app-bar-h) + var(--app-safe-top));
  padding: var(--app-safe-top) max(8px, env(safe-area-inset-right, 0px)) 0 max(8px, env(safe-area-inset-left, 0px));
  background: var(--app-surface);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--app-border);
  color: var(--app-text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}
.pc-appbar__btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font-size: 1.1rem;
  cursor: pointer;
  text-decoration: none;
}
.pc-appbar__btn:active { background: rgba(148, 163, 184, 0.18); }
.pc-appbar__title {
  flex: 1;
  min-width: 0;
  padding-left: 6px;
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pc-appbar__title small {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--app-muted);
}
.pc-appbar__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
}

/* Réserve l'espace des barres sur les pages de l'appli */
html.is-app body.dashboard-page,
html.is-app body.admin-page,
html.is-app body.pc-has-appbar {
  padding-top: calc(var(--app-bar-h) + var(--app-safe-top)) !important;
}
html.is-app body.dashboard-page,
html.is-app body.admin-page,
html.is-app body.pc-has-tabbar {
  padding-bottom: calc(var(--app-tab-h) + var(--app-safe-bottom) + 16px) !important;
}
html.is-app .dashboard-page .container {
  padding-top: 8px;
}
html.is-app .admin-page .admin-tabs {
  top: calc(var(--app-bar-h) + var(--app-safe-top)) !important;
}
html.is-app .navbar-with-toggle { position: static; }

/* ——— Barre d'onglets ——— */
.pc-tabbar { display: none; }
html.is-app .pc-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10040;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: calc(var(--app-tab-h) + var(--app-safe-bottom));
  padding: 0 max(4px, env(safe-area-inset-right, 0px)) var(--app-safe-bottom) max(4px, env(safe-area-inset-left, 0px));
  background: var(--app-surface);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--app-border);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.22s ease;
}
html.is-app body.pc-tabbar-hidden .pc-tabbar { transform: translateY(110%); }
.pc-tab {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--app-muted);
  font: inherit;
  font-size: 0.66rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}
.pc-tab i {
  font-size: 1.22rem;
  transition: transform 0.18s ease;
}
.pc-tab:active i { transform: scale(0.86); }
.pc-tab.is-active { color: var(--app-accent); }
.pc-tab.is-active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 30%;
  right: 30%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--app-accent);
}
.pc-tab__badge {
  position: absolute;
  top: 6px;
  left: calc(50% + 6px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.64rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border: 2px solid var(--app-bg);
}
.pc-tab__badge[hidden] { display: none; }

/* ——— Feuille « Plus » ——— */
.pc-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10060;
  background: rgba(2, 6, 23, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}
.pc-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10070;
  max-height: 86vh;
  overflow-y: auto;
  padding: 8px 12px calc(16px + var(--app-safe-bottom, 0px));
  border-radius: 22px 22px 0 0;
  background: #0f172a;
  color: #e2e8f0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
  transform: translateY(105%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}
html[data-theme="light"] .pc-sheet { background: #fff; color: #0f172a; }
body.pc-sheet-open .pc-sheet-backdrop { opacity: 1; visibility: visible; }
body.pc-sheet-open .pc-sheet { transform: translateY(0); }
body.pc-sheet-open { overflow: hidden; }
.pc-sheet__handle {
  width: 40px;
  height: 5px;
  margin: 4px auto 12px;
  border-radius: 3px;
  background: rgba(148, 163, 184, 0.45);
}
.pc-sheet__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 14px;
}
.pc-sheet__head strong { display: block; font-size: 1.05rem; }
.pc-sheet__head span { font-size: 0.8rem; color: #94a3b8; }
.pc-sheet__group {
  margin: 0 0 12px;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(148, 163, 184, 0.1);
}
.pc-sheet__item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.98rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.pc-sheet__item:last-child { border-bottom: 0; }
.pc-sheet__item:active { background: rgba(148, 163, 184, 0.16); }
.pc-sheet__item i:first-child {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--pc-ico, #3b82f6);
  color: #fff;
  font-size: 0.9rem;
}
.pc-sheet__item span { flex: 1; }
.pc-sheet__item .pc-sheet__chev { color: #64748b; font-size: 0.8rem; }
.pc-sheet__item--danger { color: #f87171; }
.pc-sheet__foot {
  text-align: center;
  font-size: 0.75rem;
  color: #64748b;
  padding: 6px 0 2px;
}

/* ——— Toast, hors connexion, tirer pour actualiser ——— */
.pc-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--app-tab-h, 58px) + var(--app-safe-bottom, 0px) + 18px);
  z-index: 10080;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.95);
  color: #f8fafc;
  font: 600 0.88rem Inter, system-ui, sans-serif;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, 20px);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.pc-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.pc-offline {
  position: fixed;
  top: calc(var(--app-bar-h, 52px) + var(--app-safe-top, 0px) + 8px);
  left: 50%;
  z-index: 10050;
  padding: 7px 14px;
  border-radius: 999px;
  background: #b45309;
  color: #fff;
  font: 600 0.8rem Inter, system-ui, sans-serif;
  transform: translateX(-50%);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.pc-offline[hidden] { display: none; }

.pc-ptr {
  position: fixed;
  top: calc(var(--app-bar-h, 52px) + var(--app-safe-top, 0px));
  left: 50%;
  z-index: 10035;
  width: 38px;
  height: 38px;
  margin-left: -19px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: #2563eb;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  transform: translateY(-60px);
  opacity: 0;
  pointer-events: none;
}
.pc-ptr.is-ready i { transform: rotate(180deg); }
.pc-ptr i { transition: transform 0.2s ease; }
.pc-ptr.is-loading i { animation: pcSpin 0.8s linear infinite; }
@keyframes pcSpin { to { transform: rotate(360deg); } }

/* ——— Messagerie dans l'appli ——— */
html.is-app body.chat-app { padding: 0 !important; }
html.is-app body.chat-app .chat-shell {
  height: calc(100dvh - var(--app-tab-h) - var(--app-safe-bottom));
  transition: height 0.22s ease;
}
html.is-app body.chat-app.pc-tabbar-hidden .chat-shell { height: 100dvh; }

/* ——— Écran de connexion ——— */
html.is-app body.auth-page {
  min-height: 100dvh;
  padding: calc(24px + var(--app-safe-top)) 16px calc(24px + var(--app-safe-bottom)) !important;
  display: flex;
  align-items: center;
  justify-content: center;
}
html.is-app body.auth-page .auth-container { width: 100%; max-width: 420px; }
html.is-app body.auth-page .auth-card { border-radius: 24px; }
html.is-app body.auth-page .logo-img-auth { max-height: 120px !important; }
html.is-app body.auth-page .auth-form input { font-size: 16px; min-height: 50px; border-radius: 14px; }
html.is-app body.auth-page .btn-login { min-height: 52px; border-radius: 14px; font-size: 1.02rem; }

/* ——— Tableau de bord dans l'appli ——— */
html.is-app .dashboard-page .dashboard-header { padding-top: 4px; margin-bottom: 12px; }
html.is-app .dashboard-page .dashboard-header h2 { font-size: 1.5rem; }
html.is-app .dashboard-page .dashboard-card { animation: pcAppEnter 0.2s ease-out both; }
@media (max-width: 768px) {
  html.is-app .dashboard-page .dashboard-header > div { gap: 10px; }
}
