:root {
    --hms-blue: #0d6efd;
    --hms-deep: #0a3d62;
    --hms-green: #20c997;
    --hms-soft: #f4f8fb;
    --hms-border: #dce7f1;
}

body {
    background: var(--hms-soft);
    color: #22313f;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Keep every page inside the device width. */
html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Make media shrink cleanly on small screens. */
img,
svg,
canvas,
video {
    max-width: 100%;
    height: auto;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        linear-gradient(135deg, rgba(13,110,253,.92), rgba(32,201,151,.82)),
        url("../images/hospital-bg.svg");
    background-size: cover;
    padding: 24px;
}

.auth-card {
    width: min(960px, 100%);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(10, 61, 98, .24);
    overflow: hidden;
}

.auth-side {
    background: linear-gradient(160deg, #0a3d62, #0d6efd);
    color: #fff;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    box-sizing: border-box;
    width: 268px;
    flex: 0 0 268px;
    background: #082f49;
    color: #d8eefb;
    padding: 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .28) transparent;
    z-index: 1040;
}

.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .28);
    border-radius: 999px;
}

.brand {
    color: #fff;
    text-decoration: none;
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
}

.brand:hover {
    color: #fff;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #fff;
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 2px;
}

.brand-mark img {
    display: block;
    height: 100%;
    object-fit: contain;
    width: 100%;
}

.brand small {
    display: block;
    color: #bde8f6;
}

.sidebar .nav-link {
    color: #c8dce9;
    border-radius: 8px;
    padding: 9px 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 2px;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    background: rgba(255, 255, 255, .12);
    color: #fff;
}

.main-content {
    flex: 1;
    min-width: 0;
    width: 100%;
}

.topbar {
    min-height: 72px;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.content-wrap {
    padding: 24px;
}

/* Stop cards and panels from forcing horizontal scroll. */
.panel,
.metric-card {
    min-width: 0;
}

.metric-card {
    border: 1px solid var(--hms-border);
    border-radius: 8px;
    background: #fff;
    padding: 20px;
    height: 100%;
}

.metric-icon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--hms-blue);
}

.metric-icon.green {
    background: var(--hms-green);
}

.panel {
    background: #fff;
    border: 1px solid var(--hms-border);
    border-radius: 8px;
    padding: 20px;
}

.appointment-calendar {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
}

.calendar-head {
    color: #60758a;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
}

.calendar-day {
    min-height: 92px;
    border: 1px solid var(--hms-border);
    border-radius: 8px;
    color: #22313f;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    text-decoration: none;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.calendar-day:hover {
    border-color: var(--hms-blue);
    box-shadow: 0 8px 22px rgba(13, 110, 253, .12);
    color: #22313f;
    transform: translateY(-1px);
}

.calendar-day.is-muted {
    background: #f7fafc;
    color: #95a5b2;
}

.calendar-day.is-today {
    border-color: var(--hms-green);
}

.calendar-day.is-selected {
    background: #eef6ff;
    border-color: var(--hms-blue);
}

.calendar-date {
    font-weight: 700;
}

.calendar-count {
    align-self: flex-start;
    background: var(--hms-blue);
    border-radius: 999px;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    padding: 5px 8px;
}

.table thead th {
    background: #eef6ff;
    color: #0a3d62;
}

/* Table mobile scroll fix. */
.table-responsive,
.dt-layout-table {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.table-responsive .table,
.dt-layout-table .table {
    min-width: 760px;
}

.table th,
.table td {
    word-break: normal;
    overflow-wrap: normal;
    vertical-align: middle;
}

.table thead th {
    white-space: nowrap;
}

/* DataTable controls mobile fix. */
.dt-container .row {
    row-gap: 10px;
}

.dt-container .dt-search,
.dt-container .dt-length {
    max-width: 100%;
}

.dt-container .dt-search input,
.dt-container .dt-length select {
    max-width: 100%;
}

.btn {
    border-radius: 8px;
}

.voice-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

.voice-lang {
    width: 112px;
}

.voice-input-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 132px;
    justify-content: center;
}

.voice-recorder-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 132px;
    justify-content: center;
}

.voice-input-btn.is-listening {
    background: #dc3545;
    border-color: #dc3545;
    color: #fff;
}

.voice-recorder-btn.is-listening {
    background: #dc3545;
    border-color: #dc3545;
    color: #fff;
}

.voice-help {
    display: block;
    margin-top: 6px;
}

.voice-preview audio,
.table-audio {
    width: min(100%, 260px);
    height: 34px;
}

.badge {
    font-weight: 600;
}

.letterhead-template {
    display: none;
}

.standalone-print {
    background: var(--hms-soft);
    padding: 24px;
}

.print-toolbar {
    align-items: center;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin: 0 auto 16px;
    max-width: 900px;
}

.print-document {
    background: #fff url("../images/print-letterhead.jpg") center / 100% 100% no-repeat;
    border: 1px solid var(--hms-border);
    box-shadow: 0 18px 50px rgba(10, 61, 98, .14);
    margin: 0 auto;
    max-width: 900px;
    min-height: 1260px;
    padding: 170px 72px 142px;
}

.certificate-letterhead .print-document {
    background-image: url("../images/certificate-letterhead.jpg");
    padding-top: 205px;
}

.print-card {
    background: transparent;
    color: #22313f;
    margin: 0;
    max-width: 100%;
}

.print-card .brand {
    color: var(--hms-blue);
}

.print-attachment {
    border: 1px solid var(--hms-border);
    border-radius: 8px;
    max-width: 100%;
    padding: 8px;
}

@media (max-width: 1199.98px) {
    /* Slightly reduce spacing on tablets and small laptops. */
    .content-wrap {
        padding: 20px;
    }

    .panel,
    .metric-card {
        padding: 18px;
    }
}

@media (max-width: 991.98px) {
    /* Turn the sidebar into a slide menu on touch devices. */
    .app-shell {
        display: block;
    }

    .sidebar {
        width: min(82vw, 280px);
        position: fixed;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 18px 0 42px rgba(8, 47, 73, .22);
        height: 100dvh;
        min-height: 100dvh;
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .topbar .container-fluid {
        gap: 12px;
    }

    .topbar h1 {
        line-height: 1.25;
        overflow-wrap: anywhere;
    }

    .topbar .ms-auto {
        gap: 8px !important;
    }

    .content-wrap {
        padding: 16px;
    }

    .appointment-calendar {
        gap: 4px;
    }

    .calendar-day {
        min-height: 74px;
        padding: 8px;
    }

    .calendar-day small {
        display: none;
    }
}

@media (max-width: 767.98px) {
    /* Stack busy header controls neatly on phones. */
    .topbar {
        min-height: auto;
    }

    .topbar .container-fluid {
        align-items: flex-start;
        flex-wrap: wrap;
        padding-bottom: 10px;
        padding-top: 10px;
    }

    .topbar .ms-auto {
        margin-left: 0 !important;
        width: 100%;
    }

    .topbar .badge {
        white-space: normal;
    }

    .content-wrap {
        padding: 12px;
    }

    .panel,
    .metric-card {
        padding: 14px;
    }

    /* Simple table mobile scroll fix. */
    .panel > .table,
    .panel > h2 + .table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        width: 100%;
        -webkit-overflow-scrolling: touch;
    }

    .metric-icon {
        height: 42px;
        width: 42px;
    }

    .auth-page {
        align-items: start;
        padding: 14px;
    }

    .auth-side {
        padding: 24px !important;
    }

    .auth-card .p-5 {
        padding: 24px !important;
    }

    .voice-tools {
        align-items: stretch;
        flex-direction: column;
        width: 100%;
    }

    .voice-lang,
    .voice-input-btn,
    .voice-recorder-btn {
        width: 100%;
    }

    .print-toolbar {
        flex-wrap: wrap;
        justify-content: stretch;
    }

    .print-toolbar .btn {
        flex: 1 1 auto;
    }

    .standalone-print {
        padding: 12px;
    }

    .print-document {
        min-height: auto;
        padding: 110px 18px 90px;
    }

    .certificate-letterhead .print-document {
        padding-top: 130px;
    }
}

@media (max-width: 575.98px) {
    /* Use tighter sizing for very small phones. */
    body {
        font-size: 14px;
    }

    .brand {
        gap: 10px;
    }

    .brand-mark {
        height: 38px;
        width: 38px;
    }

    .sidebar {
        padding: 12px;
        width: min(88vw, 268px);
    }

    .sidebar .nav-link {
        padding: 9px 10px;
    }

    .content-wrap {
        padding: 10px;
    }

    .panel,
    .metric-card {
        padding: 12px;
    }

    .h3,
    h3 {
        font-size: 1.35rem;
    }

    .btn {
        white-space: normal;
    }

    .btn-sm {
        min-height: 32px;
    }

    /* Keep table columns readable on phones. */
    .table-responsive .table,
    .dt-layout-table .table {
        min-width: 780px;
    }

    .table th,
    .table td {
        font-size: 13px;
        white-space: nowrap;
    }

    .appointment-calendar {
        grid-template-columns: repeat(7, minmax(34px, 1fr));
    }

    .calendar-head {
        font-size: 11px;
    }

    .calendar-day {
        border-radius: 6px;
        min-height: 56px;
        padding: 6px;
    }

    .calendar-count {
        font-size: 10px;
        padding: 4px 6px;
    }
}

@media print {
    @page {
        margin: 0;
        size: A4;
    }

    .sidebar,
    .topbar,
    .no-print,
    .dataTables_filter,
    .dataTables_length,
    .dataTables_info,
    .dataTables_paginate {
        display: none !important;
    }

    html,
    body {
        background: #fff !important;
    }

    body.print-letterhead {
        margin: 0 !important;
        padding: 0 !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    body.print-letterhead .letterhead-template {
        display: block !important;
        height: 100%;
        inset: 0;
        object-fit: fill;
        pointer-events: none;
        position: fixed;
        width: 100%;
        z-index: 0;
    }

    body.print-letterhead .app-shell,
    body.print-letterhead .print-document {
        position: relative;
        z-index: 1;
    }

    .main-content,
    .content-wrap {
        padding: 0;
        margin: 0;
    }

    body.print-letterhead .content-wrap {
        box-decoration-break: clone;
        -webkit-box-decoration-break: clone;
        padding: 52mm 18mm 38mm !important;
    }

    body.print-letterhead .print-document {
        background: transparent;
        border: 0;
        box-decoration-break: clone;
        -webkit-box-decoration-break: clone;
        box-shadow: none;
        margin: 0;
        max-width: none;
        min-height: 297mm;
        padding: 52mm 18mm 38mm;
        width: 210mm;
    }

    body.certificate-letterhead .print-document {
        padding-top: 58mm;
    }

    .panel {
        border: 0;
    }

    body.print-letterhead .panel,
    body.print-letterhead .metric-card {
        background: transparent;
        box-shadow: none;
    }
}
