/* VitaraAfya — Premium mobile shell (patient-first) */

:root {
    --m-header-h: 56px;
    --m-tab-h: 64px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --touch-min: 44px;
    --m-radius: 16px;
    --m-page-pad: 1rem;
}

.m-accent { color: var(--accent); }

/* App shell */
.m-app {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    padding-top: calc(var(--m-header-h) + var(--safe-top));
    padding-bottom: calc(var(--m-tab-h) + var(--safe-bottom) + 0.5rem);
}

.m-app--immersive {
    padding-bottom: calc(var(--safe-bottom) + 0.5rem);
}

.m-content {
    padding: var(--m-page-pad);
    max-width: 640px;
    margin: 0 auto;
}

.m-offline-banner,
.m-flash {
    margin-bottom: 0.75rem;
}

/* Top bar */
.m-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    height: calc(var(--m-header-h) + var(--safe-top));
    padding-top: var(--safe-top);
    background: var(--card);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.m-topbar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--m-header-h);
    padding: 0 var(--m-page-pad);
    max-width: 640px;
    margin: 0 auto;
}

.m-topbar__brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    text-decoration: none;
}

.m-topbar__logo {
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 119, 182, 0.25);
}

.m-topbar__actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.m-lang-toggle {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border: 1px solid rgba(0, 119, 182, 0.14);
    border-radius: 999px;
    background: rgba(0, 119, 182, 0.06);
}

.m-lang-toggle a {
    min-width: 30px;
    min-height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.03em;
}

.m-lang-toggle a.is-active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 6px 16px rgba(0, 119, 182, 0.22);
}

.m-topbar__btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--touch-min);
    height: var(--touch-min);
    border-radius: 12px;
    color: var(--text);
    text-decoration: none;
    transition: background 0.15s;
}

.m-topbar__btn:active {
    background: rgba(0, 119, 182, 0.1);
    transform: scale(0.96);
}

.m-topbar__btn--avatar {
    padding: 0;
    overflow: hidden;
}

.m-topbar__avatar .user-avatar-img,
.m-topbar__avatar .user-avatar-initial {
    border-radius: 50%;
}

.m-list-card__avatar .user-avatar-wrap,
.m-list-card__avatar .user-avatar-img,
.m-list-card__avatar .user-avatar-initial {
    width: 44px;
    height: 44px;
}

.doctor-avatar .user-avatar-wrap,
.doctor-avatar .user-avatar-img,
.doctor-avatar .user-avatar-initial {
    width: 100%;
    height: 100%;
}

.m-topbar__badge {
    position: absolute;
    top: 4px;
    right: 4px;
    margin: 0;
}

.m-topbar__page-title {
    display: none;
    flex: 1;
    margin: 0;
    font-size: 1.1rem;
}

/* Bottom tab bar */
.m-tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: calc(var(--m-tab-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--card);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
}

.m-tabbar__item {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: var(--m-tab-h);
    padding: 0.35rem 0.25rem;
    color: var(--text);
    opacity: 0.65;
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
    transition: opacity 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.m-tabbar__item.is-active {
    opacity: 1;
    color: var(--primary);
}

.m-tabbar__item:active {
    transform: scale(0.94);
}

.m-tabbar__icon {
    width: 22px;
    height: 22px;
    stroke-width: 2px;
}

.m-tabbar__item.is-active .m-tabbar__icon {
    stroke: var(--primary);
}

.m-tabbar__badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 22px);
    font-size: 0.65rem;
}

/* Icons (Iconify) */
.m-icon {
    width: 20px;
    height: 20px;
    vertical-align: middle;
}

.m-icon--sm {
    width: 16px;
    height: 16px;
}

.m-icon--btn {
    width: 18px;
    height: 18px;
    margin-right: 0.35rem;
}

/* More sheet */
.m-sheet {
    position: fixed;
    inset: 0;
    z-index: 300;
    pointer-events: none;
    visibility: hidden;
    transition: visibility 0.25s;
}

.m-sheet.is-open {
    pointer-events: auto;
    visibility: visible;
}

.m-sheet__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    transition: opacity 0.25s;
}

.m-sheet.is-open .m-sheet__backdrop {
    opacity: 1;
}

.m-sheet__panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 85vh;
    max-height: 85dvh;
    padding-bottom: calc(var(--m-tab-h) + var(--safe-bottom));
    background: var(--card);
    border-radius: var(--m-radius) var(--m-radius) 0 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.m-sheet.is-open .m-sheet__panel {
    transform: translateY(0);
}

.m-sheet__handle {
    width: 40px;
    height: 4px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    margin: 0.65rem auto 0;
}

.m-sheet__title {
    padding: 0.75rem 1.25rem 0.5rem;
    font-size: 1.1rem;
    color: var(--primary);
}

.m-sheet__list {
    list-style: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 0.5rem 1rem;
}

.m-sheet__link {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 0.75rem;
    border-radius: 12px;
    text-decoration: none;
    color: var(--text);
    min-height: var(--touch-min);
    transition: background 0.15s;
}

.m-sheet__link:active {
    background: rgba(0, 119, 182, 0.08);
}

.m-sheet__link--danger strong {
    color: #dc3545;
}

.m-sheet__icon-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(0, 119, 182, 0.1);
    color: var(--primary);
    flex-shrink: 0;
}

.m-sheet__text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.m-sheet__text strong {
    font-size: 0.95rem;
}

.m-sheet__text small {
    font-size: 0.78rem;
    opacity: 0.65;
}

.m-sheet__chevron {
    width: 18px;
    height: 18px;
    opacity: 0.35;
}

/* Mobile page sections */
.m-hero {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    border-radius: var(--m-radius);
    padding: 1.35rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 8px 24px rgba(0, 119, 182, 0.25);
}

.m-hero h1 {
    font-size: 1.35rem;
    margin-bottom: 0.35rem;
    font-weight: 700;
}

.m-hero p {
    opacity: 0.92;
    font-size: 0.92rem;
    margin-bottom: 1rem;
}

.m-hero .btn {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.m-stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.m-stat-tile {
    background: var(--card);
    border-radius: 14px;
    padding: 1rem;
    text-align: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.m-stat-tile__value {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.m-stat-tile__label {
    font-size: 0.78rem;
    opacity: 0.7;
    margin-top: 0.25rem;
}

.m-quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.m-quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 88px;
    padding: 0.85rem;
    background: var(--card);
    border-radius: 14px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 600;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.04);
    transition: transform 0.15s, box-shadow 0.15s;
}

.m-quick-action:active {
    transform: scale(0.97);
}

.m-quick-action__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(0, 119, 182, 0.12);
    color: var(--primary);
}

.m-quick-action__icon .m-icon {
    width: 22px;
    height: 22px;
}

.m-section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
    margin: 1.25rem 0 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.m-section-title a {
    font-size: 0.82rem;
    font-weight: 600;
}

/* List cards */
.m-card-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.m-list-card {
    background: var(--card);
    border-radius: 14px;
    padding: 1rem;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.m-list-card__head {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
}

.m-list-card__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.m-list-card__title {
    flex: 1;
    min-width: 0;
}

.m-list-card__title strong {
    display: block;
    font-size: 0.95rem;
}

.m-list-card__sub {
    display: block;
    font-size: 0.8rem;
    opacity: 0.7;
}

.m-list-card__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem 1rem;
    font-size: 0.82rem;
    opacity: 0.85;
    margin-bottom: 0.65rem;
}

.m-list-card__meta span {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.m-list-card__actions {
    margin-top: 0.5rem;
}

.m-list-card__actions .btn {
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Doctor horizontal scroll */
.m-scroll-row {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
    margin: 0 -0.25rem;
    scroll-snap-type: x mandatory;
}

.m-scroll-row::-webkit-scrollbar {
    display: none;
}

.m-doctor-chip {
    flex: 0 0 auto;
    width: 160px;
    scroll-snap-align: start;
    background: var(--card);
    border-radius: 14px;
    padding: 1rem;
    text-align: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.m-doctor-chip .doctor-avatar {
    margin: 0 auto 0.5rem;
}

.m-doctor-chip h4 {
    font-size: 0.85rem;
    margin-bottom: 0.15rem;
}

.m-doctor-chip .specialty {
    font-size: 0.75rem;
}

/* Mobile overrides for shared components */
.m-app .page-header {
    margin: 0 0 1rem;
    flex-direction: column;
    align-items: stretch;
}

.m-app .page-header h1 {
    font-size: 1.35rem;
}

.m-app .form-control {
    font-size: 16px;
    min-height: var(--touch-min);
}

.m-app .btn {
    min-height: var(--touch-min);
    padding: 0.7rem 1.25rem;
}

.m-app .btn-sm {
    min-height: 40px;
    padding: 0.5rem 0.85rem;
}

.m-app .card {
    border-radius: 14px;
    padding: 1rem;
}

.m-app .chat-panel {
    max-height: calc(100dvh - var(--m-header-h) - var(--safe-top) - 1rem);
}

.m-app--immersive .chat-panel {
    max-height: calc(100dvh - var(--m-header-h) - var(--safe-top) - var(--safe-bottom) - 1rem);
}

.m-app--immersive .chat-compose {
    position: sticky;
    bottom: 0;
    background: var(--card);
}

.m-app .chat-compose textarea {
    font-size: 16px;
}

.m-check-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
    min-height: var(--touch-min);
}

.m-search-bar label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

@media (min-width: 768px) {
    .m-content {
        max-width: 720px;
        padding: 1.25rem;
    }

    .m-stat-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Patient Assist — Phase 4 */
.patient-assist-bar {
    margin-bottom: 1rem;
    padding: 1rem 1.1rem;
}
.patient-assist-bar__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.75rem;
    margin-bottom: 0.65rem;
}
.patient-assist-bar__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.patient-assist-loading {
    font-size: 0.85rem;
    color: var(--muted, #64748b);
    margin-top: 0.5rem;
}
.patient-assist-panel {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border, #e2e8f0);
}
.patient-assist-panel__label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--primary, #0077B6);
    font-weight: 600;
    margin: 0 0 0.35rem;
}
.patient-assist-panel__body {
    font-size: 0.92rem;
    line-height: 1.5;
}
.patient-book-copilot {
    margin-bottom: 1rem;
    padding: 1rem 1.1rem;
    border-left: 3px solid var(--accent, #00A870);
}
.patient-book-copilot__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.75rem;
    margin-bottom: 0.5rem;
}
.patient-book-copilot__summary {
    font-size: 0.92rem;
    line-height: 1.45;
    margin: 0 0 0.5rem;
}
.patient-book-copilot__reasons {
    margin: 0 0 0.75rem;
    padding-left: 1.1rem;
    font-size: 0.85rem;
    color: var(--muted, #64748b);
}
.patient-book-copilot__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
