/* ============================================================
   MedEx Pharma — Frontend Styles
   Brand: #13848c (primary) / #23bfc3 (accent)
   ============================================================ */

:root {
    --medex-primary:  #13848c;
    --medex-accent:   #23bfc3;
    --medex-gradient: linear-gradient(135deg, #13848c, #23bfc3);
    --medex-light:    #e8f7f8;
    --medex-border:   #c8e8ea;
    --medex-text:     #1d2327;
    --medex-muted:    #6b7280;
    --medex-white:    #ffffff;
    --medex-radius:   10px;
    --medex-shadow:   0 2px 12px rgba(19, 132, 140, 0.10);
}

/* ── Base ───────────────────────────────────────────────── */
.medex-search-wrap,
.medex-detail-wrap,
.medex-pharmacy-wrap {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--medex-text);
    line-height: 1.6;
}

/* ── Buttons ─────────────────────────────────────────────── */
.medex-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid transparent;
    text-decoration: none;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.medex-btn-primary {
    background: var(--medex-gradient);
    color: var(--medex-white);
}
.medex-btn-primary:hover { opacity: 0.88; color: var(--medex-white); }

.medex-btn-outline {
    background: transparent;
    border-color: var(--medex-primary);
    color: var(--medex-primary);
}
.medex-btn-outline:hover {
    background: var(--medex-light);
    color: var(--medex-primary);
}

.medex-btn-ghost {
    background: transparent;
    color: var(--medex-muted);
    border-color: transparent;
}
.medex-btn-ghost:hover { color: #d63638; }

.medex-btn-sm { padding: 6px 14px; font-size: 13px; }

/* ── Search Bar ──────────────────────────────────────────── */
.medex-search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.medex-search-input-wrap {
    position: relative;
    flex: 1;
}

.medex-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--medex-primary);
    pointer-events: none;
}

.medex-search-input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    border: 2px solid var(--medex-border);
    border-radius: 6px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}
.medex-search-input:focus { border-color: var(--medex-primary); }

.medex-search-meta {
    font-size: 13px;
    color: var(--medex-muted);
    margin-bottom: 16px;
    min-height: 20px;
}

.medex-search-hint {
    color: var(--medex-muted);
    font-size: 15px;
    padding: 30px 0;
    text-align: center;
}

/* ── Results Grid ────────────────────────────────────────── */
.medex-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.medex-no-results {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--medex-muted);
    padding: 40px 0;
    font-size: 15px;
}

/* ── Drug Card ───────────────────────────────────────────── */
.medex-drug-card {
    border: 1px solid var(--medex-border);
    border-radius: var(--medex-radius);
    background: var(--medex-white);
    box-shadow: var(--medex-shadow);
    transition: box-shadow 0.2s, transform 0.2s;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
}
.medex-drug-card:hover {
    box-shadow: 0 6px 24px rgba(19, 132, 140, 0.16);
    transform: translateY(-2px);
}

/* Top section: left info + right badges side by side */
.medex-card-top {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 16px;
}

/* Left column — grows to fill available width */
.medex-card-left {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.medex-card-title {
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 4px;
    color: var(--medex-primary);
    line-height: 1.3;
}

.medex-card-dci {
    font-size: 13px;
    color: var(--medex-muted);
    margin: 0;
    font-style: italic;
}

.medex-card-label {
    font-weight: 600;
    color: var(--medex-muted);
    font-style: normal;
}

.medex-card-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    line-height: 1.3;
    color: var(--medex-text);
    margin: 0 0 6px 0 !important;
    padding: 0;
}

.medex-meta-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--medex-muted);
}

/* Right column — fixed width, right-aligned stack */
.medex-card-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
    width: 160px;
}

.medex-card-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    width: 100%;
}

.medex-card-local {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    color: #2e7d32;
    background: #e8f5e9;
    border-radius: 20px;
    padding: 2px 8px;
    white-space: nowrap;
}
.medex-card-local svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

/* ── Badges ──────────────────────────────────────────────── */
.medex-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.medex-badge-active   { background: #e8f7e8; color: #00a32a; }
.medex-badge-inactive { background: #fdeaea; color: #d63638; }
.medex-badge-withdrawn { background: #f0f0f1; color: #646970; }

/* Reimbursement badge */
.medex-reimb-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.medex-reimb-yes     { background: #e8f7f8; color: var(--medex-primary); border: 1px solid var(--medex-border); }
.medex-reimb-no      { background: #fdeaea; color: #d63638; border: 1px solid #fca5a5; }
.medex-reimb-unknown { background: #f9f9f9; color: #9ca3af; border: 1px solid #e5e7eb; }

/* ── Pagination ──────────────────────────────────────────── */
.medex-pagination {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 28px;
}

.medex-page-btn {
    padding: 7px 14px;
    border: 2px solid var(--medex-border);
    border-radius: 6px;
    background: var(--medex-white);
    color: var(--medex-text);
    font-size: 14px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.15s;
}
.medex-page-btn:hover,
.medex-page-btn.medex-page-active {
    background: var(--medex-gradient);
    border-color: transparent;
    color: var(--medex-white);
}

/* ── Drug Detail Page ────────────────────────────────────── */
.medex-detail-wrap {
    max-width: 900px;
    margin: 0 auto;
}

.medex-detail-card {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 40px;
    background: var(--medex-white);
    border: 1px solid var(--medex-border);
    border-radius: var(--medex-radius);
    box-shadow: var(--medex-shadow);
    padding: 32px;
    margin-bottom: 24px;
}

.medex-detail-image-col {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.medex-detail-image-col .medex-drug-image-wrap {
    width: 100%;
    height: 200px;
    border-radius: 8px;
    border: 1px solid var(--medex-border);
}

.medex-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--medex-light);
}

.medex-detail-title {
    font-size: 26px;
    font-weight: 800;
    margin: 0;
    color: var(--medex-primary);
    line-height: 1.2;
}

.medex-detail-badges {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
    flex-shrink: 0;
}

/* Detail table */
.medex-detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.medex-detail-table th,
.medex-detail-table td {
    padding: 9px 12px;
    text-align: left;
    border-bottom: 1px solid var(--medex-border);
}
.medex-detail-table th {
    width: 38%;
    color: var(--medex-muted);
    font-weight: 600;
    background: var(--medex-light);
    white-space: nowrap;
}
.medex-detail-table td {
    font-weight: 500;
}

/* Observations */
.medex-detail-observations {
    background: var(--medex-light);
    border: 1px solid var(--medex-border);
    border-radius: var(--medex-radius);
    padding: 20px 24px;
    margin-bottom: 24px;
}
.medex-detail-observations h3 {
    margin-top: 0;
    color: var(--medex-primary);
    font-size: 16px;
}

.medex-detail-back { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 8px; margin-bottom: 0; }

.medex-not-found {
    text-align: center;
    padding: 60px 20px;
    color: var(--medex-muted);
    font-size: 16px;
}

/* ── Mobile pharmacy — hidden on desktop ─────────────────── */
.medex-pharmacy-toggle  { display: none; }
.medex-sidebar-close    { display: none; }

/* Group the right-side header actions (expand + clear) */
.medex-pharmacy-list-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Expand button — permanently hidden (feature removed) */
.medex-drawer-expand-btn { display: none !important; }

/* Backdrop */
.medex-pharmacy-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
}

/* ── Pharmacy Simulation ─────────────────────────────────── */
.medex-pharmacy-wrap {
    container-type: inline-size;
}

.medex-pharmacy-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 28px;
    align-items: start;
}

.medex-pharmacy-panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 700;
    color: var(--medex-primary);
    margin: 0 0 16px;
}
.medex-pharmacy-panel-title svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Search panel */
.medex-pharmacy-search-panel {
    min-width: 0;
}

.medex-pharmacy-search-bar {
    margin-bottom: 16px;
}

.medex-pharmacy-results {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

/* In pharmacy mode cards are compact */
.medex-pharmacy-results .medex-drug-card { padding: 20px; gap: 10px; }
.medex-pharmacy-results .medex-card-title { font-size: 14px; }
.medex-pharmacy-results .medex-card-dci   { font-size: 12px; }
.medex-pharmacy-results .medex-card-meta  { font-size: 12px; }
.medex-pharmacy-results .medex-card-right { width: 130px; }

/* Panel injected directly into <body> on drug detail pages.
   Desktop: completely hidden and non-interactive.
   Mobile: becomes the fixed slide-in sidebar (rules added inside the media query below). */
body > .medex-pharmacy-list-panel {
    display: none;
    visibility: hidden;
    pointer-events: none;
}

/* Drug list panel */
.medex-pharmacy-list-panel {
    position: sticky;
    top: 24px;
    background: var(--medex-white);
    border: 1px solid var(--medex-border);
    border-radius: var(--medex-radius);
    box-shadow: var(--medex-shadow);
    overflow: hidden;
}

.medex-pharmacy-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 0;
}

.medex-pharmacy-list-body {
    padding: 0 20px 16px;
    max-height: 480px;
    overflow-y: auto;
}

.medex-pharmacy-empty {
    text-align: center;
    color: var(--medex-muted);
    font-size: 14px;
    padding: 32px 0;
}

/* Individual list item */
.medex-pharmacy-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px 0;
    border-bottom: 1px solid var(--medex-border);
    gap: 12px;
}
.medex-pharmacy-item:last-child { border-bottom: none; }

.medex-pharmacy-item-info { flex: 1; min-width: 0; }
.medex-pharmacy-item-name {
    font-weight: 700;
    font-size: 14px;
    color: var(--medex-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.medex-pharmacy-item-dci {
    font-size: 12px;
    color: var(--medex-muted);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.medex-pharmacy-item-form { font-size: 12px; color: var(--medex-text); }

.medex-pharmacy-item-remove {
    background: none;
    border: none;
    color: var(--medex-muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}
.medex-pharmacy-item-remove:hover { color: #d63638; background: #fdeaea; }

/* Footer */
.medex-pharmacy-list-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--medex-border);
    background: var(--medex-light);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.medex-pharmacy-note {
    font-size: 12px;
    color: var(--medex-muted);
    margin: 0;
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

/* Print */
@media print {
    .medex-pharmacy-search-panel,
    .medex-pharmacy-list-footer,
    .medex-search-bar,
    .medex-btn,
    .medex-pagination { display: none !important; }
    .medex-pharmacy-layout { display: block; }
    .medex-pharmacy-list-panel { box-shadow: none; border: none; }
    .medex-pharmacy-list-body { max-height: none; }
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .medex-search-bar { flex-direction: column; }
    .medex-btn-primary { width: 100%; justify-content: center; }

    .medex-detail-card {
        grid-template-columns: 1fr;
        padding: 20px;
        gap: 20px;
    }
    .medex-detail-image-col .medex-drug-image-wrap {
        height: 160px;
        max-width: 240px;
        margin: 0 auto;
    }
    .medex-detail-header { flex-direction: column; }
    .medex-detail-badges { align-items: flex-start; }
    .medex-detail-title { font-size: 20px; }

    /* ── Mobile pharmacy sidebar ─────────────────────────────── */

    /* Toggle button — pill fixed at bottom-right */
    .medex-pharmacy-toggle {
        display: flex;
        align-items: center;
        gap: 8px;
        position: fixed;
        bottom: 24px;
        right: 16px;
        z-index: 1002;
        background: var(--medex-gradient);
        color: var(--medex-white);
        border: none;
        border-radius: 50px;
        padding: 13px 20px;
        font-size: 14px;
        font-weight: 700;
        cursor: pointer;
        box-shadow: 0 4px 20px rgba(19, 132, 140, 0.5);
        white-space: nowrap;
        transition: transform 0.15s, box-shadow 0.15s;
    }
    .medex-pharmacy-toggle:active {
        transform: scale(0.95);
        box-shadow: 0 2px 10px rgba(19, 132, 140, 0.35);
    }
    .medex-toggle-count {
        background: rgba(255, 255, 255, 0.28);
        border-radius: 50px;
        min-width: 22px;
        height: 22px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        font-weight: 800;
        padding: 0 5px;
    }

    /* Search panel fills full width */
    .medex-pharmacy-layout { display: block; }

    /* Override container-type to prevent Chromium from including the fixed panel height in the layout */
    .medex-pharmacy-wrap { container-type: normal; }


    /* List panel — fixed right sidebar, slides in from right.
       Applied to both the pharmacy-page panel and the body-injected panel on drug detail pages. */
    .medex-pharmacy-layout .medex-pharmacy-list-panel,
    body > .medex-pharmacy-list-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 85vw;
        max-width: 360px;
        z-index: 1001;
        border-radius: 0;
        overflow-y: auto;
        transform: translateX(100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
    }
    /* Show and make interactive on mobile */
    body > .medex-pharmacy-list-panel {
        display: block;
        visibility: visible;
        pointer-events: auto;
    }
    .medex-pharmacy-layout .medex-pharmacy-list-panel.medex-sidebar-open,
    body > .medex-pharmacy-list-panel.medex-sidebar-open {
        transform: translateX(0);
    }

    /* Close × button inside the sidebar header */
    .medex-sidebar-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        border: none;
        background: transparent;
        color: var(--medex-muted);
        border-radius: 6px;
        cursor: pointer;
        font-size: 22px;
        line-height: 1;
        flex-shrink: 0;
        transition: color 0.15s, background 0.15s;
    }
    .medex-sidebar-close:hover,
    .medex-sidebar-close:active { color: #d63638; background: #fdeaea; }

    /* Allow inner body to scroll freely — sidebar handles the viewport */
    .medex-pharmacy-list-body { max-height: none; }

    /* Lock page scroll while sidebar is open */
    body.medex-sidebar-active { overflow: hidden; }

    /* Card layout — top row stays, actions already at bottom */
    .medex-card-top { gap: 8px; }
}

@media (max-width: 480px) {
    .medex-results-grid { grid-template-columns: 1fr; }
    .medex-detail-table th { width: auto; font-size: 12px; }
}
