/* RxNotes. Same palette as the study guides so the portal and the documents feel like one thing.
   Kept to widely supported CSS (no color-mix, no :has, no container queries) for older phones. */
:root {
  --bg: #f6f4ef; --card: #fff; --ink: #1f2328; --mute: #5b6370; --line: #e3e0d8;
  --acc: #1f6f78; --acc-ink: #fff; --acc-soft: #e6f1f2; --acc2: #b4532a;
  --ok: #3a9d78; --ok-soft: rgba(58, 157, 120, .14); --bad: #c94a4a; --bad-soft: rgba(201, 74, 74, .12);
  --chip: #eeebe4; --gold: #ffd166;
  --band1: #1f6f78; --band2: #1f4f7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 6px 20px rgba(0, 0, 0, .06);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, .06), 0 12px 30px rgba(0, 0, 0, .10);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13161a; --card: #1c2026; --ink: #e6e8eb; --mute: #9aa3ae; --line: #2e343c;
    --acc: #5fb7c0; --acc-ink: #0d1417; --acc-soft: #1b2e31; --acc2: #e08a5f;
    --ok: #4fb88f; --ok-soft: rgba(79, 184, 143, .16); --bad: #d06464; --bad-soft: rgba(208, 100, 100, .16);
    --chip: #262b32; --band1: #174f56; --band2: #172f4d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-hover: 0 8px 26px rgba(0, 0, 0, .45);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--acc); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--mute); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 560px) { .hide-sm { display: none; } }

/* ---------- header / brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.25rem; letter-spacing: -.01em; color: inherit; text-decoration: none; }
.brand img { width: 36px; height: 36px; border-radius: 9px; }
.nav { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.navlink { color: inherit; text-decoration: none; font-size: .9rem; font-weight: 600; padding: 7px 11px; border-radius: 999px; background: rgba(255, 255, 255, .14); white-space: nowrap; }
.navlink:hover { background: rgba(255, 255, 255, .24); }
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top .wrap { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.top .navlink { background: var(--chip); }

.hero-band { color: #fff; background: var(--band1); background: linear-gradient(135deg, var(--band1), var(--band2)); position: relative; overflow: hidden; padding: 18px 0 26px; }
.hero-band::after { /* soft pills pattern */
  content: ""; position: absolute; right: -40px; top: -30px; width: 340px; height: 340px; opacity: .10; pointer-events: none;
  background: radial-gradient(circle at 30% 30%, #fff 0 18px, transparent 19px), radial-gradient(circle at 70% 60%, #fff 0 30px, transparent 31px), radial-gradient(circle at 40% 80%, #fff 0 12px, transparent 13px);
}
.hero-band .wrap { position: relative; z-index: 1; }
.topline { display: flex; align-items: center; gap: 12px; }
.tagline { margin: 14px 0 16px; font-size: 1.12rem; opacity: .92; max-width: 640px; }
.counters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.counter { background: rgba(255, 255, 255, .14); border-radius: 999px; padding: 4px 12px; font-size: .9rem; }
.counter b { font-size: 1rem; }

.search { position: relative; max-width: 720px; }
.search input { width: 100%; padding: 14px 16px 14px 46px; border: 0; border-radius: 999px; background: #fff; color: #1f2328; font-size: 1rem; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); -webkit-appearance: none; appearance: none; }
.search input:focus { outline: 3px solid var(--gold); outline-offset: 2px; }
.search svg { position: absolute; left: 17px; top: 50%; transform: translateY(-50%); color: #5b6370; }

/* ---------- recent comments ---------- */
.section-title { font-size: 1.05rem; margin: 26px 0 12px; color: var(--mute); font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.section-title b { color: var(--ink); }
.group-count { background: var(--chip); color: var(--mute); border-radius: 999px; font-size: .78rem; padding: 1px 9px; font-weight: 600; }
.recent-row { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
.quote { flex: 0 0 280px; scroll-snap-align: start; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.quote p { margin: 0 0 6px; font-size: .93rem; }
.quote small { color: var(--mute); }

/* ---------- filters ---------- */
.controls { padding: 6px 0 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); max-width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: .9rem; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); }
.chip.subject { border-left: 4px solid var(--subj, var(--acc)); }
.chip.subject[aria-pressed="true"] { background: var(--subj, var(--acc)); border-color: var(--subj, var(--acc)); color: #fff; }
.tagbox { margin-top: 10px; }
.tagbox summary { cursor: pointer; color: var(--mute); font-size: .9rem; }
.tagbox .chips { margin-top: 8px; }
.tagbox .chip { font-size: .82rem; padding: 3px 10px; }
.linkbtn { background: none; border: 0; color: var(--acc); cursor: pointer; padding: 4px 6px; text-decoration: underline; font-size: .9rem; }
.count { color: var(--mute); font-size: .9rem; margin: 8px 0 0; min-height: 1em; }

/* ---------- document cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--subj, var(--acc)); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; transition: transform .15s ease, box-shadow .15s ease; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.cover { position: relative; display: block; height: 150px; background: #fff; overflow: hidden; border-bottom: 1px solid var(--line); }
.cover img { width: 100%; height: 100%; object-fit: cover; object-position: center top; display: block; transition: transform .3s ease; }
.card:hover .cover img { transform: scale(1.04); }
.cover-icon { display: flex; height: 100%; align-items: center; justify-content: center; font-size: 3.2rem; background: var(--chip); }
.subject-pill, .new-pill { position: absolute; top: 10px; font-size: .78rem; font-weight: 700; border-radius: 999px; padding: 3px 10px; box-shadow: 0 2px 8px rgba(0, 0, 0, .18); }
.subject-pill { left: 10px; background: var(--subj, var(--acc)); color: #fff; }
.new-pill { right: 10px; background: var(--gold); color: #3b2a00; }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card h3 { margin: 0; font-size: 1.16rem; line-height: 1.3; }
.card h3 a { color: var(--ink); text-decoration: none; }
.card h3 a:hover { color: var(--acc); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: .8rem; }
.badge { background: var(--acc-soft); color: var(--acc); border-radius: 6px; padding: 2px 8px; font-weight: 700; }
.badge.plain { background: var(--chip); color: var(--mute); font-weight: 500; }
.desc { margin: 0; color: var(--mute); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.snippet { font-size: .88rem; border-left: 3px solid var(--acc); padding: 4px 10px; color: var(--mute); background: var(--acc-soft); border-radius: 4px; }
.snippet mark { background: none; color: var(--ink); font-weight: 700; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-size: .76rem; background: var(--chip); border-radius: 999px; padding: 2px 9px; color: var(--mute); border: 0; cursor: pointer; }
.stats { display: flex; gap: 12px; color: var(--mute); font-size: .86rem; margin-top: auto; padding-top: 4px; }
.card-actions { display: flex; gap: 8px; }
.card-actions .btn { flex: 1; justify-content: center; }
.extras { margin: 0; font-size: .8rem; color: var(--mute); }
.extras a { color: var(--mute); }
.extras a:hover { color: var(--acc); }

.btn { display: inline-flex; align-items: center; gap: 6px; border-radius: 10px; padding: 9px 14px; font-weight: 650; text-decoration: none; border: 1px solid var(--acc); cursor: pointer; font-size: .93rem; line-height: 1.2; }
.btn.primary { background: var(--acc); color: var(--acc-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--acc); }
.btn.ghost:hover { background: var(--acc-soft); }
.btn:disabled { opacity: .5; cursor: default; }
.empty { text-align: center; padding: 50px 10px; color: var(--mute); }
footer.site { color: var(--mute); font-size: .85rem; padding: 44px 16px 30px; text-align: center; }

/* ---------- login ---------- */
body.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--band1); background: linear-gradient(135deg, var(--band1), var(--band2)); }
.login-card { background: var(--card); border-radius: 18px; padding: 28px 24px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); text-align: center; }
.login-card h1 { margin: 10px 0 4px; }
.login-card form { text-align: left; }
.login-card img { border-radius: 14px; }

/* ---------- reader ---------- */
.readerbar { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); border-top: 4px solid var(--subj, var(--acc)); }
.readerbar .wrap { display: flex; align-items: center; gap: 10px; min-height: 54px; max-width: none; }
.readerbar .title { flex: 1; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.readerbar .back { text-decoration: none; font-weight: 650; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.readerbar .back img { width: 26px; height: 26px; border-radius: 7px; }
.iconbtn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); text-decoration: none; color: var(--ink); cursor: pointer; font-size: .9rem; white-space: nowrap; }
.menu { position: relative; }
.menu .pop { position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px rgba(0, 0, 0, .15); min-width: 260px; padding: 6px; display: none; }
.menu.open .pop { display: block; }
.pop a { display: block; padding: 9px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.pop a:hover { background: var(--chip); }
.pop small { display: block; color: var(--mute); }
.pop .navlink { display: block; background: none; border-radius: 8px; padding: 9px 10px; font-weight: 500; }
.pop .navlink:hover { background: var(--chip); }
.pop .hide-sm { display: inline; }
iframe.doc { display: block; width: 100%; border: 0; min-height: 70vh; background: var(--bg); }

/* ---------- comments ---------- */
.feedback { border-top: 1px solid var(--line); background: var(--card); padding: 26px 0 50px; }
.feedback .wrap { max-width: 760px; }
.feedback h2 { margin: 0 0 4px; font-size: 1.3rem; }
.dlrow { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
form.comment { display: grid; gap: 10px; margin: 16px 0 28px; }
form.comment label { font-size: .9rem; font-weight: 600; }
form.comment input[type=text], form.comment input[type=password], form.comment textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 1rem; }
form.comment textarea { min-height: 110px; resize: vertical; }
.votes { display: flex; gap: 8px; flex-wrap: wrap; }
.vote { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 7px 14px; cursor: pointer; }
.vote[aria-pressed="true"][data-v="1"] { border-color: var(--ok); background: var(--ok-soft); }
.vote[aria-pressed="true"][data-v="-1"] { border-color: var(--bad); background: var(--bad-soft); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400 !important; color: var(--mute); }
.check input { margin-top: 4px; }
.hp { position: absolute; left: -5000px; }
.msg { font-size: .92rem; min-height: 1.2em; }
.msg.err { color: var(--bad); } .msg.ok { color: var(--ok); }
.clist { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.clist li { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--bg); }
.clist .who { font-size: .85rem; color: var(--mute); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.clist .who b { color: var(--ink); }
.clist p { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: break-word; word-wrap: break-word; }

/* ---------- admin ---------- */
.hero { padding: 28px 0 8px; }
.hero h1 { margin: 0 0 4px; font-size: 1.8rem; }
table.admin { width: 100%; border-collapse: collapse; background: var(--card); font-size: .92rem; }
table.admin th, table.admin td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; vertical-align: top; }
table.admin tr.hidden td { opacity: .5; }
table.admin td.body { white-space: pre-wrap; overflow-wrap: break-word; max-width: 420px; }
.tablewrap { overflow-x: auto; }
.tabs { display: flex; gap: 6px; margin: 22px 0 6px; border-bottom: 1px solid var(--line); }
.tabs [role=tab] { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 14px; font-weight: 650; color: var(--mute); cursor: pointer; }
.tabs [role=tab][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--acc); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 14px 0 4px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; }
.kpi b { font-size: 1.6rem; line-height: 1.1; }
.kpi span { color: var(--mute); font-size: .86rem; }
.kpi.warn b { color: var(--bad); }
.small { font-size: .85rem; margin: -4px 0 8px; }
.bad { color: var(--bad); font-weight: 600; }
.journal { list-style: none; padding: 0; margin: 10px 0 0; border: 1px solid var(--line); border-radius: 12px; background: var(--card); overflow: hidden; }
.journal li { display: grid; grid-template-columns: 120px 1fr auto; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: .92rem; align-items: baseline; }
.journal li:last-child { border-bottom: 0; }
.ev-time { color: var(--mute); font-size: .84rem; white-space: nowrap; }
.ev-where { color: var(--mute); font-size: .8rem; text-align: right; }
.ev-signin_failed { background: var(--bad-soft); }
@media (max-width: 560px) {
  .journal li { grid-template-columns: 1fr; gap: 2px; }
  .ev-where { text-align: left; }
}

/* ---------- phones ---------- */
@media (max-width: 560px) {
  .hero-band { padding: 12px 0 20px; }
  .tagline { font-size: 1rem; margin: 10px 0 14px; }
  .grid { grid-template-columns: 1fr; gap: 14px; }
  .cover { height: 130px; }
  .quote { flex-basis: 78vw; }
  select { flex: 1 1 45%; }
}
/* companion document (medication table) under the guide's buttons */
.card-actions.companion { margin-top: -2px; }
.btn.soft { background: var(--acc-soft); color: var(--acc); border-color: transparent; }
.btn.soft:hover { filter: brightness(.97); border-color: var(--acc); }
.card-actions .btn.icon { flex: 0 0 auto; padding: 9px 12px; }
.card-actions .btn { white-space: nowrap; }
