/* ===============================================
   AiReply Mobile Responsive — Additional Fixes
   Loaded AFTER style.css to override and supplement
   =============================================== */

/* == OVERRIDE: Show sidebar as slide-in overlay (matching PC menu exactly) == */
@media (max-width: 768px) {
    /* Undo the display:none from style.css line 3370 */
    .sidebar {
        display: flex !important;
        flex-direction: column !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: 280px !important;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 9999 !important;
        box-shadow: none;
        overflow-y: auto;
        background: #111827 !important;
    }
    .sidebar.collapsed {
        width: 280px !important;
    }
    .sidebar.collapsed .nav-label {
        opacity: 1 !important;
        width: auto !important;
        position: static !important;
    }
    .sidebar.collapsed .sidebar-toggle {
        display: none;
    }
    .sidebar.collapsed .sidebar-user-info {
        display: block !important;
    }
    .sidebar.collapsed .sidebar-logout {
        justify-content: flex-start !important;
    }
    .sidebar.collapsed .nav-item {
        justify-content: flex-start !important;
        padding: 12px 20px !important;
    }
    .sidebar.collapsed .nav-section-title {
        display: block !important;
    }
    .sidebar.collapsed .nav-divider {
        display: block !important;
    }
    .sidebar.open {
        transform: translateX(0) !important;
        box-shadow: 4px 0 24px rgba(0,0,0,0.25) !important;
    }
    /* Sidebar overlay backdrop — visibility controlled by Alpine x-show */
    .sidebar-overlay {
        position: fixed !important;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.4) !important;
        z-index: 9998 !important;
        -webkit-tap-highlight-color: transparent;
    }
    /* Touch-friendly nav items */
    .sidebar .nav-item {
        padding: 12px 20px !important;
        min-height: 44px !important;
        font-size: 0.95rem !important;
    }
    .sidebar .settings-sub-item {
        padding: 10px 20px 10px 36px !important;
        min-height: 40px !important;
    }
    .sidebar-footer {
        padding: 12px 16px 16px !important;
    }
    .sidebar-logout {
        min-height: 44px !important;
    }
    /* Hide the collapse toggle on mobile */
    .sidebar-toggle {
        display: none !important;
    }
    /* Hide bottom nav — sidebar replaces it */
    .bottom-nav {
        display: none !important;
    }
    /* Hide more menu overlay — sidebar replaces it */
    .more-menu-overlay {
        display: none !important;
    }
}

/* == MOBILE TOP BAR with hamburger == */
@media (max-width: 768px) {
    .mobile-top-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 14px;
        background: #fff;
        border-bottom: 1px solid #e5e7eb;
        position: sticky;
        top: 0;
        z-index: 100;
        min-height: 48px;
    }
    .mobile-top-bar-left {
        display: flex;
        align-items: center;
        gap: 10px;
        min-width: 0;
    }
    /* Hamburger icon */
    .mobile-hamburger {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 4px;
        width: 28px;
        height: 28px;
        cursor: pointer;
        padding: 4px;
        -webkit-tap-highlight-color: transparent;
        flex-shrink: 0;
    }
    .mobile-hamburger span {
        display: block;
        width: 20px;
        height: 2px;
        background: #374151;
        border-radius: 1px;
        transition: all 0.2s;
    }
    .mobile-top-bar-logo {
        font-weight: 700;
        font-size: 1rem;
        color: var(--primary, #6C63FF);
        white-space: nowrap;
    }
    .mobile-top-bar-page {
        font-size: 0.85rem;
        color: #6b7280;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .mobile-top-bar-right {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
    }
    .mobile-credits-pill {
        background: #ECFDF5;
        color: #059669;
        font-size: 0.72rem;
        font-weight: 600;
        padding: 3px 8px;
        border-radius: 12px;
        white-space: nowrap;
    }
    .mobile-top-avatar {
        width: 30px;
        height: 30px;
        border-radius: 50%;
        background: var(--primary, #6C63FF);
        color: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.7rem;
        font-weight: 600;
        flex-shrink: 0;
    }
    /* Main content — no bottom padding needed since no bottom nav */
    .main-content {
        padding-bottom: 24px !important;
    }
}
@media (min-width: 769px) {
    .mobile-top-bar {
        display: none !important;
    }
    .mobile-hamburger {
        display: none !important;
    }
}

/* == MODALS -- full-width on mobile == */
@media (max-width: 768px) {
    .modal-overlay > div,
    .ads-modal,
    .tmpl-detail-panel {
        max-width: 95vw !important;
        width: 95vw !important;
        margin: 10px auto;
        max-height: 90vh;
        overflow-y: auto;
    }
    .modal-overlay {
        padding: 8px !important;
    }
}

/* == BROADCAST -- form stacking == */
@media (max-width: 768px) {
    .broadcast-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
    }
    .broadcast-tabs::-webkit-scrollbar { display: none; }
    .broadcast-tab {
        white-space: nowrap;
        flex-shrink: 0;
    }
}

/* == IMAGE GENERATOR -- doctor photo section == */
@media (max-width: 768px) {
    .ig-segmented-control {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        gap: 6px;
        padding-bottom: 4px;
    }
    .ig-segmented-control::-webkit-scrollbar { display: none; }
    .ig-seg-btn {
        flex-shrink: 0;
        white-space: nowrap;
        min-height: 40px;
    }
    .ig-suggestions {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        padding-bottom: 4px;
    }
    .ig-suggestions::-webkit-scrollbar { display: none; }
    .ig-suggestions > * {
        flex-shrink: 0;
    }
    .ig-generate-btn {
        width: 100% !important;
        min-width: unset !important;
    }
    .ig-gallery-grid-full {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important;
    }
}
@media (max-width: 380px) {
    .ig-gallery-grid-full {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* == DASHBOARD -- additional mobile fixes == */
@media (max-width: 768px) {
    .morning-brief-card {
        border-radius: 10px;
    }
    .brief-stats-row {
        flex-direction: column;
        gap: 8px;
    }
    .brief-stat {
        flex-direction: row;
        gap: 8px;
        align-items: center;
    }
    .dash-activity-row {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px;
    }
    .dash-activity-card {
        padding: 14px;
    }
    .dash-quick-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px;
    }
    .dash-quick-card {
        padding: 14px;
    }
    .dash-credits-bar {
        flex-direction: column;
        gap: 8px;
        padding: 12px;
    }
    .dash-notice-card {
        padding: 12px;
    }
    .dash-notice-meta {
        flex-direction: column;
        align-items: flex-end;
        gap: 4px;
    }
    .dash-notice-time {
        font-size: 0.7rem;
    }
    .dash-plan-row {
        flex-wrap: wrap;
        gap: 8px;
    }
}

/* == Benefit score card (desktop + mobile) == */
.benefit-score-bar {
    height: 8px;
    border-radius: 4px;
    background: #f3f4f6;
    overflow: hidden;
    margin: 8px 0;
}
.benefit-score-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}
.benefit-score-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 16px;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
}
.benefit-score-header.expanded {
    border-radius: 12px 12px 0 0;
}
.benefit-checklist {
    padding: 0 16px 16px;
    background: #fff;
    border-radius: 0 0 12px 12px;
    border: 1px solid #e5e7eb;
    border-top: none;
}
.benefit-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.88rem;
}
.benefit-item:last-child {
    border-bottom: none;
}
.benefit-check {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    flex-shrink: 0;
}
.benefit-check.done {
    background: #ECFDF5;
    color: #059669;
}
.benefit-check.pending {
    background: #f3f4f6;
    color: #9ca3af;
}
.benefit-go-link {
    margin-left: auto;
    color: var(--primary, #6C63FF);
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
}
.benefit-go-link:hover {
    text-decoration: underline;
}
.benefit-item-text {
    flex: 1;
    min-width: 0;
}
.benefit-item-text.done {
    color: #9ca3af;
    text-decoration: line-through;
}
.benefit-item-why {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 2px;
}
.benefit-score-pct {
    font-size: 1.25rem;
    font-weight: 700;
}
.benefit-score-label {
    font-size: 0.82rem;
    color: #6b7280;
}
.benefit-score-chevron {
    font-size: 0.8rem;
    color: #9ca3af;
    transition: transform 0.2s;
}
.benefit-score-chevron.expanded {
    transform: rotate(180deg);
}

/* == TEMPLATES PAGE -- filter pills scroll == */
@media (max-width: 768px) {
    .tmpl-filter-row {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        padding-bottom: 4px;
    }
    .tmpl-filter-row::-webkit-scrollbar { display: none; }
    .tmpl-filter-pill {
        flex-shrink: 0;
        white-space: nowrap;
    }
    .template-editor-preview {
        width: 100% !important;
        max-width: 100%;
    }
}

/* == SOCIAL MEDIA PAGE -- responsive fixes == */
@media (max-width: 768px) {
    .social-tab {
        white-space: nowrap;
        flex-shrink: 0;
    }
    .social-chip {
        flex-shrink: 0;
        white-space: nowrap;
    }
}

/* == CLINIC SETTINGS -- pill scroll == */
@media (max-width: 768px) {
    .cs-pill {
        flex-shrink: 0;
        white-space: nowrap;
    }
    .day-pill {
        min-width: 38px;
    }
}

/* == INVOICE PAGE -- responsive grid == */
@media (max-width: 768px) {
    .invoice-items-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* == GLOBAL -- touch target minimums == */
@media (max-width: 768px) {
    .btn-text {
        min-height: 36px;
        display: inline-flex;
        align-items: center;
    }
}

/* == ADS PAGE -- campaign cards == */
@media (max-width: 768px) {
    .ads-campaign-card {
        padding: 14px;
    }
    .ads-step-v2-label {
        font-size: 0.72rem;
    }
}

/* == VIDEO GENERATOR -- responsive == */
@media (max-width: 768px) {
    .video-preview-container {
        max-width: 100%;
    }
}

/* == PATIENTS PAGE -- table responsive == */
@media (max-width: 768px) {
    .patients-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* == ANALYTICS PAGE -- grid fix == */
@media (max-width: 768px) {
    .analytics-grid-2 {
        grid-template-columns: 1fr !important;
    }
}

/* Hide floating avatar on mobile — mobile-top-bar has its own avatar */
@media (max-width: 768px) {
    .floating-avatar-wrap {
        display: none !important;
    }
}

/* =====================================================
   Mobile Polish — Fix 2: Broadcast form vertical stack
   ===================================================== */
@media (max-width: 768px) {
  /* Stack the two-column compose layout */
  .broadcast-compose-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px;
  }
  .broadcast-compose-grid > div:last-child {
    display: none !important; /* Hide phone preview on mobile — saves space */
  }
}

/* =====================================================
   Mobile Polish — Fix 3: Invoice-new header field stack
   ===================================================== */
@media (max-width: 768px) {
  .inv-header-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px;
  }
  .inv-header-grid > * {
    width: 100% !important;
  }
}

/* =====================================================
   Mobile Polish — Fix 4: Category tab horizontal scroll
   (Extends existing ig-segmented-control rules)
   ===================================================== */
@media (max-width: 768px) {
  .ig-category-scroll {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  .ig-category-scroll::-webkit-scrollbar { display: none; }
  .ig-category-scroll > .ig-seg-btn {
    flex-shrink: 0 !important;
    white-space: nowrap;
  }
}

/* =====================================================
   Mobile Polish — Fix 5: Table-to-card conversion
   ===================================================== */
@media (max-width: 768px) {
  .mobile-card-table thead {
    display: none !important;
  }
  .mobile-card-table tbody tr {
    display: block;
    border: 0.5px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    background: #fff;
  }
  .mobile-card-table tbody tr[style*="background:#fff5f5"] {
    border-left: 3px solid #ef4444;
  }
  .mobile-card-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
    border: none !important;
    font-size: 13px;
    background: none !important;
  }
  .mobile-card-table tbody td::before {
    content: attr(data-label);
    font-size: 12px;
    color: #6b7280;
    font-weight: 500;
    flex-shrink: 0;
    margin-right: 12px;
  }
  /* Card header (name + status) */
  .mobile-card-table tbody td.card-header {
    font-weight: 600;
    font-size: 14px;
    padding-bottom: 6px;
    margin-bottom: 4px;
    border-bottom: 0.5px solid #f3f4f6 !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .mobile-card-table tbody td.card-header::before {
    display: none;
  }
  /* Action buttons row */
  .mobile-card-table tbody td.card-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: 8px;
    margin-top: 4px;
    border-top: 0.5px solid #f3f4f6 !important;
    justify-content: flex-start;
  }
  .mobile-card-table tbody td.card-actions::before {
    display: none;
  }
  .mobile-card-table tbody td.card-actions button {
    font-size: 12px !important;
    padding: 5px 10px !important;
    min-height: 32px;
  }
  /* Empty-state row should stay centered */
  .mobile-card-table tbody tr:only-child td[colspan] {
    display: block;
    text-align: center;
  }
  .mobile-card-table tbody tr:only-child td[colspan]::before {
    display: none;
  }
  /* Hide columns we want to skip on mobile */
  .mobile-card-table tbody td.mobile-hide {
    display: none !important;
  }
}

/* Card-header ordering — put name first in cards regardless of HTML td position */
@media (max-width: 768px) {
  .mobile-card-table tbody tr {
    display: flex;
    flex-direction: column;
  }
  .mobile-card-table tbody td.card-header {
    order: -2;
  }
  .mobile-card-table tbody td.card-actions {
    order: 99;
  }
}
