/* ============================================================
   TopAnnonces.ch — App mobile (iOS-style)
   ============================================================ */

* { -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overscroll-behavior-y: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    background: #F2F2F7;
    color: #1C1C1E;
}

#app { min-height: 100vh; }

/* Safe-areas iOS */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --tabbar-height: 64px;
    --header-height: 56px;
    --primary: #0EA5E9;
    --primary-dark: #0284C7;
    --primary-soft: #E0F2FE;
}

/* ====================== Loading splash ====================== */
.splash {
    position: fixed; inset: 0; z-index: 9999;
    background: linear-gradient(160deg, #0EA5E9 0%, #0284C7 100%);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 1.25rem; color: white;
}
.splash .logo { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; }
.splash .spinner {
    width: 36px; height: 36px;
    border: 3px solid rgba(255,255,255,.3); border-top-color: white;
    border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ====================== App shell ====================== */
.app-shell {
    min-height: 100vh;
    padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom));
}

/* ====================== Header ====================== */
.app-header {
    position: sticky; top: 0; z-index: 50;
    background: rgba(255,255,255,0.92);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid rgba(0,0,0,0.06);
    padding-top: var(--safe-top);
}
.app-header-inner {
    display: flex; align-items: center; gap: 0.5rem;
    height: var(--header-height); padding: 0 1rem;
}
.app-header-title {
    font-weight: 700; font-size: 1.0625rem; flex: 1; text-align: center;
}
.app-header-back, .app-header-action {
    width: 40px; height: 40px; border-radius: 12px; background: transparent; border: none;
    display: flex; align-items: center; justify-content: center;
    color: var(--primary); cursor: pointer; font-size: 1.125rem;
    transition: background .15s ease;
}
.app-header-back:active, .app-header-action:active { background: rgba(0,0,0,0.05); }

.app-search {
    display: flex; align-items: center; gap: 0.5rem;
    background: #EFEFF4; border-radius: 12px;
    padding: 0.625rem 0.875rem; font-size: 0.9375rem; color: #6B7280;
    margin: 0 1rem 0.75rem; cursor: pointer;
}
.app-search i { color: #8E8E93; }

/* ====================== Bottom Tab Bar ====================== */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: rgba(255,255,255,0.92);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid rgba(0,0,0,0.08);
    padding-bottom: var(--safe-bottom);
}
.tabbar-inner {
    display: grid; grid-template-columns: repeat(5, 1fr);
    height: var(--tabbar-height);
}
.tab-btn {
    background: transparent; border: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; color: #8E8E93; cursor: pointer; padding: 6px 4px;
    transition: color .15s ease, transform .15s ease;
    position: relative;
}
.tab-btn i { font-size: 1.35rem; }
.tab-btn span {
    font-size: 0.6875rem; font-weight: 600;
    letter-spacing: 0.01em;
}
.tab-btn.active { color: var(--primary); }
.tab-btn:active { transform: scale(0.94); }
.tab-btn .badge {
    position: absolute; top: 4px; left: 50%;
    transform: translateX(6px);
    background: #FF3B30; color: white;
    font-size: 0.625rem; font-weight: 700;
    border-radius: 999px; min-width: 18px; height: 18px;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0 5px; line-height: 1;
}
/* Bouton central "Publier" en surépaisseur */
.tab-btn.tab-cta {
    color: white;
}
.tab-btn.tab-cta .cta-bubble {
    width: 50px; height: 50px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 22px -4px rgba(14,165,233,.55);
    margin-bottom: 2px;
    transition: transform .15s ease;
}
.tab-btn.tab-cta i { color: white; font-size: 1.35rem; }
.tab-btn.tab-cta span { color: var(--primary); }
.tab-btn.tab-cta:active .cta-bubble { transform: scale(0.92); }

/* ====================== Cards & lists ====================== */
.section { padding: 0.75rem 1rem 0.25rem; }
.section-title {
    font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.06em; color: #6B7280; margin: 0 0 0.5rem;
}

.card {
    background: white; border-radius: 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 1px 1px rgba(0,0,0,0.03);
    overflow: hidden;
}

.menu-list { display: flex; flex-direction: column; gap: 1px; background: #E5E5EA; border-radius: 14px; overflow: hidden; }
.menu-row {
    display: flex; align-items: center; gap: 0.875rem;
    padding: 0.875rem 1rem; background: white; cursor: pointer;
    transition: background .15s ease;
}
.menu-row:active { background: #F2F2F7; }
.menu-row .icon-bubble {
    width: 36px; height: 36px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 1rem; flex-shrink: 0;
}
.menu-row .menu-body { flex: 1; min-width: 0; }
.menu-row .menu-title { font-size: 0.9375rem; font-weight: 600; color: #1C1C1E; }
.menu-row .menu-sub { font-size: 0.8125rem; color: #6B7280; margin-top: 1px; }
.menu-row .menu-trail { color: #C7C7CC; font-size: 0.875rem; }
.menu-row .menu-badge {
    font-size: 0.75rem; font-weight: 700; color: white;
    background: #FF3B30; border-radius: 999px; padding: 2px 8px; line-height: 1.3;
}
.menu-row.danger .menu-title { color: #FF3B30; }

/* Catégories grid */
.cat-grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.875rem 0.5rem;
    padding: 0.5rem 0.75rem 1rem;
}
.cat-tile {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    cursor: pointer; transition: transform .15s ease;
}
.cat-tile:active { transform: scale(0.94); }
.cat-tile .cat-bubble {
    width: 56px; height: 56px; border-radius: 18px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.375rem;
}
.cat-tile .cat-name {
    font-size: 0.6875rem; font-weight: 600; color: #1C1C1E;
    text-align: center; line-height: 1.2;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 80px;
}

/* Listing tiles */
.lst-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.625rem;
    padding: 0.25rem 0.75rem 1rem;
}
.lst-tile {
    background: white; border-radius: 14px; overflow: hidden; cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    display: flex; flex-direction: column;
    transition: transform .15s ease;
}
.lst-tile:active { transform: scale(0.97); }
.lst-tile .lst-img {
    aspect-ratio: 1 / 1; width: 100%;
    background: #F2F2F7 center/cover no-repeat;
    position: relative;
}
.lst-tile .lst-img .lst-fav {
    position: absolute; top: 8px; right: 8px;
    width: 32px; height: 32px; border-radius: 999px;
    background: rgba(0,0,0,0.45); color: white; backdrop-filter: blur(8px);
    border: none; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: transform .15s ease, background .15s ease;
}
.lst-tile .lst-img .lst-fav:active { transform: scale(0.85); }
.lst-tile .lst-img .lst-fav.is-fav { background: #FF3B30; }
.lst-tile .lst-img .lst-badge {
    position: absolute; top: 8px; left: 8px;
    background: rgba(0,0,0,0.55); color: white; backdrop-filter: blur(8px);
    font-size: 0.6875rem; font-weight: 700;
    padding: 3px 7px; border-radius: 6px;
}
.lst-tile .lst-body { padding: 0.5rem 0.625rem 0.625rem; display: flex; flex-direction: column; gap: 2px; }
.lst-tile .lst-title { font-size: 0.8125rem; font-weight: 600; color: #1C1C1E;
    overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; min-height: 2.05em; }
.lst-tile .lst-price { font-size: 0.9375rem; font-weight: 800; color: var(--primary-dark); margin-top: 2px; }
.lst-tile .lst-meta { font-size: 0.6875rem; color: #8E8E93; margin-top: 2px; }

/* Listing rows (1 col format) */
.lst-row {
    display: flex; gap: 0.75rem; background: white; border-radius: 14px;
    padding: 0.625rem; align-items: stretch;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05); cursor: pointer;
    transition: transform .15s ease;
}
.lst-row:active { transform: scale(0.98); }
.lst-row .lst-row-img {
    width: 92px; height: 92px; border-radius: 10px;
    background: #F2F2F7 center/cover no-repeat; flex-shrink: 0;
}
.lst-row .lst-row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lst-row .lst-row-title { font-size: 0.9375rem; font-weight: 600; color: #1C1C1E;
    overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.2; }
.lst-row .lst-row-price { font-size: 1rem; font-weight: 800; color: var(--primary-dark); }
.lst-row .lst-row-meta { font-size: 0.75rem; color: #8E8E93; margin-top: auto; }
.lst-row-stack { display: flex; flex-direction: column; gap: 0.5rem; padding: 0 1rem 1rem; }

/* Empty / loading state */
.placeholder {
    text-align: center; padding: 3rem 1.5rem; color: #6B7280;
    display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
}
.placeholder .ph-icon {
    width: 56px; height: 56px; border-radius: 16px;
    background: var(--primary-soft); color: var(--primary);
    display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
}
.placeholder .ph-title { font-size: 1.0625rem; font-weight: 700; color: #1C1C1E; }
.placeholder .ph-sub { font-size: 0.875rem; max-width: 280px; line-height: 1.4; }
.placeholder .btn-primary { margin-top: 0.5rem; }

/* ====================== Buttons ====================== */
.btn-primary, .btn-secondary, .btn-ghost {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 0.5rem; font-weight: 600; font-size: 0.9375rem;
    border-radius: 12px; padding: 0.875rem 1.25rem; border: none;
    cursor: pointer; transition: transform .15s ease, background .15s ease, opacity .15s ease;
    width: 100%;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:active { transform: scale(0.97); background: var(--primary-dark); }
.btn-primary:disabled { background: #C7C7CC; cursor: not-allowed; }
.btn-secondary { background: #EFEFF4; color: #1C1C1E; }
.btn-secondary:active { background: #E5E5EA; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:active { background: rgba(14,165,233,0.08); }

.fab-publish {
    position: fixed; right: 1rem;
    bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 1rem);
    width: 56px; height: 56px; border-radius: 18px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white; border: none; font-size: 1.5rem;
    box-shadow: 0 12px 28px -8px rgba(14,165,233,.55);
    display: flex; align-items: center; justify-content: center;
    z-index: 55; cursor: pointer;
}

/* ====================== Inputs ====================== */
.field { display: flex; flex-direction: column; gap: 0.375rem; margin-bottom: 0.875rem; }
.field label { font-size: 0.8125rem; font-weight: 600; color: #3A3A3C; }
.field input, .field select, .field textarea {
    border: 1px solid #E5E5EA; background: white; color: #1C1C1E;
    border-radius: 12px; padding: 0.875rem 0.875rem; font-size: 1rem; font-family: inherit;
    -webkit-appearance: none; appearance: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(14,165,233,0.12);
}
.field textarea { resize: vertical; min-height: 100px; }
.field .hint { font-size: 0.75rem; color: #8E8E93; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

/* ====================== Modale (sheet) ====================== */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: flex-end; justify-content: center;
    animation: bd-in .2s ease;
}
@keyframes bd-in { from { opacity: 0; } to { opacity: 1; } }
.sheet {
    background: white; width: 100%; max-width: 480px;
    border-top-left-radius: 22px; border-top-right-radius: 22px;
    padding: 1.25rem 1.25rem calc(1.25rem + var(--safe-bottom));
    box-shadow: 0 -8px 24px rgba(0,0,0,0.15);
    animation: sheet-in .25s cubic-bezier(.2,.9,.3,1.2);
    max-height: 92vh; overflow-y: auto;
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet .sheet-handle {
    width: 38px; height: 4px; background: #D1D1D6;
    border-radius: 999px; margin: 0 auto 0.875rem;
}
.sheet h2 { margin: 0 0 0.5rem; font-size: 1.25rem; font-weight: 700; }

/* OTP */
.otp-row { display: flex; gap: 0.4rem; justify-content: center; margin: 1rem 0 0.75rem; }
.otp-input {
    width: 44px; height: 52px; text-align: center;
    border-radius: 10px; border: 1.5px solid #E5E5EA;
    font-size: 1.25rem; font-weight: 700; background: white;
    transition: all .15s ease;
}
.otp-input:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(14,165,233,0.15);
    transform: scale(1.04);
}

/* Toasts */
.toast-stack {
    position: fixed; left: 1rem; right: 1rem; top: calc(var(--safe-top) + 0.75rem);
    z-index: 9000; display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none;
}
.toast {
    pointer-events: auto;
    padding: 0.75rem 1rem; border-radius: 14px; color: white;
    font-size: 0.875rem; font-weight: 600;
    box-shadow: 0 12px 28px -8px rgba(0,0,0,0.25);
    animation: toast-in .25s cubic-bezier(.2,.9,.3,1.2);
}
.toast.success { background: linear-gradient(135deg, #10B981 0%, #059669 100%); }
.toast.error { background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%); }
.toast.info { background: linear-gradient(135deg, #0EA5E9 0%, #0284C7 100%); }
@keyframes toast-in { from { transform: translateY(-30%) scale(.95); opacity: 0; } to { transform: none; opacity: 1; } }

/* Animations utilitaires */
.fade-in { animation: fadeIn .35s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.fade-in-up { animation: fadeInUp .45s ease both; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* Skeleton loaders */
.sk { background: linear-gradient(90deg, #EFEFF4 0%, #F8F8F8 50%, #EFEFF4 100%);
    background-size: 200% 100%; animation: sk 1.4s infinite; border-radius: 8px; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Listing detail */
.detail-hero {
    position: relative; aspect-ratio: 4 / 3; background: #000 center/cover no-repeat;
}
.detail-hero .nav-back {
    position: absolute; top: calc(var(--safe-top) + 0.5rem); left: 0.75rem;
    width: 40px; height: 40px; border-radius: 999px;
    background: rgba(0,0,0,0.45); color: white; backdrop-filter: blur(8px);
    border: none; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.detail-hero .dots {
    position: absolute; bottom: 0.75rem; left: 50%; transform: translateX(-50%);
    display: flex; gap: 4px;
}
.detail-hero .dot { width: 6px; height: 6px; border-radius: 999px; background: rgba(255,255,255,0.45); }
.detail-hero .dot.active { background: white; width: 18px; }
.detail-section { padding: 1rem; }
.detail-title { font-size: 1.125rem; font-weight: 700; line-height: 1.25; margin: 0 0 0.25rem; }
.detail-price { font-size: 1.5rem; font-weight: 800; color: var(--primary-dark); margin: 0 0 0.25rem; }
.detail-meta { font-size: 0.8125rem; color: #6B7280; }

.contact-bar {
    position: fixed; left: 0; right: 0;
    bottom: calc(var(--tabbar-height) + var(--safe-bottom));
    background: rgba(255,255,255,0.96); backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0,0,0,0.08);
    padding: 0.75rem 1rem; display: flex; gap: 0.5rem; z-index: 40;
}
.contact-bar .btn-primary { flex: 1; }

/* Inbox / Conversation */
.conv-row {
    display: flex; gap: 0.75rem; padding: 0.875rem 1rem; background: white;
    border-bottom: 1px solid #F2F2F7; align-items: center; cursor: pointer;
}
.conv-avatar {
    width: 44px; height: 44px; border-radius: 999px;
    background: linear-gradient(135deg, #0EA5E9, #0284C7); color: white;
    display: flex; align-items: center; justify-content: center; font-weight: 700;
    flex-shrink: 0;
}
.conv-body { flex: 1; min-width: 0; }
.conv-name { font-size: 0.9375rem; font-weight: 700; color: #1C1C1E;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-preview { font-size: 0.8125rem; color: #6B7280;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 0.75rem; color: #8E8E93; flex-shrink: 0; }

.msg-list { padding: 1rem; display: flex; flex-direction: column; gap: 6px; padding-bottom: 80px; }
.msg { max-width: 75%; padding: 0.625rem 0.875rem; border-radius: 16px;
    font-size: 0.9375rem; line-height: 1.3; word-wrap: break-word; }
.msg.them { background: #EFEFF4; color: #1C1C1E; align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.me { background: var(--primary); color: white; align-self: flex-end; border-bottom-right-radius: 4px; }

.msg-composer {
    position: fixed; left: 0; right: 0;
    bottom: calc(var(--tabbar-height) + var(--safe-bottom));
    background: white; border-top: 1px solid rgba(0,0,0,0.08);
    padding: 0.5rem 0.75rem; display: flex; gap: 0.5rem; align-items: end; z-index: 40;
}
.msg-composer textarea {
    flex: 1; border: 1px solid #E5E5EA; border-radius: 18px;
    padding: 0.625rem 0.875rem; font-size: 1rem; font-family: inherit;
    resize: none; min-height: 38px; max-height: 120px;
}
.msg-composer button {
    width: 40px; height: 40px; border-radius: 999px;
    background: var(--primary); color: white; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 1rem;
    flex-shrink: 0;
}

/* Avatar header (compte) */
.profile-card {
    margin: 0.75rem 1rem; padding: 1rem;
    background: white; border-radius: 16px;
    display: flex; align-items: center; gap: 0.875rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.profile-avatar {
    width: 56px; height: 56px; border-radius: 999px;
    background: linear-gradient(135deg, #0EA5E9, #0284C7); color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; font-weight: 700; flex-shrink: 0;
    background-size: cover; background-position: center;
}
.profile-name { font-size: 1.0625rem; font-weight: 700; }
.profile-mail { font-size: 0.8125rem; color: #6B7280; }
.profile-cta { font-size: 0.8125rem; color: var(--primary); font-weight: 600; }

/* Stat chips compte */
.stat-row {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem;
    padding: 0 1rem 0.5rem;
}
.stat-card { background: white; border-radius: 14px; padding: 0.75rem 0.5rem;
    text-align: center; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.stat-card .v { font-size: 1.125rem; font-weight: 800; color: #1C1C1E; }
.stat-card .l { font-size: 0.75rem; color: #6B7280; margin-top: 2px; }

/* Pull-down spacing */
.scroll-area { padding-top: 0.25rem; }

/* Image gallery scroll */
.gallery {
    display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.gallery::-webkit-scrollbar { display: none; }
.gallery .slide { flex: 0 0 100%; scroll-snap-align: start; aspect-ratio: 4/3;
    background: #000 center/cover no-repeat; }

/* Disable text selection in app chrome */
.app-header, .tabbar { user-select: none; -webkit-user-select: none; }

/* Pleine largeur safe */
@media (min-width: 540px) {
    .lst-grid { grid-template-columns: repeat(3, 1fr); }
    .cat-grid { grid-template-columns: repeat(6, 1fr); }
}
