/*
Theme Name: HITOP-App
Theme URI: https://hitop.fr
Author: Pierre-Jean MARQUET - HITOP
Author URI: https://hitop.fr
Description: Thème WordPress léger à deux styles : « Application » (contenu en cartes, comme une app) ou « Site classique » (en-tête, contenu pleine page, pied de page). Compatible avec le plugin HITOP-RDV.
Version: 1.11.0
Requires at least: 6.0
Tested up to: 6.8
Requires PHP: 8.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: hitop-app
*/

:root {
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --bg: #f4f5fb;
  --surface: #ffffff;
  --ink: #141626;
  --muted: #5d6178;
  --line: #e3e5f0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 22, 38, .06), 0 8px 24px rgba(20, 22, 38, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Cartes de contenu : toujours claires, car les plugins (dont HITOP-RDV) sont conçus pour un fond clair. */
:root {
  --card: #ffffff;
  --card-ink: #141626;
  --card-line: #e3e5f0;
  --card-muted: #5d6178;
}

/* Mode sombre : réglage « Sombre », ou « Automatique » si l'appareil est en mode sombre. */
:root[data-hitop-scheme="dark"] {
  --bg: #0e1020;
  --surface: #171a2e;
  --ink: #eceefb;
  --muted: #9aa0c0;
  --line: #272b47;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}
@media (prefers-color-scheme: dark) {
  :root[data-hitop-scheme="auto"] {
    --bg: #0e1020;
    --surface: #171a2e;
    --ink: #eceefb;
    --muted: #9aa0c0;
    --line: #272b47;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

a { color: var(--accent); }
img { max-width: 100%; height: auto; }

/* ---------- Barre d'application ---------- */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -.01em;
}

.app-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #ec4899));
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 800;
}

.app-nav { margin-left: auto; }
.app-nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; flex-wrap: wrap; }
.app-nav a {
  display: block;
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}
.app-nav a:hover,
.app-nav .current-menu-item > a { background: var(--bg); color: var(--ink); }

/* ---------- Contenu ---------- */
.app-main {
  max-width: var(--content-w, 1040px);
  margin: 0 auto;
  padding: 28px 20px 56px;
}

.app-head h1 {
  margin: 0 0 4px;
  font-size: clamp(1.5rem, 3.4vw, 2.1rem);
  letter-spacing: -.02em;
  line-height: 1.2;
}
.app-head p { margin: 0; color: var(--muted); }
.archive-description { margin-top: 8px; max-width: 70ch; }
.archive-description p { margin: 0 0 8px; color: var(--muted); }
.archive-description p:last-child { margin-bottom: 0; }
body.style-classic .archive-description p { color: var(--card-muted); }

/* Contenu (pages, articles) */
.entry { background: var(--card); color: var(--card-ink); border: 1px solid var(--card-line); border-radius: var(--radius); padding: clamp(16px, 3vw, 30px); box-shadow: var(--shadow); margin-bottom: 18px; }
.entry-title { margin: 0 0 6px; letter-spacing: -.02em; line-height: 1.25; }
.entry-title a { color: inherit; text-decoration: none; }
.entry-meta { margin: 0 0 14px; font-size: 13px; color: var(--card-muted); }
.entry-meta a { color: inherit; text-decoration: underline; }
.entry-more { margin: 10px 0 0; font-weight: 600; }
.entry-more a { color: var(--accent); }
.post-navigation { margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--card-line); }
.post-navigation .nav-links { justify-content: space-between; }
.post-navigation .nav-links a { background: transparent; color: var(--card-ink); border-color: var(--card-line); }
.entry-content > :first-child { margin-top: 0; }
.entry-content > :last-child { margin-bottom: 0; }
.app-logo-img { width: 32px; height: 32px; object-fit: contain; border-radius: 8px; }
.nav-links { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 0; }
.nav-links a, .nav-links span { padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); text-decoration: none; }
.nav-links .current { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.alignwide, .alignfull { max-width: 100%; }
.wp-caption { max-width: 100%; }

/* Image mise en avant dans les listes d'articles */
.entry-thumb { display: block; flex: 0 0 auto; max-width: 100%; }
.entry-thumb-img { display: block; width: var(--thumb-w, 300px); max-width: 100%; height: auto; aspect-ratio: var(--thumb-ratio, 1 / 1); object-fit: cover; border-radius: 10px; }
.entry.has-thumb.thumb-top .entry-thumb { margin-bottom: 14px; }
.entry.has-thumb.thumb-left { display: flex; align-items: flex-start; gap: 18px; }
.entry.has-thumb.thumb-left .entry-thumb { max-width: 45%; }
.entry-body { min-width: 0; flex: 1 1 auto; }
@media (max-width: 640px) {
  .entry.has-thumb.thumb-left { flex-direction: column; gap: 0; }
  .entry.has-thumb.thumb-left .entry-thumb { max-width: 100%; margin-bottom: 14px; }
}

.app-footer { max-width: var(--content-w, 1040px); margin: 0 auto; padding: 8px 20px 32px; text-align: center; font-size: 13px; color: var(--muted); }
.app-footer p { margin: 0 0 6px; }
.app-footer-text > :last-child { margin-bottom: 0; }
.app-footer-nav ul { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; }
.app-footer-nav a { color: var(--muted); text-decoration: none; }
.app-footer-nav a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- Mode application mobile (activé dans Personnaliser) ---------- */
body.hitop-app-mobile {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
body.hitop-app-mobile input,
body.hitop-app-mobile select,
body.hitop-app-mobile textarea { font-size: 16px; } /* évite le zoom automatique sur iOS */
body.hitop-app-mobile button,
body.hitop-app-mobile input[type="submit"],
body.hitop-app-mobile .button { min-height: 44px; }

.app-tabbar, .app-install { display: none; }

@media (max-width: 640px) {
  body.hitop-app-mobile .app-main { padding: 12px 0 calc(24px + env(safe-area-inset-bottom)); }
  body.hitop-app-mobile.has-app-tabbar .app-main { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  body.hitop-app-mobile .app-head { padding: 0 14px; }
  body.hitop-app-mobile .entry { border-radius: 0; border-left: 0; border-right: 0; box-shadow: none; margin-bottom: 10px; }

  body.hitop-app-mobile .app-tabbar {
    display: block;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .app-tabbar ul { list-style: none; margin: 0; padding: 0; display: flex; }
  .app-tabbar li { flex: 1; min-width: 0; }
  .app-tabbar li:nth-child(n+6) { display: none; } /* 5 onglets maximum */
  .app-tabbar a {
    display: flex; align-items: center; justify-content: center;
    min-height: 56px; padding: 6px 4px;
    font-size: 12px; font-weight: 600; text-align: center;
    color: var(--muted); text-decoration: none;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .app-tabbar .current-menu-item > a,
  .app-tabbar .current_page_item > a { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

  body.hitop-app-mobile .app-install {
    display: flex;
    align-items: center;
    gap: 10px;
    position: fixed;
    left: 12px; right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 70;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  body.hitop-app-mobile.has-app-tabbar .app-install { bottom: calc(68px + env(safe-area-inset-bottom)); }
  body.hitop-app-mobile .app-install[hidden] { display: none; }
  .app-install-text { flex: 1; font-size: 13px; line-height: 1.35; }
  .app-install-text b { display: block; font-size: 14px; }
  .app-install-text span { color: var(--muted); }
  .app-install-go {
    border: 0; border-radius: 10px; padding: 0 14px;
    background: var(--accent); color: var(--accent-ink); font-weight: 600;
  }
  .app-install-close {
    border: 0; background: transparent; color: var(--muted);
    font-size: 24px; line-height: 1; width: 36px;
  }
}

/* Commentaires */
.comments-area { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--card-line); }
.comments-title { font-size: 1.1rem; margin: 0 0 14px; }
.comment-list { list-style: none; margin: 0 0 20px; padding: 0; }
.comment-list .children { list-style: none; margin: 0; padding-left: 20px; }
.comment-body { padding: 12px 0; border-bottom: 1px solid var(--card-line); }
.comment-meta { font-size: 13px; color: #5d6178; }
.comment-meta .avatar { vertical-align: middle; border-radius: 50%; margin-right: 8px; }
.comment-content p { margin: 8px 0; }
.comment-reply-link { font-size: 13px; }
.comment-respond label { display: block; font-size: 14px; margin: 10px 0 4px; }
.comment-respond input[type="text"], .comment-respond input[type="email"], .comment-respond input[type="url"], .comment-respond textarea { width: 100%; max-width: 100%; padding: 10px; border: 1px solid var(--card-line); border-radius: 8px; font: inherit; }
.comment-respond .submit { margin-top: 12px; padding: 10px 18px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; }

/* ---------- Menu hamburger (téléphone, réglable dans Personnaliser) ---------- */
.app-burger { display: none; }

@media (max-width: 640px) {
  .app-burger { display: block; position: fixed; top: calc(6px + env(safe-area-inset-top)); z-index: 80; }
  .app-burger-right { right: calc(10px + env(safe-area-inset-right)); }
  .app-burger-left { left: calc(10px + env(safe-area-inset-left)); }
  body.has-burger:not(.has-app-header) .app-main { padding-top: 62px; }
  body.burger-left .app-bar { padding-left: calc(64px + env(safe-area-inset-left)); } /* le bouton ne recouvre pas le logo */

  .app-burger-btn {
    list-style: none;
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .app-burger-btn::-webkit-details-marker { display: none; }
  .app-burger-btn::marker { content: ''; }
  .app-burger-icon,
  .app-burger-icon::before,
  .app-burger-icon::after { display: block; width: 20px; height: 2px; border-radius: 2px; background: var(--ink); }
  .app-burger-icon { position: relative; transition: background .15s; }
  .app-burger-icon::before,
  .app-burger-icon::after { content: ''; position: absolute; left: 0; transition: transform .15s, top .15s; }
  .app-burger-icon::before { top: -6px; }
  .app-burger-icon::after { top: 6px; }
  .app-burger[open] .app-burger-icon { background: transparent; }
  .app-burger[open] .app-burger-icon::before { top: 0; transform: rotate(45deg); }
  .app-burger[open] .app-burger-icon::after { top: 0; transform: rotate(-45deg); }

  .app-burger-panel {
    position: absolute; top: 52px;
    min-width: 220px; max-width: calc(100vw - 20px); max-height: calc(100vh - 90px);
    overflow: auto; padding: 6px;
    background: var(--surface); color: var(--ink);
    border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  }
  .app-burger-right .app-burger-panel { right: 0; }
  .app-burger-left .app-burger-panel { left: 0; }
  .app-burger-panel ul { list-style: none; margin: 0; padding: 0; }
  .app-burger-panel a { display: block; padding: 12px 14px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 600; }
  .app-burger-panel a:hover { background: var(--bg); }
  .app-burger-panel .current-menu-item > a,
  .app-burger-panel .current_page_item > a { color: var(--accent); background: var(--bg); }
  .app-burger-panel .sub-menu { padding-left: 14px; }
  .app-burger-panel .sub-menu a { font-weight: 500; font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .app-burger-icon, .app-burger-icon::before, .app-burger-icon::after { transition: none; }
}

/* ---------- Style « site classique » (Personnaliser > HITOP-App > Style du site) ---------- */
body.style-classic { background: var(--card); color: var(--card-ink); }
body.style-classic .app-bar {
  position: static;
  flex-wrap: wrap;
  padding: 14px max(24px, calc((100vw - var(--content-w, 1040px)) / 2));
  background: var(--surface);
  backdrop-filter: none;
}
body.style-classic .app-brand { font-size: 1.15rem; }
body.style-classic .app-logo-img { width: auto; height: 44px; max-width: 220px; border-radius: 0; object-fit: contain; }
body.style-classic .app-nav a { padding: 8px 14px; font-size: 15px; }
body.style-classic .app-main { padding: 40px 24px 64px; }
body.style-classic .app-head { margin-bottom: 24px; }
body.style-classic .entry { background: transparent; border: 0; border-radius: 0; box-shadow: none; padding: 0; margin-bottom: 36px; }
body.style-classic .entry + .entry { padding-top: 32px; border-top: 1px solid var(--card-line); }
body.style-classic .entry-title { font-size: clamp(1.8rem, 4vw, 2.6rem); }
body.style-classic h2.entry-title { font-size: clamp(1.3rem, 3vw, 1.7rem); }
body.style-classic .entry-content { font-size: 1.05rem; line-height: 1.7; }
body.style-classic .app-footer { max-width: none; padding: 28px max(24px, calc((100vw - var(--content-w, 1040px)) / 2)); background: var(--surface); border-top: 1px solid var(--line); }

@media (max-width: 640px) {
  body.style-classic .app-bar { padding: 12px 16px; }
  body.style-classic.burger-left .app-bar { padding-left: calc(64px + env(safe-area-inset-left)); }
  body.style-classic.has-app-header .app-burger { top: calc(12px + env(safe-area-inset-top)); }
  body.style-classic.has-burger .app-bar { min-height: 68px; } /* le bouton tient dans l'en-tête */
  body.style-classic .app-main { padding: 24px 16px 48px; }
  body.style-classic:not(.has-burger) .app-nav { display: block; width: 100%; margin-left: 0; } /* sans hamburger, le menu reste visible */
  body.style-classic .app-footer { padding: 24px 16px; }
}

/* Accessibilité */
.screen-reader-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link:focus { position: fixed; top: 8px; left: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 640px) {
  .app-bar { padding: 8px 14px; gap: 10px; }
  .app-nav { display: none; }
  .app-main { padding: 18px 12px 40px; }
}
