/* ═══════════════════════════════════════════════════════════════
   HMS Custom Styles — ST MED & ST MARY CLINIC
   Sierra Leone Healthcare ERP — v2.0 Full UX Overhaul
═══════════════════════════════════════════════════════════════ */

:root {
    --hms-primary:        #0096C7;
    --hms-primary-dark:   #0077a0;
    --hms-primary-light:  #e0f4fb;
    --hms-primary-xlight: #f0faff;
    --hms-secondary:      #0096C7;
    --hms-success:        #2e7d32;
    --hms-warning:        #f57c00;
    --hms-error:          #D61F2C;
    --hms-danger:         #D61F2C;
    --hms-bg:             #f5f7f9;
    --hms-surface:        #ffffff;
    --hms-text:           #1F2937;
    --hms-text-secondary: #6B7280;
    --hms-border:         #e5e7eb;
    --hms-border-light:   #f0f1f3;
    --hms-sidebar-width:  260px;
    --hms-radius:         12px;
    --hms-radius-sm:      8px;
    --hms-radius-xs:      6px;
    --hms-shadow-sm:      0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
    --hms-shadow:         0 2px 8px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
    --hms-shadow-md:      0 4px 16px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.05);
    --hms-shadow-hover:   0 8px 28px rgba(0,150,199,0.14), 0 3px 10px rgba(0,0,0,0.06);
    --hms-transition:     all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ────────────────────────────────────────────── */
* { box-sizing: border-box; }
body {
    font-family: 'Inter', 'Roboto', sans-serif;
    background: var(--hms-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Page fade-in ────────────────────────────────────────────── */
.mud-main-content { animation: hmsPageIn 0.18s ease-out both; }
@keyframes hmsPageIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ── Focus ring (accessibility) ──────────────────────────────── */
:focus-visible {
    outline: 2px solid var(--hms-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ══════════════════════════════════════════════════════════════
   SIDEBAR NAVIGATION
═══════════════════════════════════════════════════════════════ */

.mud-nav-link {
    border-radius: 8px !important;
    transition: background 0.15s ease !important;
    margin-bottom: 1px;
}
.mud-nav-link.active {
    background: rgba(255,255,255,0.18) !important;
    font-weight: 600;
}
.mud-nav-link:hover {
    background: rgba(255,255,255,0.12) !important;
}
.mud-nav-group-header:hover {
    background: rgba(255,255,255,0.08) !important;
    border-radius: 8px !important;
}

/* ══════════════════════════════════════════════════════════════
   CARDS & PAPERS
═══════════════════════════════════════════════════════════════ */

.rounded-lg  { border-radius: 12px !important; }
.rounded-xl  { border-radius: 16px !important; }
.rounded-sm  { border-radius:  8px !important; }

/* Subtle hover lift on interactive papers */
.mud-paper.hms-hover {
    transition: box-shadow var(--hms-transition), transform var(--hms-transition) !important;
    cursor: pointer;
}
.mud-paper.hms-hover:hover {
    box-shadow: var(--hms-shadow-hover) !important;
    transform: translateY(-2px);
}

/* ══════════════════════════════════════════════════════════════
   TABLES — MOBILE HORIZONTAL SCROLL
═══════════════════════════════════════════════════════════════ */

.mud-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--hms-radius);
}

/* Sticky header so columns stay visible on scroll */
.mud-table-head th,
.mud-table-head .mud-table-cell {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #fafbfc;
    font-weight: 600 !important;
    font-size: 12px !important;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--hms-text-secondary) !important;
    border-bottom: 2px solid var(--hms-border) !important;
}

.mud-table-row:hover { background: rgba(0,150,199,0.04) !important; }
.mud-table-row.mud-selected-item { background: var(--hms-primary-light) !important; }

/* Mobile: tighter cells */
@media (max-width: 767px) {
    .mud-table          { min-width: 540px; }
    .mud-table-cell     { padding: 8px 10px !important; font-size: 12px !important; }
}

/* MudDataGrid mobile */
@media (max-width: 767px) {
    .mud-data-grid .mud-table-cell     { padding: 6px 8px !important; font-size: 12px !important; }
    .mud-data-grid .mud-table-head th  { font-size: 11px !important; padding: 6px 8px !important; }
}

/* Pagination compact on mobile */
@media (max-width: 599px) {
    .mud-table-pagination-toolbar      { flex-wrap: wrap; gap: 4px; }
    .mud-table-pagination-rows-per-page { display: none !important; }
    .mud-table-pagination-display      { font-size: 12px !important; }
}

/* ══════════════════════════════════════════════════════════════
   DIALOGS — MOBILE FULL-WIDTH
═══════════════════════════════════════════════════════════════ */

@media (max-width: 599px) {
    .mud-dialog-container .mud-dialog {
        margin: 8px !important;
        max-height: calc(100dvh - 16px) !important;
        width: calc(100vw - 16px) !important;
        max-width: calc(100vw - 16px) !important;
        border-radius: var(--hms-radius) !important;
    }
    .mud-dialog-title    { padding: 14px 16px 10px !important; }
    .mud-dialog-content  { padding: 4px 16px 12px !important; }
    .mud-dialog-actions  {
        padding: 8px 16px 14px !important;
        flex-wrap: wrap;
        gap: 8px;
    }
    .mud-dialog-actions .mud-button-root {
        flex: 1 1 auto;
        min-width: 90px;
        justify-content: center;
    }
}

/* ══════════════════════════════════════════════════════════════
   FORM INPUTS
═══════════════════════════════════════════════════════════════ */

/* Consistent border radius */
.mud-input-outlined .mud-input-outlined-border { border-radius: 8px !important; }

/* Form section grouping */
.hms-form-section {
    background: var(--hms-surface);
    border-radius: var(--hms-radius);
    padding: 20px 20px 4px;
    margin-bottom: 16px;
    border: 1px solid var(--hms-border);
}
.hms-form-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--hms-primary);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--hms-primary-light);
}

/* ══════════════════════════════════════════════════════════════
   PAGE HEADER (flex, wraps on mobile)
═══════════════════════════════════════════════════════════════ */

.hms-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.hms-page-header-title { flex: 1 1 auto; min-width: 0; }
.hms-page-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}
@media (max-width: 599px) {
    .hms-page-header-actions {
        width: 100%;
        flex-direction: column;
    }
    .hms-page-header-actions .mud-button-root {
        width: 100%;
        justify-content: center;
    }
}

/* ══════════════════════════════════════════════════════════════
   EMPTY STATES
═══════════════════════════════════════════════════════════════ */

.hms-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 56px 24px;
    text-align: center;
}
.hms-empty-icon {
    opacity: 0.25;
    margin-bottom: 20px;
    color: var(--hms-text-secondary);
}
.hms-empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--hms-text);
    margin-bottom: 6px;
}
.hms-empty-subtitle {
    font-size: 14px;
    color: var(--hms-text-secondary);
    max-width: 320px;
    line-height: 1.6;
    margin-bottom: 20px;
}

/* ══════════════════════════════════════════════════════════════
   STAT / KPI CARDS
═══════════════════════════════════════════════════════════════ */

.hms-stat-card {
    border-radius: var(--hms-radius) !important;
    transition: var(--hms-transition) !important;
    cursor: default;
}
.hms-stat-card.clickable {
    cursor: pointer !important;
}
.hms-stat-card.clickable:hover {
    box-shadow: var(--hms-shadow-hover) !important;
    transform: translateY(-2px);
}

/* ══════════════════════════════════════════════════════════════
   CHARTS — RESPONSIVE
═══════════════════════════════════════════════════════════════ */

.hms-chart-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.hms-chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding: 8px 0;
    min-width: 400px;
}
.chart-bar-primary { background: linear-gradient(180deg, #0096C7, #00b4ed) !important; }
.chart-bar-success { background: linear-gradient(180deg, #2e7d32, #66bb6a) !important; }

/* ══════════════════════════════════════════════════════════════
   STATUS INDICATORS
═══════════════════════════════════════════════════════════════ */

/* Chips */
.mud-chip { font-weight: 500 !important; }

/* Status dot */
.hms-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.hms-dot-green   { background: #2e7d32; }
.hms-dot-orange  { background: #f57c00; }
.hms-dot-red     { background: #D61F2C; }
.hms-dot-grey    { background: #9e9e9e; }
.hms-dot-blue    { background: #0096C7; }

/* ══════════════════════════════════════════════════════════════
   MOBILE APPBAR SEARCH
═══════════════════════════════════════════════════════════════ */

/* Hide text label in global search box on narrow screens */
@media (max-width: 767px) {
    .hms-global-search-text { display: none !important; }
    .hms-global-search       { max-width: 140px !important; }
}
@media (max-width: 479px) {
    .hms-global-search       { max-width: 100px !important; }
}

/* ══════════════════════════════════════════════════════════════
   BADGES & ALERTS
═══════════════════════════════════════════════════════════════ */

.mud-alert { border-radius: var(--hms-radius-sm) !important; }

/* Alert pulse for critical items */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.08); }
}
.alert-pulse { animation: pulse 2s ease-in-out infinite; }

/* Nav badge count */
.hms-nav-badge {
    margin-left: 6px;
    background: rgba(214,31,44,0.85);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    vertical-align: middle;
    letter-spacing: 0.3px;
}

/* ══════════════════════════════════════════════════════════════
   LOADING STATES
═══════════════════════════════════════════════════════════════ */

@keyframes shimmer {
    0%   { background-position: -400px 0; }
    100% { background-position:  400px 0; }
}
.shimmer {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 400px 100%;
    animation: shimmer 1.4s ease-in-out infinite;
    border-radius: var(--hms-radius-xs);
}

/* ══════════════════════════════════════════════════════════════
   SPECIAL ROWS / HIGHLIGHTS
═══════════════════════════════════════════════════════════════ */

/* VIP patient row */
.vip-row { background: linear-gradient(90deg, rgba(255,193,7,0.06), transparent) !important; }
.vip-row:hover { background: linear-gradient(90deg, rgba(255,193,7,0.10), rgba(0,150,199,0.04)) !important; }

/* ══════════════════════════════════════════════════════════════
   MOBILE DRAWER — Close on tap outside
═══════════════════════════════════════════════════════════════ */

@media (max-width: 959px) {
    /* Ensure nav drawer overlay doesn't block MudPopover */
    .mud-overlay { z-index: 1199 !important; }
}

/* ══════════════════════════════════════════════════════════════
   FAB (Floating Action Button)
═══════════════════════════════════════════════════════════════ */

.hms-fab-container {
    position: fixed !important;
    bottom: 24px;
    right: 24px;
    z-index: 1100;
}
@media (max-width: 599px) {
    .hms-fab-container { bottom: 16px; right: 16px; }
}

/* ══════════════════════════════════════════════════════════════
   PRINT STYLES — Hide screen-only elements
═══════════════════════════════════════════════════════════════ */

.print-only         { display: none !important; }
.print-brand-header { display: none; }
.thermal-receipt    { display: none; }

@media print {

    @page {
        size: A4 portrait;
        margin: 15mm 18mm 18mm 18mm;
    }

    html, body {
        background: white !important;
        color: black !important;
        font-size: 11pt;
        font-family: 'Inter', Arial, sans-serif;
    }

    .mud-drawer,
    .mud-appbar,
    .mud-fab,
    .no-print,
    .hms-fab-container,
    .mud-snackbar-location,
    [class*="quick-action"],
    .mud-dialog-container { display: none !important; }

    .mud-main-content {
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
        animation: none !important;
    }

    .mud-container { max-width: none !important; padding: 0 !important; }
    .mud-paper     { box-shadow: none !important; border: 1px solid #e0e0e0; }

    .print-only         { display: block  !important; }
    .print-brand-header {
        display: flex !important;
        align-items: center;
        gap: 16px;
        margin-bottom: 20px;
        padding-bottom: 14px;
        border-bottom: 2.5px solid #0096C7;
    }

    h1, .mud-typography-h1 { font-size: 20pt !important; }
    h2, .mud-typography-h2 { font-size: 16pt !important; }
    h3, .mud-typography-h3 { font-size: 14pt !important; }
    h5, .mud-typography-h5 { font-size: 13pt !important; }
    h6, .mud-typography-h6 { font-size: 11pt !important; }
    p,  .mud-typography-body1,
        .mud-typography-body2  { font-size: 10pt !important; }
    .mud-typography-caption    { font-size:  9pt !important; }

    table, .mud-table  { border-collapse: collapse !important; width: 100% !important; }
    thead, .mud-table-head { background: #f5f5f5 !important; }
    th, .mud-table-cell[role="columnheader"] {
        border: 1px solid #d0d0d0 !important;
        padding: 5px 8px !important;
        font-size: 9.5pt !important;
        font-weight: 700 !important;
    }
    td, .mud-table-cell {
        border: 1px solid #e0e0e0 !important;
        padding: 5px 8px !important;
        font-size: 9.5pt !important;
    }

    .page-break-before { page-break-before: always; }
    .page-break-after  { page-break-after:  always; }
    .no-break          { page-break-inside: avoid; }
    tr                 { page-break-inside: avoid; }

    .mud-chip {
        border: 1px solid #aaa !important;
        background: #f5f5f5 !important;
        color: #333 !important;
    }
    .mud-grid      { display: block !important; }
    .mud-grid-item { display: block !important; width: 100% !important; max-width: 100% !important; }

    .mud-primary-text { color: #0096C7 !important; }
    .mud-success-text { color: #2e7d32 !important; }
    .mud-error-text   { color: #D61F2C !important; }

    .invoice-totals    { border-top: 2px solid #333; margin-top: 8px; padding-top: 8px; }
    .invoice-total-row { display: flex; justify-content: space-between; padding: 3px 0; }
    .invoice-grand-total { font-weight: 700; font-size: 12pt; border-top: 1.5px solid #333; padding-top: 5px; }
}

/* ══════════════════════════════════════════════════════════════
   THERMAL RECEIPT — 80mm layout
═══════════════════════════════════════════════════════════════ */

.thermal-receipt-preview {
    width: 300px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.4;
    background: white;
    padding: 12px;
    border: 1px dashed #bbb;
    border-radius: 4px;
}
@media print {
    .thermal-receipt-preview {
        width: 80mm;
        border: none;
        padding: 0;
        font-size: 10px;
    }
}
