/* ===== CRM Customer Admin - Mobile Optimizations ===== */
/* Applies to all CRM pages on mobile (max-width: 768px) */

/* ============================================
   MOBILE HAMBURGER BUTTON IMPROVEMENT
   ============================================ */

@media (max-width: 768px) {
    /* Hamburger button — nổi bật hơn với màu VinFast */
    .mobile-nav-toggle {
        background: #0047AB !important;
        color: white !important;
        border: none !important;
        border-radius: 6px !important;
        padding: 8px 14px !important;
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        font-size: 18px !important;
        cursor: pointer !important;
        min-height: 44px !important;
    }

    .mobile-nav-toggle:active {
        background: #003a8c !important;
    }

    .mobile-nav-label {
        font-size: 13px !important;
        font-weight: 600 !important;
        letter-spacing: 0.3px !important;
    }
}

/* ============================================
   MOBILE CRM NAVIGATION DROPDOWN
   ============================================ */

/* Ẩn theo mặc định — visibility do inline style trong base_site.html quản lý */
.mobile-crm-menu {
    display: none;
}

@media (max-width: 768px) {
    /* Container */
    .mobile-crm-menu {
        position: relative;
        margin: 0 15px 12px 15px;
        z-index: 500;
    }

    /* Nút toggle — màu xanh lá để phân biệt với nút xanh dương của báo cáo */
    .mobile-crm-toggle {
        background: #1a7a3c;
        color: white;
        border: none;
        padding: 12px 20px;
        border-radius: 6px;
        cursor: pointer;
        font-size: 15px;
        font-weight: 600;
        width: 100%;
        text-align: left;
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: 48px;
        box-shadow: 0 2px 6px rgba(26, 122, 60, 0.25);
    }

    .mobile-crm-toggle:hover,
    .mobile-crm-toggle:active {
        background: #155e30;
    }

    /* Dropdown panel */
    .mobile-crm-dropdown {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: white;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
        z-index: 1000;
        max-height: 70vh;
        overflow-y: auto;
        margin-top: 6px;
    }

    .mobile-crm-dropdown.show {
        display: block;
    }

    /* Tiêu đề nhóm */
    .mobile-crm-group-header {
        padding: 8px 16px;
        background: #f5f7fa;
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.6px;
        color: #6b7280;
        border-top: 1px solid #e5e7eb;
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .mobile-crm-group-header:first-child {
        border-top: none;
    }

    .mobile-crm-group-header i {
        color: #1a7a3c;
        font-size: 12px;
    }

    /* Từng mục menu */
    .mobile-crm-item {
        border-bottom: 1px solid #f3f4f6;
        transition: background 0.15s;
    }

    .mobile-crm-item:last-child {
        border-bottom: none;
    }

    .mobile-crm-item a {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 20px 12px 28px;
        color: #374151;
        text-decoration: none;
        font-size: 14px;
        min-height: 46px;
    }

    .mobile-crm-item:hover,
    .mobile-crm-item:focus-within {
        background: #f0faf4;
    }

    .mobile-crm-item a i {
        color: #1a7a3c;
        width: 18px;
        text-align: center;
        flex-shrink: 0;
        font-size: 14px;
    }

    /* Mục đang active (trang hiện tại) */
    .mobile-crm-item.active {
        background: #ecfdf5;
        border-left: 3px solid #1a7a3c;
    }

    .mobile-crm-item.active a {
        font-weight: 600;
        color: #1a7a3c;
        padding-left: 25px;
    }
}

/* ============================================
   CUSTOMER LIST - MOBILE CARD VIEW
   ============================================ */

@media (max-width: 768px) {
    /* Search toolbar */
    .app-crm #toolbar {
        padding: 10px !important;
    }

    .app-crm #searchbar {
        display: flex !important;
        gap: 8px !important;
        width: 100% !important;
    }

    .app-crm #searchbar input[type="text"] {
        flex: 1 !important;
        font-size: 16px !important; /* prevent iOS auto-zoom */
        min-height: 44px !important;
        padding: 8px 12px !important;
        border-radius: 6px !important;
        border: 1px solid #ccc !important;
        box-sizing: border-box !important;
    }

    .app-crm #searchbar input[type="submit"],
    .app-crm #searchbar button[type="submit"] {
        min-height: 44px !important;
        padding: 8px 16px !important;
        font-size: 14px !important;
        white-space: nowrap !important;
        border-radius: 6px !important;
    }

    /* Object-tools buttons (Import Excel, Tìm kiếm nhanh) */
    .app-crm ul.object-tools {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding: 8px 10px !important;
        margin: 0 !important;
        list-style: none !important;
    }

    .app-crm ul.object-tools li {
        flex: 1 1 auto !important;
    }

    .app-crm ul.object-tools a {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-height: 44px !important;
        padding: 10px 16px !important;
        font-size: 13px !important;
        text-align: center !important;
        border-radius: 6px !important;
        white-space: nowrap !important;
    }

    /* Bulk actions bar */
    .app-crm .actions {
        padding: 8px 10px !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        align-items: center !important;
    }

    .app-crm .actions select {
        flex: 1 !important;
        min-height: 44px !important;
        font-size: 14px !important;
        border-radius: 4px !important;
    }

    .app-crm .actions button,
    .app-crm .actions input[type="submit"] {
        min-height: 44px !important;
        padding: 8px 16px !important;
        font-size: 14px !important;
        border-radius: 4px !important;
    }

    /* ---- Table → Cards transformation ---- */
    .app-crm #result_list {
        width: 100% !important;
        border: none !important;
        background: transparent !important;
        border-collapse: separate !important;
        border-spacing: 0 !important;
    }

    .app-crm #result_list thead {
        display: none !important;
    }

    .app-crm #result_list tbody {
        display: block !important;
        padding: 6px 10px 10px !important;
    }

    /* Each row becomes a card */
    .app-crm #result_list tbody tr {
        display: block !important;
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 10px !important;
        margin-bottom: 10px !important;
        padding: 12px !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07) !important;
        position: relative !important;
    }

    .app-crm #result_list tbody tr:hover,
    .app-crm #result_list tbody tr:focus-within {
        border-color: #0047AB !important;
        box-shadow: 0 2px 8px rgba(0, 71, 171, 0.12) !important;
    }

    /* Each cell becomes a label-value row */
    .app-crm #result_list tbody td {
        display: flex !important;
        align-items: baseline !important;
        gap: 6px !important;
        padding: 3px 0 !important;
        border: none !important;
        font-size: 14px !important;
        line-height: 1.5 !important;
    }

    /* Label prefix from data-label attribute (injected by JS) */
    .app-crm #result_list tbody td::before {
        content: attr(data-label);
        font-weight: 700 !important;
        color: #94a3b8 !important;
        min-width: 115px !important;
        flex-shrink: 0 !important;
        font-size: 11px !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
        padding-top: 2px !important;
    }

    /* Hide pseudo-element when data-label is empty */
    .app-crm #result_list tbody td[data-label=""]::before {
        display: none !important;
    }

    /* Checkbox — absolute top-right of card */
    .app-crm #result_list tbody td.action-checkbox {
        display: block !important;
        position: absolute !important;
        top: 10px !important;
        right: 12px !important;
        padding: 0 !important;
    }

    .app-crm #result_list tbody td.action-checkbox::before {
        display: none !important;
    }

    .app-crm #result_list tbody td.action-checkbox input[type="checkbox"] {
        width: 20px !important;
        height: 20px !important;
        cursor: pointer !important;
    }

    /* Customer name — prominent heading */
    .app-crm #result_list tbody td.field-full_name {
        font-size: 16px !important;
        font-weight: 700 !important;
        padding-bottom: 8px !important;
        margin-bottom: 4px !important;
        border-bottom: 1px solid #f1f5f9 !important;
    }

    .app-crm #result_list tbody td.field-full_name::before {
        display: none !important;
    }

    .app-crm #result_list tbody td.field-full_name a {
        color: #0047AB !important;
        text-decoration: none !important;
    }

    /* Phone — slightly larger */
    .app-crm #result_list tbody td.field-phone_display {
        font-size: 15px !important;
        font-weight: 600 !important;
    }

    /* Interaction button — full-width at bottom of card */
    .app-crm #result_list tbody td.field-interaction_button {
        padding-top: 8px !important;
        margin-top: 4px !important;
        border-top: 1px solid #f1f5f9 !important;
        justify-content: flex-end !important;
    }

    .app-crm #result_list tbody td.field-interaction_button::before {
        display: none !important;
    }

    .app-crm .interaction-btn {
        min-height: 40px !important;
        padding: 8px 20px !important;
        font-size: 14px !important;
        border-radius: 6px !important;
    }

    /* Paginator — touch-friendly */
    .app-crm .paginator {
        padding: 12px 10px !important;
        text-align: center !important;
        font-size: 14px !important;
    }

    .app-crm .paginator a,
    .app-crm .paginator .this-page {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-width: 40px !important;
        min-height: 40px !important;
        padding: 0 10px !important;
        margin: 2px !important;
        border-radius: 6px !important;
        border: 1px solid #e2e8f0 !important;
    }

    .app-crm .paginator a {
        background: white !important;
        color: #0047AB !important;
        text-decoration: none !important;
    }

    .app-crm .paginator a:hover {
        background: #0047AB !important;
        color: white !important;
        border-color: #0047AB !important;
    }

    /* CRM top filter */
    .app-crm #changelist-filter-top {
        margin: 6px 10px 0 !important;
    }

    /* Date hierarchy bar */
    .app-crm .xfull {
        font-size: 13px !important;
        padding: 8px 10px !important;
    }
}

/* ============================================
   CUSTOMER ADD / CHANGE FORM — MOBILE
   ============================================ */

@media (max-width: 768px) {
    /* Fieldset modules */
    .app-crm .module {
        margin: 8px 10px !important;
        border-radius: 8px !important;
        border: 1px solid #e2e8f0 !important;
        overflow: hidden !important;
    }

    .app-crm .module h2 {
        padding: 12px 15px !important;
        font-size: 13px !important;
        letter-spacing: 0.5px !important;
    }

    /* Form rows — single column */
    .app-crm .form-row {
        display: block !important;
        padding: 12px 15px !important;
        border-bottom: 1px solid #f8fafc !important;
    }

    .app-crm .form-row:last-child {
        border-bottom: none !important;
    }

    .app-crm .form-row .field-box {
        display: block !important;
        width: 100% !important;
        margin-bottom: 0 !important;
    }

    /* Labels */
    .app-crm .form-row label,
    .app-crm .form-row .field-box label {
        display: block !important;
        font-size: 11px !important;
        font-weight: 700 !important;
        color: #64748b !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
        margin-bottom: 6px !important;
    }

    /* All form inputs — full-width, touch-friendly, prevent iOS zoom */
    .app-crm input[type="text"],
    .app-crm input[type="email"],
    .app-crm input[type="tel"],
    .app-crm input[type="date"],
    .app-crm input[type="number"],
    .app-crm input[type="password"],
    .app-crm select,
    .app-crm textarea {
        width: 100% !important;
        min-height: 48px !important;
        font-size: 16px !important;
        padding: 10px 14px !important;
        border: 1.5px solid #e2e8f0 !important;
        border-radius: 8px !important;
        box-sizing: border-box !important;
        -webkit-appearance: none !important;
        appearance: none !important;
        background-color: #fff !important;
        color: #1a1a2e !important;
        transition: border-color 0.2s !important;
    }

    .app-crm input[type="text"]:focus,
    .app-crm input[type="email"]:focus,
    .app-crm input[type="tel"]:focus,
    .app-crm input[type="date"]:focus,
    .app-crm input[type="number"]:focus,
    .app-crm select:focus,
    .app-crm textarea:focus {
        border-color: #0047AB !important;
        outline: none !important;
        box-shadow: 0 0 0 3px rgba(0, 71, 171, 0.15) !important;
    }

    /* Select — custom arrow */
    .app-crm select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24'%3E%3Cpath fill='%23555' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") !important;
        background-repeat: no-repeat !important;
        background-position: right 12px center !important;
        padding-right: 40px !important;
    }

    .app-crm textarea {
        min-height: 100px !important;
        resize: vertical !important;
    }

    /* Date/time shortcuts */
    .app-crm .datetimeshortcuts {
        display: flex !important;
        gap: 8px !important;
        margin-top: 6px !important;
        flex-wrap: wrap !important;
    }

    .app-crm .datetimeshortcuts a {
        font-size: 13px !important;
        padding: 4px 10px !important;
        min-height: 32px !important;
        display: inline-flex !important;
        align-items: center !important;
    }

    /* Related widget (foreign-key selects) */
    .app-crm .related-widget-wrapper {
        display: block !important;
        width: 100% !important;
    }

    .app-crm .related-widget-wrapper select {
        width: calc(100% - 64px) !important;
    }

    /* Collapse toggle */
    .app-crm .collapse-toggle {
        min-height: 44px !important;
        padding: 10px 15px !important;
        font-size: 14px !important;
    }

    /* Read-only values */
    .app-crm .readonly {
        font-size: 14px !important;
        line-height: 1.6 !important;
        padding: 4px 0 !important;
    }

    /* Help text */
    .app-crm .help {
        font-size: 12px !important;
        margin-top: 4px !important;
        color: #64748b !important;
    }

    /* Error messages */
    .app-crm .errorlist {
        font-size: 13px !important;
        padding: 6px 10px !important;
    }

    /* Submit row — sticky at bottom of viewport */
    .app-crm .submit-row {
        position: sticky !important;
        bottom: 0 !important;
        background: #fff !important;
        border-top: 1px solid #e2e8f0 !important;
        padding: 12px 10px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        z-index: 100 !important;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08) !important;
        margin: 0 !important;
    }

    .app-crm .submit-row input[type="submit"],
    .app-crm .submit-row button[type="submit"] {
        width: 100% !important;
        min-height: 50px !important;
        font-size: 16px !important;
        font-weight: 600 !important;
        border-radius: 8px !important;
        margin: 0 !important;
        cursor: pointer !important;
    }

    .app-crm .submit-row .deletelink,
    .app-crm .submit-row a.deletelink {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100% !important;
        min-height: 44px !important;
        border-radius: 8px !important;
        font-size: 14px !important;
        box-sizing: border-box !important;
    }

    /* Inline admin forms */
    .app-crm .inline-group {
        margin: 8px 10px !important;
        overflow-x: auto !important;
    }

    .app-crm .inline-group h2 {
        font-size: 13px !important;
    }

    .app-crm .inline-related {
        padding: 10px !important;
    }

    .app-crm .inline-related h3 {
        font-size: 13px !important;
    }
}
