/* BIEMR — offline stylesheet (no external fonts or CDNs) */
:root {
  --bg: #f5f5f5; --surface: #ffffff; --ink: #1a1a1a; --muted: #666666; --line: #e2e2e2;
  --brand: #111111; --brand-ink: #ffffff; --brand-soft: #ececec; --accent: #3a3a3a;
  --blue: #2c5d8f; --blue-bg: #e6eef7; --green: #2e6b3c; --green-bg: #e3f1e6;
  --amber: #8a5a00; --amber-bg: #fbf0d9; --red: #a3302a; --red-bg: #fbe5e3; --gray-bg: #eceeee;
  --radius: 8px; --shadow: 0 1px 2px rgba(20, 40, 40, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
html { font-size: 14px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0 0 .15rem; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; font-weight: 650; }
h3 { font-size: .95rem; margin: 1.3rem 0 .5rem; font-weight: 650; color: var(--brand); text-transform: uppercase; letter-spacing: .04em; }
h2 small, h3 small { font-weight: 400; text-transform: none; letter-spacing: 0; }
.muted { color: var(--muted); } .small { font-size: .88rem; } .center { text-align: center; }
.mono { font-family: var(--mono); font-size: .92em; } .strong { font-weight: 650; }
.pre { white-space: pre-wrap; margin: .2rem 0 .6rem; }
code { font-family: var(--mono); background: var(--gray-bg); padding: 0 .3em; border-radius: 3px; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: 0 1.25rem; height: 52px;
  background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 10; }
.topbar a { color: var(--brand-ink); }
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: .02em; display: flex; align-items: center; gap: 2px; }
.logo-img { width: 32px; height: 32px; border-radius: 6px; object-fit: contain; margin-right: 6px; display: block; }
.brand-text { color: #ffffff; }
.topbar nav { display: flex; gap: .25rem; flex: 1; }
.topbar nav a { padding: .4rem .75rem; border-radius: 6px; opacity: .85; }
.topbar nav a:hover { background: rgba(255,255,255,.12); text-decoration: none; opacity: 1; }
.topbar nav a.on { background: rgba(255,255,255,.2); opacity: 1; font-weight: 600; }
.who { display: flex; gap: .75rem; align-items: center; font-size: .9rem; }
.role { background: rgba(255,255,255,.18); padding: .1rem .5rem; border-radius: 99px; font-size: .78rem; }

/* layout */
.wrap { max-width: 1320px; margin: 0 auto; padding: 1.25rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem;
  margin-bottom: 1rem; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; gap: .5rem; }
.card-head h2 { margin: 0; }
.narrow { max-width: 680px; }
.cols { display: flex; gap: 1rem; align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.side { width: 330px; flex-shrink: 0; }
.grid2, .grid4 { display: grid; gap: .25rem 1rem; }
.grid2 { grid-template-columns: repeat(2, 1fr); }
.grid4 { grid-template-columns: repeat(4, 1fr); }
.span2 { grid-column: span 2; } .span4 { grid-column: 1 / -1; }
@media (max-width: 960px) { .cols { flex-direction: column; } .side { width: 100%; }
  .grid4 { grid-template-columns: repeat(2, 1fr); } .topbar { overflow-x: auto; } }
@media (max-width: 600px) { .grid2, .grid4 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.stat span { display: block; color: var(--muted); font-size: .85rem; }
.stat b { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); margin-left: .3rem; }
.stat.alert { border-color: var(--amber); background: var(--amber-bg); }

/* forms */
.field { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .7rem; }
.field > span { font-size: .82rem; color: var(--muted); font-weight: 500; }
.req { color: var(--red); font-weight: 600; }
input, select, textarea { font: inherit; color: inherit; background: #fff; border: 1px solid #cccccc; border-radius: 6px;
  padding: .42rem .55rem; width: 100%; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; min-height: 2.4rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: .45rem; margin: .4rem 0 .8rem; }
.filters { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.filters input[type=search] { max-width: 340px; }
.filters select, .filters input[type=date] { width: auto; }
.filters label { display: flex; align-items: center; gap: .4rem; color: var(--muted); }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.form-actions.sticky { position: sticky; bottom: 0; background: var(--surface); padding-bottom: .4rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-head h3 { margin-bottom: .5rem; }
form.inline { display: inline-flex; gap: .3rem; align-items: center; margin: 0; }
form.inline select { width: auto; padding: .2rem .4rem; font-size: .88rem; }
.add-box { margin-top: .8rem; border-top: 1px dashed var(--line); padding-top: .6rem; }
.add-box summary { cursor: pointer; color: var(--brand); font-weight: 600; margin-bottom: .6rem; }
.wide-input { min-width: 320px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; font: inherit; font-weight: 550;
  padding: .45rem .85rem; border-radius: 6px; border: 1px solid #cccccc; background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--brand-soft); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--accent); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn.ghost.danger { color: var(--red); border-color: transparent; }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.btn.wide { width: 100%; margin-top: .3rem; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 600; padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
.tbl td { padding: .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:hover { background: #f8f8f8; }
.tbl tfoot td { font-weight: 600; border-bottom: none; border-top: 2px solid var(--line); }
.tbl tr.sub td { background: var(--gray-bg); font-style: italic; }
.tbl tr.bal td { border-top: 2px solid var(--ink); }
.tbl input { padding: .3rem .4rem; }
.num { text-align: right; }
td.num, th.num { text-align: right; }
input.num { text-align: right; }
.dim td { color: var(--muted); }
.clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); font-style: italic; padding: .8rem .5rem; }
.lines td { padding: .3rem; }

/* tags */
.tag { display: inline-block; font-size: .76rem; font-weight: 600; padding: .08rem .5rem; border-radius: 99px; background: var(--gray-bg); color: var(--muted); }
.tag.blue { background: var(--blue-bg); color: var(--blue); }
.tag.green { background: var(--green-bg); color: var(--green); }
.tag.amber { background: var(--amber-bg); color: var(--amber); }
.tag.red { background: var(--red-bg); color: var(--red); }
.status-select.s-arrived { background: var(--amber-bg); } .status-select.s-completed { background: var(--green-bg); }
.status-select.s-no-show { background: var(--red-bg); } .status-select.s-cancelled { background: var(--gray-bg); }

/* flash */
.flash { padding: .6rem .9rem; border-radius: 6px; margin-bottom: 1rem; background: var(--green-bg); color: var(--green); border: 1px solid #c3e0c9; }
.flash.error { background: var(--red-bg); color: var(--red); border-color: #f0c4c0; }
.flash.warn { background: var(--amber-bg); color: var(--amber); border-color: #f0dcae; }

/* patient chart */
.pt-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-left: 4px solid var(--brand); }
.pt-name { display: flex; align-items: center; gap: .6rem; }
.meta { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; color: var(--muted); margin-top: .2rem; }
.primary-dx { margin-top: .45rem; }
.tabs { display: flex; gap: .25rem; margin: 0 0 1rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs a { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
section[id] { scroll-margin-top: 64px; }
.row-link { display: flex; justify-content: space-between; gap: .5rem; padding: .45rem 0; border-bottom: 1px solid var(--line); color: var(--ink); }
.row-link small { color: var(--muted); }
.row-link:last-child { border-bottom: none; }
.dx-line { margin: .25rem 0; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: .35rem 1rem; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; white-space: pre-wrap; }
.kv.cols4 { grid-template-columns: 90px 1fr 90px 1fr 90px 1fr; }
.right-kv { grid-template-columns: auto auto; justify-content: end; }
.mse-view { grid-template-columns: 200px 1fr; }
ul.plain { margin: .2rem 0; padding-left: 1.2rem; }

/* notes & invoices */
.note-head { display: flex; justify-content: space-between; align-items: flex-start; padding-bottom: .7rem; margin-bottom: .9rem; border-bottom: 2px solid var(--brand); }
.note-head .right { text-align: right; }
.big { font-size: 1.2rem; }
.note h3 { border-bottom: 1px solid var(--line); padding-bottom: .2rem; }
.sig { margin-top: 1.5rem; padding-top: .7rem; border-top: 1px solid var(--line); color: var(--muted); font-style: italic; }
.invoice-doc .grid2 { margin-bottom: 1rem; }

/* login */
.login { max-width: 380px; margin: 9vh auto 0; }
.login .card { padding: 1.8rem; }
.login h1 { font-size: 1.3rem; }
.login-brand { font-weight: 700; font-size: 1.4rem; color: #fff; background: var(--brand); margin: -1.8rem -1.8rem 1.2rem;
  padding: .9rem 1.8rem; border-radius: var(--radius) var(--radius) 0 0; display: flex; align-items: center; }
.login-brand .logo-img { width: 34px; height: 34px; }

.print-only { display: none; }
@media print {
  @page { margin: 14mm; }
  html { font-size: 11pt; }
  body { background: #fff; }
  .no-print, .topbar, .tabs, .flash:not(.error), .add-box, form.inline, .side { display: none !important; }
  .print-only { display: block; }
  .wrap { max-width: none; padding: 0; }
  .card { border: none; box-shadow: none; padding: 0; }
  .cols { display: block; }
  a { color: inherit; }
}
