:root {
  --bg: #f7f7f5; --panel: #ffffff; --ink: #1d1d1b; --muted: #6b6b66; --line: #e3e2dc;
  --accent: #2f5bd3; --accent-ink: #ffffff; --warn: #b4410b; --ok: #1f7a3d; --chip: #eeede7;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161615; --panel: #1f1f1d; --ink: #ecebe6; --muted: #9b9a93; --line: #34342f;
          --accent: #7d9cff; --accent-ink: #10131c; --warn: #ff9a63; --ok: #6fd391; --chip: #2a2a27; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
.bar { display: flex; gap: 1.2rem; align-items: center; padding: .7rem 1rem; border-bottom: 1px solid var(--line);
       background: var(--panel); position: sticky; top: 0; flex-wrap: wrap; }
.brand { font-weight: 650; color: var(--ink); }
.bar nav { display: flex; gap: 1rem; }
.who { margin-left: auto; color: var(--muted); font-size: .9rem; }
main { max-width: 980px; margin: 0 auto; padding: 1.2rem 16px 4rem; }
h1 { font-size: 1.3rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .5rem; }
.muted { color: var(--muted); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 7px; padding: .5rem .6rem; width: 100%; }
textarea { min-height: 4rem; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .8rem 0 .25rem; }
button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 7px;
  padding: .45rem .9rem; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.search { margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--chip); }
.chip { display: inline-block; background: var(--chip); border-radius: 99px; padding: .05rem .55rem; font-size: .78rem;
  color: var(--muted); white-space: nowrap; }
.field { display: grid; grid-template-columns: 9rem 1fr auto; gap: .6rem; align-items: center; padding: .5rem 0;
  border-bottom: 1px solid var(--line); }
.field .k { color: var(--muted); font-size: .9rem; }
.field .v { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.fieldedit { display: grid; grid-template-columns: 10rem 1fr auto auto; gap: .5rem; align-items: center; margin: .4rem 0; }
@media (max-width: 640px) {
  .field { grid-template-columns: 1fr auto; } .field .k { grid-column: 1 / -1; }
  .fieldedit { grid-template-columns: 1fr 1fr; }
}
.note { border-left: 3px solid var(--accent); padding: .4rem .8rem; background: var(--chip); border-radius: 0 7px 7px 0;
  margin: .8rem 0; font-size: .9rem; }
.err { color: var(--warn); margin: .6rem 0; }
#toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: .6rem 1rem; border-radius: 8px; max-width: 90vw; }
.scroll { overflow-x: auto; }
.hist td { font-size: .88rem; }
.mt { margin-top: .8rem; }
.mb { margin-bottom: 1rem; }
.nowrap { flex-wrap: nowrap; }
label.m0 { margin: 0; }
.spread { justify-content: space-between; }
label.inline { display: inline-flex; gap: .3rem; align-items: center; color: var(--muted); }
.pre { white-space: pre-wrap; }
tr.archived td { opacity: .6; }
.small { font-size: .82rem; }
p.m0, .m0 { margin: 0; }
.filters { display: grid; grid-template-columns: minmax(10rem, 16rem) 1fr; gap: .6rem; margin-bottom: .6rem; }
.filters .search { margin: 0; }
@media (max-width: 640px) { .filters { grid-template-columns: 1fr; } }
tr.group td { background: var(--chip); font-weight: 600; padding-top: .7rem; }
tr.group:hover { background: none; }
.chip { margin: 0 .25rem .2rem 0; }
a.chip.org { color: var(--accent); background: transparent; border: 1px solid var(--accent); }
.scope { margin: -.4rem 0 .4rem; }
.clinicbox { border: 1px solid var(--line); border-radius: 7px; padding: .5rem; margin-top: .5rem; }
.clinicbox .row input[type=search] { flex: 1; width: auto; padding: .35rem .5rem; }
.clinics { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .15rem .8rem;
  max-height: 16rem; overflow-y: auto; margin-top: .5rem; }
label.clinic { color: var(--ink); font-size: .88rem; padding: .15rem 0; }
label.clinic input, label.inline input { width: auto; }
