/* ============================================================
   RESPONSIVE.CSS — iPhone & iPad Mobile Adaptation
   Shared across all pages of the Business Suite
   ============================================================ */

/* ── iOS Safari Safe Area Support ── */
html {
    -webkit-text-size-adjust: 100%;
}

/* ── Mobile Hamburger Menu ── */
.mobile-hamburger {
    display: none;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: background 0.2s;
    flex-shrink: 0;
    z-index: 5200;
    position: relative;
}

.mobile-hamburger:hover,
.mobile-hamburger:active {
    background: rgba(255, 255, 255, 0.15);
}

.mobile-hamburger span {
    display: block;
    width: 18px;
    height: 2px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 1px;
    transition: all 0.3s;
    position: relative;
}

.mobile-hamburger span::before,
.mobile-hamburger span::after {
    content: '';
    display: block;
    width: 18px;
    height: 2px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 1px;
    position: absolute;
    left: 0;
    transition: all 0.3s;
}

.mobile-hamburger span::before {
    top: -6px;
}

.mobile-hamburger span::after {
    top: 6px;
}

/* Hamburger animation when open */
.mobile-hamburger.open span {
    background: transparent;
}

.mobile-hamburger.open span::before {
    top: 0;
    transform: rotate(45deg);
}

.mobile-hamburger.open span::after {
    top: 0;
    transform: rotate(-45deg);
}

/* Mobile menu overlay */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 4999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.mobile-menu-overlay.show {
    display: block !important;
    opacity: 1;
    pointer-events: auto;
}

/* Mobile dropdown panel */
.mobile-nav-panel {
    display: none;
    position: fixed;
    top: 0;
    right: -100%;
    width: 280px;
    max-width: 85vw;
    height: 100dvh;
    background: rgba(26, 26, 46, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    z-index: 5100;
    padding: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: right 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
}

body.dark-mode .mobile-nav-panel {
    background: rgba(28, 20, 16, 0.95);
}

.mobile-nav-header {
    padding: 20px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.mobile-nav-logo {
    font-weight: 800;
    font-size: 18px;
    color: #fff;
    letter-spacing: -0.5px;
}

.mobile-nav-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
}

.mobile-nav-panel.open {
    right: 0;
    display: flex !important;
}

.mobile-nav-panel .mobile-nav-section {
    padding: 12px 12px;
}

.mobile-nav-panel .mobile-nav-title {
    font-size: 10px;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 8px;
    padding-left: 14px;
    padding-top: 8px;
}

.mobile-nav-panel a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 15px;
    font-weight: 600;
    border-radius: 12px;
    transition: all 0.2s;
    margin-bottom: 2px;
}

.mobile-nav-panel a span {
    font-size: 18px;
    display: inline-flex;
    width: 24px;
    justify-content: center;
}

.mobile-nav-panel a:active {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(0.98);
}

.mobile-nav-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.15);
    margin-top: auto;
}

.mobile-nav-panel .mobile-nav-signout {
    display: block;
    padding: 12px;
    color: #ff6b6b;
    font-size: 15px;
    font-weight: 700;
    border: 1px solid rgba(255, 107, 107, 0.2);
    background: rgba(255, 107, 107, 0.05);
    width: 100%;
    text-align: center;
    cursor: pointer;
    border-radius: 12px;
    font-family: inherit;
    transition: all 0.2s;
}

.mobile-nav-panel .mobile-nav-signout:active {
    background: rgba(255, 107, 107, 0.1);
    transform: scale(0.98);
}

.mobile-nav-panel .mobile-nav-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.04);
    margin: 8px 20px;
}

/* ============================================================
   TABLET (iPad) — max-width: 1024px
   ============================================================ */
@media (max-width: 1024px) {

    /* ── Navigation ── */
    .nav-bar {
        padding: 0 20px !important;
    }

    .nav-logo {
        margin-right: 20px !important;
        font-size: 16px !important;
    }

    .nav-menu {
        gap: 18px !important;
    }

    .nav-item {
        font-size: 13px !important;
    }

    /* ── Dashboard ── */
    .dashboard-container {
        padding: 24px 16px 40px !important;
    }

    .welcome-header h1 {
        font-size: 28px !important;
    }

    .card-grid {
        grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)) !important;
        gap: 12px !important;
    }

    .chart-panel {
        padding: 20px !important;
    }

    .stats-row {
        gap: 8px !important;
    }

    /* ── CRM / Customer Page ── */
    .sidebar {
        width: 260px !important;
    }

    .main-view.sidebar-open {
        margin-left: 260px !important;
    }

    .main-view {
        padding: 24px 20px 24px 40px !important;
    }

    .profile-header {
        padding: 20px 24px !important;
    }

    .header-actions {
        position: relative !important;
        top: auto !important;
        right: auto !important;
        margin-top: 16px !important;
        flex-wrap: wrap !important;
    }

    .split-container {
        gap: 8px !important;
    }

    .history-panel {
        padding: 16px !important;
        min-width: 200px !important;
    }

    /* ── Invoice/Quote Preview ── */
    .invoice-box,
    .paper {
        width: 100% !important;
        max-width: 100% !important;
        padding: 32px !important;
    }

    .nav-controls,
    .top-bar {
        width: 100% !important;
        padding: 0 16px !important;
    }

    /* ── Editor Forms ── */
    .editor-card {
        padding: 28px 24px !important;
        margin: 20px 16px !important;
    }

    .form-grid {
        grid-template-columns: 2fr 1fr 1fr !important;
        gap: 12px !important;
    }

    .items-header,
    .item-row {
        gap: 10px !important;
    }

    /* ── Action Bar ── */
    .action-bar {
        padding: 0 20px !important;
        flex-wrap: wrap !important;
        height: auto !important;
        min-height: 56px !important;
        padding-top: 10px !important;
        padding-bottom: 10px !important;
        gap: 8px !important;
    }

    .action-btns {
        gap: 6px !important;
    }

    .btn-back,
    .btn-save,
    .btn-gen {
        padding: 8px 16px !important;
        font-size: 12px !important;
    }

    /* ── Modal ── */
    .modal-content,
    .nc-modal,
    .paid-modal-box {
        width: 90% !important;
        max-width: 440px !important;
        margin: 5% auto !important;
    }
}

/* ============================================================
   PHONE (iPhone) — max-width: 768px
   ============================================================ */
@media (max-width: 640px) {

    /* ── Show hamburger, hide desktop nav ── */
    .mobile-hamburger {
        display: flex !important;
    }

    .mobile-nav-panel {
        display: block !important;
    }

    .nav-menu {
        display: none !important;
    }

    .nav-signout {
        display: none !important;
    }

    .nav-bar {
        height: 48px !important;
        padding: 0 12px !important;
        justify-content: space-between !important;
    }

    .nav-left {
        flex: 0 0 auto !important;
        width: auto !important;
    }

    .nav-logo {
        font-size: 15px !important;
        margin-right: 0 !important;
    }

    .nav-bar .theme-toggle {
        margin-left: auto !important;
        margin-right: 8px !important;
        width: 32px !important;
        height: 32px !important;
        order: 0 !important;
    }

    .mobile-hamburger {
        order: 1 !important;
    }

    /* ── Dashboard ── */
    .dashboard-container {
        padding: 16px 12px 30px !important;
    }

    .welcome-header {
        margin-bottom: 24px !important;
    }

    .welcome-header h1 {
        font-size: 22px !important;
    }

    .welcome-header p {
        font-size: 14px !important;
    }

    .card-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .card {
        padding: 20px 14px !important;
    }

    .icon-circle {
        width: 44px !important;
        height: 44px !important;
        font-size: 22px !important;
        margin-bottom: 10px !important;
    }

    .card h3 {
        font-size: 12px !important;
    }

    .card p {
        font-size: 10px !important;
    }

    /* ── Chart Panel ── */
    .chart-panel {
        padding: 16px !important;
        border-radius: 14px !important;
    }

    .chart-title {
        font-size: 16px !important;
    }

    .chart-sub {
        font-size: 11px !important;
    }

    .chart-top {
        flex-direction: column !important;
    }

    .stats-row {
        width: 100% !important;
        gap: 6px !important;
        flex-wrap: wrap !important;
    }

    .stat-box {
        min-width: 70px !important;
        padding: 8px 10px !important;
        flex: 1 !important;
    }

    .stat-num {
        font-size: 16px !important;
    }

    .stat-lbl {
        font-size: 8px !important;
    }

    .chart-wrap {
        height: 200px !important;
    }

    .chart-controls {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    .ctrl-select {
        font-size: 12px !important;
        padding: 6px 28px 6px 10px !important;
    }

    .tog-btn {
        padding: 5px 12px !important;
        font-size: 11px !important;
    }

    /* ── CRM Customer Page (Mobile App Layout) ── */
    /* Only lock body scroll if we are in a mobile-app container view */
    body:has(.crm-container),
    body.is-mobile-app {
        overflow: hidden !important;
    }

    .crm-container {
        position: relative !important;
        flex-direction: column !important;
        height: calc(100vh - 48px) !important;
        width: 100% !important;
        overflow: hidden !important;
    }

    /* Make the Customer "Sidebar" full screen */
    .sidebar {
        width: 100% !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        height: 100% !important;
        max-height: 100% !important;
        transform: translateX(0) !important;
        border-right: none !important;
        border-bottom: none !important;
        padding: 12px 16px !important;
        overflow-y: auto !important;
        z-index: 10 !important;
        box-shadow: none !important;
        cursor: default !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        background: var(--bg-color) !important;
        transition: transform 0.3s ease, opacity 0.3s ease !important;
    }

    .sidebar::after {
        display: none !important;
        content: none !important;
    }

    .sidebar.open {
        transform: translateX(0) !important;
        width: 100% !important;
    }

    .sidebar-header {
        margin-bottom: 12px !important;
    }

    .main-view {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        padding: 16px !important;
        margin-left: 0 !important;
        overflow-y: auto !important;
        background: var(--bg-color) !important;
        transform: translateX(100%) !important;
        transition: transform 0.3s ease !important;
        z-index: 20 !important;
    }

    /* Sub-view behavior for when a customer is selected */
    .crm-container.mobile-detail-view .sidebar {
        transform: translateX(-30%) !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }

    .crm-container.mobile-detail-view .main-view {
        transform: translateX(0) !important;
        padding-top: 0 !important;
        /* Start content immediately */
    }

    .profile-header {
        padding: 12px 16px !important;
        border-radius: 0 !important;
        /* Edge to edge looks cleaner on mobile list */
        margin: 0 -16px 12px -16px !important;
        background: var(--card-bg) !important;
        box-shadow: 0 1px 0 var(--border-color) !important;
        border-bottom: 1px solid var(--border-color) !important;
    }

    .profile-header h1 {
        font-size: 18px !important;
        margin: 0 !important;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .profile-details-grid {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 12px !important;
        margin-top: 8px !important;
        padding: 0 !important;
    }

    .profile-details-grid>div {
        background: transparent !important;
        padding: 0 !important;
        border-radius: 0 !important;
        font-size: 12px !important;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .profile-details-grid label {
        display: none !important;
        /* Hide 'PHONE', 'EMAIL' text labels on mobile */
    }

    /* Add simple emoji or icons conceptually */
    .profile-details-grid>div:nth-child(1)::before {
        content: '📞';
        font-size: 10px;
    }

    .profile-details-grid>div:nth-child(2)::before {
        content: '✉️';
        font-size: 10px;
    }

    .profile-details-grid>div:nth-child(3)::before {
        content: '📍';
        font-size: 10px;
        width: 100%;
        margin-top: 4px;
        border-top: 1px dashed var(--border-color);
        padding-top: 4px;
    }

    .profile-subheader {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 12px;
    }

    .cust-id-badge {
        margin-bottom: 0 !important;
    }

    /* Redundant absolute position removed */
    .profile-edit-container {
        display: none;
    }

    .btn-edit-p {
        width: auto !important;
        padding: 6px 12px !important;
        font-size: 10px !important;
        border-radius: 20px !important;
        background: var(--bg-color) !important;
        color: var(--accent-blue) !important;
        border: 1px solid var(--accent-blue) !important;
    }

    .mobile-back-btn {
        display: inline-flex !important;
        align-items: center !important;
        background: rgba(0, 0, 0, 0.05) !important;
        /* Subtle background */
        border: none !important;
        color: var(--accent-blue) !important;
        font-size: 12px !important;
        font-weight: 600 !important;
        margin-top: 4px !important;
        margin-bottom: 16px !important;
        /* Proper gap created here */
        padding: 6px 14px !important;
        /* More breathing room */
        border-radius: 20px !important;
        cursor: pointer !important;
        text-decoration: none !important;
        transition: all 0.2s;
    }

    body.dark-mode .mobile-back-btn {
        background: rgba(255, 255, 255, 0.1) !important;
    }

    .main-view.sidebar-open {
        margin-left: 0 !important;
    }

    /* ── Login Page ── */
    .login-card {
        position: relative !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        width: 92% !important;
        max-width: 380px !important;
        margin: 20px auto !important;
        transform: none !important;
    }

    @keyframes cardEntrance {
        to {
            opacity: 1;
            transform: none;
        }
    }

    .gesture-btn {
        bottom: auto !important;
        top: 16px !important;
        right: 16px !important;
        padding: 8px 14px !important;
        font-size: 11px !important;
    }

    #camera-status {
        bottom: auto !important;
        top: 60px !important;
        right: 16px !important;
    }

    /* Old bulky rules removed */
    .profile-details-grid {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 12px !important;
        margin-top: 8px !important;
    }

    .history-panel>div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 16px !important;
        padding-bottom: 12px !important;
    }

    .history-panel>div:first-child>div {
        width: 100% !important;
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        gap: 8px !important;
        padding-bottom: 4px !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .history-panel>div:first-child>div:last-child {
        flex-wrap: wrap !important;
        overflow-x: visible !important;
        justify-content: flex-start !important;
    }

    .history-panel>div:first-child>div::-webkit-scrollbar {
        height: 0px !important;
        /* hide scrollbar for tabs */
    }

    .split-container {
        flex-direction: column !important;
        gap: 16px !important;
        overflow: visible !important;
    }

    .split-resizer {
        display: none !important;
    }

    .history-panel {
        min-width: 0 !important;
        width: 100% !important;
        padding: 16px !important;
        overflow: visible !important;
        border-radius: 12px !important;
    }

    /* ── Mobile Card Format for Tables ── */
    .history-panel .table-wrapper {
        width: 100% !important;
        overflow-x: hidden !important;
        background: transparent !important;
        box-shadow: none !important;
        margin-top: 8px !important;
    }

    .history-table,
    .history-table tbody {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        border: none !important;
    }

    .history-table thead {
        display: none !important;
    }

    .history-table tr {
        display: grid !important;
        grid-template-areas:
            "check title total"
            "check desc desc"
            "check date date"
            "check status action";
        grid-template-columns: auto 1fr auto !important;
        gap: 6px 12px !important;
        background: var(--card-bg) !important;
        border-radius: 12px !important;
        padding: 14px 14px !important;
        margin-bottom: 12px !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04) !important;
        border: 1px solid var(--border-color) !important;
    }

    body.dark-mode .history-table tr {
        background: rgba(255, 255, 255, 0.03) !important;
    }

    .history-table td {
        display: none !important;
        /* Hide other columns natively */
        border: none !important;
        padding: 0 !important;
        text-align: left !important;
        white-space: normal !important;
    }

    .history-table td.td-checkbox {
        display: flex !important;
        grid-area: check;
        align-items: flex-start !important;
        padding-top: 2px !important;
    }

    .history-table td.td-num {
        display: block !important;
        grid-area: title;
        font-weight: 800 !important;
        font-size: 15px !important;
        color: var(--text-primary) !important;
    }

    .history-table td.td-total {
        display: block !important;
        grid-area: total;
        font-weight: 800 !important;
        font-size: 15px !important;
        color: var(--text-primary) !important;
        text-align: right !important;
    }

    .history-table td.td-description {
        display: -webkit-box !important;
        grid-area: desc;
        font-size: 12px !important;
        color: var(--text-secondary) !important;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .history-table td.td-date {
        display: block !important;
        grid-area: date;
        font-size: 11px !important;
        color: var(--text-secondary) !important;
        align-self: center !important;
    }

    .history-table td.td-status {
        display: block !important;
        grid-area: status;
        align-self: center !important;
    }

    .history-table td.td-action {
        display: flex !important;
        grid-area: action;
        justify-content: flex-end !important;
        align-items: center !important;
    }

    .history-table .actions-cell {
        display: flex !important;
        gap: 8px !important;
        width: auto !important;
        justify-content: flex-end !important;
    }

    .history-table .actions-cell .badge-status {
        display: none !important;
        /* Hide the badge status inside actions-cell since we map td-status */
    }

    .paid-stamp-inline {
        font-size: 11px !important;
        padding: 2px 6px !important;
        margin-left: 6px !important;
        margin-top: 6px !important;
        display: inline-block !important;
    }

    /* ── Invoice Preview Page ── */
    .invoice-box,
    .paper {
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        padding: 20px 16px !important;
        border-radius: 10px !important;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06) !important;
    }

    .nav-controls,
    .top-bar {
        width: 100% !important;
        padding: 0 12px !important;
    }

    #vTitle {
        font-size: 24px !important;
    }

    .invoice-header {
        flex-direction: column !important;
        gap: 12px !important;
    }

    .header-top,
    .header-top>div {
        flex-wrap: wrap !important;
    }

    #compLogo,
    .header-right img {
        max-height: 80px !important;
        max-width: 160px !important;
    }

    .items-table th,
    table.main-table th {
        padding: 8px 4px !important;
        font-size: 9px !important;
    }

    .items-table td,
    table.main-table td {
        padding: 8px 4px !important;
        font-size: 10px !important;
    }

    .summary-box {
        width: 100% !important;
    }

    .total-text {
        font-size: 18px !important;
    }

    .payment-info {
        font-size: 10px !important;
    }

    .payment-advice-section {
        padding-top: 12px !important;
    }

    .advice-header {
        font-size: 20px !important;
    }

    .advice-flex {
        flex-direction: column !important;
        gap: 12px !important;
    }

    .advice-table {
        width: 100% !important;
    }

    .advice-flex>div:first-child {
        width: 100% !important;
    }

    /* ── Quote ── */
    .header {
        flex-direction: column !important;
        gap: 12px !important;
        margin-bottom: 20px !important;
    }

    .header-left h1 {
        font-size: 26px !important;
    }

    .info-bar {
        flex-direction: column !important;
        gap: 16px !important;
    }

    .info-col-left,
    .info-col-right {
        width: 100% !important;
    }

    .info-col-right {
        align-items: flex-start !important;
    }

    .details-box {
        text-align: left !important;
        align-items: flex-start !important;
    }

    .details-header {
        border-right: none !important;
        border-left: 3px solid #007AFF !important;
        padding-right: 0 !important;
        padding-left: 8px !important;
    }

    .details-table td {
        padding: 3px 12px 3px 0 !important;
        text-align: left !important;
    }

    .totals {
        align-items: flex-start !important;
    }

    .t-row,
    .t-final {
        width: 100% !important;
    }

    /* Buttons */
    .btn {
        padding: 10px 16px !important;
        font-size: 12px !important;
    }

    /* ── Editor (Create Invoice / Quotation) ── */
    .invoice-container {
        padding: 16px 8px !important;
        width: 100% !important;
    }

    .editor-card {
        padding: 20px 12px !important;
        margin: 0 0 16px 0 !important;
        border-radius: 14px !important;
        width: 100% !important;
    }

    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
        width: 100% !important;
    }

    .field {
        width: 100% !important;
        min-width: 0 !important;
    }

    .form-grid>div:empty {
        display: none !important;
    }

    .field input,
    .field select {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        font-size: 16px !important;
        /* iOS Safari date input fixes */
        -webkit-appearance: none;
        appearance: none;
        min-width: 0 !important;
    }

    .field input[type="date"] {
        display: block !important;
        width: 100% !important;
    }

    .items-header {
        display: none !important;
    }

    .item-row {
        grid-template-columns: 1fr 1fr !important;
        grid-template-areas:
            "desc desc"
            "qty price"
            "tax tax"
            "total total" !important;
        gap: 12px 10px !important;
        padding: 16px 14px 20px !important;
        background: var(--bg-color, #f5f5f7) !important;
        border-radius: 12px !important;
        margin-bottom: 12px !important;
        position: relative !important;
    }

    body.dark-mode .item-row {
        background: rgba(255, 255, 255, 0.04) !important;
    }

    .item-row>.i-desc {
        grid-area: desc;
        min-height: 80px !important;
        padding-right: 44px !important;
        /* avoid overlapping remove button */
        font-size: 16px !important;
        /* Prevents iOS auto-zoom */
        padding: 12px 40px 12px 12px !important;
        border-radius: 10px !important;
        background: var(--input-bg) !important;
        border: 1px solid var(--border-color) !important;
        appearance: none;
    }

    .item-row>.qty-wrap {
        grid-area: qty;
    }

    .item-row>.price-wrap {
        grid-area: price;
    }

    .item-row>.tax-wrap {
        grid-area: tax;
    }

    .item-row>.total-wrap {
        grid-area: total;
        background: rgba(0, 122, 255, 0.05) !important;
        border: none !important;
    }

    .item-row>.m-input-wrap {
        display: flex !important;
        align-items: center !important;
        background: var(--input-bg) !important;
        border: 1px solid var(--border-color) !important;
        border-radius: 10px !important;
        padding-left: 12px !important;
        height: 48px !important;
        width: 100% !important;
    }

    body.dark-mode .item-row>.m-input-wrap {
        background: rgba(255, 255, 255, 0.03) !important;
    }

    .item-row>.m-input-wrap::before {
        content: attr(data-label);
        font-weight: 700 !important;
        font-size: 13px !important;
        color: var(--text-secondary) !important;
        margin-right: 12px !important;
    }

    .item-row>.m-input-wrap input,
    .item-row>.m-input-wrap select,
    .item-row>.m-input-wrap .i-total {
        flex: 1 !important;
        border: none !important;
        background: transparent !important;
        height: 100% !important;
        padding: 0 12px 0 0 !important;
        text-align: right !important;
        outline: none !important;
        font-size: 16px !important;
        /* prevent iOS zoom */
        appearance: none;
        box-shadow: none !important;
        color: var(--text-primary) !important;
    }

    .item-row>.m-input-wrap .i-total {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
    }

    .item-row .i-remove {
        position: absolute !important;
        top: 14px !important;
        right: 14px !important;
        width: 32px !important;
        height: 32px !important;
        padding: 0 !important;
        border-radius: 50% !important;
        background: rgba(255, 59, 48, 0.1) !important;
        color: #ff3b30 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border: none !important;
    }

    /* Fixed Bar Fixes for Mobile Keyboard */
    .action-bar {
        position: sticky !important;
        top: 0 !important;
        z-index: 1000 !important;
    }

    /* ── Totals section on forms ── */
    .totals-section {
        align-items: stretch !important;
    }

    .total-row,
    .total-final {
        width: 100% !important;
    }

    /* ── Notes Grid ── */
    .notes-grid {
        grid-template-columns: 1fr !important;
    }

    /* ── Action Bar ── */
    .action-bar {
        padding: 8px 12px !important;
        height: auto !important;
        min-height: 48px !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .action-bar .title {
        font-size: 13px !important;
        width: 100% !important;
    }

    .action-btns {
        width: 100% !important;
        justify-content: flex-end !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    .btn-back,
    .btn-save,
    .btn-gen {
        padding: 8px 14px !important;
        font-size: 11px !important;
        border-radius: 10px !important;
    }

    /* ── Modal Dialogs ── */
    .modal-content,
    .nc-modal,
    .paid-modal-box {
        width: 92% !important;
        max-width: 380px !important;
        margin: 12% auto !important;
        padding: 24px 20px !important;
        border-radius: 16px !important;
    }

    .nc-btns,
    .paid-modal-btns {
        flex-direction: column !important;
    }

    /* ── Search Dropdown ── */
    #searchDropdown {
        max-height: 150px !important;
    }

    /* ── Controls row (GST toggle, etc) ── */
    .controls-row {
        flex-wrap: wrap !important;
        gap: 10px !important;
    }

    /* ── Columns dropdown ── */
    .columns-dropdown {
        width: 220px !important;
    }

    /* ── Save dropdown ── */
    .save-dropdown-menu {
        min-width: 160px !important;
    }

    /* ── Bank Reconciliation, SOA, etc ── */
    .container,
    .main-container,
    .page-container {
        padding: 12px !important;
        width: 100% !important;
    }
}

/* ============================================================
   SMALL PHONE (iPhone SE, mini) — max-width: 430px
   ============================================================ */
@media (max-width: 430px) {

    .card-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

    .card {
        padding: 16px 10px !important;
    }

    .icon-circle {
        width: 38px !important;
        height: 38px !important;
        font-size: 18px !important;
        border-radius: 12px !important;
        margin-bottom: 8px !important;
    }

    .card h3 {
        font-size: 11px !important;
    }

    .card p {
        font-size: 9px !important;
    }

    .welcome-header h1 {
        font-size: 20px !important;
    }

    .welcome-header p {
        font-size: 12px !important;
    }

    .stat-box {
        min-width: 60px !important;
    }

    .stat-num {
        font-size: 14px !important;
    }

    .chart-wrap {
        height: 170px !important;
    }

    /* Invoice/Quote on very small screens */
    .invoice-box,
    .paper {
        padding: 14px 10px !important;
    }

    #vTitle {
        font-size: 20px !important;
    }

    .items-table th,
    table.main-table th {
        font-size: 8px !important;
        padding: 6px 3px !important;
    }

    .items-table td,
    table.main-table td {
        font-size: 9px !important;
        padding: 6px 3px !important;
    }

    .total-text {
        font-size: 16px !important;
    }

    .t-final {
        font-size: 16px !important;
    }

    /* CRM page on very small phones */
    .sidebar {
        max-height: 100% !important;
        transform: translateX(0) !important;
    }

    .profile-header h1 {
        font-size: 16px !important;
    }

    .btn-act {
        padding: 6px 10px !important;
        font-size: 10px !important;
    }

    /* Login page */
    .login-card {
        width: 90% !important;
        margin: 16px auto !important;
    }
}

/* ============================================================
   iOS-specific Fixes
   ============================================================ */

/* Fix iOS momentum scrolling */
.crm-container,
.sidebar,
.main-view,
.history-panel {
    -webkit-overflow-scrolling: touch;
}

/* Fix iOS input zoom (inputs below 16px trigger zoom on focus) */
@media (max-width: 640px) {

    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    .field input,
    .field select,
    .item-row input,
    .item-row textarea,
    .item-row select {
        font-size: 16px !important;
    }

    .modal-content input,
    .nc-modal input,
    .paid-modal-box input {
        font-size: 16px !important;
    }
}

/* Fix 100vh issue on iOS Safari (address bar) */
@supports (-webkit-touch-callout: none) {
    .crm-container {
        min-height: -webkit-fill-available !important;
    }
}

/* ── Smooth scrolling and touch optimizations ── */
@media (hover: none) and (pointer: coarse) {

    /* Larger touch targets */
    .cust-card {
        padding: 16px !important;
        margin-bottom: 8px !important;
    }

    .icon-btn {
        padding: 8px !important;
        font-size: 16px !important;
    }

    .badge-status {
        padding: 6px 12px !important;
        font-size: 10px !important;
        min-width: 70px !important;
    }

    /* Disable hover effects on touch devices */
    .card:hover {
        transform: none !important;
    }

    .card:active {
        transform: scale(0.97) !important;
    }

    .btn-act:hover {
        transform: none !important;
    }

    /* Remove dropdown hover (requires tap on mobile) */
    .nav-item:hover .dropdown {
        display: none !important;
    }
}

/* ============================================================
   Print: Ensure responsive CSS doesn't affect print
   ============================================================ */
@media print {

    .mobile-hamburger,
    .mobile-nav-panel,
    .mobile-menu-overlay {
        display: none !important;
    }

    /* Force desktop layout for invoice/quote print */
    .invoice-box,
    .paper {
        width: 100% !important;
        max-width: 100% !important;
        padding: 30px 40px !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        min-height: 100vh !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* Keep header side-by-side (logo left, title right) */
    .header-top,
    .invoice-header,
    .header {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
        flex-wrap: nowrap !important;
    }

    .header-top>div {
        flex-wrap: nowrap !important;
    }

    /* Keep info-bar side-by-side (bill-to left, details right) */
    .info-bar {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
    }

    .info-col-left {
        width: 50% !important;
    }

    .info-col-right {
        width: 40% !important;
        align-items: flex-end !important;
    }

    .details-box {
        text-align: right !important;
        align-items: flex-end !important;
    }

    .details-header {
        border-left: none !important;
        border-right: 3px solid #007AFF !important;
        padding-left: 0 !important;
        padding-right: 8px !important;
    }

    .details-table td {
        text-align: right !important;
        padding: 3px 0 3px 12px !important;
    }

    /* Keep logo full size */
    #compLogo,
    .header-right img {
        max-height: 120px !important;
        max-width: 250px !important;
    }

    /* Keep title full size */
    #vTitle {
        font-size: 32px !important;
    }

    /* Keep table text full size */
    .items-table th,
    table.main-table th {
        padding: 10px 6px !important;
        font-size: 11px !important;
    }

    .items-table td,
    table.main-table td {
        padding: 10px 6px !important;
        font-size: 12px !important;
    }

    /* Keep summary/total at full size */
    .summary-box {
        width: 260px !important;
    }

    .total-text {
        font-size: 22px !important;
    }

    .t-final {
        font-size: 22px !important;
    }

    /* Keep advice section side-by-side */
    .advice-flex {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
    }

    .advice-flex>div:first-child {
        width: 50% !important;
    }

    .advice-table {
        width: 45% !important;
    }

    .advice-header {
        font-size: 28px !important;
    }

    /* Keep totals right-aligned */
    .totals {
        align-items: flex-end !important;
    }

    .t-row {
        width: 260px !important;
        display: flex !important;
        justify-content: space-between !important;
    }

    .t-final {
        width: 260px !important;
        display: flex !important;
        justify-content: space-between !important;
    }
}

/* ── Hide forced scrollbar track ── */
html {
    overflow-y: auto !important;
}
html::-webkit-scrollbar {
    width: 0 !important;
    background: transparent !important;
}

/* ── Nav right-side: lang toggle / theme toggle / account — global consistency ── */
.nav-bar .theme-toggle {
    width: 36px !important;
    height: 36px !important;
    flex-shrink: 0;
    margin-left: auto;   /* push group to right when no lang toggle */
    margin-right: 10px !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    transition: background 0.2s;
}
.nav-bar .theme-toggle:hover {
    background: rgba(255, 255, 255, 0.1) !important;
}
.nav-bar .theme-toggle svg {
    width: 18px !important;
    height: 18px !important;
    fill: rgba(255, 255, 255, 0.8) !important;
}
#desktopLangToggle {
    margin-left: auto !important;  /* push group to right when lang toggle present */
    margin-right: 12px !important;
}
#desktopLangToggle ~ .theme-toggle {
    margin-left: 0 !important;    /* lang toggle handles the push */
}
.nav-bar .account-dropdown-wrap {
    margin-right: 14px !important;
    flex-shrink: 0;
}
.nav-bar .account-btn {
    width: 36px !important;
    height: 36px !important;
}

/* ── Smooth nav dropdown (desktop only) ── */
@media (min-width: 641px) {
    .nav-item .dropdown {
        display: block !important;
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
        transform: translateY(-6px);
        transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s linear 0.3s;
    }

    .nav-item:hover .dropdown {
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0);
        transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s linear 0s;
        animation: none !important;
    }
}

/* ============================================================
   MOBILE BOTTOM TAB BAR
   ============================================================ */
.mobile-tab-bar {
    display: none;
}

@media (max-width: 640px) {
    .mobile-tab-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: var(--nav-bg, rgba(28, 28, 30, 0.92));
        backdrop-filter: saturate(180%) blur(20px);
        -webkit-backdrop-filter: saturate(180%) blur(20px);
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        z-index: 6000;
        align-items: stretch;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .mobile-tab-bar .tab-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        text-decoration: none;
        color: rgba(255, 255, 255, 0.45);
        font-size: 10px;
        font-weight: 500;
        letter-spacing: 0.2px;
        transition: color 0.2s;
        cursor: pointer;
        background: none;
        border: none;
        padding: 0;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-tab-bar .tab-item.active {
        color: #007aff;
    }

    .mobile-tab-bar .tab-item svg {
        width: 22px;
        height: 22px;
        fill: currentColor;
    }

    /* Push page content above tab bar */
    body {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Mobile nav-bar back button */
    .mobile-nav-back {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border-radius: 8px;
        color: rgba(255, 255, 255, 0.85);
        cursor: pointer;
        background: none;
        border: none;
        padding: 0;
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
        margin-right: 4px;
    }

    .mobile-nav-back svg {
        width: 20px;
        height: 20px;
        fill: currentColor;
    }

    /* On mobile, hide the action-bar back button when mobile-nav-back exists */
    .has-mobile-back .btn-back {
        display: none !important;
    }
}

/* Desktop: always hide mobile-nav-back */
@media (min-width: 641px) {
    .mobile-nav-back {
        display: none !important;
    }
}