/* ===================================================================
   RESPONSIVE.CSS — ImobSys 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; }
  #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; }

  /* --- 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 */
  .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 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: hidden; }
  .topbar-left { flex: 1; min-width: 0; overflow: hidden; }
  .topbar-right { flex-shrink: 0; min-width: max-content; }
  .topbar-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-right [onclick*="profile"] { padding-right: 8px !important; }
  .topbar-right [onclick*="profile"] > div:last-child { display: none !important; }
}

/* ===== SMALL MOBILE (≤ 480px) ===== */
@media (max-width: 480px) {
  .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;
  }
  .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; flex-shrink: 0; min-width: max-content; }
  .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; }

  /* 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); }
}

