/* ==========================================================================
   Responsive — responsive.css
   Layout responsive e mobile
   Sistema Gestionale Immobiliare — Design System Luxury
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Mobile-First Quick Search Overlay (< 768px)
   -------------------------------------------------------------------------- */
.mobile-search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1060;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.mobile-search-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.mobile-search-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--white);
  padding: var(--space-md);
  z-index: 1061;
  transform: translateY(-100%);
  transition: transform var(--transition-base);
  box-shadow: var(--shadow-lg);
}

.mobile-search-panel.active {
  transform: translateY(0);
}

.mobile-search-panel .quick-search-wrapper {
  width: 100%;
}

.mobile-search-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--gray-dark);
  cursor: pointer;
  z-index: 1;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --------------------------------------------------------------------------
   2. Pull-to-Refresh (Touch devices)
   -------------------------------------------------------------------------- */
.pull-to-refresh {
  position: fixed;
  top: var(--navbar-height);
  left: 0;
  right: 0;
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-light);
  z-index: 1020;
  transition: height 0.2s ease;
}

.pull-to-refresh.pulling {
  height: 50px;
}

.pull-to-refresh.refreshing {
  height: 50px;
}

.pull-to-refresh-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--gray-medium);
  border-top-color: var(--primary);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.pull-to-refresh.pulling .pull-to-refresh-spinner {
  opacity: 1;
}

.pull-to-refresh.refreshing .pull-to-refresh-spinner {
  opacity: 1;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------------------
   3. Tablet (768px – 1199px): Sidebar collapsed, content adjusts
   -------------------------------------------------------------------------- */
@media (min-width: 768px) and (max-width: 1199.98px) {
  .quick-search-results {
    max-height: 50vh;
    overflow-y: auto;
  }
}

/* --------------------------------------------------------------------------
   4. Mobile (< 768px): Bottom nav, single-column, native app feel
   -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {

  /* --- Global mobile resets --- */
  body {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
  }

  /* Mobile search overlay visible */
  .mobile-search-overlay {
    display: block;
  }

  /* Pull-to-refresh adjusts for no navbar offset on mobile */
  .pull-to-refresh {
    top: var(--navbar-height);
  }

  /* --- Navbar compact on mobile --- */
  .top-navbar {
    padding: 0 var(--space-md);
    height: 56px;
    justify-content: space-between;
  }

  /* Mobile brand in navbar */
  .navbar-mobile-brand {
    display: flex;
    align-items: center;
    flex-shrink: 0;
  }

  .navbar-mobile-logo {
    height: 20px;
    width: auto;
  }

  .navbar-actions {
    gap: var(--space-sm);
  }

  .navbar-action-btn {
    width: 44px;
    height: 44px;
  }

  .navbar-user-btn {
    padding: 3px;
    border-color: transparent;
  }

  .navbar-user-btn .navbar-user-name,
  .navbar-user-btn .navbar-user-chevron {
    display: none;
  }

  /* Notification dropdown full-width on mobile */
  .navbar-actions .dropdown-menu {
    position: fixed !important;
    top: 56px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    transform: none !important;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
  }

  /* --- Content area --- */
  .main-content {
    padding-top: 56px;
    padding-bottom: 72px; /* space for mobile nav */
  }

  .content-wrapper {
    padding: var(--space-md);
  }

  .container-fluid {
    padding-left: var(--space-sm);
    padding-right: var(--space-sm);
  }

  /* --- Page headers --- */
  .page-header {
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
  }

  .page-header h1,
  .page-title {
    font-size: 1.5rem;
  }

  .page-subtitle {
    font-size: 0.8125rem;
  }

  /* --- Property grid single column --- */
  .property-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }

  /* --- Property cards --- */
  .property-card {
    border-radius: var(--radius-md);
  }

  .property-card-body {
    padding: var(--space-md);
  }

  .property-card-overlay {
    padding: var(--space-md);
  }

  .property-card-meta {
    gap: var(--space-sm);
    flex-wrap: wrap;
  }

  /* --- Stat cards --- */
  .stat-card {
    padding: var(--space-md);
  }

  .stat-card-value {
    font-size: 1.5rem;
  }

  .stat-card .card-body {
    padding: var(--space-md);
  }

  .stat-card .stat-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .stat-card .stat-icon i {
    font-size: 1rem;
  }

  .stat-card .stat-value {
    font-size: 1.25rem;
  }

  .stat-card .stat-label {
    font-size: 0.6875rem;
  }

  /* --- Cards general --- */
  .card-body {
    padding: var(--space-md);
  }

  .card-header {
    padding: var(--space-md);
  }

  /* --- Side panel full-width on mobile --- */
  .side-panel {
    width: 100vw;
    right: -100vw;
  }

  .side-panel.open {
    right: 0;
  }

  /* --- Quick search results full-width --- */
  .quick-search-results {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    max-height: calc(100vh - 60px);
    overflow-y: auto;
    border-radius: 0;
    z-index: 1062;
  }

  /* --- Toast repositioned above mobile nav --- */
  .toast-luxury {
    bottom: calc(72px + var(--space-sm));
    right: var(--space-sm);
    left: var(--space-sm);
    min-width: auto;
    max-width: none;
  }

  .toast-luxury:nth-child(2) {
    bottom: calc(72px + var(--space-sm) + 80px);
  }

  .toast-luxury:nth-child(3) {
    bottom: calc(72px + var(--space-sm) + 160px);
  }

  /* --- Tables: always scrollable on mobile --- */
  .table-responsive,
  .table-responsive-mobile {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 calc(-1 * var(--space-md));
    padding: 0 var(--space-md);
  }

  .table {
    font-size: 0.8125rem;
    white-space: nowrap;
  }

  .table thead th {
    font-size: 0.6875rem;
    padding: var(--space-sm);
  }

  .table tbody td {
    padding: var(--space-sm);
  }

  /* --- Modal: slide-up sheet style --- */
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    min-height: auto;
    display: flex;
    align-items: flex-end;
  }

  .modal-content {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    min-height: auto;
    max-height: 92vh;
    overflow-y: auto;
  }

  .modal-header {
    padding: var(--space-md);
    position: sticky;
    top: 0;
    z-index: 1;
  }

  .modal-body {
    padding: var(--space-md);
  }

  .modal-footer {
    padding: var(--space-md);
    position: sticky;
    bottom: 0;
    background: var(--white);
  }

  .modal-title {
    font-size: 1.125rem;
  }

  /* Full-screen modals for complex forms */
  .modal-lg .modal-dialog,
  .modal-xl .modal-dialog {
    align-items: stretch;
  }

  .modal-lg .modal-content,
  .modal-xl .modal-content {
    border-radius: 0;
    max-height: 100vh;
    min-height: 100vh;
  }

  /* --- Forms: full-width inputs --- */
  .form-control,
  .form-select {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 0.75rem 1rem;
  }

  .input-group .form-control,
  .input-group .form-select {
    font-size: 16px;
  }

  .input-group .btn {
    padding: 0.75rem 1rem;
  }

  /* Form rows stack on mobile */
  .row.g-3 > [class*="col-md-"],
  .row.g-4 > [class*="col-md-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  /* Keep col-6 as half-width for compact fields */
  .row.g-3 > .col-6,
  .row.g-4 > .col-6 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  /* --- Buttons: touch-friendly sizes --- */
  .btn {
    min-height: 44px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
  }

  .btn-sm {
    min-height: 38px;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
  }

  .btn-group .btn {
    min-height: 38px;
  }

  /* Action button groups wrap nicely */
  .d-flex.gap-2 {
    flex-wrap: wrap;
  }

  /* --- Breadcrumb compact --- */
  .breadcrumb {
    font-size: 0.75rem;
    margin-bottom: var(--space-sm);
  }

  /* --- Kanban board: vertical stack on mobile --- */
  .kanban-board {
    flex-direction: column;
    overflow-x: visible;
  }

  .kanban-column {
    min-width: 100%;
    max-width: 100%;
    flex: none;
  }

  .kanban-column-body {
    min-height: auto;
    max-height: 300px;
    overflow-y: auto;
  }

  .kanban-card-body {
    padding: var(--space-sm);
  }

  /* --- Calendar compact --- */
  .calendar-cell {
    min-height: 52px;
    padding: 2px;
  }

  .calendar-cell-date {
    font-size: 0.6875rem;
    width: 22px;
    height: 22px;
  }

  .calendar-event {
    font-size: 0.5625rem;
    padding: 1px 3px;
  }

  .calendar-event-time {
    display: none;
  }

  .calendar-header-cell {
    font-size: 0.625rem;
    padding: 0.375rem 0.125rem;
  }

  /* Week view: horizontal scroll */
  .calendar-week-grid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .calendar-week-body {
    max-height: 400px;
  }

  /* --- Gallery / Lightbox --- */
  .gallery-main img {
    max-height: 250px;
  }

  .gallery-thumb {
    width: 60px;
    height: 45px;
  }

  .lightbox-prev,
  .lightbox-next {
    padding: 0.5rem;
    font-size: 1.25rem;
  }

  .lightbox-prev { left: 0.5rem; }
  .lightbox-next { right: 0.5rem; }

  .lightbox-close {
    top: 0.5rem;
    right: 0.75rem;
    font-size: 1.75rem;
    min-width: 44px;
    min-height: 44px;
  }

  /* --- Photo grid compact --- */
  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.5rem;
  }

  /* --- Upload zone compact --- */
  .upload-zone {
    padding: 1rem;
  }

  .upload-zone i {
    font-size: 1.5rem;
  }

  /* --- Property show page sidebar stacks below --- */
  .col-lg-4 .card-luxury {
    margin-bottom: var(--space-md);
  }

  /* Price display smaller on mobile */
  .display-6 {
    font-size: 1.5rem;
  }

  /* --- Dropdown menus --- */
  .dropdown-menu {
    font-size: 0.875rem;
  }

  .dropdown-item {
    padding: 0.625rem 1rem;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* --- Badges --- */
  .badge {
    font-size: 0.6875rem;
  }

  /* --- Alert compact --- */
  .alert {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.8125rem;
  }

  /* --- Activity list compact --- */
  .activity-item {
    padding: var(--space-sm) 0;
  }

  .activity-item .small {
    font-size: 0.75rem;
  }

  /* --- Pagination compact --- */
  .pagination {
    flex-wrap: wrap;
    gap: 2px;
  }

  .page-link {
    padding: 0.375rem 0.625rem;
    font-size: 0.8125rem;
    min-width: 36px;
    text-align: center;
  }

  /* --- Empty state compact --- */
  .empty-state {
    padding: var(--space-xl) var(--space-md);
  }

  .empty-state i {
    font-size: 2rem;
  }

  /* --- Map page --- */
  #map {
    height: calc(100vh - 56px - 72px - 60px) !important;
    min-height: 300px;
  }

  .map-filters-panel {
    max-height: 50vh;
    overflow-y: auto;
  }

  /* --- Reports page --- */
  .chart-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* --- Settings / Metadata tables --- */
  .settings-page .table {
    font-size: 0.75rem;
  }

  /* --- Compare page: stack cards --- */
  .compare-grid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* --- Shortlist grid --- */
  .shortlist-grid {
    grid-template-columns: 1fr;
  }

  /* --- File manager --- */
  .file-list .list-group-item {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.8125rem;
  }

  /* --- Page headers: stack on mobile, buttons wrap --- */
  .d-flex.flex-wrap.justify-content-between {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .d-flex.flex-wrap.justify-content-between > div:first-child {
    min-width: 0;
    width: 100%;
  }

  .d-flex.flex-wrap.justify-content-between > .d-flex {
    flex-wrap: wrap;
    width: 100%;
  }

  .page-title {
    text-align: left;
  }

  /* --- Mobile nav adjustments --- */
  .mobile-nav {
    height: 64px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  }

  .mobile-nav-link {
    font-size: 0.625rem;
    gap: 2px;
  }

  .mobile-nav-link i {
    font-size: 1.25rem;
  }

  /* "Altro" button in bottom nav — reset button styles */
  #altroMenuToggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
  }

  /* --- Altro slide-up panel --- */
  .altro-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1070;
    opacity: 0;
    transition: opacity 0.25s ease;
  }

  .altro-overlay.open {
    display: block;
    opacity: 1;
  }

  .altro-panel {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white, #fff);
    z-index: 1071;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    max-height: 70vh;
    overflow-y: auto;
    padding-bottom: 72px; /* space for bottom nav behind */
  }

  .altro-panel.open {
    display: block;
    transform: translateY(0);
  }

  .altro-panel-handle {
    width: 36px;
    height: 4px;
    background: var(--gray-medium, #ccc);
    border-radius: 2px;
    margin: 10px auto 0;
  }

  .altro-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px 8px;
  }

  .altro-panel-title {
    font-family: 'Bellefair', serif;
    font-size: 1.25rem;
    font-weight: 400;
    color: var(--primary, #183028);
  }

  .altro-panel-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--gray-dark, #666);
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .altro-panel-body {
    padding: 4px 12px 16px;
  }

  .altro-menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 12px;
    border-radius: 10px;
    color: var(--gray-dark, #444);
    text-decoration: none;
    font-size: 0.9375rem;
    transition: background 0.15s ease;
  }

  .altro-menu-item:hover,
  .altro-menu-item:active {
    background: rgba(24, 48, 40, 0.06);
    color: var(--primary, #183028);
  }

  .altro-menu-item.active {
    background: rgba(24, 48, 40, 0.1);
    color: var(--primary, #183028);
    font-weight: 600;
  }

  .altro-menu-item i {
    font-size: 1.25rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
  }

  .altro-section-divider {
    height: 1px;
    background: var(--gray-light, #eee);
    margin: 4px 12px;
  }

  /* --- Flex overflow prevention --- */
  .d-flex {
    min-width: 0;
  }

  .d-flex > * {
    min-width: 0;
  }

  /* Prevent horizontal overflow from flex gaps */
  .row {
    margin-left: 0;
    margin-right: 0;
  }

  /* --- Share link input compact --- */
  .list-group-item input[readonly] {
    font-size: 0.6875rem;
  }
}

/* --------------------------------------------------------------------------
   5. Small Phones (< 576px)
   -------------------------------------------------------------------------- */
@media (max-width: 575.98px) {
  .auth-card {
    padding: var(--space-lg) var(--space-md);
    margin: var(--space-sm);
  }

  .auth-logo h1 {
    font-size: 1.125rem;
  }

  .navbar-actions {
    gap: var(--space-xs);
  }

  .content-wrapper {
    padding: var(--space-sm);
  }

  /* Stat cards: 2 per row, tighter */
  .stat-card .card-body {
    padding: var(--space-sm);
    gap: var(--space-sm);
  }

  .stat-card .stat-icon {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  .stat-card .stat-value {
    font-size: 1.125rem;
  }

  .stat-card .stat-label {
    font-size: 0.625rem;
  }

  /* Page title even smaller */
  .page-title {
    font-size: 1.25rem;
  }

  /* Action buttons: compact on small phones */
  .page-header .d-flex.gap-2 {
    width: 100%;
    flex-wrap: wrap;
  }

  .page-header .d-flex.gap-2 .btn {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    font-size: 0.8125rem;
    padding: 0.375rem 0.625rem;
  }

  /* Property show header buttons */
  .d-flex.gap-2.flex-wrap .btn,
  .d-flex.gap-2.flex-wrap form {
    flex: 1 1 auto;
  }

  .d-flex.gap-2.flex-wrap form .btn {
    width: 100%;
  }

  /* Calendar header controls stack */
  .d-flex.gap-2.flex-wrap.align-items-center {
    width: 100%;
  }

  .d-flex.gap-2.flex-wrap.align-items-center .btn-group {
    flex: 0 0 auto;
  }
}

/* --------------------------------------------------------------------------
   6. Landscape Mobile
   -------------------------------------------------------------------------- */
@media (max-height: 500px) and (orientation: landscape) {
  .auth-wrapper {
    padding: var(--space-md);
  }

  .auth-card {
    padding: var(--space-lg);
  }

  .mobile-nav {
    height: 48px;
  }

  .mobile-nav-link {
    font-size: 0.625rem;
  }

  .mobile-nav-link i {
    font-size: 1rem;
  }

  .main-content {
    padding-bottom: 56px;
  }

  /* Modal doesn't need to be full height in landscape */
  .modal-content {
    max-height: 90vh;
  }
}

/* --------------------------------------------------------------------------
   7. Touch-specific Enhancements
   -------------------------------------------------------------------------- */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .sidebar-link {
    padding: 0.875rem var(--space-lg);
  }

  .mobile-nav-link {
    min-width: 48px;
    min-height: 48px;
  }

  .dropdown-item {
    padding: 0.625rem 1rem;
    min-height: 44px;
  }

  /* Disable hover effects on touch */
  .property-card:hover {
    transform: none;
    box-shadow: var(--shadow-card);
  }

  .btn:hover {
    transform: none;
  }

  .card:hover {
    box-shadow: var(--shadow-card);
  }

  .card-hover-lift:hover {
    transform: none;
    box-shadow: var(--shadow-card);
  }

  .kanban-card:hover {
    transform: none;
  }

  /* Smooth scrolling for lists */
  .content-wrapper {
    -webkit-overflow-scrolling: touch;
  }

  /* Photo delete button always visible on touch */
  .photo-grid-item .photo-delete-btn {
    opacity: 0.85;
  }

  /* Ensure all interactive elements have adequate tap targets */
  a, button, [role="button"], input, select, textarea {
    min-height: 44px;
  }

  /* Exceptions for inline/small elements */
  .badge, .form-check-input, .photo-delete-btn,
  .pagination .page-link, .btn-sm, .btn-close {
    min-height: auto;
  }
}

/* --------------------------------------------------------------------------
   8. Reduced Motion Preference
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .pull-to-refresh-spinner {
    animation: none !important;
  }
}

/* --------------------------------------------------------------------------
   9. Print Overrides
   -------------------------------------------------------------------------- */

/* Altro panel: hidden on desktop (only visible inside mobile media query) */
.altro-overlay,
.altro-panel {
  display: none;
}

@media print {
  .mobile-nav,
  .pull-to-refresh,
  .mobile-search-overlay,
  .mobile-search-panel,
  .toast-container,
  .toast-luxury {
    display: none !important;
  }
}
