* { box-sizing: border-box; }

:root {
    font-family: Arial, Helvetica, sans-serif;
    color: #1f2937;
    background: #f4f7fb;
}

body {
    margin: 0;
    min-height: 100vh;
    background: #f4f7fb;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(430px, 100%);
    background: #fff;
    padding: 32px;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0,0,0,.08);
}

.brand { margin-bottom: 24px; }
.brand h1 { margin-bottom: 6px; }

label {
    display: block;
    margin: 16px 0 6px;
    font-weight: 600;
}

input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font: inherit;
}

button, .button-link {
    display: inline-block;
    width: 100%;
    margin-top: 20px;
    padding: 12px 16px;
    border: 0;
    border-radius: 8px;
    background: #0f766e;
    color: #fff;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.alert {
    padding: 11px 13px;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 8px;
}

.success {
    padding: 11px 13px;
    background: #dcfce7;
    color: #166534;
    border-radius: 8px;
}

.muted { color: #64748b; margin-top: 18px; }

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 16px 24px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
}

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 32px auto;
}

.trial-badge {
    display: inline-block;
    padding: 7px 12px;
    border-radius: 999px;
    background: #fff3cd;
    color: #7c5a00;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .04em;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px;
}

/* Administration */
.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-link {
    color: inherit;
    text-decoration: none;
    font-weight: 800;
}

.topbar-section {
    opacity: .65;
    font-size: 14px;
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

.page-space {
    padding-top: 34px;
    padding-bottom: 48px;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.page-header h1 {
    margin: 4px 0 8px;
}

.eyebrow {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    opacity: .65;
}

.page-description {
    margin: 0;
    opacity: .7;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-height: 40px;
    margin-top: 0;
    padding: 0 16px;
    border: 0;
    border-radius: 9px;
    background: #1f2937;
    color: #fff;
    text-decoration: none;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.button:hover {
    opacity: .9;
}

.button-small {
    min-height: 34px;
    padding: 0 11px;
    font-size: 13px;
}

.button-secondary {
    background: #eef1f5;
    color: #1f2937;
}

.button-ghost {
    background: transparent;
    border: 1px solid rgba(255,255,255,.22);
    color: inherit;
}

.button-danger {
    background: #b42318;
}

.button-success {
    background: #147a52;
}

.success,
.alert {
    padding: 12px 14px;
    border-radius: 9px;
    margin-bottom: 18px;
}

.success {
    background: #eaf8f0;
    color: #146c43;
}

.alert {
    background: #fff0ef;
    color: #a32118;
}

.table-card {
    padding: 0;
    overflow: hidden;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 14px 16px;
    border-bottom: 1px solid #edf0f3;
    text-align: left;
    white-space: nowrap;
}

th {
    background: #f8fafb;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

tr:last-child td {
    border-bottom: 0;
}

.text-right {
    text-align: right;
}

.actions-cell {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.role-badge,
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.role-admin {
    background: #ede9fe;
    color: #5b21b6;
}

.role-reception {
    background: #e0f2fe;
    color: #075985;
}

.role-doctor {
    background: #dcfce7;
    color: #166534;
}

.status-active {
    background: #eaf8f0;
    color: #146c43;
}

.status-inactive {
    background: #f1f3f5;
    color: #6b7280;
}

.empty-state {
    text-align: center;
    padding: 36px;
    opacity: .65;
}

.form-card {
    max-width: 860px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.form-field-wide {
    grid-column: 1 / -1;
}

.form-field input,
.form-field select {
    width: 100%;
    box-sizing: border-box;
}

.field-help {
    font-size: 12px;
    opacity: .65;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

@media (max-width: 720px) {
    .page-header,
    .topbar,
    .topbar-right {
        align-items: flex-start;
    }

    .page-header,
    .topbar {
        flex-direction: column;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-field-wide {
        grid-column: auto;
    }
}

/* Patient management */
.topbar-section {
    color: #6b7280;
    font-size: 14px;
}

.page-header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.eyebrow {
    color: #6b7280;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    margin-bottom: 4px;
}

.search-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin: 24px 0 16px;
}

.search-field {
    flex: 1;
}

.search-field label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 700;
}

.search-field input {
    width: 100%;
    box-sizing: border-box;
}

.table-card,
.form-card-wide {
    background: #fff;
    border: 1px solid #dce3ea;
    border-radius: 12px;
    overflow: hidden;
}

.table-card-header {
    min-height: 52px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #e8edf2;
}

.table-wrap {
    overflow-x: auto;
}

.table-subtext {
    color: #6b7280;
    font-size: 12px;
    margin-top: 2px;
}

.muted {
    color: #6b7280;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 16px;
    border-top: 1px solid #e8edf2;
    color: #6b7280;
    font-size: 13px;
}

.button-light {
    background: #f1f4f7;
    color: #172033;
    border: 1px solid #e0e6ec;
}

.button-light:hover {
    background: #e7ebef;
}

.alert {
    border-radius: 10px;
    padding: 12px 14px;
    margin: 18px 0;
    font-size: 14px;
}

.alert ul {
    margin: 8px 0 0 18px;
}

.alert-success {
    background: #edf9f1;
    color: #146c43;
    border: 1px solid #ccebd7;
}

.alert-error {
    background: #fff1f1;
    color: #a61b1b;
    border: 1px solid #f1cccc;
}

.card-link {
    display: block;
    color: inherit;
    text-decoration: none;
    transition: border-color .15s ease, transform .15s ease;
}

.card-link:hover {
    border-color: #bcc8d4;
    transform: translateY(-1px);
}

.narrow-container {
    max-width: 1080px;
}

.form-card-wide {
    padding: 0;
}

.form-section {
    padding: 24px;
    border-bottom: 1px solid #e5e9ee;
}

.form-section:last-of-type {
    border-bottom: 0;
}

.form-section-title,
.section-heading-row,
.card-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
}

.form-section-title h2,
.section-heading-row h2,
.card-title-row h2 {
    margin: 0;
    font-size: 20px;
}

.form-section-title .muted,
.section-heading-row p {
    margin: 2px 0 0;
    font-size: 13px;
}

.form-field textarea {
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    min-height: 90px;
    font: inherit;
    padding: 10px 11px;
    border: 1px solid #cfd7df;
    border-radius: 8px;
    color: #172033;
    background: #fff;
}

.form-field textarea:focus,
.form-field input:focus,
.form-field select:focus,
.search-field input:focus {
    outline: none;
    border-color: #7b8ea3;
    box-shadow: 0 0 0 3px rgba(74, 99, 126, .10);
}

.history-grid,
.history-view-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.profile-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 18px;
    align-items: start;
}

.profile-card,
.profile-section {
    margin-bottom: 18px;
}

.patient-code-large {
    letter-spacing: .04em;
}

.patient-code-badge {
    background: #eef2f6;
    color: #263548;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .04em;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 24px;
    margin: 0;
}

.details-grid > div {
    min-width: 0;
}

.details-grid .details-wide {
    grid-column: 1 / -1;
}

.details-grid dt {
    color: #6b7280;
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 4px;
}

.details-grid dd {
    margin: 0;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.stats-grid {
    display: grid;
    gap: 12px;
}

.stat-card {
    background: #fff;
    border: 1px solid #dce3ea;
    border-radius: 12px;
    padding: 18px;
}

.stat-card span {
    display: block;
    color: #6b7280;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.stat-card strong {
    display: block;
    font-size: 28px;
    margin-top: 7px;
}

.profile-section {
    padding: 22px;
}

.history-item {
    border: 1px solid #e1e7ec;
    border-radius: 10px;
    padding: 15px;
    min-height: 100px;
}

.history-item h3 {
    margin: 0 0 9px;
    font-size: 14px;
}

.history-item > div {
    color: #344154;
    font-size: 14px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.compact-empty {
    padding: 22px;
}

@media (max-width: 900px) {
    .profile-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 720px) {
    .page-header-actions,
    .search-bar,
    .form-section-title,
    .section-heading-row,
    .card-title-row {
        flex-direction: column;
        align-items: stretch;
    }

    .search-bar .button {
        width: 100%;
        box-sizing: border-box;
    }

    .history-grid,
    .history-view-grid,
    .details-grid,
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .details-grid .details-wide {
        grid-column: auto;
    }

    .form-section,
    .profile-section {
        padding: 18px;
    }
}

/* Phase 4 — Billing & Services */
select,
textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: inherit;
    font: inherit;
}

textarea {
    min-height: 90px;
    resize: vertical;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-field-wide {
    grid-column: 1 / -1;
}

.form-field label,
.search-field label {
    margin-top: 0;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 22px;
}

.form-actions .button {
    min-width: 120px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: 18px;
}

.checkbox-label input {
    width: auto;
}

.search-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.search-field {
    flex: 1 1 360px;
}

.search-field-small {
    flex: 0 1 180px;
}

.search-bar .button {
    flex: 0 0 auto;
}

.search-bar .button-ghost {
    color: #1f2937;
    border-color: #cbd5e1;
    background: #fff;
}

.table-card-header,
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 16px;
    border-bottom: 1px solid #edf0f3;
}

.pagination {
    border-bottom: 0;
    border-top: 1px solid #edf0f3;
}

.pagination > div {
    display: flex;
    gap: 8px;
}

.pagination .button {
    min-width: 80px;
}

.welfare-note {
    margin-top: 18px;
    padding: 12px 14px;
    border-radius: 9px;
    background: #fff8e1;
    color: #725500;
    font-size: 14px;
    line-height: 1.5;
}

.billing-items-wrap {
    overflow-x: auto;
}

.billing-items {
    min-width: 760px;
}

.billing-items th,
.billing-items td {
    vertical-align: middle;
}

.billing-items select,
.billing-items input {
    min-width: 0;
}

.billing-items td:first-child {
    min-width: 310px;
}

.billing-items td:nth-child(2) {
    width: 110px;
}

.billing-items td:nth-child(3) {
    width: 170px;
}

.billing-items td:nth-child(4) {
    width: 150px;
    font-weight: 700;
}

.billing-items td:last-child {
    width: 100px;
}

.remove-item {
    min-width: 82px;
}

.billing-summary {
    width: min(420px, 100%);
    margin-left: auto;
    margin-top: 22px;
}

.billing-summary > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 9px 0;
    border-bottom: 1px solid #edf0f3;
}

.billing-summary .billing-total {
    border-bottom: 0;
    padding-top: 14px;
    font-size: 18px;
}

.discount-row label {
    margin: 0;
}

.discount-row input {
    width: 150px;
}

.status-paid {
    background: #eaf8f0;
    color: #146c43;
}

.status-partial {
    background: #fff4d6;
    color: #8a5a00;
}

.status-unpaid {
    background: #fff0ef;
    color: #a32118;
}

.status-void {
    background: #f1f3f5;
    color: #6b7280;
}

.billing-detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(320px, .8fr);
    gap: 16px;
}

.compact-summary {
    max-width: 420px;
}

.payment-balance {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 18px 0;
}

.payment-balance > div {
    padding: 12px;
    border: 1px solid #e1e7ec;
    border-radius: 9px;
}

.payment-balance span {
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #64748b;
}

.payment-balance strong {
    display: block;
    margin-top: 5px;
}

.payment-form .button {
    width: 100%;
    margin-top: 18px;
}

@media (max-width: 900px) {
    .billing-detail-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .form-actions,
    .search-bar,
    .payment-balance {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }

    .search-field,
    .search-field-small,
    .search-bar .button {
        width: 100%;
        flex-basis: auto;
    }

    .form-actions .button {
        width: 100%;
    }

    .payment-balance {
        display: grid;
    }
}


/* Doctor Queue */
.queue-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.queue-stats .card {
    padding: 16px 18px;
}

.queue-stats span {
    display: block;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #64748b;
}

.queue-stats strong {
    display: block;
    margin-top: 5px;
    font-size: 24px;
}

.token-number {
    font-size: 18px;
}

.muted-small {
    margin-top: 3px;
    font-size: 12px;
    color: #64748b;
}

.queue-waiting {
    background: #fff4d6;
    color: #8a5a00;
}

.queue-called {
    background: #e0f2fe;
    color: #075985;
}

.queue-consultation {
    background: #ede9fe;
    color: #5b21b6;
}

.queue-completed {
    background: #eaf8f0;
    color: #146c43;
}

.queue-cancelled {
    background: #f1f3f5;
    color: #6b7280;
}

@media (max-width: 720px) {
    .queue-stats {
        grid-template-columns: 1fr;
    }
}

/* Doctor Consultation */
.consultation-page {
    padding-top: 28px;
    padding-bottom: 60px;
}

.consultation-summary-grid,
.consultation-main-grid,
.history-columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.consultation-main-grid {
    align-items: start;
}

.patient-summary-card,
.history-card,
.consultation-section {
    min-width: 0;
}

.compact-details {
    margin-top: 12px;
}

.history-mini-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.history-mini-grid > div {
    padding: 11px;
    background: #f8fafc;
    border: 1px solid #edf0f3;
    border-radius: 9px;
}

.history-mini-grid strong {
    display: block;
    font-size: 12px;
    color: #475569;
}

.history-mini-grid p {
    margin: 7px 0 0;
    line-height: 1.45;
    font-size: 13px;
}

.vitals-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.form-grid-wide {
    grid-column: 1 / -1;
}

.vitals-form textarea,
.clinical-form textarea,
.prescription-section textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font: inherit;
    resize: vertical;
}

.vitals-form .form-actions {
    margin-top: 16px;
}

.token-pill {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 9px;
    background: #eef2ff;
    color: #3730a3;
    font-weight: 800;
}

.notice {
    padding: 12px 14px;
    border-radius: 9px;
    margin-bottom: 16px;
    background: #fff7df;
    color: #795b00;
    border: 1px solid #f1dfaa;
}

.clinical-fieldset {
    margin: 0;
    padding: 0;
    border: 0;
}

.clinical-fieldset:disabled {
    opacity: .82;
}

.clinical-form label,
.prescription-section label {
    margin-top: 14px;
}

.previous-vitals-list {
    display: grid;
    gap: 8px;
}

.previous-vital-row {
    display: grid;
    grid-template-columns: 100px repeat(4, minmax(70px, 1fr));
    gap: 8px;
    align-items: center;
    padding: 10px 11px;
    border: 1px solid #edf0f3;
    border-radius: 8px;
    font-size: 12px;
}

.previous-vital-row strong {
    font-size: 13px;
}

.prescription-section {
    overflow: hidden;
}

.prescription-table-wrap {
    margin-top: 8px;
}

.prescription-table {
    min-width: 1120px;
}

.prescription-table th,
.prescription-table td {
    padding: 9px 7px;
}

.prescription-table input {
    min-width: 90px;
    padding: 9px 8px;
    border-radius: 7px;
}

.prescription-table td:first-child input {
    min-width: 180px;
}

.prescription-table td:last-child {
    width: 1%;
}

.prescription-actions {
    margin-top: 16px;
}

.prescription-draft {
    background: #fff4d6;
    color: #8a5a00;
}

.prescription-final {
    background: #eaf8f0;
    color: #146c43;
}

.history-rx-card {
    padding: 12px;
    border: 1px solid #edf0f3;
    border-radius: 9px;
    margin-bottom: 10px;
}

.history-rx-card:last-child {
    margin-bottom: 0;
}

.history-rx-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.rx-history-list {
    margin: 10px 0 0;
    padding-left: 20px;
}

.rx-history-list li {
    margin-bottom: 5px;
    font-size: 13px;
}

@media (max-width: 1050px) {
    .vitals-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .consultation-summary-grid,
    .consultation-main-grid,
    .history-columns {
        grid-template-columns: 1fr;
    }

    .vitals-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .history-mini-grid,
    .vitals-grid {
        grid-template-columns: 1fr;
    }

    .form-grid-wide {
        grid-column: auto;
    }

    .previous-vital-row {
        grid-template-columns: 1fr 1fr;
    }
}

/* Phase 7 clinical setup */
.field-help{display:block;margin-top:5px;font-size:12px;color:#667085;line-height:1.4}
.prescription-tools{display:flex;align-items:flex-end;gap:8px;flex-wrap:wrap;justify-content:flex-end}
.template-picker{font-size:12px;font-weight:700;color:#667085;display:flex;flex-direction:column;gap:4px;min-width:170px}
.template-picker select{font-size:13px;padding:8px 10px}
.checkbox-label{display:flex;align-items:center;gap:8px;font-weight:600}
.checkbox-label input{width:auto}
.alert-error{border:1px solid #efb0b0;background:#fff3f3;color:#a61b1b;padding:12px 14px;border-radius:8px;margin:14px 0}
.status-inactive{background:#f2f4f7;color:#667085}
