/*! KeyMax Responsive v3 — Global mobile-first overrides
 *  Injected via manager_header.php → all /manager/ pages
 *  Breakpoints: 320 → 480 → 768 → 1024 → 1440
 * ─────────────────────────────────────────────────── */

/* ═══ 0. FOUNDATIONS ═══ */
*,*::before,*::after{box-sizing:border-box}
html{-webkit-text-size-adjust:100%;scroll-behavior:smooth}
body{-webkit-tap-highlight-color:transparent;overflow-x:hidden}
img,video,iframe{max-width:100%}
input,select,textarea,button{font-size:16px!important}

a,button,.btn,[role="button"]{min-height:44px;min-width:44px}
.btn-xs{min-height:36px;min-width:36px}

/* ═══ 1. NAV — Hamburger & Slide-out ═══ */

/* Desktop: hide mobile-only elements */
@media(min-width:992px){
  .km-mobile-toggle{display:none!important}
  .km-mobile-overlay{display:none!important}
  .km-drawer-actions{display:none!important}
}

/* Mobile/Tablet */
@media(max-width:991.98px){
  /* Hide top action row — links cloned into drawer by JS */
  .nav-top-row{display:none!important}

  /* Compact header */
  .nav-header{padding:4px 10px 2px!important;margin-bottom:10px!important}
  .km-header-bar{position:sticky;top:0;z-index:1040}
  .km-header-inner{flex-wrap:nowrap;overflow:visible!important}

  /* Hamburger button */
  .km-mobile-toggle{
    display:flex!important;align-items:center;justify-content:center;
    position:fixed;top:6px;right:10px;z-index:1060;
    background:#1a56db;color:#fff;border:2px solid rgba(255,255,255,.4);
    font-size:24px;width:44px;height:44px;border-radius:8px;
    cursor:pointer;padding:0;line-height:1;
    -webkit-tap-highlight-color:rgba(0,0,0,0.2)
  }

  /* Logo cleanup */
  .km-header-bar .nav-scroll .km-logo{display:none}
  .km-header-inner>.nav-logo-wrap{flex-shrink:0}

  /* ── Nav drawer: HIDDEN by default (bulletproof) ── */
  .km-header-bar .nav-scroll{
    display:none!important
  }

  /* ── Nav drawer: VISIBLE when .open class added ── */
  .km-header-bar .nav-scroll.open{
    display:flex!important;flex-direction:column!important;
    position:fixed!important;top:0!important;right:0!important;left:auto!important;
    width:270px!important;height:100vh!important;
    background:linear-gradient(180deg,#1a3f8a 0%,#122c6b 100%)!important;
    padding:70px 16px 100px!important;gap:4px!important;
    box-shadow:-4px 0 24px rgba(0,0,0,.3)!important;
    overflow-x:hidden!important;overflow-y:auto!important;z-index:1050!important;
    border-bottom:none!important;
    white-space:normal!important;
    flex:none!important;
    align-items:stretch!important;
    scrollbar-width:none!important
  }

  /* Nav links inside drawer */
  .nav-link-custom{
    padding:14px 16px!important;width:100%;border-radius:8px;
    font-size:14px!important;letter-spacing:.03em
  }
  .nav-link-custom.active-nav{background:rgba(255,255,255,.12);color:#fbbf24}

  /* Logout button */
  .km-logout-btn{
    margin:12px 0 0!important;padding:14px 16px!important;
    text-align:center;border-radius:8px;font-size:14px!important;
    display:block;width:100%
  }

  /* Action links (Profile/FAQs/Packets) cloned into drawer */
  .km-drawer-actions{
    margin-top:auto;padding-top:16px;
    border-top:1px solid rgba(255,255,255,.15);
    display:flex;flex-direction:column;gap:4px
  }
  .km-drawer-actions a{
    display:flex;align-items:center;gap:8px;
    padding:12px 16px;border-radius:8px;
    color:#fff;text-decoration:none;
    font-size:13px;font-weight:500;letter-spacing:.03em
  }
  .km-drawer-actions a:hover,.km-drawer-actions a:active{
    background:rgba(255,255,255,.12)
  }

  /* Overlay */
  .km-mobile-overlay{
    display:none;position:fixed;top:0;left:0;right:0;bottom:0;
    background:rgba(0,0,0,.5);z-index:1045
  }
  .km-mobile-overlay.active{display:block}
}

/* ═══ 2. LAYOUT — Stacked Sections ═══ */
@media(max-width:767.98px){
  .container-fluid{padding-left:10px!important;padding-right:10px!important}
  .container{padding-left:10px!important;padding-right:10px!important}
  .row>[class*="col-md-"],.row>[class*="col-lg-"]{flex:0 0 100%!important;max-width:100%!important}
  .row>.col-6{flex:0 0 50%!important;max-width:50%!important}
  .d-flex:not(.km-header-inner):not(.align-items-center){flex-wrap:wrap!important}
  .card{margin-bottom:8px!important}
  .card-body{padding:12px!important}
  .card-header{padding:10px 12px!important;font-size:13px}
  h1,.h1{font-size:1.5rem!important}
  h2,.h2{font-size:1.3rem!important}
  h3,.h3{font-size:1.15rem!important}
  h4,.h4{font-size:1.05rem!important}
  .scroll-box{max-height:250px!important}
}

/* ═══ 3. TABLES ═══ */
@media(max-width:767.98px){
  .table-responsive{-webkit-overflow-scrolling:touch}
  table.table{min-width:700px;white-space:nowrap}
  table.table th,table.table td{padding:6px 8px!important;font-size:11px!important}
  table.table td{max-width:180px;overflow:hidden;text-overflow:ellipsis}
}
@media(max-width:479.98px){
  table.table th,table.table td{padding:4px 6px!important;font-size:10px!important}
}

/* ═══ 4. FORMS ═══ */
@media(max-width:767.98px){
  .form-control,.form-select{min-height:48px!important;font-size:16px!important;border-radius:8px!important;padding:10px 12px!important}
  .form-label,.form-check-label{font-size:13px!important;font-weight:600}
  .input-group{flex-wrap:wrap}
  .input-group .form-control,.input-group .form-select{flex:1 1 100%!important;margin-bottom:4px}
  .input-group .btn{flex:1 1 100%}
  [class*="d-flex"][class*="gap"]{flex-wrap:wrap!important}
}

/* ═══ 5. BUTTONS ═══ */
@media(max-width:767.98px){
  .btn{padding:10px 16px!important;font-size:14px!important;border-radius:8px!important;min-height:44px}
  .btn-sm{padding:8px 12px!important;font-size:13px!important;min-height:40px}
  .btn-xs{padding:6px 10px!important;font-size:12px!important;min-height:36px}
  .btn-group{flex-wrap:wrap;gap:4px}
  .btn-group .btn{flex:1 1 auto}
  .d-flex.gap-2,.d-flex.gap-1{gap:6px!important;flex-wrap:wrap!important}
}

/* ═══ 6. MODALS ═══ */
@media(max-width:767.98px){
  .modal-dialog{margin:0!important;max-width:100%!important;min-height:100dvh}
  .modal-content{border-radius:0!important;min-height:100dvh;border:none}
  .modal-header{position:sticky;top:0;z-index:10;background:#fff}
  .modal-body{padding:12px!important;overflow-y:auto}
  .modal-footer{position:sticky;bottom:0;z-index:10;background:#fff;border-top:1px solid #dee2e6;padding:10px 12px!important}
  .modal-footer .btn{flex:1}
}

/* ═══ 7. INSPECTION ═══ */
input[type="file"]{min-height:48px;padding:10px;font-size:14px;cursor:pointer;width:100%}
.inspection-upload-zone,.upload-zone,[class*="drop-zone"],[class*="dropzone"]{
  min-height:120px;border:3px dashed #a0aec0;border-radius:12px;
  display:flex;align-items:center;justify-content:center;
  padding:20px;text-align:center;cursor:pointer;background:#f7fafc
}
@media(max-width:767.98px){
  .inspection-room,.room-card,[class*="room-section"]{margin-bottom:16px!important}
  .photo-grid,.inspection-photos{display:grid!important;grid-template-columns:repeat(2,1fr)!important;gap:8px!important}
  .photo-grid img,.inspection-photos img{width:100%!important;height:auto!important;border-radius:8px;object-fit:cover;aspect-ratio:4/3}
  input[type="file"][accept*="image"]{min-height:56px;font-size:16px!important}
}

/* ═══ 8. DASHBOARD ═══ */
@media(max-width:767.98px){
  .row.g-2>.col-12.col-md-4{flex:0 0 100%!important;max-width:100%!important}
}
@media(max-width:479.98px){
  .row>.col-6{flex:0 0 100%!important;max-width:100%!important}
}

/* ═══ 9. CTA BAR ═══ */
.km-mobile-cta{display:none;position:fixed;bottom:0;left:0;right:0;background:#fff;border-top:2px solid #e2e8f0;padding:8px 12px;z-index:1035;box-shadow:0 -2px 10px rgba(0,0,0,.08)}
.km-mobile-cta-inner{display:flex;gap:8px;max-width:600px;margin:0 auto;justify-content:center}
.km-mobile-cta .btn{flex:1;font-size:12px!important;padding:10px 8px!important;display:flex;flex-direction:column;align-items:center;gap:2px;min-height:54px;border-radius:10px}
.km-mobile-cta .btn i{font-size:18px}
@media(max-width:767.98px){
  .km-mobile-cta{display:block}
  body{padding-bottom:80px!important}
}

/* ═══ 10. FINANCIALS ═══ */
@media(max-width:767.98px){
  .rent-roll-table{font-size:10px!important}
  .rent-roll-table th{font-size:9px!important;padding:4px 6px!important}
  .stat-card .stat-val{font-size:1.2rem!important}
  .stat-card .stat-label{font-size:9px!important}
}

/* ═══ 11. PROPERTIES ═══ */
@media(max-width:767.98px){
  .property-card,.tenant-card{margin-bottom:12px!important}
  [class*="kanban"]{flex-direction:column!important}
  .badge{font-size:10px!important;padding:4px 8px!important}
}

/* ═══ 12. DOCUMENTS ═══ */
@media(max-width:767.98px){
  .doc-type-card,.doc-shortcut{min-width:100px!important;padding:12px!important}
  .doc-row{flex-wrap:wrap!important}
}

/* ═══ 13. TABLET ═══ */
@media(min-width:768px) and (max-width:1024px){
  .container-fluid{padding-left:16px!important;padding-right:16px!important}
  .row>[class*="col-md-4"]{flex:0 0 50%!important;max-width:50%!important}
  .row>[class*="col-md-3"]{flex:0 0 50%!important;max-width:50%!important}
}

/* ═══ 14. PRINT ═══ */
@media print{
  .km-mobile-cta,.km-mobile-toggle,.km-mobile-overlay{display:none!important}
  body{padding-bottom:0!important}
}

/* ═══ 15. SAFE AREA ═══ */
@supports(padding-top:env(safe-area-inset-top)){
  .km-header-bar{padding-top:env(safe-area-inset-top)}
  .km-mobile-cta{padding-bottom:env(safe-area-inset-bottom)}
}
/* === Phase 2: Global Mobile Table + Modal + Touch Fixes === */
@media (max-width: 768px) {
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  table thead, table tbody, table tr { display: table; width: 100%; table-layout: auto; }
  .container, .container-fluid, .card, .card-custom { max-width: 100% !important; }
  .modal-dialog { margin: 0; max-width: 100%; height: 100%; }
  .modal-content { border-radius: 0; min-height: 100vh; }
  .modal-body { max-height: calc(100vh - 120px); overflow-y: auto; }
  .btn, button, a.btn, input[type=submit] { min-height: 44px; min-width: 44px; }
  .btn-xs, .btn-sm { min-height: 38px; padding: 8px 12px !important; font-size: 13px !important; }
  select.form-select-sm, input.form-control-sm { min-height: 38px; font-size: 14px !important; }
  body { overflow-x: hidden; }
  img, video, canvas, svg { max-width: 100%; height: auto; }
  pre, code { white-space: pre-wrap; word-break: break-word; }
  .nav-header { flex-wrap: wrap; padding: 8px !important; }
  .nav-link-custom { font-size: 11px !important; margin-left: 4px !important; }
  .dataTables_wrapper { overflow-x: auto; }
  .dataTables_filter input { width: 120px !important; }
  .signature-container, #signature-pad, canvas.sig { max-width: 100% !important; width: 100% !important; }
}

/* === Phase 3: Hover-Tap + Mobile Polish === */
@media (hover: none) and (pointer: coarse) {
  .btn:hover, a:hover, .nav-link-custom:hover { transition: none !important; }
  input[type=checkbox], input[type=radio] { min-width: 20px; min-height: 20px; }
  button, .btn, a.btn { touch-action: manipulation; }
}
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  .km-bottom-nav, .km-tenant-nav { padding-bottom: env(safe-area-inset-bottom); }
}
@media print {
  .nav-header, .km-bottom-nav, .km-tenant-nav, .km-pwa-popup { display: none !important; }
  body { padding: 0 !important; }
}

/* Fix oversized logos in old nav headers */
.nav-header img{max-height:40px!important;width:auto!important}

/* ═══ LEDGER ARCHIVE TABLE MOBILE ═══ */
@media(max-width:767.98px){
  /* Hide Action column (8th) and Ref/Reason (4th) on mobile */
  #archiveTable th:nth-child(4),
  #archiveTable td:nth-child(4),
  #archiveTable th:nth-child(8),
  #archiveTable td:nth-child(8){display:none!important}

  /* Compact all cells */
  #archiveTable{font-size:11px!important;table-layout:fixed;width:100%!important}
  #archiveTable th,
  #archiveTable td{padding:6px 4px!important;vertical-align:middle;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

  /* Column widths: Date|Address|Type|Credit|Charge|Media */
  #archiveTable th:nth-child(1),
  #archiveTable td:nth-child(1){width:62px}  /* Date */
  #archiveTable th:nth-child(2),
  #archiveTable td:nth-child(2){width:auto;max-width:120px}  /* Address */
  #archiveTable th:nth-child(3),
  #archiveTable td:nth-child(3){width:58px;text-align:center}  /* Type */
  #archiveTable th:nth-child(5),
  #archiveTable td:nth-child(5){width:68px;text-align:right}  /* Credit */
  #archiveTable th:nth-child(6),
  #archiveTable td:nth-child(6){width:62px;text-align:right}  /* Charge */
  #archiveTable th:nth-child(7),
  #archiveTable td:nth-child(7){width:36px;text-align:center}  /* Media */

  /* Thumbnails */
  #archiveTable td img{width:28px!important;height:28px!important;object-fit:cover;border-radius:4px}

  /* Type badges */
  #archiveTable .badge{font-size:9px!important;padding:2px 5px!important}

  /* Header */
  #archiveTable thead th{font-size:10px!important;font-weight:700;letter-spacing:.02em}

  /* DataTables pagination - above CTA bar */
  .dataTables_paginate{padding-bottom:70px!important}
}

/* ═══ PROPERTIES PAGE MOBILE ═══ */
@media(max-width:767.98px){

  /* ── Page header: stack title + buttons ── */
  .prop-header,.page-header{flex-direction:column!important;align-items:flex-start!important;gap:8px}
  .prop-header .btn,.page-header .btn{font-size:11px!important;padding:6px 12px!important}

  /* ── Property card ── */
  .prop-card{border:1px solid #e2e8f0;border-radius:12px;padding:14px!important;margin-bottom:14px!important;box-shadow:0 1px 4px rgba(0,0,0,.06)}

  /* ── Stack prop-line: address on top, actions below ── */
  .prop-line{flex-direction:column!important;align-items:stretch!important;gap:10px}

  /* ── Address block ── */
  .prop-line > .d-flex:first-child{font-size:14px}
  .prop-line > .d-flex:first-child h5,
  .prop-line > .d-flex:first-child h4,
  .prop-line > .d-flex:first-child strong{font-size:15px!important;line-height:1.3}

  /* ── Action buttons: horizontal wrap row ── */
  .prop-actions{display:flex!important;flex-direction:row!important;flex-wrap:wrap!important;gap:6px!important;justify-content:flex-start!important;align-items:center!important;padding-top:4px;border-top:1px solid #f1f5f9}
  .prop-actions .btn,
  .prop-actions a{font-size:11px!important;padding:5px 10px!important;border-radius:6px!important;white-space:nowrap}
  .prop-actions .btn i{font-size:12px!important}

  /* ── Tenant line: compact ── */
  .tenant-line{padding:8px 0!important}
  .tenant-block{flex-wrap:wrap!important;gap:6px}
  .tenant-block .btn-group{gap:2px}
  .tenant-block .btn-group .btn{padding:4px 8px!important;font-size:11px!important}

  /* ── Rent & deposit text ── */
  .prop-card .badge{font-size:10px!important}
  .prop-card small{font-size:11px!important}
}


/* ═══ App Store Touch Targets (44px minimum) ═══ */
@media (max-width: 991.98px) {
  a, button, input, select, textarea,
  [role="button"], .btn, .nav-link,
  .km-nav-link, .km-bottom-nav a,
  .tn-item {
    min-height: 44px;
    min-width: 44px;
  }
  input[type="text"], input[type="email"],
  input[type="password"], input[type="date"],
  input[type="tel"], input[type="number"],
  select, textarea {
    min-height: 44px;
    padding: 8px 12px;
    font-size: 16px;
  }
  .btn, button {
    min-height: 44px;
    padding: 8px 16px;
  }
  table td, table th {
    padding: 10px 8px;
    font-size: 13px;
  }
  .km-role-badge {
    font-size: 11px;
  }
  small, .small, .text-muted.small {
    font-size: 12px;
  }
}
