/* Medibox v368 — Mobile Enhanced UX
   Mobile-first refinement for Calendar, Ordination and bottom navigation.
   UI only: no database or business-logic changes. */

@media (max-width: 900px) {
    :root {
        --m368-gap: 10px;
        --m368-radius: 16px;
        --m368-border: #dde7ed;
        --m368-text: #17263b;
        --m368-muted: #728096;
        --m368-primary: #4f46e5;
        --m368-surface: #ffffff;
        --m368-soft: #f6f8fc;
    }

    body.app-body .content {
        padding-top: 10px;
    }

    /* Bottom navigation: easier thumb targets and clearer active state. */
    body.app-body .mobile-bottom-nav {
        padding-inline: 8px;
        border-top-color: rgba(213,224,231,.96);
        box-shadow: 0 -8px 28px rgba(23,38,59,.10);
    }
    body.app-body .mobile-nav-item {
        min-height: 58px;
        border-radius: 15px;
    }
    body.app-body .mobile-nav-item .ui-icon {
        width: 21px;
        height: 21px;
    }
    body.app-body .mobile-nav-item > span:last-child {
        max-width: 100%;
        font-size: 10px;
        letter-spacing: -.01em;
    }
    body.app-body .mobile-nav-item.active {
        color: var(--m368-primary);
        background: #eef0ff;
    }
    body.app-body .mobile-nav-item.active::before {
        width: 28px;
        background: var(--m368-primary);
    }

    /* Calendar toolbar becomes a compact mobile control surface. */
    #weeklyCalendarApp .reference-calendar-toolbar {
        display: grid !important;
        grid-template-columns: auto minmax(0,1fr) !important;
        gap: 9px !important;
        padding: 10px !important;
        border: 1px solid var(--m368-border);
        border-radius: 17px !important;
        background: rgba(255,255,255,.97);
        box-shadow: 0 7px 22px rgba(23,38,59,.07);
    }
    #weeklyCalendarApp .reference-calendar-toolbar > .cw-view-switch {
        grid-column: 1;
        grid-row: 1;
        justify-self: start;
        padding: 3px;
        border-radius: 12px;
        background: #f3f5fa;
    }
    #weeklyCalendarApp .cw-view-button {
        width: 42px;
        height: 40px;
        flex-basis: 42px;
        border-radius: 10px;
    }
    #weeklyCalendarApp .cw-view-button .ui-icon {
        width: 19px;
        height: 19px;
    }
    #weeklyCalendarApp .reference-calendar-navigation {
        grid-column: 2;
        grid-row: 1;
        width: 100%;
        min-width: 0;
        justify-content: flex-end;
        gap: 5px;
    }
    #weeklyCalendarApp .calendar-date-navigation-compact .calendar-nav-arrow {
        width: 42px;
        height: 40px;
        min-width: 42px;
        border-radius: 11px;
    }
    #weeklyCalendarApp .calendar-date-navigation-compact .calendar-current-date {
        min-width: 0;
        flex: 1;
        max-width: 150px;
        height: 40px;
        padding: 3px 9px;
        border: 1px solid var(--m368-border);
        border-radius: 11px;
        background: #fff;
    }
    #weeklyCalendarApp .calendar-date-navigation-compact .calendar-current-date small {
        font-size: 9px;
        line-height: 1;
    }
    #weeklyCalendarApp .calendar-date-navigation-compact .calendar-current-date strong {
        font-size: 13px;
        line-height: 1.15;
    }
    #weeklyCalendarApp .reference-calendar-status-cards {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
        display: flex !important;
        gap: 7px;
        overflow-x: auto;
        padding: 1px 0 2px;
        scrollbar-width: none;
        scroll-snap-type: x proximity;
        overscroll-behavior-inline: contain;
    }
    #weeklyCalendarApp .reference-calendar-status-cards::-webkit-scrollbar { display: none; }
    #weeklyCalendarApp .reference-calendar-status-card {
        min-width: 112px;
        min-height: 46px;
        flex: 0 0 auto;
        padding: 7px 9px;
        gap: 7px;
        border-radius: 12px;
        scroll-snap-align: start;
    }
    #weeklyCalendarApp .reference-calendar-status-card .reference-calendar-status-icon {
        width: 28px;
        height: 28px;
        min-width: 28px;
    }
    #weeklyCalendarApp .reference-calendar-status-card .reference-calendar-status-icon .ui-icon {
        width: 15px;
        height: 15px;
    }
    #weeklyCalendarApp .reference-calendar-status-card small { font-size: 9px; }
    #weeklyCalendarApp .reference-calendar-status-card strong { font-size: 16px; }

    /* Mobile calendar: one clean day, no accidental sideways page scroll. */
    #weeklyCalendarApp .weekly-calendar-card {
        overflow: visible;
        border-radius: 18px;
    }
    #weeklyCalendarApp .weekly-calendar-scroll {
        width: 100%;
        max-height: calc(100dvh - 238px);
        overflow-y: auto;
        overflow-x: hidden;
        border-radius: 15px;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    #weeklyCalendarApp .weekly-calendar.calendar-view-five-days {
        min-width: 100% !important;
        width: 100% !important;
        --calendar-days: 1 !important;
    }
    #weeklyCalendarApp .calendar-corner { width: 52px; min-width: 52px; }
    #weeklyCalendarApp .calendar-slot { min-height: 54px; }
    #weeklyCalendarApp .calendar-appointment {
        border-radius: 11px;
        box-shadow: 0 4px 10px rgba(23,38,59,.08);
    }

    /* Ordination toolbar — compact two-row mobile workspace. */
    .ordination-page { gap: 10px; }
    .ordination-page .ordination-toolbar {
        display: grid !important;
        grid-template-columns: auto minmax(0,1fr) auto !important;
        align-items: center !important;
        gap: 8px !important;
        padding: 10px !important;
        min-height: 0 !important;
        border: 1px solid var(--m368-border);
        border-radius: 17px;
        background: #fff;
        box-shadow: 0 7px 22px rgba(23,38,59,.07);
    }
    .ordination-page .ordination-view-switch {
        grid-column: 1;
        grid-row: 1;
        order: unset;
        align-self: center;
        margin: 0;
        padding: 3px;
        border-radius: 12px;
        background: #f3f5fa;
    }
    .ordination-page .ordination-view-button {
        width: 42px;
        height: 40px;
        flex-basis: 42px;
        border-radius: 10px;
    }
    .ordination-page .ordination-view-button .ui-icon { width: 19px; height: 19px; }

    .ordination-page .ordination-date-nav {
        grid-column: 2;
        grid-row: 1;
        order: unset;
        width: 100% !important;
        min-width: 0;
        margin: 0 !important;
        justify-content: flex-end !important;
        gap: 5px;
    }
    .ordination-page .ordination-date-arrow {
        width: 42px;
        height: 40px;
        min-width: 42px;
        border-radius: 11px;
    }
    .ordination-page .ordination-current-date {
        min-width: 0;
        flex: 1;
        max-width: 150px;
        height: 40px;
        padding: 3px 9px;
        border: 1px solid var(--m368-border);
        border-radius: 11px;
        background: #fff;
    }
    .ordination-page .ordination-current-date small { font-size: 9px; line-height: 1; }
    .ordination-page .ordination-current-date strong { font-size: 13px; line-height: 1.15; }

    .ordination-page .ordination-new-visit-button {
        grid-column: 3;
        grid-row: 1;
        order: unset;
        width: 42px !important;
        min-width: 42px !important;
        height: 40px;
        min-height: 40px;
        padding: 0 !important;
        border-radius: 11px;
        box-shadow: 0 5px 14px rgba(79,70,229,.20);
    }
    .ordination-page .ordination-new-visit-button span { display: none; }

    .ordination-page .ordination-summary-grid-toolbar {
        grid-column: 1 / -1;
        grid-row: 2;
        order: unset;
        width: 100%;
        max-width: none;
        margin: 0;
        display: flex !important;
        gap: 7px;
        overflow-x: auto;
        padding: 1px 0 2px;
        scrollbar-width: none;
        scroll-snap-type: x proximity;
    }
    .ordination-page .ordination-summary-grid-toolbar::-webkit-scrollbar { display: none; }
    .ordination-page .ordination-summary-grid-toolbar .ordination-summary-card {
        min-width: 108px;
        min-height: 46px;
        flex: 0 0 auto;
        padding: 7px 10px;
        border-radius: 12px;
        scroll-snap-align: start;
    }
    .ordination-page .ordination-summary-grid-toolbar .ordination-summary-card:last-child { grid-column: auto; }
    .ordination-page .ordination-summary-grid-toolbar .ordination-summary-card small {
        font-size: 9.5px;
        white-space: nowrap;
    }
    .ordination-page .ordination-summary-grid-toolbar .ordination-summary-card strong { font-size: 17px; }

    /* Ordination list becomes native-feeling cards; no 1020px table on a phone. */
    .ordination-page .ordination-list-card {
        padding: 0;
        overflow: visible;
        border: 0;
        background: transparent;
        box-shadow: none;
    }
    .ordination-page .ordination-table-wrap { overflow: visible; }
    .ordination-page .ordination-table {
        min-width: 0 !important;
        width: 100%;
        display: block;
        border-collapse: separate;
    }
    .ordination-page .ordination-table thead { display: none; }
    .ordination-page .ordination-table tbody { display: grid; gap: 9px; }
    .ordination-page .ordination-record-row {
        position: relative;
        display: grid;
        grid-template-columns: minmax(0,1fr);
        gap: 0;
        padding: 13px;
        border: 1px solid var(--m368-border);
        border-radius: 16px;
        background: #fff;
        box-shadow: 0 6px 18px rgba(23,38,59,.06);
        overflow: hidden;
    }
    .ordination-page .ordination-record-row::before {
        content: "";
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        width: 4px;
        background: #94a3b8;
    }
    .ordination-page .ordination-record-row.status-scheduled::before { background: #4f46e5; }
    .ordination-page .ordination-record-row.status-waiting::before { background: #d97706; }
    .ordination-page .ordination-record-row.status-in_progress::before { background: #0f766e; }
    .ordination-page .ordination-record-row.status-completed::before { background: #16a34a; }
    .ordination-page .ordination-record-row.status-cancelled::before,
    .ordination-page .ordination-record-row.status-no_show::before { background: #b91c1c; }

    .ordination-page .ordination-table td {
        width: 100%;
        padding: 8px 0;
        display: grid;
        grid-template-columns: 105px minmax(0,1fr);
        gap: 10px;
        align-items: start;
        border: 0;
        border-bottom: 1px solid #edf1f5;
        font-size: 13px;
        line-height: 1.4;
        text-align: left !important;
    }
    .ordination-page .ordination-table td::before {
        content: attr(data-label);
        padding-top: 1px;
        color: var(--m368-muted);
        font-size: 10px;
        font-weight: 800;
        letter-spacing: .02em;
        text-transform: uppercase;
    }

    .ordination-page .ordination-table .ordination-time-cell {
        grid-template-columns: 1fr auto;
        align-items: center;
        padding-top: 0;
        padding-bottom: 10px;
    }
    .ordination-page .ordination-table .ordination-time-cell::before { display: none; }
    .ordination-page .ordination-mobile-time {
        display: flex;
        align-items: baseline;
        gap: 7px;
    }
    .ordination-page .ordination-mobile-time strong {
        color: var(--m368-text);
        font-size: 22px;
        line-height: 1;
        letter-spacing: -.03em;
    }
    .ordination-page .ordination-mobile-time small {
        display: inline;
        margin: 0;
        color: var(--m368-muted);
        font-size: 11px;
    }
    .ordination-page .ordination-mobile-time small::before { content: "– "; }
    .ordination-page .ordination-mobile-status {
        display: inline-flex;
        align-items: center;
        min-height: 28px;
        padding: 4px 9px;
        border-radius: 999px;
        color: #536176;
        background: #f1f5f9;
        font-size: 10px;
        font-weight: 850;
        white-space: nowrap;
    }
    .ordination-page .ordination-mobile-status.status-scheduled { color: #4338ca; background: #eef0ff; }
    .ordination-page .ordination-mobile-status.status-waiting { color: #a15c00; background: #fff4d8; }
    .ordination-page .ordination-mobile-status.status-in_progress { color: #0f766e; background: #e7f7f3; }
    .ordination-page .ordination-mobile-status.status-completed { color: #15803d; background: #eaf8ef; }
    .ordination-page .ordination-mobile-status.status-cancelled,
    .ordination-page .ordination-mobile-status.status-no_show { color: #b42318; background: #fff0ef; }

    .ordination-page .ordination-patient-cell {
        display: block !important;
        padding: 9px 0 10px !important;
    }
    .ordination-page .ordination-patient-cell::before { display: none; }
    .ordination-page .ordination-patient-link,
    .ordination-page .ordination-patient-name {
        display: inline-block;
        color: var(--m368-text);
        font-size: 16px;
        font-weight: 800;
        line-height: 1.25;
    }
    .ordination-page .ordination-patient-link { color: #3346c8; }
    .ordination-page .ordination-patient-cell small {
        margin-top: 4px;
        color: var(--m368-muted);
        font-size: 10px;
    }
    .ordination-page .ordination-services-cell { max-width: none; }
    .ordination-page .ordination-actions-cell {
        display: block !important;
        padding: 11px 0 0 !important;
        border-bottom: 0 !important;
    }
    .ordination-page .ordination-actions-cell::before { display: none; }
    .ordination-page .ordination-row-actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(3, minmax(0,1fr));
        gap: 8px;
    }
    .ordination-page .ordination-action-plus,
    .ordination-page .ordination-icon-action {
        width: 100%;
        min-width: 0;
        height: 44px;
        min-height: 44px;
        border-radius: 11px;
    }
    .ordination-page .ordination-action-plus { font-size: 24px; }
    .ordination-page .ordination-icon-action svg { width: 18px; height: 18px; }

    /* Empty state is compact and centered on phones. */
    .ordination-page .ordination-empty {
        min-height: 44dvh;
        padding: 24px;
        border: 1px dashed #d6e0e8;
        border-radius: 16px;
        background: #fff;
    }

    /* Appointment modal: stronger mobile hierarchy and sticky primary actions. */
    body.app-body #appointmentDialog.appointment-modal-modern.standard-edit-dialog > form {
        height: 100dvh !important;
        max-height: 100dvh !important;
        display: flex;
        flex-direction: column;
    }
    body.app-body #appointmentDialog .appointment-modal-header-modern {
        flex: 0 0 auto;
        padding: calc(12px + env(safe-area-inset-top,0px)) 14px 11px !important;
        border-bottom: 1px solid #e4eaf0;
        background: rgba(255,255,255,.98);
    }
    body.app-body #appointmentDialog .appointment-form-pro {
        flex: 1 1 auto;
        overflow-y: auto;
        padding: 10px 10px 90px !important;
        overscroll-behavior: contain;
    }
    body.app-body #appointmentDialog .appointment-pro-panel {
        padding: 12px !important;
        border-radius: 15px !important;
    }
    body.app-body #appointmentDialog .modal-footer {
        flex: 0 0 auto;
        margin: 0 !important;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom,0px)) !important;
        grid-template-columns: .8fr 1.2fr;
    }
}

/* Desktop/tablet keeps the existing table status badge hidden. */
@media (min-width: 901px) {
    .ordination-mobile-status { display: none; }
    .ordination-mobile-time { display: contents; }
}

@media (max-width: 420px) {
    #weeklyCalendarApp .reference-calendar-status-card { min-width: 102px; }
    .ordination-page .ordination-summary-grid-toolbar .ordination-summary-card { min-width: 101px; }
    .ordination-page .ordination-table td { grid-template-columns: 92px minmax(0,1fr); }
    .ordination-page .ordination-view-button,
    #weeklyCalendarApp .cw-view-button { width: 40px; flex-basis: 40px; }
    .ordination-page .ordination-date-arrow,
    #weeklyCalendarApp .calendar-date-navigation-compact .calendar-nav-arrow { width: 39px; min-width: 39px; }
}
