:root {
    --wine: #7d1831;
    --green: #174c38;
    --orange: #ed8b23;
    --light: #f4f6f8;
    --dark: #20252b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: var(--light);
    color: var(--dark);
}

a {
    color: inherit;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-card {
    width: min(430px, 100%);
    background: white;
    padding: 32px;
    border-radius: 12px;
    box-shadow: 0 5px 25px rgba(0,0,0,.08);
}

.login-card h1 {
    color: var(--wine);
    margin-bottom: 5px;
}

label {
    display: block;
    font-weight: 600;
    margin-top: 10px;
}

input, select, textarea {
    width: 100%;
    padding: 12px;
    margin: 7px 0 14px;
    border: 1px solid #d9dee5;
    border-radius: 6px;
    font: inherit;
}

button {
    background: var(--wine);
    color: white;
    padding: 12px 18px;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

button:hover {
    background: var(--green);
}

.login-card button {
    width: 100%;
}

.topbar {
    background: var(--green);
    color: white;
    padding: 17px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.topbar a {
    color: white;
    text-decoration: none;
}

.container {
    max-width: 1400px;
    margin: auto;
    padding: 25px;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin: 20px 0;
}

.stat-card, .panel {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0,0,0,.04);
    margin-bottom: 20px;
}

.stat-card h2 {
    color: var(--wine);
    font-size: 30px;
    margin: 0 0 8px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 18px;
}

.full {
    grid-column: 1 / -1;
}

.check-label {
    display: flex;
    align-items: center;
    gap: 10px;
}

.check-label input {
    width: auto;
    margin: 0;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

th, td {
    padding: 12px;
    border-bottom: 1px solid #e9edf1;
    text-align: left;
    white-space: nowrap;
}

th {
    background: #f1f3f5;
}

.error {
    background: #ffe6e6;
    color: #9b1717;
    padding: 12px;
    border-radius: 6px;
    margin: 12px 0;
}

.notice {
    background: #fff2dc;
    color: #70420b;
    padding: 13px;
    border-radius: 7px;
    margin: 15px 0;
}

@media(max-width:600px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .container {
        padding: 14px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .full {
        grid-column: auto;
    }
}

/* =========================================
   PABS BRANDING
========================================= */

.login-brand {
    text-align: center;
    margin: 0 auto 25px;
}

.login-brand img {
    width: 150px;
    max-width: 50%;
    height: auto;
    object-fit: contain;
}

.login-brand p {
    margin-top: 8px;
    color: #64748b;
    font-size: 13px;
}

.admin-brand img {
    width: 150px;
    max-width: 50%;
    height: auto;
    object-fit: contain;
}

.facility-brand h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
}

/* =========================================
   MOBILE RESPONSIVENESS
========================================= */

* {
    box-sizing: border-box;
}

img {
    max-width: 100%;
}

@media (max-width: 760px) {

    body {
        overflow-x: hidden;
    }

    .container,
    .main-content,
    .dashboard-content,
    .page-content {
        width: 100%;
        max-width: 100%;
        padding-left: 12px;
        padding-right: 12px;
    }

    /* Dashboard statistics */

    .stats-grid,
    .dashboard-stats,
    .stat-cards {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    /* Forms */

    input,
    select,
    textarea {
        width: 100%;
        max-width: 100%;
        font-size: 16px;
    }

    .form-row,
    .form-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
    }

    button,
    .btn {
        max-width: 100%;
    }

    /* Navigation */

    .navbar,
    .topbar,
    .dashboard-header {
        flex-wrap: wrap;
        gap: 10px;
    }

    /* Tables become vertical cards */

    table {
        width: 100%;
        border-collapse: separate;
        border-spacing: 0;
    }

    table thead {
        display: none;
    }

    table,
    table tbody,
    table tr,
    table td {
        display: block;
        width: 100%;
    }

    table tr {
        margin-bottom: 15px;
        padding: 10px 14px;
        background: #fff;
        border: 1px solid #e5e7eb;
        border-radius: 10px;
        box-shadow: 0 2px 5px rgba(0,0,0,0.04);
    }

    table td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        padding: 9px 0;
        border: 0;
        border-bottom: 1px solid #f1f5f9;
        text-align: right;
        overflow-wrap: anywhere;
    }

    table td:last-child {
        border-bottom: 0;
    }

    table td::before {
        content: attr(data-label);
        flex: 0 0 40%;
        font-weight: 700;
        color: #475569;
        text-align: left;
    }

    table td:empty::before {
        content: attr(data-label);
    }

    /* Action buttons */

    table td .btn,
    table td button {
        margin: 2px;
    }

    /* Modals */

    .modal,
    .modal-content {
        width: calc(100% - 20px);
        max-width: 100%;
        margin: 10px auto;
    }

    /* Login */

    .login-container,
    .login-card {
        width: calc(100% - 24px);
        max-width: 440px;
        margin: 20px auto;
    }
}

@media (max-width: 400px) {
    .stats-grid,
    .dashboard-stats,
    .stat-cards {
        grid-template-columns: 1fr;
    }
}

/* =================================
   PABS TOPBAR BUTTONS
================================= */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.user-role {
    background: #02935c;
    color: #ffffff;
    padding: 9px 15px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.topbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
}

.password-btn {
    background: #f97316;
    color: #ffffff;
}

.password-btn:hover {
    background: #ea580c;
    color: #ffffff;
}

.logout-btn {
    background: #7f1d1d;
    color: #ffffff;
}

.logout-btn:hover {
    background: #991b1b;
    color: #ffffff;
}

@media (max-width: 600px) {
    .topbar {
        align-items: flex-start;
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .topbar-btn {
        flex: 1;
    }
}

/* ==========================================
   PABS PASSWORD CHANGE MODAL
========================================== */

body.modal-open {
    overflow: hidden;
}

.pabs-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(3px);
}

.pabs-modal-overlay[hidden] {
    display: none !important;
}

.pabs-modal {
    background: #ffffff;
    width: 100%;
    max-width: 460px;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    animation: pabsModalIn 0.2s ease;
}

@keyframes pabsModalIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pabs-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
    padding: 22px;
    border-bottom: 1px solid #e5e7eb;
}

.pabs-modal-header h3 {
    margin: 0 0 6px;
    color: #7f1d1d;
}

.pabs-modal-header p {
    margin: 0;
    color: #64748b;
    font-size: 13px;
}

.modal-close {
    border: none;
    background: #f1f5f9;
    color: #334155;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
}

.pabs-modal-body {
    padding: 22px;
}

.password-field {
    margin-bottom: 17px;
}

.password-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 7px;
}

.password-field input {
    width: 100%;
    padding: 12px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    outline: none;
    font-size: 15px;
}

.password-field input:focus {
    border-color: #064e3b;
    box-shadow: 0 0 0 3px rgba(6, 78, 59, 0.1);
}

.password-field small {
    display: block;
    margin-top: 5px;
    color: #64748b;
}

.password-modal-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 24px;
}

.modal-cancel-btn,
.modal-save-btn {
    padding: 11px 17px;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
}

.modal-cancel-btn {
    background: #e2e8f0;
    color: #334155;
}

.modal-save-btn {
    background: #064e3b;
    color: #ffffff;
}

.modal-save-btn:hover {
    background: #065f46;
}

.modal-save-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.password-message {
    display: none;
    padding: 11px;
    border-radius: 7px;
    margin-bottom: 15px;
    font-size: 13px;
}

.password-message.success-message {
    display: block;
    background: #dcfce7;
    color: #166534;
}

.password-message.error-message {
    display: block;
    background: #fee2e2;
    color: #991b1b;
}

/* Facility URL display */

.facility-url {
    display: block;
    max-width: 250px;
    overflow-wrap: anywhere;
    white-space: normal;
    margin-bottom: 7px;
}

.copy-btn {
    display: inline-block;
    background: #064e3b;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 8px 11px;
    margin: 3px 0;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.copy-btn:hover {
    background: #065f46;
}

@media (max-width: 480px) {

    .pabs-modal-overlay {
        padding: 10px;
        align-items: center;
    }

    .pabs-modal {
        max-height: 90vh;
        overflow-y: auto;
    }

    .pabs-modal-header,
    .pabs-modal-body {
        padding: 16px;
    }

    .password-modal-actions {
        flex-direction: column-reverse;
    }

    .modal-cancel-btn,
    .modal-save-btn {
        width: 100%;
    }
}

.patient-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    background: #174c38;
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.patient-btn:hover {
    background: #02935c;
    color: #fff;
}

#appointmentTime option:disabled {
    color: #999999;
    background-color: #eeeeee;
}

#appointmentTime {
    width: 100%;
    padding: 10px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    background-color: #ffffff;
    cursor: pointer;
}

#appointmentTime option {
    padding: 8px;
}

#appointmentTime option:disabled {
    color: #999999;
    background-color: #eeeeee;
}

/* =====================================================
   PABS RESPONSIVE TABLES – DESKTOP AND MOBILE
   Applies to Admin and Facility dashboards and modules
===================================================== */

/* Desktop table styling */
.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrap table {
    width: 100%;
    border-collapse: collapse;
    background: #ffffff;
}

.table-wrap th {
    background: #f1f5f9;
    color: #334155;
    font-weight: 700;
    font-size: 13px;
    padding: 14px 12px;
    text-align: left;
    white-space: nowrap;
}

.table-wrap td {
    padding: 13px 12px;
    border-bottom: 1px solid #e9edf1;
    vertical-align: middle;
    font-size: 14px;
}

.table-wrap tbody tr:hover {
    background: #f8fafc;
}

/* Mobile vertical table cards */
@media (max-width: 760px) {

    .table-wrap {
        width: 100%;
        overflow: visible;
        border: 0;
        background: transparent;
    }

    .table-wrap table,
    .table-wrap table tbody {
        display: block;
        width: 100%;
        background: transparent;
    }

    .table-wrap table thead {
        display: none;
    }

    .table-wrap table tr {
        display: block;
        width: 100%;
        margin: 0 0 15px;
        padding: 12px 15px;
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        box-shadow: 0 3px 10px rgba(15, 23, 42, 0.05);
    }

    .table-wrap table td {
        display: grid;
        grid-template-columns: minmax(105px, 40%) minmax(0, 1fr);
        align-items: start;
        gap: 10px;
        width: 100%;
        padding: 11px 0;
        border: 0;
        border-bottom: 1px solid #f1f5f9;
        text-align: right;
        white-space: normal;
        overflow-wrap: anywhere;
        font-size: 13px;
    }

    .table-wrap table td:last-child {
        border-bottom: 0;
    }

    .table-wrap table td[data-label]::before {
        content: attr(data-label);
        color: #64748b;
        font-size: 12px;
        font-weight: 700;
        text-align: left;
        overflow-wrap: anywhere;
    }

    /* Action buttons */
    .table-wrap table td .btn,
    .table-wrap table td button,
    .table-wrap table td a {
        max-width: 100%;
        overflow-wrap: anywhere;
    }

    .table-wrap table td:last-child {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        align-items: center;
        gap: 7px;
    }

    .table-wrap table td:last-child::before {
        content: attr(data-label);
        margin-right: auto;
    }

    /* Empty table messages */
    .table-wrap table td[colspan] {
        display: block;
        text-align: center;
        padding: 18px 10px;
    }

    .table-wrap table td[colspan]::before {
        content: none;
    }

    /* Make long names, URLs and descriptions wrap */
    .table-wrap table td a,
    .table-wrap table td span,
    .table-wrap table td strong {
        overflow-wrap: anywhere;
        word-break: normal;
    }

    /* Prevent buttons from overflowing the card */
    .table-wrap table td button,
    .table-wrap table td .btn {
        width: auto;
        min-height: 34px;
        padding: 8px 11px;
        font-size: 12px;
    }
}

/* Very small mobile screens */
@media (max-width: 380px) {

    .table-wrap table tr {
        padding: 10px 11px;
    }

    .table-wrap table td {
        grid-template-columns: minmax(85px, 38%) minmax(0, 1fr);
        gap: 7px;
        font-size: 12px;
    }

    .table-wrap table td[data-label]::before {
        font-size: 11px;
    }
}

/* =========================================================
   PABS RESPONSIVE TABLES
   Desktop: Normal tables
   Mobile: Each row becomes a vertical card
========================================================= */

.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrap table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

.table-wrap th {
    background: #f1f5f9;
    color: #334155;
    font-weight: 700;
    font-size: 13px;
    padding: 14px 12px;
    text-align: left;
    white-space: nowrap;
}

.table-wrap td {
    padding: 13px 12px;
    border-bottom: 1px solid #e9edf1;
    vertical-align: middle;
    font-size: 14px;
}

/* Prevent long URLs and text from breaking the layout */
.table-wrap td,
.table-wrap td code {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.table-wrap tbody tr:hover {
    background: #f8fafc;
}


/* =========================================================
   MOBILE TABLE CARDS
========================================================= */

@media (max-width: 760px) {

    .table-wrap {
        width: 100%;
        overflow: visible;
        border: 0;
        background: transparent;
    }

    .table-wrap table,
    .table-wrap table tbody {
        display: block;
        width: 100%;
        background: transparent;
    }

    .table-wrap table thead {
        display: none;
    }

    .table-wrap table tr {
        display: block;
        width: 100%;
        margin: 0 0 15px;
        padding: 12px 15px;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        box-shadow: 0 3px 10px rgba(15, 23, 42, 0.05);
    }

    .table-wrap table td {
        display: grid;
        grid-template-columns: minmax(105px, 40%) minmax(0, 1fr);
        align-items: start;
        gap: 10px;
        width: 100%;
        padding: 11px 0;
        border: 0;
        border-bottom: 1px solid #f1f5f9;
        text-align: right;
        white-space: normal;
        overflow-wrap: anywhere;
        font-size: 13px;
    }

    .table-wrap table td:last-child {
        border-bottom: 0;
    }

    /* Display each field's heading */
    .table-wrap table td[data-label]::before {
        content: attr(data-label);
        color: #64748b;
        font-size: 12px;
        font-weight: 700;
        text-align: left;
        overflow-wrap: anywhere;
    }

    /* Keep URLs and code readable */
    .table-wrap table td code {
        display: block;
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    /* Keep buttons inside the card */
    .table-wrap table td button,
    .table-wrap table td .btn,
    .table-wrap table td a {
        max-width: 100%;
        overflow-wrap: anywhere;
    }

    .table-wrap table td button,
    .table-wrap table td .btn {
        width: auto;
        min-height: 34px;
        padding: 8px 11px;
        font-size: 12px;
    }

    /* Empty table messages */
    .table-wrap table td[colspan] {
        display: block;
        text-align: center;
        padding: 18px 10px;
    }

    .table-wrap table td[colspan]::before {
        content: none;
    }
}


/* =========================================================
   SMALL MOBILE SCREENS
========================================================= */

@media (max-width: 380px) {

    .table-wrap table tr {
        padding: 10px 11px;
    }

    .table-wrap table td {
        grid-template-columns: minmax(85px, 38%) minmax(0, 1fr);
        gap: 7px;
        font-size: 12px;
    }

    .table-wrap table td[data-label]::before {
        font-size: 11px;
    }

}

.branch-input-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.branch-input-row input,
.branch-input-row select {
    width: 100%;
    min-width: 0;
}

@media (max-width: 650px) {
    .branch-input-row {
        grid-template-columns: 1fr;
    }
}