/**
 * Mobile UI enhancements for Concierge Collector
 * Improves touch targets and responsive design elements
 */

/* Recording indicator animation */
.recording-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--color-error); /* tijolo — gravação em curso */
    margin-right: 8px;
    animation: pulse 1.5s infinite;
}

.additional-recording {
    background-color: var(--color-primary-600); /* oliva — segunda gravação */
}

@keyframes pulse {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.2); }
    100% { opacity: 1; transform: scale(1); }
}

/* Highlight effect for updated transcription */
.highlight-update {
    animation: highlight-fade 1s ease-in-out;
}

@keyframes highlight-fade {
    0% { background-color: rgba(92, 107, 74, 0.2); }
    100% { background-color: transparent; }
}

/* Enhanced touch targets for mobile */
@media (max-width: 768px) {
    button, .button, [type="button"] {
        min-height: 44px; /* Apple's recommended min touch target size */
        min-width: 44px;
        padding: 0.75rem 1rem;
    }
    
    input, select, textarea {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
        min-height: 44px;
    }
    
    /* Increase spacing between UI elements */
    .gap-2 {
        gap: 0.75rem !important;
    }
    
    /* Make audio controls easier to tap */
    audio {
        width: 100%;
        height: 44px;
    }
    
    /* Ensure proper timer visibility */
    #recording-time, #additional-recording-time {
        font-size: 1.125rem;
        font-weight: 500;
        padding: 0.75rem;
    }
    
    /* Make visualizer more visible */
    #audio-visualizer, #additional-audio-visualizer {
        height: 60px !important;
    }
}

/* Fix for iOS Safari issues with audio recording */
.ios-warning {
    display: none;
    border: 1px solid var(--color-warning-400);
    background-color: var(--color-warning-light);
    color: var(--color-warning-dark);
    padding: 1rem;
    border-radius: 0.25rem;
    margin-bottom: 1rem;
}

.is-ios .ios-warning {
    display: block;
}

/* Audio preview improvements */
#audio-preview, #additional-audio-preview {
    padding: 1rem;
    background: var(--color-neutral-50);
    border-radius: 0.5rem;
    margin-top: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Timer styling */
#timer.warning {
    color: var(--color-error);
    font-weight: bold;
    animation: pulse 1s infinite;
}

/* Wordmark centralizado no header em telas pequenas (ago/2026):
   logo à esquerda, controles à direita, "Collector" flutua centrado.
   O header é position:sticky, que já vira containing block para o
   absolute — por isso só transform/left são necessários. Em >=640px
   (sm) o fluxo normal é restaurado. Auditoria (ponto 15): a zona
   central precisa "ceder espaço" se o lado direito crescer — o
   wordmark trunca com ellipsis em vez de sobrepor os controles. */
@media (max-width: 639px) {
  header .brand-wordmark {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    max-width: 38%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Abaixo de 400px (mesmo breakpoint do icon-only) o wordmark some —
   o logo já representa a marca e o centro deixa de competir com
   sync/perfil em aparelhos estreitos (auditoria, ponto 15). */
@media (max-width: 400px) {
  header .brand-wordmark {
    display: none;
  }
}

/* ========================================================================
   MOBILE OPTIMIZATIONS - PHASE 3
   Added: October 19, 2025
   Purpose: Bottom sheets, touch targets, and mobile-first enhancements
   ======================================================================== */

/* Touch targets - minimum 44x44px (Apple HIG) */
@media (max-width: 768px) {
    .btn,
    /* Os controles do redesign da coleção (ago/2026) definem os
       próprios alvos de toque (chips 38px, paginação 32px, ações do
       card 36px, botão-nome de texto 0) — ficam fora do mínimo HIG
       genérico, que os inflava para 44px vencendo por especificidade
       (button:not(...) = 0,2,1 > classes de componente = 0,2,0). */
    button:not(.checkbox):not(.radio):not(.saved-view-chip):not(.collection-pagination__btn):not(.card-link-btn):not(.card-edit-btn):not(.btn-more-curation):not(.collection-card__name-link):not(.detail-gallery__thumb),
    a.btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Checkboxes and radios should have tap-friendly container, not the input itself */
    input[type="checkbox"],
    input[type="radio"] {
        width: 1.25rem; /* 20px */
        height: 1.25rem; /* 20px */
        cursor: pointer;
    }
    
    /* Label should provide touch target for checkboxes/radios */
    label:has(input[type="checkbox"]),
    label:has(input[type="radio"]) {
        min-height: 44px;
        display: flex;
        align-items: center;
        cursor: pointer;
        padding: 0.5rem;
        margin: -0.5rem; /* Negative margin to expand clickable area */
    }
    
    /* Increase tap padding for small buttons */
    .btn-sm {
        padding: 0.625rem 1rem; /* 10px 16px */
    }
    
    .btn-md {
        padding: 0.75rem 1.25rem; /* 12px 20px */
    }
    
    /* Larger text for readability */
    body {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .text-sm {
        font-size: 0.9375rem; /* 15px minimum for readability */
    }
    
    /* Full-width buttons on mobile */
    .btn-mobile-full {
        width: 100%;
    }
    
    /* Stack buttons vertically */
    .button-group-mobile-stack {
        flex-direction: column;
    }
    
    .button-group-mobile-stack .btn {
        width: 100%;
    }
}

/* Bottom Sheet Pattern */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.bottom-sheet.active {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--color-neutral-300);
    border-radius: 2px;
    margin: 12px auto 8px;
    cursor: grab;
    flex-shrink: 0;
}

.bottom-sheet-handle:active {
    cursor: grabbing;
}

.bottom-sheet-header {
    padding: 0 1.5rem 1rem;
    border-bottom: 1px solid var(--color-neutral-200);
    flex-shrink: 0;
}

.bottom-sheet-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-neutral-900);
}

.bottom-sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    -webkit-overflow-scrolling: touch; /* Smooth iOS scrolling */
}

.bottom-sheet-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-neutral-200);
    background: var(--color-neutral-50);
    flex-shrink: 0;
}

/* Overlay for bottom sheet */
.bottom-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.bottom-sheet-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* Safe area insets for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
    .bottom-sheet-footer {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
    
    .sticky-footer-inner {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
}

/* Mobile-specific modal behavior */
@media (max-width: 640px) {
    .modal-container {
        max-width: 100%;
        max-height: 100%;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        margin: 0;
        margin-top: auto; /* Push to bottom */
    }
    
    /* Full-screen modal option for mobile */
    .modal-full-mobile .modal-container {
        border-radius: 0;
        height: 100vh;
        max-height: 100vh;
    }
}

/* ========================================================================
   MOBILE BUTTON SIZE ADJUSTMENTS (consolidado ago/2026)
   ========================================================================
   Os blocos per-id com !important (quick-record, sync-button, take-photo,
   export-data, save-restaurant, modal buttons...) repetiam os MESMOS
   valores das regras genéricas .btn abaixo — e metade dos ids já não
   existia no DOM (#manual-sync, #save-sync-settings, #transcribe-audio).
   A margem extra .flex.gap-2 button { margin-right } somava espaçamento
   dentro de layouts que já usam gap (espaçamento duplo). Restaram as
   regras genéricas + o bloco icon-only <400px.
   ======================================================================== */

/* Target both viewport width AND touch devices for maximum compatibility */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
    /* Global rule for all btn-lg buttons on mobile */
    .btn.btn-lg,
    button.btn-lg,
    .btn-lg {
        padding: 0.625rem 1rem !important;
        font-size: 0.875rem !important;
        min-height: 44px !important;
        max-height: 48px !important;
    }
    
    /* Ensure btn-md buttons are also appropriately sized */
    .btn.btn-md,
    button.btn-md,
    .btn-md {
        padding: 0.5rem 1rem !important;
        font-size: 0.875rem !important;
        min-height: 44px !important;
        max-height: 48px !important;
    }
    
    /* Override btn-sm to meet 44px touch target on mobile */
    .btn.btn-sm,
    button.btn-sm,
    .btn-sm {
        padding: 0.625rem 1rem !important;
        font-size: 0.875rem !important;
        min-height: 44px !important;
        max-height: 48px !important;
    }
    
    /* Buttons with full width should maintain padding */
    .btn.w-full,
    .btn-md.w-full,
    .btn-sm.w-full {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    /* Icon-only buttons can be slightly smaller but still meet touch target */
    .btn-icon {
        min-width: 44px !important;
        min-height: 44px !important;
        padding: 0.5rem !important;
    }
}

/* ========================================================================
   RESPONSIVE BUTTON LABELS - ICON-ONLY ON SMALL SCREENS
   Added: October 19, 2025
   Purpose: Show only icons on very small screens, full labels on larger screens
   ======================================================================== */

/* On very small screens (< 400px), show icon only for specific buttons.
   Lista enxuta (ago/2026): ids mortos removidos (#add-restaurant,
   #sync-restaurants-btn, #open-places-search, #open-staging-search) —
   todos os botões da lista têm aria-label no markup. */
@media (max-width: 400px) {
    /* Toolbar buttons - show icon only */
    #save-restaurant span:not(.material-icons),
    #discard-restaurant span:not(.material-icons),
    #save-curator-compact span:not(.material-icons),
    #cancel-curator-compact span:not(.material-icons) {
        display: none;
    }

    /* Quick action buttons - show icon only */
    #quick-record span:not(.material-icons),
    #quick-location span:not(.material-icons),
    #quick-photo span:not(.material-icons) {
        display: none;
    }

    /* Import/Export buttons - show icon only */
    #export-data span:not(.material-icons),
    #import-data span:not(.material-icons) {
        display: none;
    }

    /* Ensure buttons maintain square aspect ratio when icon-only */
    #quick-record,
    #quick-location,
    #quick-photo,
    #export-data,
    #import-data {
        padding: 0.625rem !important;
        min-width: 44px !important;
    }

    /* Toolbar buttons can be slightly more compact */
    #save-restaurant,
    #discard-restaurant,
    #save-curator-compact,
    #cancel-curator-compact {
        padding: 0.5rem !important;
        min-width: 44px !important;
    }

    /* Keep the icon centered - remove margin */
    #quick-record .material-icons,
    #quick-location .material-icons,
    #quick-photo .material-icons,
    #save-restaurant .material-icons,
    #discard-restaurant .material-icons,
    #export-data .material-icons,
    #import-data .material-icons {
        margin: 0 !important;
    }
}

/* ========================================================================
   RECORDING SECTION IMPROVEMENTS
   Added: October 19, 2025
   Purpose: Fix circular timer alignment and z-index issues
   ======================================================================== */

/* Circular timer container should be centered */
#circular-timer-container {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
}

/* Elegant, minimal timer circle design */
.timer-circle {
    position: relative;
    width: 140px;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

/* Timer display - simple and clean */
.timer-display {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    font-weight: 500;
    color: var(--color-primary-600);
    letter-spacing: 0.1em;
    z-index: 2;
    line-height: 1;
}

/* SVG ring container */
.timer-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    z-index: 1;
}

/* Background ring */
.timer-ring-bg {
    fill: none;
    stroke: var(--color-primary-100);
    stroke-width: 3;
}

/* Progress ring */
.timer-ring-progress {
    fill: none;
    stroke: var(--color-primary-600);
    stroke-width: 3;
    stroke-dasharray: 289;
    stroke-dashoffset: 289;
    transition: stroke-dashoffset 1s linear, stroke 0.3s ease;
    stroke-linecap: round;
}

/* Recording active state */
.recording-active .timer-display {
    color: var(--color-primary-700);
}

.recording-active .timer-ring-progress {
    stroke: var(--color-primary-700);
    animation: timer-glow 2s ease-in-out infinite;
}

@keyframes timer-glow {
    0%, 100% {
        filter: drop-shadow(0 0 2px rgba(92, 107, 74, 0.4));
    }
    50% {
        filter: drop-shadow(0 0 6px rgba(92, 107, 74, 0.6));
    }
}

/* Warning state (when approaching time limit) */
.timer-circle.warning .timer-display {
    color: var(--color-error);
    animation: pulse-warning 1s ease-in-out infinite;
}

.timer-circle.warning .timer-ring-progress {
    stroke: var(--color-error);
}

@keyframes pulse-warning {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }
}

/* 
 * IMPORTANT: Recording section should NOT create a stacking context
 * Removed #recording-section, #circular-timer-container, #processing-status, 
 * #audio-preview z-index rules to fix overlay issues.
 * These elements now use normal document flow, allowing notifications and
 * overlays to appear above them correctly.
 */

/* #app consolidado em application.css (media max-width:640px) — o
   override !important duplicado desta camada foi removido. Ago/2026. */

/* Bloco antigo de #restaurant-list-section removido — o id não existe
   no HTML atual (a seção é #entities-section; o próprio uiManager
   corrige isso em runtime). Era CSS morto com seletores acoplados ao
   markup. Ago/2026. */

/* Previous mobile-only version removed - now applies globally */

/* Ensure loading overlay and notifications appear above EVERYTHING */
#loading-overlay {
    z-index: 10000 !important; /* Highest priority - uses design system value + buffer */
}

.toastify,
.toastify-container,
[class*="toast"] {
    z-index: 9999 !important; /* Just below loading overlay */
}

/* Posição do toast (top: 5rem abaixo do header) vem de style.css —
   regras duplicadas removidas daqui. Ago/2026. */

/* Modals should be above content */
.modal,
[id*="modal"],
.fixed.inset-0.bg-black.bg-opacity-50 {
    z-index: 1050 !important; /* --z-modal from design system */
}

/* Fix modal overflow on mobile */
@media (max-width: 768px) {
    .fixed.inset-0.bg-black.bg-opacity-50 {
        align-items: flex-start !important;
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
    
    .fixed.inset-0.bg-black.bg-opacity-50 > div {
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        max-height: calc(100vh - 2rem) !important;
    }
    
    .fixed.inset-0.bg-black.bg-opacity-50 > div > div {
        max-height: calc(100vh - 2rem) !important;
    }
}

/* Toolbars should float above content */
.toolbar-fixed-bottom,
#restaurant-edit-toolbar,
#curator-edit-toolbar {
    z-index: 1030 !important; /* --z-fixed from design system */
}

/* Pulsating effect should not interfere with other elements */
.pulsate {
    animation: pulsate-effect 2s ease-in-out infinite;
    pointer-events: none;
}

@keyframes pulsate-effect {
    0%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.05);
    }
}

/* Processing status steps should be clearly visible */
.processing-step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    border-radius: 0.375rem;
    background-color: rgba(249, 250, 251, 0.8);
}

.processing-step .material-icons {
    font-size: 1.25rem;
}

/* ========================================================================
   CURATOR SECTION ENHANCEMENTS
   Added: October 19, 2025
   Purpose: Improve curator section UX - clickable name, better transitions
   ======================================================================== */

/* Make curator name appear clickable */
#curator-name-compact {
    cursor: pointer;
    transition: color 0.2s ease, transform 0.1s ease;
    user-select: none;
}

#curator-name-compact:hover {
    color: var(--color-primary-700);
    text-decoration: underline;
    text-decoration-style: dotted;
}

#curator-name-compact:active {
    transform: scale(0.98);
}

/* Smooth transitions for curator section state changes */
#curator-section {
    transition: all 0.3s ease;
}

#curator-compact-display,
#curator-edit-form,
#curator-selector-compact {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Add visual feedback when switching views */
#curator-selector-compact:not(.hidden) {
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Horizontal scroll snap */
.scroll-snap-x {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.scroll-snap-x::-webkit-scrollbar {
    display: none;
}

.scroll-snap-item {
    scroll-snap-align: start;
    flex-shrink: 0;
}

/* .mobile-tabs removido (ago/2026): zero referências — a navegação por
   abas é a .view-tab dentro da seção de coleção. */
