/* MedLookup mobile */
:root {
    --brand: #0d7a6f;
    --brand-dark: #095c54;
    --brand-soft: #e3f3f0;
    --bg: #f4f7f6;
    --card: #ffffff;
    --text: #1b2826;
    --muted: #63736f;
    --line: #e2e8e6;
    --rx: #7c3aed;
    --rx-soft: #f1eafe;
    --otc: #0f766e;
    --otc-soft: #dcf5f1;
    --danger: #c62828;
    --danger-soft: #fdecec;
    --warn: #a15c00;
    --warn-soft: #fff4e0;
    --ok: #2e7d32;
    --radius: 14px;
    --tabbar: 64px;
    --shadow: 0 1px 2px rgba(16, 40, 36, .06), 0 2px 8px rgba(16, 40, 36, .05);
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --brand: #2bb3a3;
        --brand-dark: #5fd0c2;
        --brand-soft: #123b37;
        --bg: #0f1514;
        --card: #18201f;
        --text: #e5eeec;
        --muted: #93a5a1;
        --line: #26302e;
        --rx: #b79cff;
        --rx-soft: #2a2140;
        --otc: #5fd0c2;
        --otc-soft: #133a36;
        --danger: #ff7b7b;
        --danger-soft: #3a1c1c;
        --warn: #ffbf5e;
        --warn-soft: #362812;
        --ok: #7bd389;
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
code { font: 600 .9em ui-monospace, SFMono-Regular, Menlo, monospace; }
mark { background: #ffe58a; color: #1b2826; padding: 0 2px; border-radius: 3px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.ms-auto { margin-left: auto; }
.clamp1, .clamp2 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.clamp1 { -webkit-line-clamp: 1; }
.clamp2 { -webkit-line-clamp: 2; }
[hidden] { display: none !important; }

/* ---------- top bar & tabs ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 4px;
    min-height: 56px;
    padding: env(safe-area-inset-top) 8px 0 12px;
    background: var(--brand);
    color: #fff;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 1.1rem; }
.topbar-brand img { border-radius: 8px; box-shadow: 0 0 0 2px rgba(255, 255, 255, .35); }
.topbar-title { font-size: 1.05rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar-btn { display: grid; place-items: center; width: 44px; height: 44px; flex: none; color: #fff; font-size: 1.3rem; border-radius: 50%; }
.topbar-btn:active { background: rgba(255, 255, 255, .15); }

.page {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px 16px calc(var(--tabbar) + 28px + env(safe-area-inset-bottom));
}

.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: flex;
    height: calc(var(--tabbar) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card);
    border-top: 1px solid var(--line);
}
.tabbar a {
    position: relative;
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted);
    font-size: .72rem; font-weight: 500;
}
.tabbar a i { font-size: 1.35rem; line-height: 1; }
.tabbar a.on { color: var(--brand); }
.tabbar .tab-scan i {
    display: grid; place-items: center;
    width: 48px; height: 48px; margin-top: -22px;
    background: var(--brand); color: #fff;
    border-radius: 50%;
    border: 4px solid var(--card);
    font-size: 1.25rem;
    box-shadow: 0 4px 10px rgba(13, 122, 111, .35);
}
.cabinet-count {
    position: absolute; top: 6px; left: 50%; margin-left: 6px;
    min-width: 18px; height: 18px; padding: 0 5px;
    background: var(--danger); color: #fff;
    border-radius: 9px;
    font-size: .68rem; line-height: 18px; text-align: center;
}

/* ---------- buttons, forms ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 46px; padding: 0 18px;
    border: 1px solid transparent; border-radius: 12px;
    font-family: inherit; font-size: .95rem; font-weight: 600; line-height: 1.2;
    cursor: pointer;
    text-align: center;
}
.btn:disabled, .btn.disabled { opacity: .5; pointer-events: none; }
.btn-brand { background: var(--brand); color: #fff; }
.btn-brand:active { background: var(--brand-dark); }
.btn-ghost { background: var(--card); color: var(--text); border-color: var(--line); }
.btn-ghost:active { background: var(--brand-soft); }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: .85rem; }
.btn-block { display: flex; width: 100%; margin-top: 12px; }
.btn-danger { color: var(--danger); }
.btn.is-saved { background: var(--ok); color: #fff; border-color: var(--ok); }

.searchbar {
    display: flex; align-items: center; gap: 8px;
    height: 50px; padding: 0 6px 0 14px;
    background: var(--card);
    border: 1px solid var(--line); border-radius: 14px;
    box-shadow: var(--shadow);
}
.searchbar > i { color: var(--muted); }
.searchbar input {
    flex: 1; min-width: 0; height: 100%;
    border: 0; background: none; outline: none;
    color: var(--text); font: inherit; font-size: 16px; /* 16px stops iPhone zooming in */
}
.searchbar:focus-within { border-color: var(--brand); }
.searchbar-scan, .searchbar-go {
    display: grid; place-items: center; width: 40px; height: 40px; flex: none;
    border: 0; border-radius: 10px;
    background: var(--brand-soft); color: var(--brand); font-size: 1.15rem;
}
.searchbar-go { background: var(--brand); color: #fff; }

.form label, .cab-body label, .manual label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
.form input, .cab-body input, .cab-body textarea, .ix-row input {
    display: block; width: 100%; margin-top: 4px;
    height: 48px; padding: 0 14px;
    background: var(--card); color: var(--text);
    border: 1px solid var(--line); border-radius: 12px;
    font: inherit; font-size: 16px;
}
.cab-body textarea { height: auto; padding: 10px 14px; resize: vertical; }
.form input:focus, .cab-body input:focus, .cab-body textarea:focus, .ix-row input:focus { outline: none; border-color: var(--brand); }

/* ---------- common blocks ---------- */
.page-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 4px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.05rem; margin: 26px 0 10px; }
.section-title a { font-size: .85rem; font-weight: 600; }
.count { color: var(--muted); font-size: .85rem; margin: 14px 2px 8px; }
.fineprint { color: var(--muted); font-size: .8rem; margin-top: 24px; }
.more { display: inline-block; margin-top: 10px; font-weight: 600; font-size: .9rem; }

.note { padding: 12px 14px; border-radius: 12px; margin: 12px 0; font-size: .92rem; }
.note-info { background: var(--brand-soft); }
.note-success { background: var(--otc-soft); }
.note-warning { background: var(--warn-soft); color: var(--warn); }
.note-danger { background: var(--danger-soft); color: var(--danger); }

.empty { text-align: center; padding: 36px 12px; color: var(--muted); }
.empty > i { font-size: 2.6rem; color: var(--brand); opacity: .7; }
.empty h2 { color: var(--text); font-size: 1.15rem; margin: 10px 0 6px; }
.empty p { margin: 0; }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 12px -16px 0; padding: 0 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 14px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); color: var(--text); font-size: .88rem; text-transform: capitalize; }

.seg { display: flex; gap: 6px; overflow-x: auto; margin: 12px -16px 0; padding: 0 16px 2px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg a { flex: none; padding: 7px 14px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); color: var(--muted); font-size: .85rem; font-weight: 600; }
.seg a.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.tag { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.tag-rx { background: var(--rx-soft); color: var(--rx); }
.tag-otc { background: var(--otc-soft); color: var(--otc); }
.tag-class { background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: normal; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

.badge { flex: none; display: inline-grid; place-items: center; min-width: 34px; height: 24px; padding: 0 7px; border-radius: 7px; font-size: .72rem; font-weight: 700; }
.class-classi { background: var(--danger); color: #fff; }
.class-classii { background: #f0a020; color: #2b1a00; }
.class-classiii { background: #8a9a96; color: #fff; }

/* lists of tappable rows */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list.flat { box-shadow: none; }
.row-link { display: flex; align-items: center; gap: 12px; padding: 13px 14px; color: var(--text); border-top: 1px solid var(--line); min-height: 56px; }
.row-link:first-child { border-top: 0; }
.row-link:active { background: var(--brand-soft); }
.row-link > .bi-chevron-right, .row-link > .bi-box-arrow-up-right { color: var(--muted); font-size: .9rem; }
.row-icon { color: var(--brand); font-size: 1.2rem; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-main strong { font-weight: 600; font-size: .95rem; }
.row-main small { font-size: .8rem; color: var(--muted); }

/* ---------- home ---------- */
.hello h1 { font-size: 1.55rem; font-weight: 700; }
.hello p { color: var(--muted); margin: 4px 0 14px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); box-shadow: var(--shadow); }
.tile i { font-size: 1.5rem; color: var(--brand); margin-bottom: 6px; }
.tile strong { font-size: .95rem; }
.tile span { font-size: .8rem; color: var(--muted); }
.tile-scan { background: var(--brand); border-color: var(--brand); color: #fff; }
.tile-scan i, .tile-scan span { color: rgba(255, 255, 255, .9); }
.tile:active { transform: scale(.98); }

.refill-alert { display: flex; align-items: center; gap: 12px; margin-top: 18px; padding: 12px 14px; background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); }
.refill-alert > i { font-size: 1.4rem; }
.refill-alert div { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: .85rem; }
.refill-alert strong { font-size: .95rem; }
.refill-alert a { font-weight: 700; color: inherit; }

/* ---------- drug page ---------- */
.drug-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.drug-card h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 2px; overflow-wrap: anywhere; }
.drug-card h1.h-small { font-size: 1.1rem; margin: 10px 0; }
.drug-card .generic { color: var(--muted); margin: 0 0 10px; overflow-wrap: anywhere; }
.drug-card .tags { margin: 8px 0; }
.drug-meta { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: .85rem; margin: 10px 0 0; }
.actions { display: flex; gap: 8px; margin-top: 14px; }
.actions .btn-brand { flex: 1; }

details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }

.sections { display: flex; flex-direction: column; gap: 8px; }
.section, .boxed { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.section > summary, .boxed > summary {
    display: flex; align-items: center; gap: 8px;
    padding: 15px 16px; font-weight: 600;
}
.section > summary small { color: var(--muted); font-weight: 500; }
.section > summary::after, .boxed > summary::after { content: "\F282"; font-family: bootstrap-icons; margin-left: auto; color: var(--muted); transition: transform .2s; }
.section[open] > summary::after, .boxed[open] > summary::after { transform: rotate(180deg); }
.section > :not(summary), .boxed > :not(summary) { padding: 0 16px; }
.section[open], .boxed[open] { padding-bottom: 14px; }
.boxed { background: var(--danger-soft); border-color: var(--danger); margin-bottom: 14px; }
.boxed > summary { color: var(--danger); flex-wrap: wrap; }
.boxed > summary small { width: 100%; padding-left: 26px; font-weight: 500; font-size: .8rem; }
.label-text { font-size: .93rem; overflow-wrap: anywhere; }
.label-text p { margin: 0 0 10px; }
.label-text ul { padding-left: 20px; margin: 0 0 10px; }
.label-text table { display: block; overflow-x: auto; font-size: .8rem; border-collapse: collapse; }
.label-text td, .label-text th { border: 1px solid var(--line); padding: 4px 6px; }

.bars { list-style: none; margin: 0; padding: 0 16px !important; }
.bars li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin-bottom: 9px; font-size: .85rem; }
.bars b { grid-column: 1 / -1; grid-row: 2; height: 6px; border-radius: 3px; background: var(--line); position: relative; overflow: hidden; }
.bars b::before { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--w); background: var(--brand); border-radius: 3px; }
.bars small { color: var(--muted); }

.product { padding: 10px 0; border-top: 1px solid var(--line); font-size: .88rem; }
.product:first-of-type { border-top: 0; }
.product > span { display: block; color: var(--muted); }
.product ul { list-style: none; padding: 0; margin: 6px 0 0; }
.product li { padding: 3px 0; }

.facts { margin: 14px 0 0; display: flex; flex-direction: column; gap: 10px; }
.facts div { border-top: 1px solid var(--line); padding-top: 10px; }
.facts dt { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.facts dd { margin: 2px 0 0; font-size: .92rem; overflow-wrap: anywhere; }

/* ---------- scanner ---------- */
.scanner { margin-bottom: 18px; }
.scan-camera { position: relative; aspect-ratio: 4 / 3; background: #000; border-radius: var(--radius); overflow: hidden; }
.scan-camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 22% 10%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); }
.scan-frame::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ff5252; box-shadow: 0 0 8px #ff5252; animation: scanline 1.6s ease-in-out infinite alternate; }
@keyframes scanline { from { transform: translateY(-38px); } to { transform: translateY(38px); } }
@media (prefers-reduced-motion: reduce) { .scan-frame::after { animation: none; } }
.scan-torch { position: absolute; right: 12px; bottom: 12px; width: 46px; height: 46px; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff; font-size: 1.2rem; }
.scan-torch.on { background: #ffd54f; color: #222; }
.scan-status { text-align: center; color: var(--muted); font-size: .92rem; margin: 12px 4px 0; }
.scanner .btn-block { position: relative; }
.manual { margin-top: 10px; }
.howto { margin-top: 24px; }
.howto h2 { font-size: 1rem; margin-bottom: 8px; }
.howto ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.howto li { display: flex; gap: 12px; font-size: .88rem; color: var(--muted); }
.howto li i { color: var(--brand); font-size: 1.25rem; }
.howto strong { color: var(--text); }
.scanned { color: var(--muted); font-size: .85rem; margin: 0 0 10px; overflow-wrap: anywhere; }
.gs1 { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.gs1 div { flex: 1 1 30%; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.gs1 small { display: block; color: var(--muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; }
.gs1 strong { overflow-wrap: anywhere; }
.gs1 em { display: block; font-style: normal; color: var(--danger); font-weight: 700; font-size: .85rem; }
.gs1-expired div:first-child { border-color: var(--danger); background: var(--danger-soft); }

/* ---------- interactions ---------- */
.ix-form { margin: 14px 0 18px; }
.ix-row { display: flex; gap: 8px; margin-bottom: 8px; }
.ix-row input { margin: 0; }
.ix-remove { flex: none; width: 48px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--muted); font-size: 1rem; }
.ix-buttons { display: flex; gap: 8px; }
.ix-buttons .btn { flex: 1; }
.ix-pair { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.ix-pair > summary { padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.ix-pair > summary span { font-size: .85rem; font-weight: 600; }
.ix-found { border-left-color: var(--danger); }
.ix-found > summary span { color: var(--danger); }
.ix-class { border-left-color: #f0a020; }
.ix-class > summary span { color: var(--warn); }
.ix-none > summary span { color: var(--ok); }
.ix-pair > :not(summary) { padding: 0 16px 12px; margin: 0; }
.ix-hits { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.ix-hits li { font-size: .88rem; border-top: 1px solid var(--line); padding-top: 10px; }
.ix-hits small { display: block; color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; margin-bottom: 2px; }

/* ---------- my medicines ---------- */
.cab-add { margin: 14px 0; }
.cab-list { display: flex; flex-direction: column; gap: 8px; }
.cab-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.cab-item > summary { display: flex; align-items: center; gap: 10px; padding: 14px 16px; }
.cab-item > summary .row-main strong { font-size: 1rem; }
.cab-refill { flex: none; font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; }
.cab-refill:empty { display: none; }
.cab-refill.ok { background: var(--otc-soft); color: var(--otc); }
.cab-refill.due { background: var(--warn-soft); color: var(--warn); }
.cab-body { padding: 4px 16px 14px; border-top: 1px solid var(--line); }
.cab-body label:first-child { margin-top: 12px; }
.cab-actions { display: flex; justify-content: space-between; gap: 8px; }
.cab-saved { display: block; text-align: right; color: var(--muted); font-size: .75rem; min-height: 1em; margin-top: 6px; }

/* ---------- me ---------- */
.profile { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.profile h1 { font-size: 1.3rem; }
.profile p { margin: 0; font-size: .88rem; overflow-wrap: anywhere; }
.avatar { display: grid; place-items: center; width: 56px; height: 56px; flex: none; border-radius: 50%; background: var(--brand); color: #fff; font-size: 1.5rem; font-weight: 700; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; color: var(--muted); font-size: .85rem; }

/* ---------- toast ---------- */
.toast {
    position: fixed; left: 50%; bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); z-index: 40;
    transform: translateX(-50%);
    max-width: calc(100% - 32px);
    padding: 11px 18px; border-radius: 12px;
    background: #1b2826; color: #fff; font-size: .9rem; font-weight: 500;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
    transition: opacity .4s;
}
.toast.gone { opacity: 0; }
.class-notyetclassified { background: var(--brand-soft); color: var(--brand); }
