/* Styles for /medicines (moved out of the page so browsers can cache them) */
        :root { --legal-bg: rgba(124, 58, 237, 0.12); --legal-fg: #6d28d9; --safety-bg: rgba(220, 38, 38, 0.1); --safety-fg: #b91c1c; }
        @media (prefers-color-scheme: dark) {
            :root { --legal-bg: rgba(167, 139, 250, 0.16); --legal-fg: #c4b5fd; --safety-bg: rgba(248, 113, 113, 0.14); --safety-fg: #fca5a5; }
        }
        * { margin: 0; padding: 0; box-sizing: border-box; }
        [hidden] { display: none !important; }
        body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; background: var(--color-light); color: var(--color-text); line-height: 1.6; }
        a { color: var(--color-link); }
        .btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; height: 40px; padding: 0 1.1rem; border: none; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600; font-size: 0.93rem; text-decoration: none; white-space: nowrap; }
        .btn-primary { background: var(--color-primary); color: #fff; }
        .btn-primary:hover { background: var(--color-accent); }
        .btn-secondary { background: var(--color-light); color: var(--color-text); box-shadow: inset 0 0 0 1px var(--color-border); }
        .btn-secondary:hover { background: var(--color-tint); }
        .btn-sm { height: 32px; padding: 0 0.7rem; font-size: 0.84rem; }
        .page-hero { background: linear-gradient(135deg, #134a38 0%, #1a654c 55%, #1f6a50 100%); color: #fff; padding: 2.75rem 2rem 4.5rem; text-align: center; }
        .page-hero h1 { font-size: 2.1rem; font-weight: 800; }
        .page-hero p { font-size: 1.05rem; opacity: 0.95; }
        .container { max-width: 1100px; margin: -2.5rem auto 3rem; padding: 0 1.5rem; position: relative; }
        .card { background: var(--color-white); border-radius: 14px; box-shadow: var(--shadow-sm); }
        /* The search field is the box; no second card around it */
        .card.searchbar { padding: 0; background: none; border: none; box-shadow: none; display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
        .searchbar .search input, .searchbar .select { height: 48px; background: var(--color-white); box-shadow: var(--shadow-sm); }
        .search { flex: 1 1 260px; position: relative; }
        .search input { width: 100%; height: 46px; border: 1px solid var(--color-border); border-radius: 10px; padding: 0 1rem 0 2.6rem; font: inherit; font-size: 1rem; background: var(--color-white); color: var(--color-text); }
        .search input:focus, .select:focus { outline: 2px solid var(--color-primary); outline-offset: -1px; }
        .search::before { content: ''; position: absolute; left: 0.9rem; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2355696c' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='M16 16l4.5 4.5'/%3E%3C/svg%3E") center / contain no-repeat; }
        .select { height: 46px; border: 1px solid var(--color-border); border-radius: 10px; padding: 0 0.8rem; font: inherit; font-size: 0.93rem; background: var(--color-white); color: var(--color-text); max-width: 100%; }
        .layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 1.25rem; margin-top: 1.25rem; align-items: start; }
        .side { padding: 1rem; position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow-y: auto; overscroll-behavior: contain; }
        .side h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-gray); margin: 0.25rem 0 0.5rem; }
        .side h3:not(:first-child) { margin-top: 1rem; }
        .tagbtn { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; width: 100%; padding: 0.45rem 0.6rem; border: none; border-radius: 8px; background: none; font: inherit; font-size: 0.9rem; color: var(--color-text); cursor: pointer; text-align: left; }
        .tagbtn:hover { background: var(--color-tint); }
        .tagbtn.active { background: var(--color-primary); color: #fff; }
        .tagbtn .n { font-size: 0.78rem; color: var(--color-gray); font-weight: 600; }
        .tagbtn.active .n { color: #f5f2eb; }
        .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
        .dot-legal { background: #7c3aed; } .dot-mhra { background: #d97706; } .dot-safety { background: #dc2626; } .dot-other { background: var(--color-gray); }
        .label-row { display: flex; align-items: center; gap: 0.5rem; }
        .results-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
        .results-head .count { color: var(--color-gray); font-size: 0.92rem; }
        .active-filter { padding: 0.8rem 1rem; margin-bottom: 0.9rem; border: 1px solid color-mix(in srgb, var(--color-primary) 45%, transparent); font-size: 0.9rem; }
        .active-filter strong { color: var(--color-heading); }
        .letter { font-size: 0.85rem; font-weight: 800; color: var(--color-link); margin: 1rem 0 0.5rem 0.2rem; }
        .letter:first-child { margin-top: 0; }
        .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.65rem; }
        .med { display: block; width: 100%; text-align: left; border: none; font: inherit; color: inherit; cursor: pointer; padding: 0.85rem 0.95rem; border-radius: 12px; background: var(--color-white); box-shadow: var(--shadow-sm); transition: box-shadow 0.15s ease, transform 0.15s ease; }
        .med:hover, .med:focus-visible { box-shadow: 0 0 0 2px var(--color-primary), var(--shadow-sm); outline: none; }
        .med .name { font-weight: 700; color: var(--color-heading); text-transform: capitalize; }
        .med .brands { font-size: 0.8rem; color: var(--color-gray); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.45rem; }
        .chip { display: inline-flex; align-items: center; padding: 0.12rem 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 700; line-height: 1.5; }
        .chip-legal { background: transparent; color: var(--legal-fg); border: 1.5px solid currentColor; border-radius: 4px; letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.68rem; transform: rotate(-2deg); }
        .chip-mhra { background: rgba(217, 119, 6, 0.14); color: #b45309; }
        @media (prefers-color-scheme: dark) { .chip-mhra { color: #fbbf24; } }
        .chip-safety { background: var(--safety-bg); color: var(--safety-fg); }
        .chip-other { background: var(--color-light); color: var(--color-gray); }
        .chip-class { background: var(--color-tint); color: var(--color-link); }
        .empty { text-align: center; padding: 2.5rem 1rem; color: var(--color-gray); }
        .note { font-size: 0.82rem; color: var(--color-gray); margin-top: 1.25rem; text-align: center; }
        /* Detail */
        .modal { position: fixed; inset: 0; background: rgba(29, 27, 22, 0.55); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 1000; }
        .modal-content { background: var(--color-white); border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 860px; max-height: calc(100vh - 2rem); overflow-y: auto; }
        .detail-head { padding: 1.4rem 1.5rem 1rem; border-bottom: 1px solid var(--color-border); display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
        .detail-head h2 { font-size: 1.45rem; color: var(--color-heading); text-transform: capitalize; line-height: 1.25; }
        .detail-head .brands { font-size: 0.88rem; color: var(--color-gray); margin-top: 0.2rem; }
        .close { width: 36px; height: 36px; border: none; border-radius: 8px; background: var(--color-light); color: var(--color-text); font-size: 1.3rem; cursor: pointer; flex-shrink: 0; }
        .detail-body { padding: 1.1rem 1.5rem 1.5rem; }
        .section-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-gray); font-weight: 800; margin: 1rem 0 0.5rem; }
        .section-title:first-child { margin-top: 0; }
        .tag-explain { display: flex; gap: 0.7rem; padding: 0.7rem 0.85rem; border-radius: 10px; margin-bottom: 0.45rem; font-size: 0.88rem; }
        .tag-explain.legal { background: var(--legal-bg); }
        .tag-explain.mhra { background: rgba(217, 119, 6, 0.12); }
        .tag-explain .tag-meta { display: block; margin-top: 0.25rem; font-size: 0.8rem; }
        .mhra-item { padding: 0.55rem 0; border-top: 1px solid rgba(217, 119, 6, 0.25); }
        .mhra-item:first-of-type { border-top: none; padding-top: 0.35rem; }
        .mhra-item strong { display: block; }
        .mhra-item .row-actions { display: flex; gap: 0.35rem; margin-top: 0.35rem; }
        .tag-explain.safety { background: var(--safety-bg); }
        .tag-explain.other { background: var(--color-light); }
        .tag-explain strong { display: block; color: var(--color-heading); }
        .ix { padding: 0.7rem 0; border-bottom: 1px solid var(--color-border); font-size: 0.9rem; }
        .ix:last-child { border-bottom: none; }
        .ix-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; font-weight: 700; color: var(--color-heading); }
        .ix-head .with { text-transform: capitalize; }
        .ix .via { font-size: 0.78rem; color: var(--color-gray); font-weight: 500; }
        .ix .mgmt { color: var(--color-gray); margin-top: 0.15rem; }
        .sev { font-size: 0.7rem; font-weight: 800; text-transform: uppercase; padding: 0.1rem 0.45rem; border-radius: 4px; }
        .sev-severe { background: rgba(220, 38, 38, 0.12); color: var(--safety-fg); }
        .sev-moderate { background: rgba(245, 158, 11, 0.16); color: #b45309; }
        .sev-mild { background: var(--color-tint); color: var(--color-link); }
        @media (prefers-color-scheme: dark) { .sev-moderate { color: #fbbf24; } }
        .detail-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1.1rem; }
        .disclaimer { font-size: 0.78rem; color: var(--color-gray); margin-top: 1rem; padding-top: 0.8rem; border-top: 1px solid var(--color-border); }
        /* Monograph (BNF-style) */
        .mono-badge { display: inline-flex; align-items: center; gap: 0.2rem; font-size: 0.7rem; font-weight: 800; color: var(--color-link); background: var(--color-tint); padding: 0.1rem 0.45rem; border-radius: 999px; margin-left: 0.35rem; vertical-align: 0.22em; }
        .mono-toc { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.25rem -1.5rem 0.5rem; padding: 0.55rem 1.5rem; position: sticky; top: 0; z-index: 2; background: var(--color-white); border-bottom: 1px solid var(--color-border); }
        .dose-card { margin: 0.9rem 0 0.6rem; padding: 0.9rem 1.1rem 1rem; border-radius: 12px; background: var(--color-tint); border: 1px solid var(--color-border); }
        .dose-card h3 { font-size: 1rem; color: var(--color-heading); margin-bottom: 0.4rem; }
        .az { display: flex; flex-wrap: wrap; gap: 0.25rem; margin: 0 0 0.9rem; }
        .az a { min-width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; font-size: 0.85rem; font-weight: 700; text-decoration: none; color: var(--color-link); background: var(--color-white); border: 1px solid var(--color-border); }
        .az a:hover { background: var(--color-tint); }
        .letter { scroll-margin-top: 84px; }
        @media (prefers-reduced-motion: reduce) { .mono-toc { position: static; } }
        .mono-toc a { font-size: 0.78rem; font-weight: 600; text-decoration: none; padding: 0.2rem 0.55rem; border-radius: 999px; background: var(--color-light); color: var(--color-text); }
        .mono-toc a:hover { background: var(--color-tint); color: var(--color-link); }
        .mono-section { padding: 0.9rem 0 0.2rem; border-top: 1px solid var(--color-border); scroll-margin-top: 1rem; }
        .mono-section:focus { outline: none; }
        .mono-section h3 { font-size: 0.95rem; font-weight: 800; color: var(--color-link); margin-bottom: 0.45rem; display: flex; align-items: center; gap: 0.5rem; }
        .mono-section h3::before { content: ''; width: 4px; height: 1em; border-radius: 2px; background: var(--color-primary); }
        .mono-section.safety h3 { color: var(--safety-fg); }
        .mono-section.safety h3::before { background: #dc2626; }
        .mono-text { font-size: 0.93rem; overflow-wrap: anywhere; }
        .mono-text p { margin: 0 0 0.55rem; }
        .mono-text h4 { font-size: 0.86rem; font-weight: 800; color: var(--color-heading); margin: 0.7rem 0 0.25rem; }
        .mono-text ul { margin: 0 0 0.55rem 1.2rem; }
        .mono-text ol { margin: 0 0 0.55rem 1.3rem; }
        .mono-text a { color: var(--color-link); }
        .mono-note { border: 1px solid color-mix(in srgb, var(--color-primary) 45%, transparent); background: var(--color-light); padding: 0.55rem 0.8rem; border-radius: 8px; margin: 0.3rem 0 0.6rem; }
        .mono-table { overflow-x: auto; margin: 0.3rem 0 0.7rem; }
        .mono-table table { border-collapse: collapse; width: 100%; min-width: 420px; font-size: 0.86rem; }
        .mono-table th, .mono-table td { border: 1px solid var(--color-border); padding: 0.4rem 0.6rem; text-align: left; vertical-align: top; }
        .mono-table th { background: var(--color-light); color: var(--color-heading); }
        .mono-text li { margin-bottom: 0.15rem; }
        .dose-ind { margin-bottom: 0.8rem; }
        .dose-ind > .ind { font-weight: 800; color: var(--color-heading); margin-bottom: 0.25rem; }
        .dose-route { margin: 0 0 0.35rem 0.9rem; }
        .dose-route > .route { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-gray); margin-bottom: 0.15rem; }
        .dose-row { margin: 0 0 0.3rem 0.9rem; font-size: 0.92rem; white-space: pre-wrap; }
        .dose-row .grp { font-weight: 700; color: var(--color-heading); }
        .mono-meta { font-size: 0.78rem; color: var(--color-gray); margin-top: 0.4rem; }
        .notice { padding: 0.7rem 0.9rem; border-radius: 10px; font-size: 0.88rem; margin: 0.3rem 0 0.6rem; background: var(--color-light); }
        .notice.draft { background: rgba(245, 158, 11, 0.14); }
        /* Editor */
        #editor { z-index: 1100; }
        #editor .modal-content { max-width: 920px; }
        .ed-body { padding: 1rem 1.5rem 1.5rem; }
        .ed-help { font-size: 0.82rem; color: var(--color-gray); margin-bottom: 0.8rem; }
        .ed-help code { background: var(--color-light); padding: 0 0.3rem; border-radius: 4px; }
        .ed-block { border: 1px solid var(--color-border); border-radius: 12px; margin-bottom: 0.6rem; background: var(--color-white); }
        .ed-block > summary { cursor: pointer; padding: 0.65rem 0.9rem; font-weight: 700; color: var(--color-heading); display: flex; align-items: center; gap: 0.6rem; list-style: none; }
        .ed-block > summary .filled { margin-left: auto; }
        .ed-block > summary::-webkit-details-marker { display: none; }
        .ed-block > summary::after { content: '▾'; color: var(--color-gray); }
        .ed-block[open] > summary::after { content: '▴'; }
        .ed-block > summary .filled { font-size: 0.72rem; font-weight: 700; color: var(--q-ok, #15803d); }
        .ed-block .inner { padding: 0 0.9rem 0.9rem; }
        .ed-block textarea, .ed-input { width: 100%; font: inherit; font-size: 0.92rem; color: var(--color-text); background: var(--color-white); border: 1px solid var(--color-border); border-radius: 8px; padding: 0.55rem 0.7rem; }
        .ed-block textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
        .dose-edit { display: grid; grid-template-columns: 1.2fr 1fr 1fr auto; gap: 0.4rem; padding: 0.6rem; border-radius: 10px; background: var(--color-light); margin-bottom: 0.5rem; }
        .dose-edit textarea { grid-column: 1 / 4; min-height: 54px; }
        .dose-edit .ctl { grid-row: 1 / 3; grid-column: 4; display: flex; flex-direction: column; gap: 0.25rem; }
        .icon-btn { width: 30px; height: 30px; border: none; border-radius: 6px; background: var(--color-white); color: var(--color-text); cursor: pointer; font-size: 0.85rem; }
        .icon-btn:hover { background: var(--color-tint); }
        .ed-foot { position: sticky; bottom: 0; background: var(--color-white); border-top: 1px solid var(--color-border); padding: 0.8rem 1.5rem; display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
        .ed-foot .spacer { flex: 1; }
        .rev { padding: 0.6rem 0; border-bottom: 1px solid var(--color-border); display: flex; justify-content: space-between; gap: 0.75rem; align-items: center; font-size: 0.88rem; }
        @media (max-width: 600px) { .dose-edit { grid-template-columns: 1fr auto; } .dose-edit > input, .dose-edit textarea { grid-column: 1; } .dose-edit .ctl { grid-row: 1 / 5; grid-column: 2; } .ed-body, .ed-foot { padding-left: 1rem; padding-right: 1rem; } }
        /* Make flashcards */
        .mk-list { max-height: 52vh; overflow-y: auto; border: 1px solid var(--color-border); border-radius: 12px; }
        .mk-row { display: grid; grid-template-columns: auto 1fr 1fr; gap: 0.75rem; padding: 0.6rem 0.85rem; border-top: 1px solid var(--color-border); font-size: 0.86rem; align-items: start; }
        .mk-row:first-child { border-top: none; }
        .mk-row .f { font-weight: 700; color: var(--color-heading); }
        .mk-row .b { white-space: pre-wrap; max-height: 6.5em; overflow: hidden; color: var(--color-gray); }
        .mk-row input { margin-top: 0.2rem; }
        .mk-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-top: 0.9rem; }
        .mk-opts label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.25rem; }
        .mk-opts select, .mk-opts input { width: 100%; height: 40px; border-radius: 8px; border: 1px solid var(--color-border); background: var(--color-white); color: var(--color-text); font: inherit; padding: 0 0.6rem; }
        /* Compare */
        .cmp-tray { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 900; background: var(--color-dark); color: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); padding: 0.55rem 0.6rem 0.55rem 1rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; max-width: calc(100vw - 1.5rem); }
        .cmp-tray .chip-x { display: inline-flex; align-items: center; gap: 0.3rem; background: rgba(255,255,255,0.14); border-radius: 999px; padding: 0.2rem 0.3rem 0.2rem 0.7rem; font-size: 0.85rem; text-transform: capitalize; }
        .cmp-tray .chip-x button { border: none; background: rgba(255,255,255,0.2); color: #fff; border-radius: 50%; width: 20px; height: 20px; cursor: pointer; line-height: 1; }
        #compare .modal-content { max-width: 1200px; }
        .cmp-scroll { overflow-x: auto; }
        .cmp-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 640px; }
        .cmp-table th, .cmp-table td { text-align: left; vertical-align: top; padding: 0.75rem 0.85rem; border-bottom: 1px solid var(--color-border); font-size: 0.9rem; }
        .cmp-table thead th { position: sticky; top: 0; background: var(--color-white); z-index: 1; font-size: 1.05rem; color: var(--color-heading); text-transform: capitalize; }
        .cmp-table tbody th { width: 170px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-link); background: var(--color-light); position: sticky; left: 0; }
        .cmp-table .none { color: var(--color-gray); }
        .cmp-table .mono-text { font-size: 0.88rem; }
        .cmp-ix { padding: 0.75rem 0.9rem; border-radius: 10px; margin-bottom: 0.8rem; font-size: 0.9rem; background: var(--color-light); }
        .cmp-ix.found { background: rgba(220, 38, 38, 0.08); }
        .cmp-add { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.9rem; }
        .cmp-add input { height: 38px; border-radius: 8px; border: 1px solid var(--color-border); background: var(--color-white); color: var(--color-text); font: inherit; padding: 0 0.7rem; min-width: 220px; }
        @media (max-width: 600px) { .mk-row { grid-template-columns: auto 1fr; } .mk-row .b { grid-column: 2; } .mk-opts { grid-template-columns: 1fr; } }
        .side-toggle { display: none; }
        @media (max-width: 820px) {
            .layout { grid-template-columns: 1fr; }
            .side { position: static; display: none; }
            .side.open { display: block; }
            .side-toggle { display: inline-flex; }
        }
        @media (max-width: 600px) {
            .page-hero { padding: 2rem 1.25rem 4rem; }
            .page-hero h1 { font-size: 1.7rem; }
            .container { padding: 0 0.75rem; }
            .grid { grid-template-columns: 1fr; }
            .detail-head, .detail-body { padding-left: 1.1rem; padding-right: 1.1rem; }
            .mono-toc { margin-left: -1.1rem; margin-right: -1.1rem; padding-left: 1.1rem; padding-right: 1.1rem; flex-wrap: nowrap; overflow-x: auto; }
            .mono-toc a { flex-shrink: 0; }
        }
    
