﻿/* ═══════════════════════════════════════
   PrescriptionPage.css — Prescription Specific
   ═══════════════════════════════════════ */

.prescription-page {
    width: 100%;
    /* ارتفاع ثابت: بدون اسکرول صفحه، محتوا داخل ستون‌ها اسکرول می‌شود */
    height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Three Column Layout ── */
.prescription-page .three-column-layout {
    display: grid;
    grid-template-columns: 270px 1fr 350px;
    gap: 12px;
    padding: 0 12px 12px 12px;
    /* فضای باقی‌ماندهٔ زیر هدر را پر می‌کند */
    flex: 1;
    min-height: 0;
}

/* ── Section Card Overrides (prescription context only) ── */
/* Remove double-padding from .section-header inside MudCardHeader */
.prescription-page .section-card .section-header,
.col-section-header {
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    margin: 0;
    gap: 8px;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: flex-start !important;
    flex-wrap: nowrap;
    font-weight: 600;
    font-size: 14px;
    color: #1e293b;
}

/* Consistent card header height across all 3 columns */
.prescription-page .section-card .mud-card-header {
    padding: 6px 12px !important;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
    min-height: 38px;
    display: flex;
    align-items: center;
}

/* Tighter card content padding with minimal gap between children */
.prescription-page .section-card .mud-card-content {
    padding: 6px 10px 10px 10px !important;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* ── Search Field — fixed height, must NOT grow (base sets flex:1) ── */
.prescription-page .search-field-wrapper {
    flex: 0 0 auto !important;
    margin: 0;
}

    /* Remove MudBlazor dense top margin so search sits close to header */
    .prescription-page .search-field-wrapper .mud-input-control,
    .prescription-page .search-field-wrapper .mud-input-control-margin-dense {
        margin-top: 0 !important;
    }

/* ── Drug / Patient / Prescription Table Containers ── */
.drug-list-container,
.patient-list-container,
.prescription-table-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Inner scroll wrapper fills container ── */
.drug-list-container .table-scroll-wrapper,
.patient-list-container .table-scroll-wrapper,
.prescription-table-container .table-scroll-wrapper {
    flex: 1;
    overflow: auto;
    min-height: 0;
    max-height: none; /* let the flex parent control height */
}

/* ── Table Styles (prescription-specific) ── */
.drug-table,
.patient-table,
.prescription-table {
    min-width: 100%;
}

    .drug-table .mud-table-head th,
    .patient-table .mud-table-head th,
    .prescription-table .mud-table-head th {
        background: #f8fafc !important;
        font-weight: 600;
        color: #475569;
        position: sticky;
        top: 0;
        z-index: 10;
        padding: 5px 6px;
        font-size: 0.75rem;
        border-bottom: 2px solid #e2e8f0;
    }

    /* عنوان ستون‌های جدول نسخه روی نمایشگرهای کوچک ۲ خطی شوند تا ستون جا شود */
    .prescription-table .mud-table-head th {
        white-space: normal;
        line-height: 1.2;
        word-break: break-word;
    }

    /* سلول‌ها هم در صورت نیاز wrap شوند */
    .prescription-table .mud-table-body td {
        white-space: normal;
    }

    .drug-table .mud-table-body td,
    .patient-table .mud-table-body td,
    .prescription-table .mud-table-body td {
        padding: 3px 8px;
        font-size: 0.8rem;
        border-bottom: 1px solid #f1f5f9;
    }

        .drug-table .mud-table-body .mud-table-row:hover,
        .patient-table .mud-table-body .mud-table-row:hover,
        .prescription-table .mud-table-body .mud-table-row:hover {
            background: #f1f5f9;
        }

    .patient-table .mud-table-body .mud-table-row {
        cursor: pointer;
    }

        .patient-table .mud-table-body .mud-table-row.selected {
            background: #dbeafe;
        }

/* ── Tab Buttons Row ── */
.prescription-tabs {
    flex-shrink: 0;
    margin: 0;
}

.tab-buttons-row {
    display: flex;
    gap: 3px;
    background: #f1f5f9;
    padding: 3px;
    border-radius: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

    .tab-buttons-row::-webkit-scrollbar {
        display: none;
    }

.tab-button {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border: none;
    background: transparent;
    border-radius: 6px;
    color: #64748b;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

    .tab-button:hover {
        background: rgba(255, 255, 255, 0.5);
        color: #1a2332;
    }

    .tab-button.active {
        background: white;
        color: #1a2332;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }

    .tab-button:focus {
        outline: none;
        box-shadow: none;
    }

    .tab-button:focus-visible {
        outline: 2px solid #3b82f6;
        outline-offset: 2px;
    }

/* ── Prescription Summary ── */
.prescription-summary {
    flex-shrink: 0;
    padding: 6px 10px;
    background: #f8fafc;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    border: 1px solid #e2e8f0;
}

.summary-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.78rem;
}

.summary-label {
    color: #64748b;
    font-weight: 500;
}

.summary-value {
    color: #1a2332;
    font-weight: 700;
}

/* ── Quantity & Select Fields ── */
.quantity-field {
    max-width: 65px;
}

    .quantity-field .mud-input {
        font-size: 0.8rem;
        padding: 4px 6px;
        min-height: 30px;
    }

.usage-select,
.form-select,
.instruction-select {
    width: 100%;
}

    .usage-select .mud-input,
    .form-select .mud-input,
    .instruction-select .mud-input {
        font-size: 0.75rem;
        padding: 4px 6px;
        min-height: 30px;
    }

/* ── Prescription Fields (diagnosis + note) ── */
.prescription-fields {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ── Diagnosis Section ── */
.diagnosis-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: #f1f5f9;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.82rem;
    color: #1a2332;
    font-weight: 500;
    user-select: none;
}

    .diagnosis-header:hover {
        background: #e2e8f0;
    }

.diagnosis-count-badge {
    background: #3b82f6;
    color: white;
    font-size: 0.7rem;
    padding: 1px 8px;
    border-radius: 12px;
    margin-right: auto;
}

.diagnosis-section {
    padding: 12px;
    background: var(--mud-palette-background-grey, #f8fafc);
    border-radius: 10px;
    border: 1px solid var(--mud-palette-lines-default, #e2e8f0);
    animation: slideDown 0.3s ease-out;
}

.diagnosis-tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.diagnosis-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.74rem;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--mud-palette-surface, #fff);
    color: var(--mud-palette-text-secondary, #475569);
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid var(--mud-palette-lines-default, #e2e8f0);
    user-select: none;
    white-space: nowrap;
}

    .diagnosis-tag::before {
        content: "+";
        font-weight: 700;
        opacity: 0.5;
        font-size: 0.85rem;
        line-height: 1;
    }

    .diagnosis-tag:hover {
        border-color: var(--mud-palette-primary, #3b82f6);
        color: var(--mud-palette-primary, #3b82f6);
    }

    .diagnosis-tag.active {
        background: var(--mud-palette-primary, #3b82f6);
        color: #fff;
        border-color: var(--mud-palette-primary, #3b82f6);
        box-shadow: 0 1px 4px rgba(59, 130, 246, 0.35);
    }

        .diagnosis-tag.active::before {
            content: "✓";
            opacity: 1;
            font-size: 0.72rem;
        }

.selected-diagnosis-display {
    padding: 8px 10px;
    background: var(--mud-palette-surface, #fff);
    border-radius: 8px;
    border: 1px solid var(--mud-palette-lines-default, #e2e8f0);
    min-height: 34px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.78rem;
}

    .selected-diagnosis-display .selected-label {
        font-weight: 600;
        color: var(--mud-palette-text-secondary, #475569);
    }

    .selected-diagnosis-display .selected-tags {
        color: var(--mud-palette-primary, #2563eb);
        font-weight: 600;
    }

.empty-message {
    font-size: 0.78rem;
    color: var(--mud-palette-text-disabled, #94a3b8);
    font-style: italic;
}

/* ── Note Field ── */
.toggle-field {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: #f1f5f9;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.78rem;
    color: #475569;
    width: fit-content;
}

    .toggle-field:hover {
        background: #e2e8f0;
    }

.note-field-container {
    animation: slideDown 0.3s ease-out;
}

/* ── جدول نسخه به‌صورت کارت در موبایل ── */
.rx-mobile-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 2px 6px 2px;
}

.rx-drug-card {
    border: 1px solid var(--mud-palette-lines-default, #e2e8f0);
    border-radius: 12px;
    padding: 10px 12px;
    background: var(--mud-palette-surface, #fff);
}

.rx-drug-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.rx-drug-id {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.rx-drug-name {
    font-weight: 700;
    font-size: 14px;
    color: var(--mud-palette-text-primary, #1e293b);
}

.rx-drug-dose {
    font-size: 11px;
    color: var(--mud-palette-text-secondary, #64748b);
}

.rx-drug-fields {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px 8px;
}

.rx-drug-more {
    grid-template-columns: 1fr 1fr;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--mud-palette-lines-default, #e2e8f0);
}

.rx-mfield {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.rx-drug-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    margin-top: 8px;
    padding: 5px;
    border: none;
    background: transparent;
    color: var(--mud-palette-primary, #3b82f6);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
}

    .rx-drug-toggle:hover {
        background: var(--mud-palette-action-default-hover, rgba(0,0,0,0.04));
    }

    .rx-mfield label {
        font-size: 11px;
        font-weight: 600;
        color: var(--mud-palette-text-secondary, #475569);
    }

.rx-mobile-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 16px;
}

/* ── Selected Patient Info ── */
.selected-patient-info {
    flex-shrink: 0;
    padding: 7px 10px;
    background: #dbeafe;
    border-radius: 6px;
    border: 1px solid #93c5fd;
}

.patient-detail {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    margin-bottom: 2px;
}

.detail-label {
    color: #1e40af;
    font-weight: 500;
}

.detail-value {
    color: #1e3a8a;
    font-weight: 600;
}

/* ── Section Badge ── */
.prescription-page .section-header .badge {
    background: #e2e8f0;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    margin-right: auto;
}

/* ═══════════════════════════════════════
   Responsive
   ═══════════════════════════════════════ */

@media (max-width: 1400px) {
    .prescription-page .three-column-layout {
        grid-template-columns: 250px 1fr 320px;
    }
}

@media (max-width: 1200px) {
    .prescription-page .three-column-layout {
        grid-template-columns: 230px 1fr 280px;
        gap: 10px;
    }

    .tab-button {
        font-size: 0.7rem;
        padding: 4px 8px;
    }
}

@media (max-width: 992px) {
    /* در تبلت/موبایل صفحه به‌صورت عادی اسکرول شود */
    .prescription-page {
        height: auto;
        overflow: visible;
    }

    .prescription-page .three-column-layout {
        grid-template-columns: 1fr;
        height: auto;
        gap: 12px;
    }

    /* داروها و مریضان ارتفاع محدود با اسکرول داخلی */
    .prescription-page .column-left .section-card,
    .prescription-page .column-right .section-card {
        max-height: 58vh;
    }

    /* ستون نسخه دو برابر بلندتر تا داروهای بیشتری دیده شود */
    .prescription-page .column-middle .section-card {
        max-height: 116vh;
    }

    /* لیست کارتی داروهای نسخه: اسکرول داخلی با ارتفاع دو برابر */
    .rx-mobile-list {
        flex: 1;
        min-height: 56vh;
        overflow-y: auto;
    }

    /* لیست کارتی مریضان: اسکرول داخلی */
    .prescription-page .column-right .patient-cards-list {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    .drug-list-container,
    .prescription-table-container,
    .patient-list-container {
        min-height: 180px;
    }

    .tab-button {
        font-size: 0.7rem;
        padding: 4px 8px;
    }
}

@media (max-width: 768px) {
    .prescription-page .three-column-layout {
        padding: 0 8px 8px 8px;
        gap: 10px;
    }

    .tab-buttons-row {
        gap: 2px;
    }

    .tab-button {
        font-size: 0.65rem;
        padding: 4px 7px;
        gap: 3px;
    }

    .diagnosis-tag {
        font-size: 0.68rem;
        padding: 3px 9px;
    }
}

@media (max-width: 480px) {
    .prescription-page .three-column-layout {
        padding: 0 6px 6px 6px;
    }

    .prescription-page .section-card .mud-card-content {
        padding: 6px 8px 8px 8px !important;
    }

    .tab-button {
        font-size: 0.62rem;
        padding: 3px 6px;
    }
}
