/* =============================================
   Common OPD Rx — Module Styles
   (common_opd_rx.css)
   Inherits design tokens from style.css
   ============================================= */

.opd-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 15px 20px;
    width: 100%;
    box-sizing: border-box;
}

/* --- Search & Controls Bar --- */
.opd-search-bar {
    position: sticky;
    top: 77px; /* Below sticky header */
    z-index: 90;
    background: rgba(25, 25, 112, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 6px 0;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-input-wrap {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    font-size: 1.1rem;
    color: var(--text-muted);
    pointer-events: none;
}

.opd-search-input {
    width: 100%;
    padding: 10px 38px 10px 36px;
    border-radius: 8px;
    border: 1px solid rgba(135, 206, 235, 0.4);
    background: rgba(25, 25, 112, 0.8);
    color: var(--text);
    font-size: 1rem;
    transition: all 0.2s ease;
}

.opd-search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.3);
}

.search-clear-btn {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 2px 6px;
    display: none;
    line-height: 1;
}

.search-clear-btn:hover {
    color: var(--danger);
}

.opd-search-btn {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid rgba(0, 255, 255, 0.4);
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.opd-search-btn:hover, .opd-search-btn:active {
    background: rgba(0, 255, 255, 0.2);
    border-color: var(--primary);
    color: var(--primary);
}

/* --- Summary Stats Bar --- */
.opd-global-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 10px;
    flex-wrap: wrap;
}

.opd-summary-count {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.opd-summary-count b {
    color: var(--highlight);
}

/* =============================================
   ⭐ Top Favorites Section (Heading then Div List)
   ============================================= */
.favorites-section {
    margin-bottom: 20px;
    width: 100%;
    box-sizing: border-box;
}

.favorites-title {
    color: var(--highlight);
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 10px 0;
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
    display: block;
}

.favorites-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}

.fav-dept-tag {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.fav-h2-title {
    color: var(--text);
    font-weight: 700;
}

.fav-h1-subtext {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.88rem;
}

/* --- Empty Favorites Guidance --- */
.fav-empty-guide {
    padding: 18px 16px;
    text-align: center;
    background: rgba(25, 25, 112, 0.35);
    border: 1px dashed rgba(212, 175, 55, 0.35);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
}

.fav-empty-icon {
    font-size: 1.5rem;
    line-height: 1;
    margin-bottom: 2px;
    user-select: none;
}

.fav-empty-title {
    color: var(--text);
    font-weight: 700;
    font-size: 0.95rem;
}

.fav-empty-desc {
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.45;
    max-width: 520px;
}

.fav-empty-desc b {
    color: var(--highlight);
}

/* =============================================
   Department Section (Heading then Div List)
   ============================================= */
.subject-section {
    margin-bottom: 20px;
}

/* --- Subject Header --- */
.subject-header {
    background: linear-gradient(90deg, #001f5c 0%, #003380 100%);
    border: 1px solid rgba(0, 255, 255, 0.3);
    border-radius: 10px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
    transition: all 0.2s ease;
    margin-bottom: 10px;
    gap: 10px;
}

.subject-header:hover {
    background: linear-gradient(90deg, #002b80 0%, #0044aa 100%);
    border-color: rgba(0, 255, 255, 0.6);
}

.subject-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.subject-icon {
    font-size: 1.4rem;
    line-height: 1;
}

.subject-title {
    color: var(--highlight);
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.subject-badge {
    background: rgba(0, 255, 255, 0.15);
    color: var(--primary);
    border: 1px solid rgba(0, 255, 255, 0.3);
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 20px;
    font-weight: 600;
}

.subject-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-subject-expand {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(0, 255, 255, 0.3);
    color: var(--primary);
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-subject-expand:hover {
    background: rgba(0, 255, 255, 0.2);
    color: #ffffff;
    border-color: var(--primary);
}

.subject-chevron {
    font-size: 1rem;
    color: var(--primary);
    transition: transform 0.25s ease;
    display: inline-block;
}

.subject-section.collapsed .subject-chevron {
    transform: rotate(-90deg);
}

.subject-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.subject-section.collapsed .subject-body {
    display: none;
}

/* =============================================
   H1 Topic Widget (Direct Click to Open Popup)
   ============================================= */
.h1-topic-card {
    background: rgba(0, 71, 171, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    gap: 12px;
    transition: all 0.22s ease;
}

.h1-topic-card:hover {
    border-color: var(--primary);
    background: rgba(0, 71, 171, 0.75);
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.h1-topic-card.is-favorite {
    border-color: rgba(212, 175, 55, 0.5);
    background: rgba(0, 71, 171, 0.55);
}

.h1-topic-content {
    flex: 1;
    min-width: 0;
}

.h1-topic-title {
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 3px;
    word-break: break-word;
    overflow-wrap: break-word;
}

.h1-topic-subpreview {
    color: var(--text-pale);
    font-size: 0.82rem;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.h1-topic-right {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-shrink: 0;
    min-width: 38px;
}

.opd-fav-icon {
    font-size: 1.15rem;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s ease;
    padding: 2px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.opd-fav-icon:hover {
    transform: scale(1.25);
}

.h1-badge {
    background: rgba(212, 175, 55, 0.2);
    color: var(--highlight);
    border: 1px solid rgba(212, 175, 55, 0.4);
    font-size: 0.72rem;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.2;
}

/* --- Body Scroll Lock when Modal is Open --- */
body.modal-open {
    overflow: hidden !important;
}

/* =============================================
   Popup Modal Dialog (Single Popup for all H2s)
   ============================================= */
.opd-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 2000;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 0;
    box-sizing: border-box;
    animation: fadeInModal 0.2s ease-out;
    overscroll-behavior: contain;
}

@keyframes fadeInModal {
    from { opacity: 0; }
    to { opacity: 1; }
}

.opd-modal-card {
    background: var(--surface);
    border: none;
    border-radius: 0;
    width: 100%;
    max-width: 600px;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    box-shadow: none;
    overflow: hidden;
    box-sizing: border-box;
    animation: slideUpModal 0.2s ease-out;
    overscroll-behavior: contain;
    margin: 0 auto;
}

@keyframes slideUpModal {
    from { transform: translateY(15px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@media (min-width: 601px) {
    .opd-modal-overlay {
        padding: 20px 0;
        align-items: center;
    }
    .opd-modal-card {
        height: auto;
        max-height: calc(100dvh - 40px);
        max-height: calc(100vh - 40px);
        border-radius: 12px;
        border: 1px solid rgba(0, 255, 255, 0.3);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    }
}

.opd-modal-header {
    background: linear-gradient(90deg, #001f5c 0%, #003380 100%);
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(0, 255, 255, 0.2);
    gap: 12px;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

.opd-modal-h1 {
    color: var(--highlight);
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.35;
    flex: 1;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: break-word;
}

.opd-modal-dept-paren {
    color: var(--primary);
    font-size: 0.92rem;
    font-weight: 600;
    margin-left: 4px;
    word-break: normal;
    white-space: nowrap;
}

.modal-ped-calc-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 255, 255, 0.16);
    border: 1px solid rgba(0, 255, 255, 0.45);
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 6px;
    text-decoration: none;
    margin-left: 8px;
    vertical-align: middle;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.modal-ped-calc-link:hover, .modal-ped-calc-link:active {
    background: var(--primary);
    color: #000080;
    border-color: var(--primary);
    transform: translateY(-1px);
}

.opd-modal-close {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text);
    font-size: 1.4rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.opd-modal-close:hover {
    background: var(--danger);
    color: #ffffff;
    border-color: var(--danger);
}

.opd-modal-body {
    padding: 14px 16px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* --- H2 Block Inside Modal (Heading then List, no nested box) --- */
.modal-h2-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

.modal-h2-header {
    background: linear-gradient(90deg, #001f5c 0%, #003380 100%);
    border: 1px solid rgba(0, 255, 255, 0.3);
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

.modal-h2-header:hover {
    background: linear-gradient(90deg, #002b80 0%, #0044aa 100%);
    border-color: rgba(0, 255, 255, 0.6);
}

.modal-h2-title-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.modal-h2-title {
    color: #ffffff;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.35;
    flex: 1;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: break-word;
}

.modal-h2-chevron {
    font-size: 0.9rem;
    color: var(--primary);
    transition: transform 0.25s ease;
    display: inline-block;
    padding: 2px;
    flex-shrink: 0;
}

.modal-h2-section.collapsed .modal-h2-chevron {
    transform: rotate(-90deg);
}

.modal-drugs-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.modal-action-btns {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.modal-h2-fav-icon {
    font-size: 1.25rem;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s ease;
    padding: 2px 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.modal-h2-fav-icon:hover {
    transform: scale(1.3);
}

.btn-copy-rx-drugs {
    background: rgba(0, 255, 255, 0.12);
    border: 1px solid rgba(0, 255, 255, 0.35);
    color: var(--primary);
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-copy-rx-drugs:hover, .btn-copy-rx-drugs:active {
    background: var(--primary);
    color: #000080;
    border-color: var(--primary);
}

.btn-copy-rx-drugs.copied {
    background: #16a34a;
    border-color: #22c55e;
    color: #ffffff;
}

.modal-h2-body {
    padding: 2px 2px 10px 2px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: auto;
    min-height: auto;
    max-height: none;
    overflow: visible;
}

.modal-h2-section.collapsed .modal-h2-body {
    display: none !important;
}

/* --- General Info (Italic & Muted Colour) --- */
.modal-general-info {
    background: rgba(255, 255, 255, 0.05);
    border-left: 3px solid rgba(135, 206, 235, 0.55);
    border-radius: 0 6px 6px 0;
    padding: 8px 12px;
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.92rem;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.general-info-line {
    word-break: break-word;
}

/* --- Section Blocks (Drugs & Advice) --- */
.modal-section-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.modal-section-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 3px 8px;
    border-radius: 4px;
    width: fit-content;
    user-select: none;
}

.modal-label-drugs {
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.15);
    border: 1px solid rgba(56, 189, 248, 0.35);
}

.modal-label-advice {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.15);
    border: 1px solid rgba(251, 191, 36, 0.35);
}

.section-label-icon {
    font-size: 0.95rem;
    line-height: 1;
}

.section-label-text {
    line-height: 1;
}

.modal-lines-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* --- Line Items (Drugs & Advice) --- */
.rx-line {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 0 6px 6px 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text);
    word-break: break-word;
    transition: background-color 0.15s ease;
}

.rx-num {
    font-weight: 700;
    min-width: 18px;
    color: var(--highlight);
    font-size: 0.92rem;
    line-height: 1.5;
    user-select: none;
    flex-shrink: 0;
}

.rx-text {
    flex: 1;
    min-width: 0;
    line-height: 1.5;
}

.drug-line {
    background: rgba(0, 71, 171, 0.32);
    border-left: 3px solid #00ffff;
}

.drug-line:hover {
    background: rgba(0, 71, 171, 0.55);
}

.advice-line {
    background: rgba(212, 175, 55, 0.08);
    border-left: 3px solid #d4af37;
}

.advice-line:hover {
    background: rgba(212, 175, 55, 0.18);
}

.modal-empty-advice {
    padding: 8px 12px;
    text-align: center;
    font-size: 0.9rem;
}

.opd-modal-footer {
    background: var(--surface);
    padding: 12px 18px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.btn-close-modal {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    padding: 8px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-close-modal:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: var(--primary);
}

/* Highlight search matches */
mark.opd-highlight {
    background-color: rgba(212, 175, 55, 0.4);
    color: #ffffff;
    font-weight: bold;
    padding: 1px 3px;
    border-radius: 3px;
}

/* Favorite Hint */
.fav-hint {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 20px 0 10px 0;
    padding: 0 10px;
}

/* --- Empty / Loading States --- */
.opd-loading {
    text-align: center;
    padding: 50px 20px;
    font-size: 1.1rem;
    color: var(--primary);
}

.opd-spinner {
    display: inline-block;
    width: 36px;
    height: 36px;
    border: 3px solid rgba(0, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.opd-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    background: var(--surface);
    border-radius: 12px;
    border: 1px dashed rgba(255, 255, 255, 0.2);
}

.opd-empty h3 {
    color: var(--highlight);
    margin-bottom: 8px;
}

/* --- Bottom Button Group --- */
.opd-button-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px auto 30px auto;
    width: 90%;
    max-width: 450px;
}

.btn-refresh-db {
    background-color: var(--surface);
    color: var(--text);
    border: 1px solid #007BA7;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-refresh-db:hover, .btn-refresh-db:active {
    background-color: var(--card-bg);
    border-color: var(--primary);
}

.btn-whatsapp-req {
    background-color: #25D366;
    color: #ffffff;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    text-align: center;
    text-decoration: none;
    display: block;
    transition: background-color 0.2s ease;
}

.btn-whatsapp-req:hover, .btn-whatsapp-req:active {
    background-color: #16a34a;
}

/* --- Responsive Breakpoints --- */
@media (max-width: 600px) {
    .opd-container {
        padding: 10px;
    }
    
    .subject-header {
        padding: 12px 14px;
    }
    
    .subject-title {
        font-size: 1.1rem;
    }
    
    .h1-topic-card {
        padding: 10px 12px;
    }
    
    .h1-topic-title {
        font-size: 0.98rem;
    }
    
    .opd-search-bar {
        padding: 4px 0;
    }

    .opd-search-btn {
        padding: 10px 14px;
        font-size: 0.9rem;
    }
    
    .opd-modal-overlay {
        padding: 0;
    }
    
    .opd-modal-card {
        width: 100%;
        height: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border: none;
        border-radius: 0;
        box-shadow: none;
        margin: 0;
    }
    
    .opd-modal-header {
        padding: 12px 14px;
    }
    
    .opd-modal-h1 {
        font-size: 1.05rem;
    }
    
    .opd-modal-body {
        padding: 10px;
        gap: 8px;
    }
    
    .modal-h2-body {
        padding: 2px 0 8px 0;
        gap: 8px;
    }
    
    .opd-modal-footer {
        padding: 10px 14px;
    }
}
