/* ═══════════════════════════════════════════════════════
   ASCLEPIUS — Mobile Optimisation Stylesheet
   Targets: iPhone SE → iPhone 15 Pro Max, Android phones
   ═══════════════════════════════════════════════════════ */

/* ── 1. Scrollable Table Wrapper ─────────────────────── */
.asc-table-wrap {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
}

.asc-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}

.asc-table-scroll::-webkit-scrollbar {
    height: 4px;
}
.asc-table-scroll::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

/* Gradient fade — right edge (shows when scrollable) */
.asc-table-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 48px;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.92));
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.25s;
    border-radius: 0 8px 8px 0;
    z-index: 2;
}

/* Gradient fade — left edge */
.asc-table-wrap::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 48px;
    height: 100%;
    background: linear-gradient(to left, transparent, rgba(255,255,255,0.92));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s;
    border-radius: 8px 0 0 8px;
    z-index: 2;
}

.asc-table-wrap.show-left::before  { opacity: 1; }
.asc-table-wrap.hide-right::after  { opacity: 0; }

/* Scroll arrow buttons */
.asc-scroll-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 102, 204, 0.85);
    color: #fff;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    transition: opacity 0.25s, background 0.2s;
    padding: 0;
    line-height: 1;
}
.asc-scroll-btn:active { background: rgba(0,70,150,0.95); }
.asc-scroll-btn.asc-scroll-left  { left:  6px; opacity: 0; pointer-events: none; }
.asc-scroll-btn.asc-scroll-right { right: 6px; }
.asc-scroll-btn.hidden { opacity: 0 !important; pointer-events: none; }

.asc-table-wrap.show-left  .asc-scroll-left  { opacity: 1; pointer-events: auto; }
.asc-table-wrap.hide-right .asc-scroll-right { opacity: 0; pointer-events: none; }

/* Scroll hint pill shown once on first visit */
.asc-scroll-hint {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: #0066cc;
    background: #e8f0fe;
    border-radius: 20px;
    padding: 3px 10px;
    margin-bottom: 6px;
    animation: asc-hint-fade 3s forwards;
}
@keyframes asc-hint-fade {
    0%   { opacity: 1; }
    70%  { opacity: 1; }
    100% { opacity: 0; }
}

/* ── 2. Table cells tighter on mobile ───────────────── */
@media (max-width: 767px) {
    .table th, .table td {
        padding: 7px 8px;
        font-size: 13px;
        white-space: nowrap;
    }

    .table th {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.4px;
    }

    /* Badge & status pills slightly smaller */
    .badge {
        font-size: 10px;
        padding: 3px 7px;
    }

    /* ── 3. Two-column forms → single column ─────────── */
    .row .col-md-6,
    .row .col-md-4,
    .row .col-md-3,
    .row .col-md-8,
    .row .col-md-9 {
        padding-left: 8px;
        padding-right: 8px;
    }

    /* Full-width form inputs */
    .form-control, .form-control-sm {
        font-size: 15px;
        padding: 9px 12px;
        border-radius: 8px;
    }

    select.form-control {
        padding-right: 28px;
        background-size: 12px;
    }

    /* Tighter section headings */
    h3.section-title,
    .card-header h4,
    .card-header h5 {
        font-size: 1rem;
    }

    /* Action buttons full-width stacked */
    .btn-mobile-full {
        width: 100%;
        margin-bottom: 8px;
    }

    /* Card padding reduced */
    .card-body {
        padding: 14px 12px;
    }

    .card-header {
        padding: 10px 14px;
    }

    /* Page header margins */
    .container.mt-4 {
        margin-top: 12px !important;
    }

    /* Bottom padding so last button isn't hidden behind Safari toolbar */
    main {
        padding-bottom: 80px;
    }

    /* Modals full screen */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    .modal-content {
        border-radius: 0;
        min-height: 100vh;
    }

    .modal-dialog-centered {
        align-items: flex-start;
    }

    /* Patient picker modal — keep rounded on mobile */
    #patientPickerModal .modal-dialog,
    #quickAddPatientModal .modal-dialog {
        margin: 12px;
        max-width: calc(100% - 24px);
        height: auto;
    }

    #patientPickerModal .modal-content,
    #quickAddPatientModal .modal-content {
        border-radius: 16px;
        min-height: auto;
    }

    /* Stats row on dashboard */
    .stat-card .stat-value { font-size: 1.4rem; }

    /* Hide less important table columns on very small screens */
    .d-mobile-none { display: none !important; }

    /* Breadcrumb smaller */
    .breadcrumb {
        font-size: 12px;
        padding: 6px 10px;
    }

    /* Footer compact */
    .footer {
        padding: 12px 0;
        font-size: 12px;
    }

    /* Alert top position adjustment for mobile nav */
    #alertPlaceholder {
        top: 70px;
        right: 10px;
        left: 10px;
        max-width: 100%;
    }

    /* Two-eye RE/LE table layout stays side by side but scrolls */
    .re-le-table {
        min-width: 480px;
    }
}

/* ── 4. Very small phones (SE, Galaxy A) ──────────────── */
@media (max-width: 400px) {
    .navbar-brand strong {
        font-size: 0.75rem !important;
    }

    .btn {
        font-size: 13px;
        padding: 9px 12px;
    }

    .card-body {
        padding: 10px 8px;
    }

    .table th, .table td {
        font-size: 11px;
        padding: 5px 6px;
    }
}

/* ── 5. Sticky bottom action bar ──────────────────────── */
.mobile-action-bar {
    display: none;
}

@media (max-width: 767px) {
    .mobile-action-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1040;
        background: #fff;
        border-top: 1px solid #e0e0e0;
        padding: 8px 12px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
        gap: 8px;
        box-shadow: 0 -2px 12px rgba(0,0,0,0.10);
    }

    .mobile-action-bar .btn {
        flex: 1;
        font-size: 13px;
        padding: 9px 6px;
    }
}

/* ── 6. Landscape phone — give tables more space ───────── */
@media (max-width: 900px) and (orientation: landscape) {
    .navbar { min-height: 44px; }
    .navbar-brand strong { font-size: 0.8rem !important; }
    main { padding-bottom: 20px; }
    .modal-dialog { margin: 4px auto; }
}

/* ── 7. Swipe-down hint on modals ──────────────────────── */
.modal-swipe-bar {
    display: none;
}

@media (max-width: 767px) {
    .modal-swipe-bar {
        display: block;
        width: 40px;
        height: 4px;
        background: #ccc;
        border-radius: 2px;
        margin: 8px auto 0;
    }
}

/* ── 8. Touch-friendly tap targets ─────────────────────── */
@media (max-width: 767px) {
    .dropdown-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .list-group-item {
        padding: 12px 14px;
    }

    .nav-tabs .nav-link {
        padding: 10px 12px;
        font-size: 13px;
    }

    .close {
        font-size: 1.8rem;
        padding: 8px 12px;
    }

    /* Checkbox / radio bigger tap target */
    input[type="checkbox"],
    input[type="radio"] {
        width: 18px;
        height: 18px;
        cursor: pointer;
    }

    .form-check {
        padding-left: 28px;
    }

    .form-check-input {
        margin-left: -28px;
        margin-top: 3px;
    }
}
