:root {
  color-scheme: light;
  --ink: #15283e;
  --muted: #50647b;
  --navy: #11263c;
  --teal: #08766b;
  --paper: #f2f5f9;
  --line: #dbe4ed;
  --sidebar-width: 14.75rem;
  font-family: system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
body.menu-is-open { overflow: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(1.8rem, 3.4vw, 2.55rem); letter-spacing: -.045em; }
h2 { font-size: 1.15rem; margin-bottom: .8rem; }
h3 { font-size: 1rem; margin: 1.45rem 0 .5rem; }
.brand { display: flex; align-items: center; gap: .65rem; font-size: 1.2rem; font-weight: 750; letter-spacing: -.03em; white-space: nowrap; }
.mark { display: grid; place-items: center; width: 2rem; height: 2rem; background: #a8e5d6; color: var(--navy); border-radius: .55rem; font-size: 1.5rem; line-height: 1; }
.entry { display: grid; grid-template-columns: 1fr 1fr; max-width: 59rem; min-height: 26rem; margin: clamp(1.5rem, 9vh, 7rem) auto; width: calc(100% - 2rem); border: 1px solid var(--line); border-radius: 1.2rem; overflow: hidden; background: white; box-shadow: 0 14px 45px #15283e0e; }
.entry-intro { display: flex; flex-direction: column; justify-content: center; padding: clamp(1.65rem, 4.5vw, 3.3rem); color: #f6fbff; background: var(--navy); }
.entry-intro .brand { margin-bottom: 2.25rem; }
.entry-intro h1 { font-size: clamp(2rem, 5vw, 3.35rem); max-width: 12ch; }
.entry-intro p { margin-bottom: 0; max-width: 25rem; line-height: 1.6; color: #c8d7e6; }
.entry .sheet { align-self: center; padding: clamp(1.65rem, 4.5vw, 3.3rem); box-shadow: none; }
.entry .primary { width: 100%; }
.sheet { background: white; padding: clamp(1rem, 2.3vw, 1.65rem); min-width: 0; box-shadow: 0 2px 6px #15283e06; }
label { display: block; margin: .85rem 0 .35rem; font-weight: 625; font-size: .875rem; }
input, select, button { font: inherit; }
input, select { width: 100%; border: 1px solid #aabacb; border-radius: .5rem; padding: .6rem .72rem; min-height: 2.65rem; color: var(--ink); background: white; }
button { border-radius: .5rem; cursor: pointer; min-height: 2.65rem; padding: .55rem .9rem; font-weight: 650; }
button:disabled { opacity: .62; cursor: default; }
.primary { margin-top: 1.05rem; background: var(--teal); color: white; border: 1px solid var(--teal); }
.primary:hover:not(:disabled) { background: #065d55; }
.quiet { color: #edf6fc; background: transparent; border: 1px solid #587089; text-align: start; width: 100%; }
.quiet:hover { background: #243e58; }
:focus-visible { outline: 3px solid #147faa; outline-offset: 3px; }
.muted { color: var(--muted); line-height: 1.55; }
.feedback { margin-bottom: 0; font-size: .9rem; color: #843c20; }
.feedback:empty { margin: 0; }
#desk { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100dvh; }
.workspace-sidebar { display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh; overflow-y: auto; padding: 1.45rem .9rem 1rem; background: var(--navy); color: #edf6fc; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin: 0 .4rem 1.8rem; }
.sidebar-label { margin: 0 .55rem .65rem; color: #a6bcce; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .11em; }
.screen-nav { display: grid; gap: .24rem; }
.nav-item { position: relative; display: flex; width: 100%; align-items: center; gap: .65rem; text-align: start; padding: .55rem .65rem; border: 1px solid transparent; border-radius: .5rem; background: transparent; color: #d5e3ef; font-size: .875rem; font-weight: 600; }
.nav-item svg { flex: 0 0 1.15rem; width: 1.15rem; height: 1.15rem; color: #a0bad0; }
.nav-item:hover { background: #243e58; color: white; }
.nav-item[aria-current] { background: #214958; color: white; border-color: #345d66; box-shadow: inset 3px 0 #7dd9c6; }
.nav-item[aria-current] svg { color: #a8e5d6; }
.workspace-sidebar :focus-visible { outline-color: #9be3d6; }
.sidebar-footer { margin-top: auto; padding: 1rem .15rem 0; }
.sidebar-close { background: transparent; border: 1px solid #587089; color: white; padding: 0 .7rem; font-size: 1.35rem; }
.workspace-content { min-width: 0; }
.workspace-bar { min-height: 4.3rem; background: white; border-bottom: 1px solid var(--line); display: flex; justify-content: flex-end; align-items: center; padding: .6rem clamp(1rem, 3.4vw, 2.5rem); gap: .75rem; }
.organization-control { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.organization-control label { margin: 0; color: var(--muted); }
.organization-control select { min-width: 0; max-width: 25rem; }
.workspace-body { max-width: 94rem; margin: auto; padding: clamp(1.1rem, 3vw, 2.5rem); }
#desk-title { margin-bottom: 1.25rem; }
.desk-grid { display: grid; grid-template-columns: minmax(15rem, 1fr) minmax(0, 1.65fr); gap: 1rem; align-items: start; }
.desk-grid .sheet { border: 1px solid var(--line); border-radius: .85rem; }
.desk-grid .reader { border-top: 3px solid var(--teal); }
.record-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.record-meta { border-bottom: 1px solid var(--line); padding-bottom: .6rem; color: var(--muted); }
dt { font-weight: 650; margin-top: .8rem; }
dd { margin: .2rem 0 0; }
ul { padding-inline-start: 1.15rem; }
li { margin-block: .4rem; }
.skip { position: absolute; z-index: 5; top: .5rem; inset-inline-start: .5rem; background: white; padding: .5rem; transform: translateY(-150%); }
.skip:focus { transform: none; }
.menu-backdrop { position: fixed; z-index: 3; inset: 0; border: 0; border-radius: 0; width: 100%; background: #0b1829a6; }
.secondary { background: white; color: var(--ink); border: 1px solid var(--line); }
.secondary:hover:not(:disabled) { background: #eaf3f7; }

.operations-actions, .operations-tables { display:grid; gap:1rem; margin-bottom:1.1rem; }
.operations-actions { grid-template-columns:repeat(auto-fit,minmax(min(100%,21rem),1fr)); }
.operations-actions:empty, .operations-tables:empty { display:none; }
.operation-card { border:1px solid var(--line); border-radius:.85rem; align-self:start; }
.operation-card h3 { margin:0 0 .8rem; font-size:1.14rem; }
.operation-header, .pagination { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:.65rem; }
.operation-header h3 { margin:0; }
.pagination { margin-top:.9rem; justify-content:flex-end; color:var(--muted); }
.operation-result { overflow-wrap:anywhere; }
.field-hint { color:var(--muted); margin:.3rem 0 0; font-size:.85rem; }
textarea { width:100%; min-height:5.5rem; resize:vertical; color:var(--ink); border:1px solid #90a7ad; border-radius:.35rem; padding:.65rem .75rem; font:inherit; }
.operation-card label > :is(input,select,textarea):not([type=checkbox]) { margin-top:.35rem; }
.confirmation { display:flex; gap:.6rem; align-items:center; }
.confirmation input { width:1.2rem; min-height:1.2rem; flex-shrink:0; }
fieldset { border:1px solid var(--line); border-radius:.35rem; margin:1rem 0 0; min-width:0; }
legend { font-weight:650; }
.medicine-row { border-bottom:1px solid var(--line); padding:0 0 .65rem; margin-bottom:.65rem; }
.table-scroll { overflow-x:auto; margin-top:.9rem; }
table { border-collapse:collapse; width:100%; text-align:start; font-size:.88rem; }
td, th { vertical-align:top; padding:.65rem .7rem; border-bottom:1px solid var(--line); min-width:6.5rem; }
th { color:#324c5d; background:#eef3f8; font-weight:650; text-wrap:pretty; }
td { max-width:16rem; overflow-wrap:anywhere; font-variant-numeric:tabular-nums; }
tbody tr:nth-child(even) { background:#f8fafc; }
.qr-canvas { display:block; width:min(100%,14rem); height:auto; margin-top:.8rem; image-rendering:pixelated; }
.document-card form > button { margin-inline-end:.5rem; }
.document-list li { display:flex; align-items:center; justify-content:space-between; gap:.6rem; }
.document-list { padding:0; }

@media (max-width: 960px) {
  .desk-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  #desk { grid-template-columns: minmax(0, 1fr); }
  .workspace-sidebar { position: fixed; z-index: 4; inset-block: 0; inset-inline-start: 0; width: min(17rem, 86vw); }
  .workspace-bar { justify-content: space-between; }
  .menu-open { flex-shrink: 0; }
  .organization-control label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .entry { grid-template-columns: 1fr; min-height: 0; }
  .entry-intro .brand { margin-bottom: 1rem; }
  .entry-intro h1 { max-width: none; }
}

/* Reference pickers */
.picker { display:grid; gap:0; margin-top:.15rem; }
.picker :is(input,select) { margin-top:.35rem; }
.picker .field-hint { min-height:1.2rem; }
input[type=search] { -webkit-appearance:none; appearance:none; }

/* Status chips: color is never the only signal; the text states the state. */
.chip { display:inline-block; white-space:nowrap; padding:.12rem .55rem; border-radius:999px; font-size:.8rem; font-weight:650; border:1px solid currentColor; }
.chip-draft, .chip-amber { color:#7a4a00; background:#fff6e0; }
.chip-signed, .chip-green { color:#0b5d3a; background:#e6f5ec; }
.chip-red { color:#8a1f11; background:#fdecea; }
.chip-grey { color:#3d4f63; background:#eef2f6; }
td .secondary { min-height:2.2rem; padding:.3rem .7rem; white-space:nowrap; }
td .secondary + .secondary { margin-inline-start:.4rem; }
.feedback.ok { color:#0b5d3a; }
.feedback.ok::before { content:'✓ '; }

/* Encounter hub */
.encounter-tools { display:grid; gap:1rem; grid-template-columns:repeat(auto-fit,minmax(min(100%,19rem),1fr)); margin-top:.9rem; }
.encounter-tools .operation-card { border:1px solid var(--line); }

/* Confirmation dialog for irreversible or money-moving actions */
.confirm-dialog { width:min(30rem,calc(100% - 2rem)); border:1px solid var(--line); border-radius:.85rem; padding:1.4rem; color:var(--ink); box-shadow:0 18px 50px #0b182940; }
.confirm-dialog::backdrop { background:#0b1829a6; }
.confirm-dialog h3 { margin:0 0 .6rem; font-size:1.2rem; }
.confirm-dialog dl { margin:0 0 .8rem; }
.confirm-actions { display:flex; gap:.6rem; justify-content:flex-end; flex-wrap:wrap; margin-top:1rem; }
.confirm-actions .primary { margin-top:0; }
.sign-tool { margin:.6rem 0 1rem; }
.sign-tool .operation-card { border-inline-start:4px solid #b9770e; }

.entry .language-toggle { margin-top: .7rem; }
[dir=rtl] .nav-item[aria-current] { box-shadow: inset -3px 0 #7dd9c6; }
[dir=rtl] .language-toggle { direction: ltr; }
