/**
 * מונה וחושב – שכבת התאמה לנייד, משותפת לכל האתר (site_3)
 *
 * כל הכללים שמשנים פריסה נמצאים בתוך media queries, כך שתצוגת הדסקטופ לא משתנה.
 * נטען אחרון ב-<head> של כל עמוד (דרך import.php או ישירות), ולכן גובר על העיצוב הקיים.
 * ההתנהגות (תפריט המבורגר, ניווט תחתון, עטיפת טבלאות) נמצאת ב-mobile.js.
 */

:root {
    --mv-primary: #667eea;
    --mv-primary-2: #764ba2;
    --mv-ink: #1f2937;
    --mv-muted: #6b7280;
    --mv-line: #e5e7eb;
    --mv-surface: #ffffff;
    --mv-tap: 44px;
    --mv-bottom-nav-h: 64px;
}

html {
    -webkit-text-size-adjust: 100%;
}

/* כפתור ההמבורגר ופס הניווט התחתון לא קיימים בדסקטופ */
.mv-nav-toggle,
.mv-bottom-nav,
.mv-sheet,
.mv-sheet-backdrop {
    display: none;
}

/* ========================================
   טאבלט ונייד (עד 991px)
   ======================================== */
@media (max-width: 991.98px) {

    /* רשת ביטחון לגלישה לרוחב. clip ולא hidden – hidden שובר position: sticky */
    html, body {
        overflow-x: clip;
    }

    img, video {
        max-width: 100%;
    }

    /* ---------- כפתור המבורגר ---------- */
    .mv-nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: var(--mv-tap);
        height: var(--mv-tap);
        border: 1px solid var(--mv-line);
        border-radius: 12px;
        background: var(--mv-surface);
        color: var(--mv-ink);
        font-size: 20px;
        cursor: pointer;
        flex-shrink: 0;
    }

    .mv-nav-toggle:focus-visible {
        outline: 3px solid rgba(102, 126, 234, .45);
        outline-offset: 2px;
    }

    /* ---------- כותרת האתר הציבורי (basic_settings/header.php) ---------- */
    .header.mv-site-header {
        padding: 8px 12px !important;
        flex-wrap: nowrap;
        gap: 8px;
    }

    .mv-site-header .mv-brand img {
        height: 42px !important;
    }

    .mv-site-header .mv-links,
    .mv-site-header .mv-user {
        display: none !important;
    }

    .mv-site-header .mv-login-btn {
        margin-inline-start: auto;
        padding: 6px 14px;
        font-size: 14px;
        white-space: nowrap;
        color: var(--mv-ink) !important;
    }

    /* תפריט פתוח: הקישורים יורדים כפאנל מתחת לכותרת */
    .mv-site-header.mv-nav-open .mv-links,
    .mv-site-header.mv-nav-open .mv-user {
        display: flex !important;
        flex-direction: column;
        align-items: stretch;
        position: absolute;
        inset-inline: 0;
        background: var(--mv-surface);
        box-shadow: 0 12px 24px rgba(0, 0, 0, .12);
        padding: 8px 12px;
        margin: 0 !important;
    }

    .mv-site-header.mv-nav-open .mv-links {
        top: 100%;
        border-top: 1px solid var(--mv-line);
    }

    .mv-site-header.mv-nav-open .mv-user {
        top: calc(100% + var(--mv-links-h, 0px));
        border-top: 1px solid var(--mv-line);
        border-radius: 0 0 14px 14px;
    }

    .mv-site-header.mv-nav-open .mv-links .btn {
        display: flex;
        align-items: center;
        gap: 10px;
        min-height: var(--mv-tap);
        margin: 0 !important;
        padding: 10px 8px;
        text-align: start;
        text-decoration: none;
        border-radius: 10px;
        font-size: 16px;
    }

    .mv-site-header.mv-nav-open .mv-links .btn i {
        width: 22px;
        text-align: center;
        color: var(--mv-primary);
    }

    .mv-site-header.mv-nav-open .mv-links .btn.active-button {
        background: rgba(102, 126, 234, .1);
        text-decoration: none;
    }

    .mv-site-header.mv-nav-open .mv-user > * {
        margin: 0 !important;
    }

    .mv-site-header.mv-nav-open .mv-user form .btn {
        width: 100%;
        min-height: var(--mv-tap);
        color: var(--mv-ink) !important;
    }

    body.mv-has-site-header {
        padding-top: 72px !important;
        margin-bottom: 0 !important;
    }

    /* ---------- פוטר האתר הציבורי ---------- */
    footer.mv-site-footer {
        position: static !important;
        height: auto !important;
        padding: 16px 0;
    }

    footer.mv-site-footer .container {
        flex-direction: column;
        gap: 6px;
        font-size: 14px;
    }

    /* ---------- כותרת האזור האישי (modern-navbar) ---------- */
    .modern-navbar {
        padding: 8px 0 !important;
    }

    .modern-navbar > .container,
    .modern-navbar > .container-fluid {
        position: relative;
    }

    .modern-navbar .navbar-brand-modern {
        font-size: 18px !important;
        gap: 8px !important;
    }

    .modern-navbar .navbar-brand-modern img {
        width: 40px !important;
        height: 40px !important;
    }

    .modern-navbar .user-info {
        display: none !important;
    }

    .modern-navbar.mv-nav-open .user-info {
        display: flex !important;
        flex-direction: column;
        align-items: stretch;
        gap: 6px !important;
        position: absolute;
        top: calc(100% + 8px);
        inset-inline: 0;
        background: var(--mv-surface);
        border-radius: 0 0 16px 16px;
        box-shadow: 0 16px 32px rgba(0, 0, 0, .14);
        padding: 12px;
        z-index: 1001;
    }

    .modern-navbar.mv-nav-open .user-info > a,
    .modern-navbar.mv-nav-open .user-info > span,
    .modern-navbar.mv-nav-open .user-info > .dropdown > .btn {
        display: flex;
        align-items: center;
        min-height: var(--mv-tap);
        width: 100%;
        border-radius: 12px;
        padding: 10px 14px;
    }

    /* תפריט "אזור אישי" בתוך הפאנל: נפתח במקום ולא כחלון צף */
    .modern-navbar.mv-nav-open .dropdown-menu {
        position: static !important;
        inset: auto !important;
        transform: none !important;
        width: 100%;
        margin-top: 6px !important;
        box-shadow: none;
        border: 1px solid var(--mv-line);
    }

    .modern-navbar.mv-nav-open .dropdown-item {
        padding: 12px 14px;
        white-space: normal;
    }

    /* ---------- כרטיס דירה: התפריט הצדדי מוחלף בניווט תחתון ---------- */
    body.mv-has-bottom-nav {
        padding-bottom: calc(var(--mv-bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 12px);
    }

    body.mv-has-bottom-nav .mv-side-nav-col {
        display: none !important;
    }

    body.mv-has-bottom-nav .toast-container {
        bottom: calc(var(--mv-bottom-nav-h) + env(safe-area-inset-bottom, 0px)) !important;
    }

    .mv-bottom-nav {
        display: flex;
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        z-index: 1040;
        height: calc(var(--mv-bottom-nav-h) + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: rgba(255, 255, 255, .97);
        backdrop-filter: blur(10px);
        border-top: 1px solid var(--mv-line);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, .06);
    }

    .mv-bottom-nav button {
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        position: relative;
        border: 0;
        background: none;
        color: var(--mv-muted);
        font-size: 12px;
        font-weight: 600;
        line-height: 1.1;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .mv-bottom-nav button i {
        font-size: 20px;
    }

    .mv-bottom-nav button.active {
        color: var(--mv-primary);
    }

    .mv-bottom-nav button.active::before {
        content: "";
        position: absolute;
        top: 0;
        width: 32px;
        height: 3px;
        border-radius: 0 0 3px 3px;
        background: var(--mv-primary);
    }

    .mv-bottom-nav .mv-badge {
        position: absolute;
        top: 6px;
        inset-inline-start: calc(50% + 6px);
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 9px;
        background: #dc3545;
        color: #fff;
        font-size: 11px;
        line-height: 18px;
        text-align: center;
    }

    /* גיליון "עוד" שעולה מלמטה */
    .mv-sheet-backdrop.show {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1045;
        background: rgba(17, 24, 39, .45);
    }

    .mv-sheet.show {
        display: block;
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        z-index: 1046;
        max-height: 80vh;
        overflow-y: auto;
        background: var(--mv-surface);
        border-radius: 20px 20px 0 0;
        padding: 8px 12px calc(16px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -10px 30px rgba(0, 0, 0, .18);
        animation: mvSheetUp .2s ease-out;
    }

    .mv-sheet .mv-sheet-handle {
        width: 40px;
        height: 4px;
        margin: 4px auto 12px;
        border-radius: 2px;
        background: var(--mv-line);
    }

    .mv-sheet button {
        display: flex;
        align-items: center;
        gap: 12px;
        width: 100%;
        min-height: 52px;
        padding: 10px 12px;
        border: 0;
        border-radius: 12px;
        background: none;
        color: var(--mv-ink);
        font-size: 16px;
        text-align: start;
    }

    .mv-sheet button i {
        width: 24px;
        text-align: center;
        color: var(--mv-primary);
    }

    .mv-sheet button.active {
        background: rgba(102, 126, 234, .1);
        font-weight: 600;
    }

    @keyframes mvSheetUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    /* העוזר החכם (bot/bot_widget.php) עולה מעל הניווט התחתון */
    body.mv-has-bottom-nav .bot-fab {
        bottom: calc(var(--mv-bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 14px) !important;
    }

    body.mv-has-bottom-nav .bot-panel {
        bottom: calc(var(--mv-bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 86px) !important;
    }
}

/* ========================================
   נייד (עד 767px)
   ======================================== */
@media (max-width: 767.98px) {

    /* 16px בשדות – אחרת אייפון עושה זום אוטומטי בכל הקלדה */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
    select,
    textarea {
        font-size: 16px !important;
    }

    /* יעדי מגע נוחים */
    .btn:not(.btn-sm):not(.btn-close):not(.btn-link) {
        min-height: var(--mv-tap);
    }

    .form-control:not(textarea):not(.form-control-sm),
    .form-select:not(.form-select-sm) {
        min-height: var(--mv-tap);
    }

    .container,
    .container-fluid {
        padding-inline: 12px;
    }

    /* row עם gutter גדול (g-5) בורח מהמסך בנייד */
    .row.g-5,
    .row.gx-5 {
        --bs-gutter-x: 1.5rem;
    }

    h1, .h1 { font-size: 1.6rem; }
    h2, .h2 { font-size: 1.35rem; }
    h3, .h3 { font-size: 1.2rem; }

    /* מודלים של Bootstrap: כמעט מסך מלא, תוכן נגלל בפנים */
    .modal-dialog {
        margin: 8px auto !important;
        max-width: calc(100% - 16px) !important;
    }

    .modal-dialog.modal-dialog-scrollable,
    .modal-dialog.modal-dialog-scrollable .modal-content {
        max-height: calc(100% - 16px);
    }

    .modal-footer {
        flex-wrap: wrap;
        gap: 8px;
    }

    .modal-footer > .btn {
        flex: 1 1 auto;
        margin: 0;
    }

    /* טבלה שלא עטופה ב-table-responsive נעטפת ב-JS בעוטף הזה */
    .mv-table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    /* טבלאות היסטוריה הופכות לכרטיסים: כל שורה כרטיס, כל תא שורה עם כותרת */
    table.mv-stack thead {
        display: none;
    }

    table.mv-stack,
    table.mv-stack tbody,
    table.mv-stack tr,
    table.mv-stack td {
        display: block;
        width: 100%;
    }

    table.mv-stack tr {
        margin-bottom: 10px;
        padding: 6px 12px;
        border: 1px solid var(--mv-line);
        border-radius: 12px;
        background: var(--mv-surface);
        box-shadow: 0 1px 3px rgba(0, 0, 0, .04);
    }

    /* התווית מימין, התוכן משמאל; תוכן ארוך (כמה תגיות/כפתורים) יורד לשורה משלו */
    table.mv-stack td {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        align-items: center;
        gap: 6px 12px;
        padding: 6px 0 !important;
        border: 0 !important;
        border-bottom: 1px dashed var(--mv-line) !important;
        text-align: start;
        overflow-wrap: break-word;
    }

    table.mv-stack td:last-child {
        border-bottom: 0 !important;
    }

    table.mv-stack td::before {
        content: attr(data-label);
        flex-shrink: 0;
        margin-inline-end: auto;
        color: var(--mv-muted);
        font-size: 13px;
        font-weight: 600;
    }

    table.mv-stack td > * {
        text-align: end;
        max-width: 100%;
    }

    /* ---------- צור קשר (tabs/contact/view.php) ---------- */
    .mv-contact-wrap {
        height: auto !important;
        margin-top: 16px !important;
        padding-block: 8px;
    }

    .mv-contact-card {
        width: 100% !important;
        border-radius: 16px;
    }

    /* ---------- הוספת דירה (addHouseForm.php) ---------- */
    /* העמוד טוען גם Bootstrap 4 (row עם margin של 15px-), והמעטפת שלו צרה יותר */
    #registrationForm .row {
        margin-inline: -8px;
    }

    #registrationForm .row > [class*="col-"] {
        padding-inline: 8px;
    }

    /* ---------- כרטיס דירה: אריחי לוח הבקרה ---------- */
    #dashboardContent .stat-value {
        font-size: 1.35rem;
        white-space: nowrap;
    }

    #dashboardContent .card-body {
        padding: 12px 8px;
    }

    /* ---------- רשימת הדירות (tabs/houses/view.php) ---------- */
    /* 4 כרטיסי הסיכום ברשת 2x2 במקום עמודה אחת ארוכה */
    .stats-container > .row > .col-md-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .stats-container > .row {
        --bs-gutter-x: 10px;
        --bs-gutter-y: 10px;
    }

    .stats-container .stat-card {
        padding: 14px !important;
        border-radius: 16px !important;
        height: 100%;
    }

    .stats-container .stat-icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 18px !important;
        border-radius: 12px !important;
        margin-bottom: 8px !important;
    }

    .stats-container .stat-number {
        font-size: 24px !important;
    }

    .stats-container .stat-label {
        font-size: 13px !important;
    }

    .search-section {
        padding: 14px !important;
    }

    .search-section .btn {
        width: 100%;
        justify-content: center;
    }

    /* SweetAlert2 */
    .swal2-popup {
        width: calc(100% - 24px) !important;
        max-width: 480px;
    }
}

@media print {
    .mv-nav-toggle,
    .mv-bottom-nav,
    .mv-sheet,
    .mv-sheet-backdrop {
        display: none !important;
    }
}
