:root {
  --brand: #0f766e; --brand-d: #115e59; --brand-l: #ccfbf1;
  --ink: #0f172a; --ink-2: #475569; --ink-3: #94a3b8;
  --bg: #f1f5f9; --card: #fff; --line: #e2e8f0;
  --red: #dc2626; --red-l: #fee2e2; --amber: #b45309; --amber-l: #fef3c7;
  --blue: #1d4ed8; --blue-l: #dbeafe; --green: #15803d; --green-l: #dcfce7; --grey-l: #f1f5f9;
  --r: 12px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 8px rgba(15,23,42,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; color: var(--ink); background: var(--bg); -webkit-tap-highlight-color: transparent; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
.hide { display: none !important; }
.muted { color: var(--ink-2); } .small { font-size: .85rem; } .tiny { font-size: .75rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.row { display: flex; gap: .6rem; align-items: center; } .row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; } .grow { flex: 1; } .right { text-align: right; }
.mt { margin-top: 1rem; } .mt-s { margin-top: .5rem; } .mb { margin-bottom: 1rem; }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff; padding: .6rem 1rem; display: flex; align-items: center; gap: .75rem; box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.top .logo { width: 30px; height: 30px; border-radius: 8px; background: #fff; color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: .8rem; }
.top .title { font-weight: 700; line-height: 1.1; }
.top .title small { display: block; font-weight: 400; opacity: .85; font-size: .75rem; }
.top .who { margin-left: auto; text-align: right; font-size: .8rem; line-height: 1.2; }
.top button { background: rgba(255,255,255,.15); color: #fff; border: 0; padding: .45rem .7rem; border-radius: 8px; font: inherit; font-size: .8rem; cursor: pointer; }
.live { width: 9px; height: 9px; border-radius: 50%; background: #fbbf24; display: inline-block; margin-right: 4px; }
.live.on { background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.3); }

main { max-width: 1180px; margin: 0 auto; padding: 1rem; padding-bottom: 6rem; }
.narrow { max-width: 460px; margin: 0 auto; }

/* cards & lists */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: .75rem; }
.list { display: grid; gap: .6rem; }
.rx { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: .8rem .9rem; display: block; color: inherit; box-shadow: var(--shadow); border-left: 4px solid var(--line); }
.rx.p-stat { border-left-color: var(--red); } .rx.p-urgent { border-left-color: var(--amber); }
.rx.fresh { animation: pulse 1.6s ease-in-out 3; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px var(--brand-l); background: #f0fdfa; } }
.rx .name { font-weight: 650; }
.rx .meta { color: var(--ink-2); font-size: .82rem; margin-top: .15rem; }
.empty { text-align: center; color: var(--ink-3); padding: 2.5rem 1rem; }

/* chips */
.chip { display: inline-block; font-size: .72rem; font-weight: 650; padding: .15rem .5rem; border-radius: 999px; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
.s-new { background: var(--blue-l); color: var(--blue); }
.s-read { background: var(--amber-l); color: var(--amber); }
.s-dispensed { background: var(--green-l); color: var(--green); }
.s-partial { background: #ffedd5; color: #c2410c; }
.s-rejected, .s-cancelled { background: var(--grey-l); color: var(--ink-2); }
.pr-stat { background: var(--red); color: #fff; } .pr-urgent { background: var(--amber-l); color: var(--amber); } .pr-routine { background: var(--grey-l); color: var(--ink-2); }
.sch { background: var(--red-l); color: var(--red); }
.badge { background: var(--red); color: #fff; border-radius: 999px; font-size: .7rem; padding: 0 .42rem; margin-left: .3rem; font-weight: 700; }

/* forms */
label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-2); margin: .65rem 0 .25rem; }
label .req { color: var(--red); }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; padding: .62rem .7rem; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-l); border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .7rem; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 .6rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 650; padding: .7rem 1rem; border-radius: 10px; border: 1px solid transparent; cursor: pointer; background: var(--brand); color: #fff; }
.btn:hover { background: var(--brand-d); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--ink); border-color: #cbd5e1; }
.btn.ghost:hover { background: var(--grey-l); }
.btn.danger { background: var(--red); } .btn.warn { background: var(--amber); }
.btn.sm { padding: .4rem .65rem; font-size: .82rem; border-radius: 8px; }
.btn.big { padding: 1rem; font-size: 1.05rem; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid #cbd5e1; border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: .6rem .3rem; font: inherit; font-weight: 600; cursor: pointer; color: var(--ink-2); }
.seg button + button { border-left: 1px solid #cbd5e1; }
.seg button.on { background: var(--brand); color: #fff; }
.seg button.on.stat { background: var(--red); } .seg button.on.urgent { background: var(--amber); }
.roles { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.roles button { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: .8rem .3rem; font: inherit; cursor: pointer; }
.roles button b { display: block; font-size: 1.4rem; }
.roles button.on { border-color: var(--brand); background: #f0fdfa; }
.err { background: var(--red-l); color: #991b1b; padding: .6rem .75rem; border-radius: 10px; margin-top: .75rem; font-size: .9rem; }
.ok { background: var(--green-l); color: #14532d; padding: .6rem .75rem; border-radius: 10px; margin-top: .75rem; font-size: .9rem; }
.note { background: var(--amber-l); color: #78350f; padding: .6rem .75rem; border-radius: 10px; font-size: .88rem; }

/* tabs */
.tabs { display: flex; gap: .35rem; overflow-x: auto; margin-bottom: .8rem; scrollbar-width: none; }
.tabs button, .tabs a { flex: none; border: 1px solid var(--line); background: #fff; color: var(--ink-2); border-radius: 999px; padding: .45rem .85rem; font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; }
.tabs .on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* medicine search */
.search { position: relative; }
.results { position: absolute; left: 0; right: 0; top: 100%; z-index: 15; background: #fff; border: 1px solid var(--line); border-radius: 10px; margin-top: 4px; box-shadow: 0 8px 24px rgba(15,23,42,.12); max-height: 320px; overflow-y: auto; }
.results button { display: block; width: 100%; text-align: left; border: 0; background: #fff; padding: .6rem .75rem; font: inherit; cursor: pointer; border-bottom: 1px solid var(--grey-l); }
.results button:hover, .results button:focus { background: #f0fdfa; }
.line { border: 1px solid var(--line); border-radius: 12px; padding: .75rem; margin-top: .6rem; background: #fcfdfd; }
.line .x { border: 0; background: var(--grey-l); color: var(--ink-2); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 1.1rem; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: .75rem .9rem; }
.stat b { font-size: 1.6rem; display: block; line-height: 1.1; }
.stat span { font-size: .78rem; color: var(--ink-2); }
.stat.hot b { color: var(--red); }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-2); font-weight: 650; }
.scroll { overflow-x: auto; }

/* detail */
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem .9rem; }
.kv div span { display: block; font-size: .72rem; text-transform: uppercase; color: var(--ink-3); font-weight: 650; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .35rem 0 .35rem 1.1rem; position: relative; font-size: .88rem; }
.timeline li::before { content: ""; position: absolute; left: 0; top: .75rem; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.timeline li.done::before { background: var(--brand); }
.disp { border: 1px solid var(--line); border-radius: 12px; padding: .75rem; margin-top: .6rem; }
.actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 1rem 0 .5rem; display: flex; gap: .5rem; flex-wrap: wrap; }

/* layout for pharmacy on desktop */
.split { display: grid; grid-template-columns: 380px 1fr; gap: 1rem; align-items: start; }
.split .pane { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow-y: auto; }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal .card { width: 100%; max-width: 460px; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 60; display: grid; gap: .5rem; max-width: 360px; }
.toast { background: var(--ink); color: #fff; padding: .75rem 1rem; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: .9rem; cursor: pointer; }
.toast.alert { background: var(--red); }
.fab { position: fixed; right: 1rem; bottom: 1rem; z-index: 25; border-radius: 999px; padding: 1rem 1.3rem; box-shadow: 0 8px 24px rgba(15,118,110,.35); }

.bars { display: grid; gap: .35rem; }
.bar { display: grid; grid-template-columns: 140px 1fr 40px; gap: .5rem; align-items: center; font-size: .85rem; }
.bar i { display: block; height: 10px; background: var(--brand); border-radius: 5px; min-width: 2px; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .split .pane { position: static; max-height: none; }
  .split .detail-pane:empty { display: none; }
}
@media (max-width: 640px) {
  main { padding: .75rem; padding-bottom: 6rem; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .top .who .nm { display: none; }
  .bar { grid-template-columns: 100px 1fr 32px; }
  .hide-m { display: none; }
}

/* print: a clean prescription slip */
@media print {
  .top, .actions, .tabs, .fab, .toasts, .no-print, .split .pane { display: none !important; }
  body { background: #fff; } main { padding: 0; max-width: none; }
  .split { display: block; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .print-head { display: block !important; }
}
.print-head { display: none; border-bottom: 2px solid #000; margin-bottom: .75rem; padding-bottom: .4rem; }
.center { text-align: center; }
input[type=checkbox] { width: auto; margin-right: .4rem; }
label.btn { margin: 0; font-size: inherit; }
.toast { white-space: pre-line; }
.rep { gap: .75rem; } .rep .card + .card { margin-top: 0; }
@media (max-width: 640px) { .rep { grid-template-columns: 1fr; } }
.pharm-rmk { color: #c2410c; margin-top: .15rem; }
.top button { white-space: nowrap; }
@media (max-width: 640px) { .top { padding: .5rem .7rem; gap: .5rem; } .top .title { font-size: .85rem; } .top .who { font-size: .7rem; } }

/* multi-hospital additions */
.planbar{background:#ecfdf5;color:#065f46;border-bottom:1px solid #a7f3d0;padding:.45rem 1rem;font-size:.85rem;text-align:center}
.planbar.hot{background:#fef2f2;color:#991b1b;border-color:#fecaca}
.codebox{display:flex;flex-direction:column;align-items:center;background:#f0fdfa;border:2px dashed #0f766e;border-radius:12px;padding:.8rem;margin:.8rem 0}
.codebox b{font-size:1.9rem;letter-spacing:.12em;color:#0f766e;font-family:ui-monospace,Menlo,monospace}
.ok-t{color:#047857;font-weight:600}
.err-t{color:#b91c1c}
