/* =====================================================================
   CareQual — application stylesheet
   Built for ward use: large tap targets, high contrast, no hover-only
   affordances. Works from a 360px phone up to a nursing station monitor.
   ===================================================================== */

:root {
  --ink:        #0f172a;
  --ink-2:      #334155;
  --ink-3:      #5b6777;
  --line:       #e2e8f0;
  --line-2:     #cbd5e1;
  --bg:         #f6f8fb;
  --surface:    #ffffff;

  --brand:      #0b5c6b;
  --brand-2:    #0d7285;
  --brand-ink:  #04333c;
  --brand-soft: #e6f2f4;

  --green:      #047857;
  --green-soft: #d1fae5;
  --blue:       #0369a1;
  --blue-soft:  #dbeafe;
  --amber:      #b45309;
  --amber-soft: #fef3c7;
  --red:        #b91c1c;
  --red-soft:   #fee2e2;
  --grey-soft:  #eef2f6;

  --radius:     8px;
  --shadow:     0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  --shadow-lg:  0 4px 6px -1px rgba(15,23,42,.08), 0 10px 20px -5px rgba(15,23,42,.12);
  --sidebar-w:  244px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }

/* ------------------------------------------------------------ LAYOUT */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--brand-ink); color: #cbd5e1;
  display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  overflow-y: auto;
}
.sidebar .brand {
  padding: 1rem 1.1rem; border-bottom: 1px solid rgba(255,255,255,.09);
}
.sidebar .brand a { color: #fff; font-weight: 700; font-size: 1.15rem; letter-spacing: -.02em; }
.sidebar .brand small { display: block; color: #7d9aa1; font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; margin-top: 2px; }

.sidebar nav { padding: .6rem 0 2rem; }
.sidebar .navgroup {
  padding: .9rem 1.1rem .3rem; font-size: .66rem; letter-spacing: .09em;
  text-transform: uppercase; color: #6b8b93; font-weight: 600;
}
.sidebar a.navlink {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem 1.1rem; color: #c3d4d8; font-size: .9rem;
  border-left: 3px solid transparent;
}
.sidebar a.navlink:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar a.navlink.active { background: rgba(255,255,255,.1); color: #fff; border-left-color: #4dd0e1; font-weight: 600; }
.sidebar a.navlink .pill {
  margin-left: auto; background: var(--red); color: #fff;
  border-radius: 10px; padding: 0 .4rem; font-size: .7rem; font-weight: 600;
}

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: .6rem 1.25rem; display: flex; align-items: center; gap: 1rem;
  position: sticky; top: 0; z-index: 30;
}
.topbar .facility-select select {
  border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: .35rem .6rem; font-size: .88rem; background: #fff; max-width: 240px;
}
.topbar .spacer { flex: 1; }
.topbar .who { text-align: right; line-height: 1.2; }
.topbar .who strong { display: block; font-size: .88rem; }
.topbar .who span { font-size: .75rem; color: var(--ink-3); }
.topbar .bell { position: relative; font-size: 1.1rem; color: var(--ink-2); }
.topbar .bell .count {
  position: absolute; top: -6px; right: -8px; background: var(--red); color: #fff;
  border-radius: 10px; font-size: .65rem; padding: 0 .32rem; font-weight: 700;
}
.menu-toggle { display: none; background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--ink); }

.content { padding: 1.25rem; flex: 1; max-width: 1400px; width: 100%; }

.page-head { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head .grow { flex: 1; min-width: 200px; }
.page-head p.sub { margin: .15rem 0 0; color: var(--ink-3); font-size: .88rem; }

.breadcrumb { font-size: .78rem; color: var(--ink-3); margin-bottom: .35rem; }
.breadcrumb a { color: var(--ink-3); }

/* ------------------------------------------------------------- CARDS */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem;
}
.card > .card-head {
  padding: .75rem 1rem; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.card > .card-head h3 { margin: 0; font-size: .98rem; }
.card > .card-head .grow { flex: 1; }
.card > .card-body { padding: 1rem; }
.card > .card-body.tight { padding: .5rem; }
.card > .card-foot { padding: .7rem 1rem; border-top: 1px solid var(--line); background: #fbfcfd; }

.grid { display: grid; gap: 1rem; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0,1fr)); }

/* KPI tiles */
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem 1rem; box-shadow: var(--shadow);
}
.kpi .label { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; }
.kpi .value { font-size: 1.75rem; font-weight: 700; line-height: 1.15; margin-top: .15rem; letter-spacing: -.02em; }
.kpi .foot  { font-size: .78rem; color: var(--ink-3); margin-top: .1rem; }
.kpi.danger  .value { color: var(--red); }
.kpi.warning .value { color: var(--amber); }
.kpi.good    .value { color: var(--green); }
.kpi a { color: inherit; }

/* ------------------------------------------------------------ TABLES */

/* Contextual help. Closed by default: help that interrupts gets switched off. */
.helpbox {
  background: #f0f7f9; border: 1px solid #cfe3e8; border-left: 3px solid var(--brand);
  border-radius: var(--radius); margin-bottom: 1rem;
}
.helpbox > summary {
  cursor: pointer; padding: .6rem .9rem; display: flex; gap: .55rem; align-items: center;
  font-size: .86rem; color: var(--ink-2); list-style: none; min-height: 44px;
}
.helpbox > summary::-webkit-details-marker { display: none; }
.helpbox .help-ic {
  flex: 0 0 20px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--brand); color: #fff; font-weight: 700; font-size: .75rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.helpbox[open] > summary { border-bottom: 1px solid #cfe3e8; font-weight: 600; }
.helpbody { padding: .7rem .9rem .9rem 2.4rem; font-size: .85rem; color: var(--ink-2); }
.helpbody ul { margin: 0 0 .4rem; padding-left: 1.1rem; }
.helpbody li { margin-bottom: .35rem; }
.helpbody .lbl { margin-top: .6rem; }
.helpbody ul.refusals li { color: var(--ink); }
@media print { .helpbox { display: none; } }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--brand); color: #fff; padding: .7rem 1rem;
  border-radius: 0 0 var(--radius) 0; font-weight: 600;
}
.skip-link:focus { left: 0; }
.content:focus { outline: none; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* A data table placed directly in a card body, without an explicit wrapper,
   would otherwise push the whole page sideways on a phone. Nineteen of these
   existed; rather than wrap each by hand and miss the next one, the behaviour
   is made implicit. display:block is what allows a table to scroll. */
.card-body > table.data,
.card > table.data {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
}
@media (min-width: 721px) {
  /* Back to normal table layout where there is room for it. */
  .card-body > table.data,
  .card > table.data { display: table; white-space: normal; }
}
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th {
  text-align: left; padding: .55rem .7rem; background: #f8fafc;
  border-bottom: 1px solid var(--line); font-size: .72rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-3); font-weight: 650; white-space: nowrap;
}
table.data td { padding: .6rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tbody tr:hover { background: #fafcfd; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.nowrap { white-space: nowrap; }
table.data tr.overdue td { background: #fff7f7; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-3); }
.empty .big { font-size: 1.05rem; color: var(--ink-2); margin-bottom: .3rem; }

/* ------------------------------------------------------------ BADGES */

.badge {
  display: inline-block; padding: .12rem .5rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; white-space: nowrap; line-height: 1.5;
}
.badge-grey  { background: var(--grey-soft);  color: var(--ink-2); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-blue  { background: var(--blue-soft);  color: var(--blue); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red   { background: var(--red-soft);   color: var(--red); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }
.sev-dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .35rem; vertical-align: baseline; }

/* ------------------------------------------------------------- FORMS */

.form-row { margin-bottom: .9rem; }
.form-row > label, .lbl {
  display: block; font-size: .8rem; font-weight: 600; color: var(--ink-2); margin-bottom: .25rem;
}
.form-row .hint { font-size: .76rem; color: var(--ink-3); margin-top: .2rem; }
.req { color: var(--red); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], input[type=datetime-local], input[type=tel],
input[type=search], select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--line-2);
  border-radius: var(--radius); font-size: .92rem; font-family: inherit;
  background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(13,114,133,.14);
}
input:disabled, select:disabled, textarea:disabled { background: #f1f5f9; color: var(--ink-3); }
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid.c3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.form-grid .span2 { grid-column: 1 / -1; }

.check { display: flex; align-items: flex-start; gap: .5rem; margin-bottom: .5rem; font-size: .9rem; }
.check input { width: auto; margin-top: .2rem; flex: 0 0 auto; }

/* Large radio cards, used for severity and yes/no/NA answers on mobile */
.optcards { display: flex; flex-wrap: wrap; gap: .5rem; }
.optcards label {
  border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: .5rem .75rem; cursor: pointer; font-size: .88rem; background: #fff;
  display: flex; align-items: center; gap: .45rem; min-height: 42px;
}
.optcards input { position: absolute; opacity: 0; width: 0; height: 0; }
.optcards label.picked,
.optcards label:has(input:checked) {
  border-color: var(--brand-2); background: var(--brand-soft);
  box-shadow: 0 0 0 2px rgba(13,114,133,.16); font-weight: 600;
}

/* ------------------------------------------------------------ BUTTONS */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .9rem; border-radius: var(--radius); border: 1px solid transparent;
  font-size: .89rem; font-weight: 600; cursor: pointer; background: #fff;
  color: var(--ink); font-family: inherit; min-height: 40px; text-decoration: none;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); color: #fff; }
.btn-outline { border-color: var(--line-2); color: var(--ink-2); }
.btn-danger  { background: var(--red); color: #fff; }
.btn-ghost   { background: transparent; color: var(--brand-2); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; min-height: 32px; }
.btn-lg { padding: .7rem 1.3rem; font-size: 1rem; min-height: 48px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------ ALERTS */

.alert {
  padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: 1rem;
  font-size: .89rem; border: 1px solid transparent;
}
.alert-success { background: var(--green-soft); color: #065f46; border-color: #a7f3d0; }
.alert-error   { background: var(--red-soft);   color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--amber-soft); color: #92400e; border-color: #fde68a; }
.alert-info    { background: var(--blue-soft);  color: #1e40af; border-color: #bfdbfe; }

/* --------------------------------------------------------- FILTER BAR */

.filters {
  display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .7rem .8rem; margin-bottom: 1rem;
}
.filters .f { min-width: 140px; flex: 0 1 auto; }
.filters .f label { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; margin-bottom: .2rem; }
.filters .f.grow { flex: 1 1 200px; }

/* ------------------------------------------------------------ TIMELINE */

.timeline { list-style: none; margin: 0; padding: 0 0 0 1.35rem; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 1.05rem .3rem; }
.timeline li::before {
  content: ''; position: absolute; left: -1.72rem; top: .3rem;
  width: .72rem; height: .72rem; border-radius: 50%;
  background: #fff; border: 2px solid var(--line-2);
}
.timeline li.done::before   { background: var(--green); border-color: var(--green); }
.timeline li.active::before { background: var(--brand-2); border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
.timeline li.alert::before  { background: var(--red); border-color: var(--red); }
.timeline .t-head { font-weight: 600; font-size: .88rem; }
.timeline .t-meta { font-size: .78rem; color: var(--ink-3); }
.timeline .t-body { font-size: .86rem; color: var(--ink-2); margin-top: .2rem; white-space: pre-wrap; }

/* --------------------------------------------------------- STAGE STEPS */

.stages { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: 1rem; }
.stages .stage {
  flex: 1 1 auto; min-width: 84px; text-align: center; padding: .4rem .3rem;
  font-size: .72rem; font-weight: 600; border-radius: var(--radius);
  background: var(--grey-soft); color: var(--ink-3); border: 1px solid var(--line);
}
.stages .stage.done    { background: var(--green-soft); color: var(--green); border-color: #a7f3d0; }
.stages .stage.current { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ----------------------------------------------------- DEFINITION LIST */

dl.kv { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: .4rem .9rem; margin: 0; font-size: .89rem; }
dl.kv dt { color: var(--ink-3); font-weight: 500; }
dl.kv dd { margin: 0; color: var(--ink); }

/* --------------------------------------------------------- PROGRESS BAR */

.bar { height: 8px; border-radius: 4px; background: var(--grey-soft); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand-2); }
.bar.good > span    { background: var(--green); }
.bar.warning > span { background: var(--amber); }
.bar.danger > span  { background: var(--red); }

/* ------------------------------------------------------------- MISC */

.muted { color: var(--ink-3); }
.small { font-size: .82rem; }
.xsmall { font-size: .74rem; }
.mono  { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: .86em; }
.mt0 { margin-top: 0 } .mb0 { margin-bottom: 0 }
.mt1 { margin-top: .5rem } .mb1 { margin-bottom: .5rem }
.mt2 { margin-top: 1rem }  .mb2 { margin-bottom: 1rem }
.right { text-align: right } .center { text-align: center }
.nowrap { white-space: nowrap; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

.pager { display: flex; gap: .3rem; align-items: center; justify-content: center; padding: .8rem; flex-wrap: wrap; }
.pager a, .pager span {
  padding: .32rem .6rem; border: 1px solid var(--line-2); border-radius: var(--radius);
  font-size: .84rem; color: var(--ink-2); min-width: 36px; text-align: center;
}
.pager .current { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }

/* --------------------------------------------------------- LOGIN PAGE */

.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1.25rem; background: linear-gradient(150deg, var(--brand-ink) 0%, #0b5c6b 55%, #12808f 100%);
}
.auth-card {
  background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 400px; padding: 1.75rem;
}
.auth-card .logo { text-align: center; margin-bottom: 1.25rem; }
.auth-card .logo h1 { color: var(--brand); font-size: 1.6rem; margin-bottom: .1rem; }
.auth-card .logo p  { color: var(--ink-3); font-size: .82rem; margin: 0; }
.auth-foot { text-align: center; margin-top: 1rem; font-size: .78rem; color: rgba(255,255,255,.75); }

/* ------------------------------------------------------------- PRINT */

@media print {
  .sidebar, .topbar, .btn, .filters, .pager, .no-print { display: none !important; }
  .main { margin-left: 0; }
  .content { padding: 0; max-width: none; }
  .card { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
  body { background: #fff; font-size: 11pt; }
  a { color: #000; text-decoration: none; }
}

/* ------------------------------------------------------------ MOBILE */

@media (max-width: 900px) {
  .grid.c4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.c3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-grid.c3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 720px) {
  body { font-size: 15px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .content { padding: .8rem; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .form-grid, .form-grid.c3 { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; gap: .1rem .5rem; }
  dl.kv dt { margin-top: .5rem; font-size: .78rem; }
  .topbar .who strong { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .kpi .value { font-size: 1.5rem; }
  /* Larger tap targets on the ward */
  .btn { min-height: 44px; }
  input, select, textarea { font-size: 16px; }  /* stops iOS zoom-on-focus */
}

/* --------------------------------------------------------------- PHONE
   The ward device is often a phone, not a tablet. The 720px rules above
   apply here too; these handle what is still wrong at 390px. */
@media (max-width: 560px) {
  .content { padding: .6rem; }

  /* Filter bars stack rather than squeezing six controls onto one line. */
  .filters { flex-direction: column; align-items: stretch; gap: .5rem; }
  .filters .f { width: 100%; }
  .filters .f.grow { width: 100%; }

  /* Page heading and its buttons stop fighting for the same row. */
  .page-head { flex-direction: column; align-items: stretch; gap: .6rem; }
  .page-head .btn-row { flex-wrap: wrap; }
  .page-head h1 { font-size: 1.25rem; }

  /* Buttons go full width so they are not 30px targets at the screen edge. */
  .btn-row > .btn, .btn-row > form > .btn { flex: 1 1 auto; }
  .card-head { flex-wrap: wrap; gap: .4rem; }

  /* An inline width set for a desktop column becomes an overflow on a phone. */
  table.data td[style*="width"], table.data th[style*="width"] { width: auto !important; }
  .form-row input[type="number"] { width: 100% !important; }

  /* The floating panels used for inline actions must not run off-screen. */
  details > form[style*="position:absolute"],
  details > div[style*="position:absolute"] {
    position: static !important; min-width: 0 !important;
    box-shadow: none !important; border-left: 3px solid var(--brand) !important;
  }

  .kpi .value { font-size: 1.35rem; }
  .kpi .label { font-size: .72rem; }
}

.scrim { display: none; }
@media (max-width: 720px) {
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 35; }
}
