/* ============================================================
   NEFROS — App shell: <aside class="sidebar"> + main column.
   Same structure as PEDCAM, with a patient context bar the industrial app
   has no equivalent of: once a record is open it stays on screen, because
   every clinical mistake starts with being in the wrong chart.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────── */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 18px 18px 14px;
  flex-shrink: 0;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--primary), var(--teal));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }

/* Once the animation is in, it IS the wordmark: the square mark and the
   lettering it replaces step aside, and only the clinic name stays under it. */
.brand.has-anim {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding-top: 16px;
}

.brand.has-anim .brand-mark,
.brand.has-anim .brand-name,
.login-logo.has-anim .brand-mark,
.login-logo.has-anim .brand-name { display: none; }

.brand.has-anim .brand-text { width: 100%; }

.brand-anim {
  display: block;
  width: 100%;
  max-width: 196px;
  height: auto;
  /* It fades in rather than appearing mid-assembly, because the fetch lands at
     an unpredictable moment and a logo that pops is worse than one that waits. */
  animation: brand-anim-in 220ms ease-out both;
}

/* The login card centres its logo on its own line; as a flex item with
   width:100% the image would collapse to its intrinsic size instead. */
.login-logo.has-anim { display: block; width: 100%; }
.login-logo .brand-anim { width: 268px; max-width: 100%; margin: 0 auto; }

@keyframes brand-anim-in { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .brand-anim { animation: none; }
}

.brand-name {
  font: 800 17px/1.1 var(--font-ui);
  letter-spacing: .06em;
  color: var(--text);
}

.brand-sub {
  font-size: var(--fs-micro);
  color: var(--text-3);
  font-weight: 600;
  letter-spacing: .04em;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Clinic switcher (platform admin only). */
.clinic-switch { padding: 2px 12px 8px; flex-shrink: 0; }

.clinic-switch label {
  display: block;
  font-size: var(--fs-micro);
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 0 4px 4px;
}

.clinic-switch select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: 600 13px var(--font-ui);
  cursor: pointer;
}

/* ── Navigation ─────────────────────────────────────────── */

.sidebar-nav {
  padding: 4px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.nav-section {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 10px 5px;
}

.sidebar-nav > .nav-section:first-child { padding-top: 4px; }

.nav-section-lbl {
  font-size: var(--fs-micro);
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
  line-height: 1;
}

.nav-section::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  font: 550 13.5px var(--font-ui);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
  position: relative;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-base) var(--ease);
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: translateX(2px);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}

.nav-icon { font-size: 16px; width: 18px; text-align: center; flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  min-width: 20px;
  height: 19px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text-2);
  font: 700 11px/19px var(--font-ui);
  text-align: center;
}

.nav-badge:empty { display: none; }
.nav-badge.is-alert { background: var(--red); color: #fff; }
.nav-badge.is-warn  { background: var(--amber); color: #1a1205; }

/* Sidebar footer: user, theme, language. */
.sidebar-foot {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  color: inherit;
  transition: background var(--t-fast);
}

.user-chip:hover { background: var(--surface-2); }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font: 700 12px var(--font-ui);
  flex-shrink: 0;
}

.user-meta { min-width: 0; flex: 1; }

.user-name {
  font: 650 13px var(--font-ui);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: var(--fs-micro);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 650;
}

.sidebar-tools { display: flex; gap: 8px; align-items: center; }

/* ── Main column ────────────────────────────────────────── */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  height: 58px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 40;
}

.topbar h1 {
  font: 700 var(--fs-lg)/1.2 var(--font-ui);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-sub {
  font-size: var(--fs-xs);
  color: var(--text-3);
  white-space: nowrap;
}

.topbar-spacer { flex: 1; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* The global search: the fastest way to reach a patient from anywhere. */
.global-search {
  position: relative;
  flex: 1;
  max-width: 460px;
}

.global-search .input { padding-left: 34px; }

.global-search .bi-search {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 14px;
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 200;
  padding: 5px;
  animation: pop var(--t-base) var(--ease);
}

.search-results:empty { display: none; }

.search-hit {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}

.search-hit:hover, .search-hit.is-active { background: var(--primary-soft); }
.search-hit-main { flex: 1; min-width: 0; }
.search-hit-name { font-weight: 650; font-size: var(--fs-sm); }

.search-hit-meta {
  font-size: var(--fs-2xs);
  color: var(--text-3);
  display: flex;
  gap: 8px;
  margin-top: 1px;
}

/* ── Patient context bar ────────────────────────────────── */
/* Pinned under the topbar while a record is open. It is the answer to
   "whose chart am I in?", which must never require scrolling. */

.patient-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 22px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 35;
  animation: slide-down var(--t-slow) var(--ease);
}

.patient-bar .avatar { width: 38px; height: 38px; font-size: 14px; }

.patient-bar-id { min-width: 0; }

.patient-bar-name {
  font: 700 var(--fs-md) var(--font-ui);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color var(--t-fast);
}

a.patient-bar-name:hover { color: var(--primary); text-decoration: underline; }

.patient-bar-meta {
  font-size: var(--fs-2xs);
  color: var(--text-3);
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  margin-top: 1px;
}

.patient-bar-stats {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ── Content ────────────────────────────────────────────── */

/*
 * No `scroll-behavior: smooth` here.
 *
 * In some engines it makes EVERY programmatic scroll on the element a silent
 * no-op, including `scrollTop = 0`. The router resets the scroll on each
 * navigation, so with it set a long record left the next view opening halfway
 * down the page. Jumping to the top instantly is also what a reader expects
 * when the whole screen has just been replaced.
 */
.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 22px;
}

.content-narrow { max-width: 900px; margin: 0 auto; }
.content-wide { max-width: 1440px; margin: 0 auto; }

/* A view with a side rail is NOT centred: centring pushes the rail away from the
   edge on a wide monitor, which is the one place it must not be. */
.content-record { max-width: 1760px; margin: 0 auto 0 0; }

.view { animation: fade-up var(--t-slow) var(--ease); }

.view-head {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.view-head h2 {
  font: 700 var(--fs-xl)/1.2 var(--font-ui);
  margin: 0;
}

.view-head .sub {
  font-size: var(--fs-sm);
  color: var(--text-3);
  margin-top: 3px;
}

.view-head-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Tabs ───────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 9px 14px;
  border: none;
  background: none;
  color: var(--text-2);
  font: 600 var(--fs-sm) var(--font-ui);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color var(--t-fast), border-color var(--t-fast);
  display: flex;
  align-items: center;
  gap: 7px;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

.tab-count {
  min-width: 18px;
  height: 17px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--surface-3);
  color: var(--text-2);
  font: 700 10px/17px var(--font-ui);
  text-align: center;
}

.tab.active .tab-count { background: var(--primary-soft); color: var(--primary); }

/* ── Login ──────────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(1200px 600px at 15% -10%, var(--primary-soft), transparent 60%),
    radial-gradient(900px 500px at 100% 110%, var(--accent-soft), transparent 60%),
    var(--bg);
  overflow-y: auto;
}

.login-card {
  width: 100%;
  max-width: 394px;
  padding: 34px 30px 28px;
  animation: fade-up var(--t-slow) var(--ease);
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 6px;
}

.login-logo .brand-mark { width: 44px; height: 44px; font-size: 23px; border-radius: 13px; }

.login-logo .brand-name { font-size: 25px; }

.login-card .tag {
  text-align: center;
  color: var(--text-3);
  font-size: var(--fs-sm);
  margin-bottom: 26px;
}

/* ── Animations ─────────────────────────────────────────── */
/* Nothing here runs longer than 200 ms, per the brief. */

@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

@keyframes slide-down {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}

@keyframes pop {
  from { opacity: 0; transform: scale(.98) translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes pulse-soft {
  0%, 100% { opacity: 1; }
  50%      { opacity: .55; }
}

/* ── Scrollbars ─────────────────────────────────────────── */

.content::-webkit-scrollbar, .sidebar::-webkit-scrollbar,
.search-results::-webkit-scrollbar, .modal-body::-webkit-scrollbar { width: 10px; height: 10px; }

.content::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb, .modal-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 6px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.content::-webkit-scrollbar-track, .sidebar::-webkit-scrollbar-track { background: transparent; }

/* ── Tablet ─────────────────────────────────────────────── */
/* The brief targets tablet and PC. Below 1024 the sidebar becomes a drawer,
   because a consulting-room tablet is usually held in portrait. */

@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform var(--t-slow) var(--ease);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.is-open { transform: none; }

  .scrim {
    position: fixed;
    inset: 0;
    background: rgba(8, 20, 26, .45);
    z-index: 45;
    animation: fade-up var(--t-base) var(--ease);
  }

  .nav-toggle-btn { display: inline-flex !important; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .patient-bar { padding: 10px 16px; }

  /* The search must give way before the primary action does: on a tablet the
     button collapses to its icon rather than sliding off the right edge. */
  .global-search { max-width: none; min-width: 0; }
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { padding: 0 11px; }
}

@media (min-width: 1025px) {
  .nav-toggle-btn { display: none !important; }
  .scrim { display: none; }
}

@media (max-width: 640px) {
  .patient-bar-stats { display: none; }
  .content { padding: 12px; }
}
