/* 
 * OmegaPharmacy Mobile Responsive CSS
 * Covers all pages: index, login, dashboards, medicines, expenses, reports, messages, sales, settings
 */

/* ============================================
   BASE - PREVENT iOS ZOOM ON INPUTS
   ============================================ */
input, select, textarea {
    font-size: 16px !important;
}

/* ============================================
   TABLET & BELOW (max 768px)
   ============================================ */

@media (max-width: 768px) {

    /* --- HEADER --- */
    .header-content {
        flex-direction: column !important;
        gap: 10px !important;
        padding: 12px 15px !important;
    }

    .logo h2 {
        font-size: 1em !important;
    }

    .logo img {
        width: 35px !important;
        height: 35px !important;
    }

    .header-nav {
        gap: 6px !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
    }

    .nav-btn {
        background: rgba(255,255,255,0.2) !important;
        color: white !important;
        padding: 6px 12px !important;
        font-size: 0.82em !important;
        border-radius: 15px !important;
    }

    .nav-btn:hover {
        background: rgba(255,255,255,0.3) !important;
    }

    /* --- MAIN CONTAINER --- */
    .main-container {
        padding: 0 12px !important;
        margin: 15px auto !important;
    }

    /* --- WELCOME SECTION --- */
    .welcome-section {
        flex-direction: column !important;
        gap: 15px !important;
        padding: 18px !important;
        text-align: center !important;
    }

    .welcome-section h1 {
        font-size: 1.4em !important;
    }

    .welcome-section p {
        font-size: 0.95em !important;
    }

    /* --- STATS GRID --- */
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }

    .stat-card {
        padding: 14px !important;
        gap: 12px !important;
    }

    .stat-icon {
        width: 52px !important;
        height: 52px !important;
        font-size: 1.5em !important;
        flex-shrink: 0 !important;
    }

    .stat-number {
        font-size: 1.3em !important;
    }

    .stat-info h3 {
        font-size: 0.78em !important;
    }

    .stat-info small {
        font-size: 0.75em !important;
    }

    /* --- ACTION GRID --- */
    .action-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .action-btn {
        padding: 14px 10px !important;
        font-size: 0.85em !important;
        gap: 8px !important;
    }

    .action-btn i {
        font-size: 1.6em !important;
    }

    /* --- QUICK ACTIONS SECTION --- */
    .quick-actions {
        padding: 18px !important;
    }

    .quick-actions h2 {
        font-size: 1.2em !important;
        margin-bottom: 15px !important;
    }

    /* --- PAGE HEADER --- */
    .page-header {
        flex-direction: column !important;
        gap: 12px !important;
        padding: 18px !important;
        text-align: center !important;
    }

    .page-header h1 {
        font-size: 1.4em !important;
    }

    /* --- BUTTONS --- */
    button, .btn, .btn-primary, .btn-secondary, .btn-add, .btn-submit {
        min-height: 44px !important;
        font-size: 0.95em !important;
    }

    .btn-add {
        width: 100% !important;
        padding: 12px !important;
    }

    /* --- FORMS --- */
    .form-group {
        margin-bottom: 12px !important;
    }

    .form-group label {
        font-size: 0.9em !important;
    }

    .form-group input,
    .form-group select,
    .form-group textarea,
    .form-control {
        padding: 11px !important;
        border-radius: 8px !important;
    }

    /* --- MODALS --- */
    .modal-content {
        margin: 15px !important;
        max-height: 88vh !important;
        overflow-y: auto !important;
        padding: 20px !important;
        border-radius: 12px !important;
    }

    .modal-header h2 {
        font-size: 1.2em !important;
    }

    /* --- TABLES (general) --- */
    .table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    table {
        min-width: 500px !important;
    }

    th, td {
        padding: 10px 8px !important;
        font-size: 0.85em !important;
    }

    /* --- MEDICINES TABLE → CARD LAYOUT --- */
    .medicines-table,
    #medicineTable {
        display: block !important;
        overflow-x: auto !important;
        min-width: unset !important;
    }

    /* --- EXPENSES TABLE → CARD LAYOUT --- */
    .expenses-table {
        display: block !important;
        overflow-x: auto !important;
        min-width: unset !important;
    }

    /* --- SUBMISSIONS TABLE --- */
    .submissions-table {
        display: block !important;
        overflow-x: auto !important;
        min-width: unset !important;
    }

    .submissions-table th,
    .submissions-table td {
        padding: 10px 8px !important;
        font-size: 0.82em !important;
    }

    /* --- RECENT SALES TABLE (admin dashboard) --- */
    .sales-table {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .recent-sales-section {
        padding: 18px !important;
    }

    .section-header {
        flex-direction: column !important;
        gap: 10px !important;
        text-align: center !important;
    }

    .section-header h2 {
        font-size: 1.2em !important;
    }

    /* --- MESSAGES PAGE --- */
    .messages-container {
        border-radius: 12px !important;
    }

    .messages-header {
        padding: 18px 15px !important;
    }

    .messages-header h1 {
        font-size: 1.4em !important;
    }

    .messages-body {
        height: calc(100vh - 280px) !important;
        min-height: 250px !important;
        padding: 12px 10px !important;
    }

    .message-bubble {
        max-width: 85% !important;
        padding: 10px 14px !important;
        font-size: 0.92em !important;
    }

    .messages-footer {
        padding: 12px 10px !important;
        gap: 8px !important;
    }

    .messages-footer input {
        padding: 10px 14px !important;
    }

    .btn-send {
        padding: 10px 18px !important;
        font-size: 0.9em !important;
        white-space: nowrap !important;
    }

    /* --- MESSAGES HEADER NAV (white header) --- */
    .main-header .header-content .user-badge {
        padding: 6px 12px !important;
        font-size: 0.85em !important;
    }

    .btn-logout {
        padding: 6px 14px !important;
        font-size: 0.85em !important;
    }

    /* --- SALES FORM (staff_sales.html) --- */
    .sales-form {
        padding: 18px !important;
    }

    .medicine-row {
        padding: 12px !important;
    }

    .total-box {
        padding: 18px !important;
    }

    .total-amount {
        font-size: 2em !important;
    }

    /* --- SALES HISTORY (staff_sales_history.html) --- */
    .sale-item {
        flex-direction: column !important;
        gap: 10px !important;
        align-items: flex-start !important;
    }

    .sale-actions {
        width: 100% !important;
        justify-content: space-between !important;
    }

    .sale-amount {
        font-size: 1.1em !important;
    }

    /* --- REPORT TABS (admin_reports.html) --- */
    .report-tabs {
        flex-direction: column !important;
        gap: 8px !important;
        padding: 15px !important;
    }

    .tab-btn {
        padding: 12px !important;
        font-size: 0.9em !important;
    }

    .summary-cards {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .summary-card {
        padding: 18px !important;
    }

    .summary-card .amount {
        font-size: 1.6em !important;
    }

    .detail-table {
        display: block !important;
        overflow-x: auto !important;
    }

    /* --- SETTINGS PAGE --- */
    .settings-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }

    .settings-card {
        padding: 20px !important;
    }

    .user-item {
        flex-direction: column !important;
        gap: 10px !important;
        align-items: flex-start !important;
    }

    .btn-change {
        width: 100% !important;
        padding: 10px !important;
    }

    /* --- STOCK / STATUS BADGES --- */
    .stock-badge, .status-badge {
        font-size: 0.8em !important;
        padding: 4px 8px !important;
    }

    /* --- FILTER BUTTONS --- */
    .filter-buttons {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .filter-btn {
        padding: 8px 14px !important;
        font-size: 0.85em !important;
    }

    /* --- SUMMARY BOX (expenses) --- */
    .summary-box {
        flex-direction: column !important;
        gap: 12px !important;
        padding: 18px !important;
    }

    .summary-box .amount {
        font-size: 1.6em !important;
    }

    /* --- FLOATING BACK BUTTON --- */
    .btn-back {
        bottom: 20px !important;
        right: 20px !important;
        width: 52px !important;
        height: 52px !important;
        font-size: 1.3em !important;
    }

    /* --- INDEX PAGE LOGIN BUTTONS --- */
    .login-buttons {
        flex-direction: column !important;
        gap: 15px !important;
        padding: 0 15px !important;
    }

    .login-btn {
        width: 100% !important;
        padding: 18px 25px !important;
    }

    /* --- DAILY REPORT BUTTON (staff dashboard) --- */
    .btn-daily-report {
        width: 100% !important;
        padding: 12px 20px !important;
        font-size: 1em !important;
    }

    /* --- REPORT MODAL BUTTONS --- */
    .btn-close-modal {
        padding: 12px !important;
        font-size: 1em !important;
    }

    /* --- SEARCH BOX --- */
    .search-box {
        padding: 15px !important;
    }

    .search-box input {
        padding: 10px 15px !important;
    }

    /* --- ADMIN REPORT SUBMISSIONS --- */
    .submissions-container {
        padding: 18px !important;
    }

    .action-btn {
        padding: 6px 10px !important;
        font-size: 0.8em !important;
        margin-bottom: 4px !important;
    }
}

/* ============================================
   SMALL MOBILE (max 480px)
   ============================================ */

@media (max-width: 480px) {

    /* Single column stats */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    /* Single column actions */
    .action-grid {
        grid-template-columns: 1fr !important;
    }

    /* Smaller headings */
    .welcome-section h1 {
        font-size: 1.2em !important;
    }

    .stat-number {
        font-size: 1.2em !important;
    }

    /* Hide logo text */
    .logo h2 {
        display: none !important;
    }

    /* Compact nav */
    .nav-btn {
        padding: 5px 9px !important;
        font-size: 0.78em !important;
    }

    /* Smaller modals */
    .modal-content {
        margin: 8px !important;
        padding: 15px !important;
    }

    /* Compact action buttons */
    .action-btn {
        padding: 12px 8px !important;
        font-size: 0.82em !important;
    }

    .action-btn i {
        font-size: 1.4em !important;
    }

    /* Sales total */
    .total-amount {
        font-size: 1.6em !important;
    }

    /* Messages body height */
    .messages-body {
        height: calc(100vh - 260px) !important;
        min-height: 200px !important;
    }

    /* Report tabs */
    .tab-btn {
        font-size: 0.82em !important;
        padding: 10px 8px !important;
    }

    /* Summary card amounts */
    .summary-card .amount {
        font-size: 1.4em !important;
    }

    /* Page header */
    .page-header h1 {
        font-size: 1.2em !important;
    }

    /* Login box */
    .login-box {
        padding: 20px 15px !important;
    }

    /* Index welcome */
    .welcome-container h1 {
        font-size: 2em !important;
    }

    .welcome-message {
        font-size: 1em !important;
    }

    .logo-image {
        width: 120px !important;
        height: 120px !important;
    }

    /* Sale item actions stack */
    .sale-actions {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .btn-view-details,
    .btn-delete {
        width: 100% !important;
        text-align: center !important;
    }

    /* Submissions action buttons */
    .action-btn {
        display: block !important;
        width: 100% !important;
        margin-bottom: 5px !important;
        text-align: center !important;
    }

    /* Settings user item */
    .user-info {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 5px !important;
    }
}

/* ============================================
   LANDSCAPE MOBILE
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    .messages-body {
        height: calc(100vh - 160px) !important;
        min-height: 150px !important;
    }

    .modal-content {
        max-height: 95vh !important;
        margin: 5px auto !important;
    }

    .hero-section {
        min-height: auto !important;
        padding: 20px !important;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .main-header,
    .header-nav,
    .nav-btn,
    .btn-logout,
    .action-grid,
    .messages-footer,
    .btn-back,
    .floating-pills {
        display: none !important;
    }

    body {
        background: white !important;
    }

    .main-container {
        max-width: 100% !important;
        padding: 0 !important;
    }
}

/* ============================================
   NEW FEATURES - BRANCH & PRODUCT STATS
   ============================================ */

@media (max-width: 768px) {

    /* Branch filter selector */
    #branchFilter {
        width: 100% !important;
        padding: 10px 14px !important;
        font-size: 0.95em !important;
        border-radius: 10px !important;
    }

    /* Welcome section with branch filter */
    .welcome-section > div:last-child {
        width: 100% !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    /* Product stats section */
    .product-stats-section {
        padding: 15px !important;
    }

    .product-table {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        min-width: unset !important;
    }

    .product-table th,
    .product-table td {
        padding: 9px 8px !important;
        font-size: 0.82em !important;
    }

    .rank-badge {
        width: 24px !important;
        height: 24px !important;
        font-size: 0.78em !important;
    }

    .revenue-badge {
        padding: 3px 8px !important;
        font-size: 0.82em !important;
    }

    /* Clear history button in page-header */
    .page-header > div {
        flex-direction: column !important;
        width: 100% !important;
        gap: 8px !important;
    }

    /* Staff login branch select */
    #branchSelect {
        padding: 12px !important;
        font-size: 1em !important;
        border-radius: 6px !important;
    }

    /* Admin medicines branch filter row */
    .page-header > div[style*="display:flex"] {
        flex-direction: column !important;
        width: 100% !important;
    }

    /* Messages clear button */
    .messages-header button {
        width: 100% !important;
        margin-top: 10px !important;
    }

    /* Expenses page header buttons */
    .page-header > div > button {
        width: 100% !important;
    }

    /* Report submissions clear button */
    .page-header > div > button[onclick*="clearAll"] {
        width: 100% !important;
        margin-top: 8px !important;
    }

    /* Quick nav with clear button */
    .quick-nav {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 8px !important;
    }

    .quick-nav-btn {
        flex: 1 1 auto !important;
        min-width: 100px !important;
        text-align: center !important;
        padding: 10px 12px !important;
        font-size: 0.85em !important;
    }
}

@media (max-width: 480px) {

    /* Product stats single column feel */
    .product-table th:nth-child(2),
    .product-table td:nth-child(2) {
        max-width: 120px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    /* Branch selector full width */
    #branchFilter,
    #branchSelect {
        width: 100% !important;
        font-size: 0.95em !important;
    }

    /* Quick nav stack on very small */
    .quick-nav {
        flex-direction: column !important;
    }

    .quick-nav-btn {
        width: 100% !important;
    }
}

/* ============================================
   MEDICINES TABLE → CARD LAYOUT ON MOBILE
   ============================================ */

@media (max-width: 768px) {

    /* Hide table headers on mobile for medicines */
    #medicineTable thead {
        display: none !important;
    }

    #medicineTable,
    #medicineTable tbody,
    #medicineTable tr,
    #medicineTable td {
        display: block !important;
        width: 100% !important;
    }

    #medicineTable tr {
        background: white !important;
        border-radius: 12px !important;
        margin-bottom: 12px !important;
        padding: 14px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important;
        border: 1px solid #f0f0f0 !important;
    }

    #medicineTable td {
        padding: 5px 0 !important;
        border: none !important;
        font-size: 0.9em !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        min-height: 32px !important;
    }

    #medicineTable td:before {
        font-weight: 700 !important;
        color: #7f8c8d !important;
        font-size: 0.82em !important;
        min-width: 90px !important;
    }

    #medicineTable td:nth-child(1):before { content: "ስም" !important; }
    #medicineTable td:nth-child(2):before { content: "ጄነሪክ" !important; }
    #medicineTable td:nth-child(3):before { content: "ምድብ" !important; }
    #medicineTable td:nth-child(4):before { content: "ብዛት" !important; }
    #medicineTable td:nth-child(5):before { content: "ዋጋ" !important; }
    #medicineTable td:nth-child(6):before { content: "ማብቂያ" !important; }
    #medicineTable td:nth-child(7):before { content: "ቅርንጫፍ" !important; }
    #medicineTable td:nth-child(8):before { content: "እርምጃ" !important; }

    /* Action buttons row */
    #medicineTable td:last-child {
        justify-content: flex-end !important;
        gap: 8px !important;
        padding-top: 10px !important;
        border-top: 1px solid #f0f0f0 !important;
        margin-top: 5px !important;
    }

    #medicineTable td:last-child:before {
        display: none !important;
    }

    .btn-add-stock,
    .btn-edit,
    .btn-delete {
        padding: 8px 14px !important;
        font-size: 0.9em !important;
        border-radius: 8px !important;
        min-height: 36px !important;
    }

    /* Table container no overflow needed with card layout */
    .table-container {
        background: transparent !important;
        box-shadow: none !important;
        overflow: visible !important;
    }

    /* Sales table amount badge fix */
    .amount-badge {
        white-space: nowrap !important;
        font-size: 0.82em !important;
        padding: 4px 8px !important;
    }

    .sales-table td:last-child {
        min-width: 80px !important;
    }

    /* Recent sales table → card layout */
    .sales-table thead {
        display: none !important;
    }

    .sales-table,
    .sales-table tbody,
    .sales-table tr,
    .sales-table td {
        display: block !important;
        width: 100% !important;
    }

    .sales-table tr {
        background: #f8f9fa !important;
        border-radius: 10px !important;
        margin-bottom: 10px !important;
        padding: 12px !important;
        border: 1px solid #ecf0f1 !important;
    }

    .sales-table td {
        padding: 4px 0 !important;
        border: none !important;
        font-size: 0.88em !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    .sales-table td:nth-child(1) { display: none !important; }
    .sales-table td:nth-child(2):before { content: "ሰራተኛ: " !important; font-weight:700; color:#7f8c8d; }
    .sales-table td:nth-child(3):before { content: "ቀን: " !important; font-weight:700; color:#7f8c8d; }
    .sales-table td:nth-child(4):before { content: "ሰዓት: " !important; font-weight:700; color:#7f8c8d; }
    .sales-table td:nth-child(5) {
        justify-content: flex-end !important;
        padding-top: 8px !important;
        border-top: 1px solid #e0e0e0 !important;
        margin-top: 4px !important;
    }
}

@media (max-width: 480px) {
    #medicineTable td:before {
        min-width: 75px !important;
        font-size: 0.78em !important;
    }

    .btn-add-stock,
    .btn-edit,
    .btn-delete {
        padding: 7px 11px !important;
        font-size: 0.85em !important;
    }
}
