/* ==========================================================================
   COFFEE OS | iOS NATIVE POLISH
   Visual-only shell tuning for iPhone/iPad/standalone/Capacitor.
   No auth, sync, or business logic changes.
   ========================================================================== */

:root {
    --font-ui: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Manrope', system-ui, sans-serif;
    --font-data: 'SF Mono', ui-monospace, 'Space Mono', 'Menlo', monospace;
}

html.is-ios,
body.is-ios {
    background: #080808;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body.is-ios {
    overscroll-behavior: none;
}

body.is-ios #app-shell {
    background: transparent;
}

body.is-ios #top-bar {
    background: linear-gradient(to bottom, rgba(10,10,12,0.94), rgba(10,10,12,0.86));
    border-bottom: 1px solid rgba(255,255,255,0.05);
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    transition: background .2s ease, border-color .2s ease, box-shadow .2s ease;
}

body.is-ios #top-bar.top-bar-scrolled {
    background: linear-gradient(to bottom, rgba(10,10,12,0.98), rgba(10,10,12,0.90));
    border-bottom-color: rgba(255,255,255,0.08);
    box-shadow: 0 12px 36px rgba(0,0,0,0.26);
}

body.is-ios #header-title {
    font-family: var(--font-ui);
    font-size: 0.84rem;
    letter-spacing: 0.16em;
    font-weight: 800;
}

body.is-ios #header-actions {
    min-width: 44px;
    min-height: 44px;
    justify-content: flex-end;
}

body.is-ios #viewport {
    scrollbar-width: none;
    scroll-behavior: smooth;
    padding-bottom: calc(var(--nav-base-height) + var(--safe-area-bottom) + 14px);
}
body.is-ios #viewport::-webkit-scrollbar { display: none; }

body.is-ios #bottom-dock {
    left: max(12px, calc(var(--safe-area-left) + 10px));
    right: max(12px, calc(var(--safe-area-right) + 10px));
    width: auto;
    transform: none;
    bottom: calc(var(--safe-area-bottom) + 6px);
    height: 58px;
    border-radius: 24px;
    border-color: rgba(255,255,255,0.07);
    background: linear-gradient(to bottom, rgba(28,28,30,0.82), rgba(16,16,18,0.90));
    box-shadow:
      0 18px 48px rgba(0,0,0,0.52),
      inset 0 0.5px 0 rgba(255,255,255,0.10);
    transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}


body.is-ios.keyboard-open #bottom-dock {
    transform: translateY(140%);
}

body.is-ios #bottom-dock.dock-scrolled {
    box-shadow:
      0 22px 52px rgba(0,0,0,0.58),
      inset 0 0.5px 0 rgba(255,255,255,0.11);
}

body.is-ios #bottom-nav {
    gap: 5px;
    padding-left: 12px;
    padding-right: 12px;
}

body.is-ios #bottom-nav .nav-item {
    width: 54px;
    min-width: 54px;
    height: 46px;
    border-radius: 15px;
}

body.is-ios #bottom-nav .nav-item i {
    font-size: 1.08rem;
}

body.is-ios #bottom-nav .nav-item.active {
    background: rgba(194,124,46,0.16);
    border-color: rgba(194,124,46,0.30);
    box-shadow:
      0 8px 18px rgba(0,0,0,0.24),
      0 0 14px rgba(194,124,46,0.12);
}

body.is-ios .btn-arch,
body.is-ios .auth-btn,
body.is-ios button,
body.is-ios select,
body.is-ios input,
body.is-ios textarea {
    font-family: var(--font-ui);
}

body.is-ios input,
body.is-ios select,
body.is-ios textarea,
body.is-ios .input,
body.is-ios .input-pro {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 14px;
    min-height: 46px;
}

body.is-ios textarea,
body.is-ios .input-pro[multiline],
body.is-ios textarea.input-pro {
    min-height: 98px;
}

body.is-ios .modal-overlay,
body.is-ios .biz-modal,
body.is-ios .ux-modal-overlay,
body.is-ios .more-sheet {
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

body.is-ios .modal-overlay,
body.is-ios .biz-modal {
    align-items: flex-end;
    padding: 10px 10px calc(12px + env(safe-area-inset-bottom));
}

body.is-ios .modal-card,
body.is-ios .biz-modal .biz-modal-card,
body.is-ios .ux-modal-card,
body.is-ios .more-sheet-panel,
body.is-ios .brew-steps-sheet {
    border-radius: 24px 24px 18px 18px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.46);
}

body.is-ios .modal-card,
body.is-ios .biz-modal .biz-modal-card,
body.is-ios .more-sheet-panel,
body.is-ios .brew-steps-sheet {
    max-height: min(88dvh, calc(100vh - 18px - env(safe-area-inset-top)));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    /* See note above on the food/drink modal — these properties are
       required together for iOS standalone PWA to render scrollable
       modals. Without min-height:0 the flex child grows unboundedly and
       overflow-y:auto is silently ignored. */
    overflow-y: auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

body.is-ios .modal-card::before,
body.is-ios .biz-modal .biz-modal-card::before,
body.is-ios .more-sheet-panel::before,
body.is-ios .brew-steps-sheet::before {
    content: '';
    display: block;
    width: 42px;
    height: 5px;
    border-radius: 999px;
    background: rgba(255,255,255,0.18);
    margin: 0 auto 14px;
}

body.is-ios .ux-modal-card {
    padding-top: 16px;
}

body.is-ios .biz-modal .biz-modal-actions,
body.is-ios .pantry-modal-actions,
body.is-ios .ux-modal-actions {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
}

body.is-ios #auth-screen {
    background:
      radial-gradient(circle at top, rgba(33,33,40,0.95) 0%, rgba(11,11,15,0.98) 42%, #080808 100%);
    padding: calc(28px + env(safe-area-inset-top)) 22px calc(30px + env(safe-area-inset-bottom));
}

body.is-ios .auth-logo {
    border-radius: 18px;
}

body.is-ios .auth-buttons {
    width: min(360px, 90vw);
}

body.is-ios .auth-btn {
    min-height: 54px;
    border-radius: 16px;
    background: rgba(255,255,255,0.06);
}

body.is-ios .auth-footer {
    margin-top: 32px;
    padding-bottom: env(safe-area-inset-bottom);
}

body.is-ios #cloud-sync-chip {
    top: calc(env(safe-area-inset-top, 0px) + 9px) !important;
    right: calc(env(safe-area-inset-right, 0px) + 10px) !important;
    min-width: 30px !important;
    height: 30px !important;
    padding: 0 8px !important;
    border-radius: 999px !important;
    background: rgba(10,12,14,0.52) !important;
    border-color: rgba(111,226,156,0.34) !important;
    box-shadow: 0 8px 22px rgba(0,0,0,0.16), inset 0 0 0 1px rgba(255,255,255,0.025) !important;
    -webkit-backdrop-filter: blur(12px) saturate(135%) !important;
    backdrop-filter: blur(12px) saturate(135%) !important;
}
body.is-ios #cloud-sync-chip-dot {
    width: 4px !important;
    height: 4px !important;
}

body.is-ios.is-ipad {
    --app-max-width: 1180px;
    --content-max-width: 980px;
    --dock-max-width: 880px;
}

body.is-ios.is-ipad #top-bar {
    width: min(100%, 1180px);
}

body.is-ios.is-ipad #viewport {
    padding-left: clamp(22px, 3vw, 34px);
    padding-right: clamp(22px, 3vw, 34px);
}

body.is-ios.is-ipad #bottom-dock {
    left: max(18px, calc((100vw - var(--dock-max-width, 880px)) / 2));
    right: max(18px, calc((100vw - var(--dock-max-width, 880px)) / 2));
}

body.is-ios.is-compact-landscape #top-bar {
    min-height: calc(50px + var(--safe-area-top));
}

body.is-ios.is-compact-landscape #bottom-dock {
    height: 50px;
    bottom: calc(var(--safe-area-bottom) + 4px);
}

body.is-ios.is-compact-landscape #bottom-nav .nav-item {
    height: 40px;
    width: 48px;
    min-width: 48px;
}


/* Specific iPhone fixes for Pantry / Foods / Drinks create modals */
body.is-ios .modal-overlay.pantry-modal,
body.is-ios .modal-overlay:has(#myfood-close),
body.is-ios .modal-overlay:has(#mydrink-close){
    align-items:center;
    justify-content:center;
    padding-top:calc(var(--header-height) + env(safe-area-inset-top) + 12px);
    padding-right:max(10px, calc(env(safe-area-inset-right) + 10px));
    padding-bottom:calc(var(--nav-base-height) + env(safe-area-inset-bottom) + 12px);
    padding-left:max(10px, calc(env(safe-area-inset-left) + 10px));
}

body.is-ios .modal-overlay.pantry-modal .modal-card,
body.is-ios .modal-overlay:has(#myfood-close) .modal-card,
body.is-ios .modal-overlay:has(#mydrink-close) .modal-card{
    width:min(96vw, 760px) !important;
    max-height:calc(100dvh - var(--header-height) - var(--nav-base-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 28px) !important;
    border-radius:22px !important;
    padding-top:14px !important;
    padding-bottom:calc(18px + env(safe-area-inset-bottom)) !important;
    overscroll-behavior:contain;
    scroll-padding-top:12px;
    /* CRITICAL: ensure scroll works on iOS standalone PWA. Without these
       three properties together, the modal renders at fixed height with no
       scroll — the last fields of long forms (Foods/Drinks recipe editor)
       become unreachable. */
    overflow-y:auto !important;
    min-height:0 !important;
    -webkit-overflow-scrolling:touch !important;
    display:flex !important;
    flex-direction:column !important;
}

body.is-ios .modal-overlay.pantry-modal .modal-card > div:first-child,
body.is-ios .modal-overlay:has(#myfood-close) .modal-card > div:first-child,
body.is-ios .modal-overlay:has(#mydrink-close) .modal-card > div:first-child{
    /* `position:sticky` was causing the modal-card to lose scroll on iOS
       standalone PWA (a known WebKit bug when sticky lives inside a flex
       column with overflow-y:auto). Reverted to static positioning so the
       scroll works. The header simply scrolls with the rest of the form,
       which is acceptable since the modal already has a Close button. */
    background:linear-gradient(180deg, rgba(26,28,34,0.98), rgba(26,28,34,0.94));
    padding-top:2px;
    padding-bottom:10px;
    margin-bottom:6px;
    border-radius:18px 18px 0 0;
}

body.is-ios .modal-overlay:has(#myfood-close) .modal-card,
body.is-ios .modal-overlay:has(#mydrink-close) .modal-card{
    padding-left:14px !important;
    padding-right:14px !important;
}

/* Final iOS BaristAI polish: compact vertical rhythm, no logic changes. */
body.is-ios #ai-root,
body.is-ios #ai-shell {
    min-height: 0;
}
body.is-ios .ai-shell {
    height: calc(var(--app-height, 100dvh) - var(--header-height) - var(--nav-base-height) - var(--safe-area-bottom) - 8px) !important;
    background: linear-gradient(180deg, rgba(8,8,10,0.96), rgba(7,7,8,0.98)) !important;
}
body.is-ios .ai-tabbar {
    padding: 8px 14px 7px !important;
    gap: 8px !important;
}
body.is-ios .ai-tab {
    padding: 8px 10px !important;
    border-radius: 12px !important;
    font-size: .68rem !important;
    letter-spacing: 1.35px !important;
}
body.is-ios .ai-quota-bar {
    padding: 7px 14px 8px !important;
}
body.is-ios .ai-quota-k {
    font-size: .55rem !important;
    margin-bottom: 3px !important;
}
body.is-ios .ai-quota-v {
    font-size: .78rem !important;
}
body.is-ios .ai-quota-bar-mini {
    height: 3px !important;
    margin-top: 5px !important;
}
body.is-ios .ai-chat-topbar {
    padding: 9px 14px 8px !important;
    background: rgba(0,0,0,.16) !important;
}
body.is-ios .ai-chat-eyebrow {
    font-size: .58rem !important;
    letter-spacing: 1.7px !important;
}
body.is-ios .ai-chat-main {
    font-size: .88rem !important;
    max-width: 62vw !important;
}
body.is-ios .ai-chat-actions .btn-arch {
    min-height: 38px !important;
    height: 38px !important;
    padding: 0 13px !important;
    border-radius: 13px !important;
}
body.is-ios .ai-messages {
    padding: 13px 14px 8px !important;
}
body.is-ios .ai-msg-row {
    margin-bottom: 14px !important;
    gap: 8px !important;
}
body.is-ios .ai-msg-avatar {
    width: 28px !important;
    height: 28px !important;
    margin-top: 16px !important;
}
body.is-ios .ai-msg-bubble-wrap {
    max-width: 82% !important;
}
body.is-ios .ai-msg-label {
    font-size: .58rem !important;
    margin-bottom: 4px !important;
}
body.is-ios .ai-msg-bubble {
    padding: 10px 13px !important;
}
body.is-ios .ai-msg-text {
    font-size: .86rem !important;
    line-height: 1.62 !important;
}
body.is-ios .ai-chip-clip {
    padding: 0 4px !important;
}
body.is-ios .ai-quick-row {
    padding: 4px 12px 6px !important;
}
body.is-ios .ai-input-area {
    gap: 8px !important;
    padding: 7px 14px calc(8px + env(safe-area-inset-bottom,0px)) !important;
}
body.is-ios .ai-input-wrap {
    border-radius: 12px !important;
}
body.is-ios .ai-textarea {
    height: 36px !important;
    min-height: 36px !important;
    max-height: 88px !important;
    padding: 8px 11px !important;
    font-size: .86rem !important;
}
body.is-ios .ai-send-btn {
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
    border-radius: 12px !important;
}
body.is-ios .ai-quota-strip {
    margin: 7px 14px 8px !important;
    max-width: calc(100% - 28px) !important;
}

/* =====================================================================
   PHASE 5 — iOS MICRO POLISH
   Visual-only: tighter native chrome + circular sync chip.
   No auth, sync, AI quota, purchase, or storage logic changes.
   ===================================================================== */
body.is-ios {
    --header-base-height: 44px;
    --viewport-pad-top-gap: 0px;
    --viewport-pad-bottom-gap: 2px;
}

body.is-ios #top-bar {
    min-height: var(--header-height) !important;
    height: var(--header-height) !important;
    padding-top: var(--safe-area-top) !important;
    align-items: center !important;
}

body.is-ios #header-title {
    line-height: 1 !important;
    transform: translateY(-1px);
}

body.is-ios #viewport.home-tight-top,
body.is-ios #viewport.brew-tight-top {
    padding-top: var(--header-height) !important;
}

body.is-ios #viewport {
    padding-bottom: calc(var(--nav-base-height) + var(--safe-area-bottom) + 2px) !important;
}

body.is-ios #bottom-dock {
    bottom: max(8px, calc(var(--safe-area-bottom) - 2px)) !important;
}

body.is-ios #cloud-sync-chip {
    top: calc(var(--safe-area-top, env(safe-area-inset-top, 0px)) + 6px) !important;
    right: calc(var(--safe-area-right, env(safe-area-inset-right, 0px)) + 12px) !important;
    width: 32px !important;
    min-width: 32px !important;
    max-width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    max-height: 32px !important;
    aspect-ratio: 1 / 1 !important;
    padding: 0 !important;
    border-radius: 50% !important;
    overflow: hidden !important;
    display: none;
    align-items: center !important;
    justify-content: center !important;
    gap: 0 !important;
}

body.is-ios #cloud-sync-chip-label {
    display: none !important;
    max-width: 0 !important;
    opacity: 0 !important;
}

body.is-ios #cloud-sync-chip-dot {
    width: 4px !important;
    height: 4px !important;
    margin: 0 !important;
}

/* =====================================================================
   PHASE 5B — iOS MICRO ADJUSTMENT
   Visual-only: tighter header gap + slightly lower dock.
   No auth, sync, AI quota, purchase, storage, or business logic changes.
   ===================================================================== */
body.is-ios {
    --header-base-height: 34px;
    --viewport-pad-top-gap: 0px;
    --viewport-pad-bottom-gap: 0px;
}

body.is-ios #top-bar {
    min-height: var(--header-height) !important;
    height: var(--header-height) !important;
    padding-top: calc(var(--safe-area-top) + 4px) !important;
    align-items: flex-start !important;
}

body.is-ios #header-title {
    line-height: 1 !important;
    transform: none !important;
}

body.is-ios #viewport.home-tight-top,
body.is-ios #viewport.brew-tight-top {
    padding-top: var(--header-height) !important;
}

body.is-ios #viewport {
    padding-bottom: calc(var(--nav-base-height) + var(--safe-area-bottom) + 0px) !important;
}

body.is-ios #bottom-dock {
    bottom: max(4px, calc(var(--safe-area-bottom) - 10px)) !important;
}

body.is-ios #cloud-sync-chip {
    top: calc(var(--safe-area-top, env(safe-area-inset-top, 0px)) + 2px) !important;
    right: calc(var(--safe-area-right, env(safe-area-inset-right, 0px)) + 12px) !important;
    width: 32px !important;
    min-width: 32px !important;
    max-width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    max-height: 32px !important;
    aspect-ratio: 1 / 1 !important;
    border-radius: 50% !important;
    padding: 0 !important;
    transform: none !important;
}

/* =====================================================================
   PHASE 5C — iOS HEADER HEIGHT FINAL TUNE
   Visual-only: reduce the real fixed header height, not just title position.
   Keeps the already-approved lower dock and circular sync chip behavior.
   No auth, sync, AI quota, purchase, storage, or business logic changes.
   ===================================================================== */
body.is-ios {
    --header-base-height: 44px;
    --header-height: calc(var(--safe-area-top) + 44px);
}

body.is-ios #top-bar {
    min-height: var(--header-height) !important;
    height: var(--header-height) !important;
    padding-top: var(--safe-area-top) !important;
    padding-bottom: 0 !important;
    align-items: center !important;
    box-sizing: border-box !important;
}

body.is-ios #header-title {
    line-height: 1 !important;
    transform: none !important;
}

body.is-ios #header-actions {
    align-items: center !important;
}

body.is-ios #viewport.home-tight-top,
body.is-ios #viewport.brew-tight-top,
body.is-ios #viewport {
    scroll-padding-top: calc(var(--header-height) + 10px) !important;
}

body.is-ios #viewport.home-tight-top,
body.is-ios #viewport.brew-tight-top {
    padding-top: var(--header-height) !important;
}

/* Sync chip: anchored INSIDE the safe area, vertically centered with the header content. */
body.is-ios #cloud-sync-chip {
    top: calc(var(--safe-area-top, env(safe-area-inset-top, 0px)) + 10px) !important;
}

/* =====================================================================
   PHASE 5D — iOS SYNC CHIP VERTICAL ALIGNMENT
   Visual-only: keep the approved dock/header and move only the circular
   sync indicator upward so it matches the tightened native header.
   No auth, sync, AI quota, purchase, storage, or business logic changes.
   ===================================================================== */
body.is-ios #cloud-sync-chip {
    top: calc(var(--safe-area-top, env(safe-area-inset-top, 0px)) + 10px) !important;
    right: calc(var(--safe-area-right, env(safe-area-inset-right, 0px)) + 12px) !important;
    width: 32px !important;
    min-width: 32px !important;
    max-width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    max-height: 32px !important;
    aspect-ratio: 1 / 1 !important;
    border-radius: 50% !important;
    padding: 0 !important;
}

/* ============================================================
   FIX chips de header amontonados/salidos en iOS (v1.90.12)
   El título + chip de rol + chip de operador no caben en iPhone.
   Solución: header-actions acotado, chips que no desbordan, y en
   pantallas angostas el texto del rol se oculta (queda solo ícono).
   El círculo de sync flota aparte (ya está bien) — no se toca aquí.
   ============================================================ */
body.is-ios #top-bar {
    padding-left: max(14px, var(--safe-area-left, 0px)) !important;
    padding-right: max(58px, calc(var(--safe-area-right, 0px) + 52px)) !important; /* deja hueco al círculo de sync */
    gap: 8px !important;
}
body.is-ios #header-title {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
}
body.is-ios #header-actions {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    justify-content: flex-end !important;
    overflow: hidden !important;
    gap: 6px !important;
}
body.is-ios #header-actions #role-chip,
body.is-ios #header-actions #operator-chip {
    max-width: 46vw !important;
    overflow: hidden !important;
    flex: 0 1 auto !important;
    min-width: 0 !important;
}
body.is-ios #header-actions #role-chip span,
body.is-ios #header-actions #operator-chip span {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    min-width: 0 !important;
}
/* Muy angosto: el chip de rol queda solo ícono (el operador conserva su nombre). */
@media (max-width: 400px) {
    body.is-ios #header-actions #role-chip span { display: none !important; }
    body.is-ios #header-actions #role-chip { padding-left: 9px !important; padding-right: 9px !important; }
}
@media (max-width: 340px) {
    body.is-ios #header-actions #operator-chip span { max-width: 30vw !important; }
}


/* ============================================================
   v1.90.25 — DOCK iOS v2: los 7 SIEMPRE caben (fix de desborde)
   Causa raíz del bug reportado: items con width fija de 54px
   (7×54 + gaps + padding = ~432px > ~393pt de viewport) →
   desborde horizontal y "GESTIÓN" cortado. Además los glifos
   fill son visualmente más densos que la monolínea anterior y
   con etiqueta en todos el dock se saturaba.
   Fix: items flexibles (flex:1) que reparten SIEMPRE el ancho
   disponible, glifo con tope duro de 20px, y etiqueta visible
   SOLO en el activo (patrón iOS original de la app).
   ============================================================ */
body.is-ios #bottom-nav {
    gap: 2px;
    padding-left: 8px;
    padding-right: 8px;
    overflow: hidden;
}
body.is-ios #bottom-nav .nav-item {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    max-width: 64px;
    height: 46px;
    padding: 4px 2px;
}
body.is-ios #bottom-nav .nav-item .nav-ic {
    width: auto;
    height: 22px;
}
body.is-ios #bottom-nav .nav-item svg {
    width: 20px !important;
    height: 20px !important;
}
body.is-ios #bottom-nav .nav-item span {
    display: none;
}
body.is-ios #bottom-nav .nav-item.active span {
    display: block;
    font-size: .42rem;
    letter-spacing: .04em;
    opacity: 1;
}
/* el box dorado del activo ya marca la selección: sin punto doble */
body.is-ios #bottom-nav .nav-item.active::after {
    display: none;
}
body.is-ios.is-compact-landscape #bottom-nav .nav-item {
    width: auto;
    min-width: 0;
    flex: 1 1 0;
}
