/* ===================================================================
   HOVER UTILITY CLASSES — substitui inline onmouseover/onmouseout
   Necessário pois CSP bloqueia inline event handlers (pentest N-02)
   =================================================================== */
.card-hover-lift:hover { transform: translateY(-2px); box-shadow: var(--shadow-md, 0 4px 16px rgba(0,0,0,0.12)); }
.card-hover-shadow:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.btn-hover-bg:hover { background: var(--border, #e2e8f0) !important; }
.btn-hover-opacity:hover { opacity: 0.88; }
.btn-remove-hover:hover { color: #e74c3c !important; }
.agenda-nav-btn:hover { background: rgba(255,255,255,.35) !important; }
.agenda-cell-hover:hover { background: #eff6ff !important; }
.agenda-item-hover:hover { background: #f8fafc !important; }
.drop-zone-hover:hover { border-color: #1a3a5c !important; }

/* ===================================================================
   RESPONSIVE.CSS — Fluxo Chave Mobile-First Responsive Layer
   Handles all breakpoints without breaking existing desktop layout
   =================================================================== */

/* ===== TOUCH IMPROVEMENTS ===== */
* { -webkit-tap-highlight-color: transparent; }
input, textarea, select { font-size: 16px !important; } /* Prevents iOS zoom */

/* ===== SIDEBAR OVERLAY ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 999;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.visible { display: block; }

/* ===== HAMBURGER BUTTON ===== */
#menuToggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--bg);
  border: 1.5px solid var(--border) !important;
  color: var(--text);
  cursor: pointer;
  margin-right: 12px;
  flex-shrink: 0;
  transition: background 0.2s;
}
#menuToggle:hover { background: #e8eef5; }
#menuToggle svg { width: 22px; height: 22px; }

/* ===== LARGE TABLETS (≤ 1100px) ===== */
@media (max-width: 1100px) {
  :root { --sidebar-w: 240px; }
  .grid-2, .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .property-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

/* ===== TABLETS / SMALL DESKTOP (≤ 900px) ===== */
@media (max-width: 900px) {
  .page-content { padding: 20px; }
  .agenda-grid { grid-template-columns: 1fr !important; }
}

/* ===== TABLETS / MOBILE (≤ 768px) ===== */
@media (max-width: 768px) {
  /* --- Sidebar slides out, overlay appears --- */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
    z-index: 1000;
    width: 280px !important;
    transition: transform 0.28s cubic-bezier(.4,0,.2,1);
  }
  .sidebar.open {
    transform: none;
    box-shadow: 4px 0 32px rgba(0,0,0,0.25);
  }
  .main-content { margin-left: 0 !important; min-width: 0; }
  #menuToggle { display: flex !important; }

  /* --- Topbar --- */
  .topbar { padding: 0 12px; height: 56px; }
  .topbar-title { font-size: 16px; }
  .topbar-breadcrumb { display: none; }
  .topbar-right { gap: 6px; }
  .topbar-btn { width: 38px; height: 38px; }

  /* --- Page content --- */
  .page-content { padding: 14px; }

  /* --- Stats grid 2-col --- */
  .stats-grid { grid-template-columns: 1fr 1fr; }

  /* --- Grid classes --- */
  .grid-2, .grid-3, .grid-1-2, .grid-2-1 { grid-template-columns: 1fr; }

  /* --- Card grids: force 1 col and cancel card-body overflow so they wrap --- */
  .fc-card-grid { grid-template-columns: 1fr !important; overflow-x: visible !important; }
  .card-body:has(.fc-card-grid) { overflow-x: visible !important; }

  /* --- Stat rows (vistoria 4 stats, etc): 2 cols on small screens --- */
  .fc-stat-row { grid-template-columns: repeat(2, 1fr) !important; }

  /* --- Property grid single col --- */
  .property-grid { grid-template-columns: 1fr; }

  /* --- Tables: force horizontal scroll --- */
  .card-body, .card > div:not(.card-header):not(.card-footer) { overflow-x: auto; }
  table { min-width: 560px; font-size: 13px; }
  th, td { padding: 10px 12px; white-space: nowrap; }

  /* --- Inline grid overrides (form rows, stat rows in all views) --- */
  .page-content [style*="grid-template-columns"],
  .modal-overlay [style*="grid-template-columns"],
  .modal-body [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Exception: preserve 7-column calendar days grid — higher specificity to beat the generic override */
  .page-content .agenda-cal-days,
  .agenda-cal-days { grid-template-columns: repeat(7, 1fr) !important; }

  /* Exception: auto-fill photo/thumbnail grids */
  .page-content [style*="grid-template-columns:repeat(auto-fill"],
  .modal-overlay [style*="grid-template-columns:repeat(auto-fill"],
  [style*="grid-template-columns: repeat(auto-fill"] {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)) !important;
  }

  /* --- Login --- */
  .login-left { display: none !important; }
  .login-right { width: 100% !important; padding: 28px 20px !important; min-height: 100vh; }
  .login-form-wrap { max-width: 420px; margin: 0 auto; }
  .login-title { font-size: 22px !important; }

  /* --- Modal --- */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100% !important;
    max-height: 92vh !important;
    border-radius: 16px 16px 0 0 !important;
    width: 100% !important;
    margin: 0 !important;
    overflow-y: auto;
  }
  .modal-lg, .modal-xl { max-width: 100% !important; }
  .modal-body { padding: 16px !important; }
  .modal-header { padding: 14px 16px !important; position: sticky; top: 0; z-index: 10; background: var(--surface); }
  .modal-footer { padding: 12px 16px !important; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); }
  .modal-footer button { flex: 1; min-width: 100px; }

  /* --- Notification dropdown --- */
  .notif-dropdown {
    width: calc(100vw - 24px) !important;
    right: -80px !important;
    max-height: 85vh !important;
  }

  /* --- Search bar stacks --- */
  .search-bar { flex-direction: column; align-items: stretch; }
  .search-bar input { width: 100% !important; }

  /* --- Filter tabs scroll --- */
  .filter-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }

  /* --- Chat layout --- */
  .chat-layout { grid-template-columns: 1fr !important; }
  .chat-sidebar { display: none; }

  /* --- Funnel kanban: horizontal scroll --- */
  .funnel-board {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    gap: 12px !important;
    padding-bottom: 12px;
  }
  .funnel-column, .kanban-column {
    min-width: 280px !important;
    max-width: 280px !important;
    scroll-snap-align: start;
    flex-shrink: 0;
  }

  /* --- Agenda nav mobile improvements --- */
  .ag-nav-bar { padding: 12px 14px !important; gap: 8px; }
  .agenda-nav-btn { min-width: 44px !important; min-height: 44px !important; }
  .ag-nav-selects select { font-size: 13px !important; padding: 4px 8px !important; }
  .ag-today-btn { min-height: 44px !important; padding: 8px 12px !important; }

  /* --- Agenda calendar compact on mobile --- */
  .agenda-cal-days > div { font-size: 11px; padding: 6px 2px !important; }

  /* --- Property detail grid --- */
  .property-detail-grid { grid-template-columns: 1fr !important; }

  /* --- Plans / portals / templates grids --- */
  .plans-grid { grid-template-columns: 1fr; }
  .portal-grid { grid-template-columns: repeat(2, 1fr); }
  .templates-grid { grid-template-columns: 1fr; }
  .plano-features { grid-template-columns: 1fr; }

  /* --- Publish property card stacks --- */
  .publish-property-card { flex-direction: column; }
  .publish-prop-img { width: 100%; height: 120px; }
  .publish-prop-actions { flex-direction: row; flex-wrap: wrap; }

  /* --- Button groups wrap --- */
  .btn-group { flex-wrap: wrap; }
  .plano-actions { flex-direction: column; }
  .plano-actions button { width: 100%; }

  /* --- Hide sidebar user role on tiny screens --- */
  .sidebar-user-role { font-size: 10px; }

  /* --- Form inputs full width --- */
  input[style*="width:"], select[style*="width:"], textarea[style*="width:"] {
    width: 100% !important;
    box-sizing: border-box;
  }

  /* --- Profile / broker hero section stacks --- */
  [style*="grid-template-columns:3fr 1fr"],
  [style*="grid-template-columns: 3fr 1fr"],
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* --- 4-col stat row → 2-col --- */
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4,1fr)"],
  [style*="grid-template-columns:repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* --- 3-col stat row → 2-col --- */
  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns: repeat(3,1fr)"],
  [style*="grid-template-columns:repeat(3, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* --- Opportunities cards grid --- */
  .opportunities-grid { grid-template-columns: 1fr !important; }

  /* --- Finance: chart containers --- */
  .finance-charts { grid-template-columns: 1fr !important; }

  /* --- Topbar flex wrap protection --- */
  .topbar { flex-wrap: nowrap; overflow: visible; }
  .topbar-left { flex: 1; min-width: 0; overflow: hidden; }
  .topbar-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* --- Notification badge must not be clipped by parent overflow --- */
  #notifBellWrap { overflow: visible !important; }
  .notif-bell-btn { overflow: visible !important; }

  /* --- Sidebar nav labels: truncate long text --- */
  .nav-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

  /* --- Topbar right: keep compact, prevent overflow --- */
  .topbar-right { flex-shrink: 0; overflow: visible; }

  /* --- User button: hide name/role text to save space on mobile --- */
  #topbarUserName,
  #topbarUserMenuWrap button > div:last-of-type > span:last-child { display: none !important; }
  #topbarUserMenuWrap button > div:last-of-type { display: none !important; }
  #topbarUserMenuWrap button > svg { display: none !important; }
  #topbarUserMenuWrap button { padding: 4px !important; border-radius: 50% !important; gap: 0 !important; }
}

/* ===== SMALL MOBILE (≤ 480px) ===== */
@media (max-width: 480px) {
  /* --- Stats card numbers: prevent overflow on tiny cards --- */
  .stat-value, .profile-stat-value {
    font-size: clamp(16px, 5vw, 26px) !important;
    word-break: break-all;
  }

  .stats-grid { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3, .grid-1-2, .grid-2-1 { grid-template-columns: 1fr; }

  .page-content [style*="grid-template-columns"],
  .modal-overlay [style*="grid-template-columns"],
  .modal-body [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  .page-content .agenda-cal-days,
  .agenda-cal-days { grid-template-columns: repeat(7, 1fr) !important; }

  .page-content [style*="grid-template-columns:repeat(auto-fill"],
  .modal-overlay [style*="grid-template-columns:repeat(auto-fill"],
  [style*="grid-template-columns: repeat(auto-fill"] {
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)) !important;
  }

  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4,1fr)"],
  [style*="grid-template-columns:repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns: repeat(3,1fr)"],
  [style*="grid-template-columns:repeat(3, 1fr)"] {
    grid-template-columns: 1fr !important;
  }

  table { min-width: 440px; font-size: 12px; }
  th, td { padding: 8px 10px; }

  .funnel-column, .kanban-column { min-width: 240px !important; max-width: 240px !important; }
  .page-content { padding: 10px; }
  .topbar { padding: 0 10px; }
  .topbar-title { font-size: 15px; }
  .topbar-right { gap: 4px; }
  .topbar-btn { width: 36px; height: 36px; }

  .modal { max-height: 96vh !important; border-radius: 12px 12px 0 0 !important; }
  .card-body { padding: 14px !important; }
  .card-header { padding: 14px 14px 0 !important; }

  .property-card-actions { flex-direction: column; }
  .portal-grid { grid-template-columns: 1fr; }
  .btn { min-height: 44px; }

  /* --- Agenda: 1-letter day headers + nav bar wraps --- */
  .ag-day-full { display: none !important; }
  .ag-day-short { display: inline !important; }
  .ag-nav-bar { flex-wrap: wrap; }
  .ag-nav-selects { width: 100%; order: -1; }
  .ag-today-btn { flex: 1; min-width: 60px; }
  .agenda-cal-days > div { font-size: 10px !important; padding: 4px 1px !important; }

  /* Login tighter on small phones */
  .login-right { padding: 20px 16px !important; }
  .login-title { font-size: 20px !important; }
  .login-sub { font-size: 13px !important; }
}

/* ===== VERY SMALL MOBILE (≤ 360px) ===== */
@media (max-width: 360px) {
  .topbar-title { font-size: 14px; }
  :root { font-size: 13px; }
  table { min-width: 340px; }
  th, td { padding: 6px 8px; font-size: 11px; }
  .page-content { padding: 8px; }
  .agenda-cal-days > div { font-size: 10px !important; padding: 4px 1px !important; }
  .login-right { padding: 16px 12px !important; }
}

/* ===== SAFE AREA (iPhone notch / Dynamic Island) ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .sidebar { padding-bottom: env(safe-area-inset-bottom); }
  .page-content { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .topbar {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-top: env(safe-area-inset-top);
  }
  .modal-footer { padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important; }
}

/* ===== BODY SCROLL LOCK when sidebar open on mobile ===== */
body.sidebar-open { overflow: hidden; }

/* ===== LANDSCAPE ORIENTATION on mobile ===== */
@media (max-width: 768px) and (orientation: landscape) {
  .modal { max-height: 98vh !important; }
  .login-right { padding: 16px 40px !important; }
  .topbar { height: 48px; }
}

/* ===== LARGE DESKTOP (≥ 1400px) ===== */
@media (min-width: 1400px) {
  :root { --sidebar-w: 280px; }
  .property-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ===== SIDEBAR AVATAR + TOUR BUTTON ===== */
/* Desktop: avatar card e tour button funcionam com largura total da sidebar */
.sidebar-user { touch-action: manipulation; }

/* Mobile (sidebar open): ajuste de padding e touch target */
@media (max-width: 768px) {
  .sidebar-bottom { padding: 12px 14px 16px; }
  .sidebar-user { padding: 10px; gap: 10px; }
  .sidebar-user-avatar { width: 36px; height: 36px; font-size: 14px; }
  /* Tour button: touch target mínimo 44px */
  .sidebar-bottom .nav-item[data-action="start-onboarding-tour"] {
    min-height: 44px;
    padding: 10px 12px;
  }
}

@media (max-width: 480px) {
  .sidebar-bottom { padding: 10px 12px 14px; }
  .sidebar-user-name { font-size: 12px; }
  .sidebar-user-role { font-size: 10px; }
}

/* ===== MODAL DO USUÁRIO (Indicações / Configurações / Suporte / Sair) ===== */
/* Os botões internos do modal já herdam .modal-body mas precisam de touch target adequado */
@media (max-width: 768px) {
  /* Modal de usuário desliza de baixo (bottom-sheet, já coberto pelo .modal global) */
  /* Garante botões com altura mínima tocável */
  .modal-body button[data-action="user-modal-nav"],
  .modal-body button[data-action="logout"] {
    min-height: 52px;
  }
  /* Avatar no header do modal: tamanho reduzido em telas pequenas */
  .modal-header img[style*="52px"],
  .modal-header div[style*="52px"] {
    width: 44px !important;
    height: 44px !important;
    font-size: 18px !important;
  }
}

@media (max-width: 480px) {
  .modal-body button[data-action="user-modal-nav"] {
    padding: 11px 12px !important;
    gap: 10px !important;
  }
  /* Ícone dos botões: levemente menor em tela muito pequena */
  .modal-body button[data-action="user-modal-nav"] > div:first-child {
    width: 32px !important;
    height: 32px !important;
  }
}

/* ===== REFERRAL VIEW — Ajustes responsivos adicionais ===== */
/* O referral.js já tem breakpoints internos em 600px e 400px.
   Aqui cobre o que não está dentro do componente. */
@media (max-width: 768px) {
  #referralViewRoot .r-wrap { padding: 16px 12px 48px; gap: 12px; }
  #referralViewRoot .r-hero { padding: 20px 16px; }
  #referralViewRoot .r-hero h2 { font-size: 18px; }
  #referralViewRoot .r-hero p { font-size: 12px; margin-bottom: 16px; }
  #referralViewRoot .r-linkbox { flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
  #referralViewRoot .r-linkurl { width: 100%; }
  #referralViewRoot .r-copybtn { width: 100%; justify-content: center; }
  #referralViewRoot .r-seal { flex-direction: column; gap: 12px; padding: 16px; }
  #referralViewRoot .r-sealicon { width: 44px; height: 44px; }
  #referralViewRoot .r-sealtitle { font-size: 14px; }
  #referralViewRoot .r-card { padding: 16px; }
  #referralViewRoot .r-stat { font-size: 24px; }
  #referralViewRoot .r-benefit { flex-direction: column; gap: 10px; }
  #referralViewRoot .r-bicon { width: 36px; height: 36px; }
  /* Botão de copiar link: tamanho tocável */
  #referralViewRoot .r-copybtn,
  #referralViewRoot .r-sbtn { min-height: 40px; }
}

@media (max-width: 480px) {
  #referralViewRoot .r-wrap { padding: 12px 10px 40px; }
  #referralViewRoot .r-hero { padding: 16px 14px; border-radius: 10px; }
  #referralViewRoot .r-hero h2 { font-size: 16px; }
  #referralViewRoot .r-infbanner { flex-direction: column; gap: 8px; padding: 10px 12px; }
  #referralViewRoot .r-refrow { gap: 8px; }
  #referralViewRoot .r-refright { gap: 2px; }
  #referralViewRoot .r-av { width: 32px; height: 32px; font-size: 12px; }
  /* Share buttons empilham em coluna */
  #referralViewRoot .r-share { flex-direction: column; }
  #referralViewRoot .r-sbtn { width: 100%; justify-content: center; }
}

