/* Mobile usability overrides (phones < 768px) */

/* Phone action buttons (all sizes) */
.phone-actions { white-space: nowrap; }
.phone-actions .phone-btn {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    color: #fff;
    text-decoration: none;
}
.phone-actions .phone-btn:hover,
.phone-actions .phone-btn:focus { color: #fff; text-decoration: none; opacity: .85; }
.phone-actions .phone-call { background: #337ab7; }
.phone-actions .phone-wa { background: #25d366; }

@media (max-width: 767px) {
    /* Stop iOS auto-zoom on focus */
    input.form-control, select.form-control, textarea.form-control,
    input[type="text"], input[type="search"], input[type="email"],
    input[type="tel"], input[type="number"], input[type="password"],
    select, textarea {
        font-size: 16px !important;
    }

    /* Comfortable tap targets */
    .btn, .btn-sm, .btn-xs { min-height: 44px; line-height: 1.8; }

    /* ---- Card layout for list tables ---- */
    .mobile-cards.table-responsive { border: 0; overflow: visible; }
    table.mobile-cards-table,
    table.mobile-cards-table tbody,
    table.mobile-cards-table tr,
    table.mobile-cards-table td { display: block; width: 100% !important; }
    table.mobile-cards-table thead { display: none; }
    table.mobile-cards-table { background: transparent; }

    table.mobile-cards-table tbody tr {
        position: relative;
        margin: 0 0 12px;
        padding: 12px 14px;
        background: #fff !important;
        border: 1px solid #e3e6ea;
        border-radius: 8px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
    }
    table.mobile-cards-table tbody td {
        border: 0 !important;
        padding: 3px 0 !important;
        text-align: left !important;
        font-size: 14px;
    }
    table.mobile-cards-table tbody td:empty { display: none; }
    table.mobile-cards-table tbody td .pull-left,
    table.mobile-cards-table tbody td .pull-right { float: none !important; display: inline-block; }

    /* label: value rows */
    table.mobile-cards-table td[data-label]::before {
        content: attr(data-label);
        display: inline-block;
        min-width: 110px;
        color: #8a9099;
        font-size: 12px;
    }

    /* Card header: name + badge */
    table.mobile-cards-table td.card-title {
        font-size: 17px;
        font-weight: 600;
        padding-right: 80px !important;
    }
    table.mobile-cards-table td.card-badge {
        position: absolute;
        top: 12px;
        right: 14px;
        width: auto !important;
        padding: 0 !important;
    }

    /* Phone row: big buttons */
    table.mobile-cards-table td.card-phone { padding: 6px 0 !important; }
    table.mobile-cards-table td.card-phone .phone-number { display: block; margin-bottom: 6px; }
    table.mobile-cards-table td.card-phone .phone-btn {
        margin: 0 6px 0 0;
        padding: 10px 16px;
        font-size: 14px;
    }

    /* Secondary fields hidden behind "More" */
    table.mobile-cards-table tr:not(.card-open) td.card-more { display: none; }
    /* Remarks: same line as label, long text wraps under the value column */
    table.mobile-cards-table td.card-remarks {
        white-space: normal !important;
        text-overflow: clip !important;
        max-width: none !important;
        max-height: none !important;
        overflow: visible !important;
        word-break: break-word;
    }
    table.mobile-cards-table td.card-remarks { position: relative; padding-left: 110px !important; }
    table.mobile-cards-table td.card-remarks::before { position: absolute; left: 0; top: 3px; }
    table.mobile-cards-table td.card-remarks * {
        display: inline !important; margin: 0 !important; padding: 0 !important;
        float: none !important; position: static !important; font-size: 14px !important;
    }
    table.mobile-cards-table td.card-remarks br { display: none !important; }
    table.mobile-cards-table td.card-remarks p::after,
    table.mobile-cards-table td.card-remarks div::after { content: " "; }
    table.mobile-cards-table td.card-remarks img { display: none !important; }

    /* Footer actions */
    table.mobile-cards-table td.card-actions {
        display: flex;
        gap: 8px;
        margin-top: 8px;
        padding-top: 10px !important;
        border-top: 1px solid #eef0f2 !important;
    }
    table.mobile-cards-table td.card-actions a,
    table.mobile-cards-table td.card-actions button {
        flex: 1;
        min-height: 44px;
        line-height: 44px;
        padding: 0;
        text-align: center;
        border-radius: 6px;
        border: 1px solid #d0d5db;
        background: #f7f8fa;
        color: #333;
        font-weight: 500;
    }
    table.mobile-cards-table td.card-actions a.viewcustomer {
        background: #337ab7;
        border-color: #337ab7;
        color: #fff;
    }
}

/* Mobile-only elements */
@media (min-width: 768px) {
    .mobile-only { display: none !important; }
}

/* ================= Detail page (mobile) ================= */
.detail-toggle-row { display: none; }

@media (max-width: 767px) {
    /* Header: stack name / contact info */
    .info1 .pull-left, .info1 .pull-right,
    .info2 .pull-left { float: none !important; display: block; }
    .info1 .label.accounts, .info1 .label.leads { position: static; margin: 0 0 0 8px; vertical-align: middle; }
    .info1 .membersince { float: none; margin: 4px 0 10px; font-size: 13px; }
    .info2 { font-size: 15px !important; }
    .info2 .cust-email, .info2 .cust-no, .info2 .cust-addr { margin: 0 0 8px !important; word-break: break-word; }
    .info2 .cust-no .phone-number { display: none; } /* number shown in button row */
    .info2 .cust-no .phone-btn { padding: 10px 16px; font-size: 14px; margin: 0 6px 0 0; }
    .alt1 .btn { margin: 0 0 8px 6px; }

    /* Info tables: label above value */
    .customerinfo-wrapper .form-wrap table.table tr { display: block; padding: 6px 0; border-bottom: 1px solid #eef0f2; }
    .customerinfo-wrapper .form-wrap table.table td { display: block; width: 100% !important; border: 0 !important; padding: 2px 0 !important; }
    .customerinfo-wrapper .form-wrap table.table td:first-child { color: #8a9099; font-size: 12px; }
    .customerinfo-wrapper .form-wrap table.table td:first-child:empty { display: none; }
    .customerinfo-wrapper .form-wrap .form-control-static { padding: 0; min-height: 0; }
    .customerinfo-wrapper:not(.details-open) tr.detail-more { display: none !important; }
    .detail-toggle-row { display: block; }
    .detail-toggle-row button {
        width: 100%; min-height: 44px; margin: 8px 0; border: 1px solid #d0d5db;
        border-radius: 6px; background: #f7f8fa; font-weight: 500;
    }

    /* Collapsible sections */
    .m-section > h3 {
        cursor: pointer; padding: 12px 0; margin: 10px 0 0;
        border-bottom: 1px solid #e3e6ea; font-size: 18px;
    }
    .m-section > h3::after { content: "\25B2"; float: right; font-size: 12px; color: #8a9099; margin-top: 6px; }
    .m-section.m-collapsed > h3::after { content: "\25BC"; }
    .m-section.m-collapsed > :not(h3) { display: none !important; }

    /* Section tables as cards: no inner scroll box */
    .mobile-cards.scrollarea { max-height: none !important; overflow: visible !important; }
    table.mobile-cards-auto td.ttlid, table.mobile-cards-auto td.ctlid,
    table.mobile-cards-auto td.histid { display: none; }
    /* Keep label + content on one line (e.g. status dot + text) */
    table.mobile-cards-table tbody td > div { display: inline-block; }
    table.mobile-cards-table tbody td.status span { float: none !important; display: inline-block; margin: 0 4px 0 0; }

}

/* Desktop (mouse) browsers can't place phone calls: hide Call buttons */
@media (hover: hover) and (pointer: fine) {
    .phone-actions .phone-call { display: none !important; }
}


/* ================= Generic list pages (phones only) ================= */
@media (max-width: 767px) {
    /* Auto cards: search plugins may set display:table-row inline */
    table.mobile-cards-table tbody tr[style*="table-row"] { display: block !important; }
    table.mobile-cards-table td.m-hide-cell { display: none !important; }
    table.mobile-cards-table tbody td { white-space: normal !important; word-break: break-word; }
    table.mobile-cards-auto tbody td:first-child:not(.m-hide-cell),
    table.mobile-cards-auto tbody td.m-hide-cell + td { font-weight: 600; }
    table.mobile-cards-auto td > .pull-right { float: none !important; }
    table.mobile-cards-auto .visible-lg { display: inline !important; }
    table.mobile-cards-auto td img { max-width: 100%; height: auto; }
    .table-responsive.mobile-cards, .scrollarea.mobile-cards {
        border: 0 !important; max-height: none !important; overflow: visible !important;
    }

    /* Page header / filter bars stack instead of overflowing */
    .filterarea .pull-right, .filterarea .pull-left,
    .encaseall, .filtencase { float: none !important; width: 100%; }
    ul.table-filter { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; }
    .pagination { display: flex; flex-wrap: wrap; }
    .pagination > li > a, .pagination > li > span { min-width: 40px; text-align: center; }

    /* Nothing wider than the screen */
    img, iframe, video, .note-editor { max-width: 100% !important; }
    .modal-dialog { margin: 10px; }
    .modal-body { overflow-x: auto; }
    .childlevel .select-level, .form-wrap .btn-select.form-control,
    .submssn .encaseimg { max-width: 100% !important; }
    .submssn .lesstype .select-lesstype.dropdown-menu { min-width: 0 !important; max-width: 90vw; }
}

/* Submission detail pages: stack label / value rows on phones */
@media (max-width: 767px) {
    .submssn table.table, .submssn table.table > tbody,
    .submssn table.table > tbody > tr, .submssn table.table > tbody > tr > td {
        display: block; width: 100% !important;
    }
    .submssn table.table > tbody > tr > td { border: 0 !important; padding: 4px 0 !important; }
    .submssn table.table > tbody > tr { border-bottom: 1px solid #eef0f2; padding: 6px 0; }
    .submssn .encaseimg { width: 100% !important; height: auto !important; min-height: 200px; }
    .submssn .encaseimg img { max-width: 100%; height: auto; }
    .submssn .radio, .submssn textarea, .submssn .form-control { max-width: 100%; }
}

/* Login page (phones only) */
@media (max-width: 767px) {
    #loginpanel { width: auto; max-width: 100%; margin: 16px; padding: 12px 16px 16px; }
    #loginpanel #header { font-size: 24px; }
    #loginpanel .login { margin-top: 16px; }
    #loginpanel .form-group { margin-left: 0; margin-right: 0; }
    #loginpanel .form-group > [class*="col-sm-"] { padding-left: 0; padding-right: 0; }
    #loginpanel .control-label { padding-top: 0; margin-bottom: 4px; }
    #loginpanel .form-control { height: 44px; }
    #loginpanel .loginbtn { float: none; width: 100%; min-height: 48px; font-size: 16px; }
    body > .navbar #sstlogo { width: auto; max-width: 180px; max-height: 50px; }
}

/* Phone-only Call/WhatsApp blocks (desktop keeps its original link) */
@media (min-width: 768px) {
    .mobile-only-phone { display: none !important; }
}

/* Dashboard + all reminders (phones only) */
@media (max-width: 767px) {
    #reminder .panel-body { padding: 10px; }
    #reminder-filter { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
    #reminder-filter .btn-danger { float: none !important; min-height: 36px; line-height: 26px; }
    #reminder #filter-btn { margin: 0 !important; }

    /* No nested scroll box */
    #reminder #reminder-list.m-reminders { height: auto !important; overflow: visible !important; }

    /* Each reminder as a card */
    #reminder-list.m-reminders > table,
    #reminder-list.m-reminders > table > tbody,
    #reminder-list.m-reminders > table > tbody > tr,
    #reminder-list.m-reminders > table > tbody > tr > td { display: block; width: 100%; background: transparent !important; }
    #reminder-list.m-reminders > table > tbody > tr > td { border: 0 !important; padding: 0 !important; }
    #reminder-list.m-reminders .reminders {
        margin: 0 0 12px; padding: 10px 12px !important; background: #fff;
        border: 1px solid #e3e6ea; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
    }
    #reminder-list.m-reminders .remindr1 { display: flex; flex-direction: column; }
    #reminder-list.m-reminders .remindr1 > span {
        float: none !important; width: 100% !important; padding: 3px 0 !important; text-align: left !important;
    }
    #reminder-list.m-reminders .remindr1 > .clearfix { display: none; }
    #reminder-list.m-reminders .remindr1 > .reminddate { order: 1; color: #8a9099; font-size: 13px; font-weight: 400; }
    #reminder-list.m-reminders .remindr1 > .remindname { order: 2; }
    #reminder-list.m-reminders .remindr1 > .remindphone { order: 3; }
    #reminder-list.m-reminders .remindr1 > .remind-remarks { order: 4; }
    #reminder-list.m-reminders .remindr1 > .remindview:not(.visible-xs) { order: 5; }
    #reminder-list.m-reminders .remindr1 > .remindview.visible-xs { order: 6; margin-top: 6px; }
    #reminder-list.m-reminders .remindr1 > .remindview.visible-xs .reminder-view { display: block; text-align: center; }
    .phone-actions .phone-btn, .phone-actions .phone-btn:hover { text-decoration: none !important; }
    #reminder-list.m-reminders .remindname { font-size: 16px; font-weight: 600; }
    #reminder-list.m-reminders .remindtel { display: none !important; }
    #reminder-list.m-reminders .remindphone { padding: 6px 0 !important; }
    #reminder-list.m-reminders .remind-remarks { color: #444; white-space: normal; word-break: break-word; }
    #reminder-list.m-reminders .remindview { text-align: left !important; color: #8a9099; font-size: 13px; }
    #reminder-list.m-reminders .reminder-view { display: inline-block; min-height: 36px; line-height: 36px; padding: 0 16px; }

    /* Phone buttons layout */
    .mobile-only-phone .phone-number { display: block; margin-bottom: 6px; }
    .mobile-only-phone .phone-btn { margin: 0 6px 0 0 !important; padding: 10px 16px !important; font-size: 14px !important; }

    /* All reminders page: hide original WhatsApp link where buttons exist */
    td > a[href*="wa.me"]:has(+ .mobile-only-phone) { display: none; }
}

/* Top menu (phones only): scrollable, account links always visible */
@media (max-width: 767px) {
    .navbar-fixed-top:has(.navbar-collapse.in),
    .navbar-fixed-top:has(.navbar-collapse.collapsing) {
        max-height: 100vh; max-height: 100dvh;
        overflow-y: auto; -webkit-overflow-scrolling: touch;
    }
    .navbar-fixed-top .navbar-collapse.in { max-height: none !important; overflow: visible !important; }
    .navbar-fixed-top .side-nav { padding-bottom: 20px; }
    .side-nav > li.dropdown.visible-xs > .dropdown-toggle { pointer-events: none; }
    .side-nav > li.dropdown.visible-xs > .dropdown-toggle .caret { display: none; }
    .side-nav > li.dropdown.visible-xs > .dropdown-menu {
        display: block !important; position: static; float: none; width: 100%;
        margin: 0; border: 0; box-shadow: none; background: transparent;
    }
    .side-nav > li.dropdown.visible-xs > .dropdown-menu > li > a {
        padding: 12px 15px 12px 30px; color: #fff;
    }
    .side-nav > li.dropdown.visible-xs > .dropdown-menu > li.divider { display: none; }
}

/* Desktop keeps plain number; phones show Call/WhatsApp buttons instead */
@media (max-width: 767px) {
    .m-desk-phone:has(+ .mobile-only-phone) { display: none; }
}

/* Named card parts: no auto label in front */
@media (max-width: 767px) {
    table.mobile-cards-table td.card-title::before,
    table.mobile-cards-table td.card-badge::before,
    table.mobile-cards-table td.card-phone::before,
    table.mobile-cards-table td.card-actions::before { content: none !important; display: none !important; }
    table.mobile-cards-table td.card-actions a { min-width: 0; }
    table.mobile-cards-table td.card-actions .visible-xl { display: none !important; }
}

/* Labelled card rows: fixed label column, long values (e.g. emails) wrap in the value column */
@media (max-width: 767px) {
    table.mobile-cards-table tbody td[data-label] {
        position: relative;
        padding-left: 110px !important;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
    table.mobile-cards-table tbody td[data-label]::before {
        position: absolute; left: 0; top: 3px;
        width: 102px; min-width: 0 !important;
        white-space: normal; line-height: 1.3;
    }
    table.mobile-cards-table tbody td.card-title[data-label],
    table.mobile-cards-table tbody td.card-badge[data-label],
    table.mobile-cards-table tbody td.card-phone[data-label],
    table.mobile-cards-table tbody td.card-actions[data-label] { padding-left: 0 !important; }
}
