/* ==========================================================================
   BioTrack Pro — Layout
   App shell: sidebar, header, content region, page scaffolding.
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns var(--duration-base) var(--ease-in-out);
}

.app[data-sidebar="collapsed"] {
  grid-template-columns: var(--sidebar-width-collapsed) minmax(0, 1fr);
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.sidebar {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  background: var(--color-sidebar-bg);
  border-right: 1px solid var(--color-sidebar-border);
  overflow: hidden;
  z-index: var(--z-sidebar);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--header-height);
  padding: 0 var(--space-4);
  flex-shrink: 0;
  border-bottom: 1px solid var(--color-sidebar-border);
  overflow: hidden;
}

.sidebar__logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--color-primary);
}

.sidebar__logo img,
.sidebar__logo svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sidebar__brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.sidebar__brand-name {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--color-sidebar-fg-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__brand-sub {
  font-size: var(--text-2xs);
  color: var(--color-sidebar-section);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  white-space: nowrap;
}

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3) var(--space-2) var(--space-4);
}

.sidebar__section {
  padding: var(--space-4) var(--space-3) var(--space-2);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--color-sidebar-section);
  white-space: nowrap;
}

.sidebar__section:first-child {
  padding-top: var(--space-1);
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  margin-bottom: 2px;
  border-radius: var(--radius-md);
  color: var(--color-sidebar-fg);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  position: relative;
  transition: var(--transition-colors);
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.sidebar__link:hover {
  background: var(--color-sidebar-hover);
  color: var(--color-sidebar-fg-strong);
}

.sidebar__link.is-active {
  background: var(--color-sidebar-active);
  color: var(--color-sidebar-active-fg);
  font-weight: var(--weight-semibold);
}

.sidebar__link.is-active::before {
  content: "";
  position: absolute;
  left: calc(var(--space-3) * -1 + 2px);
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
}

.sidebar__link .icon {
  flex-shrink: 0;
  opacity: 0.9;
}

.sidebar__link-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__badge {
  flex-shrink: 0;
  min-width: 20px;
  height: 18px;
  padding: 0 var(--space-1);
  border-radius: var(--radius-full);
  background: var(--color-danger);
  color: #fff;
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  display: grid;
  place-items: center;
  line-height: 1;
}

.sidebar__badge--muted {
  background: rgba(255, 255, 255, 0.14);
  color: var(--color-sidebar-fg-strong);
}

.sidebar__footer {
  flex-shrink: 0;
  border-top: 1px solid var(--color-sidebar-border);
  padding: var(--space-2);
}

.sidebar__collapse {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-sidebar-fg);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: var(--transition-colors);
  white-space: nowrap;
}

.sidebar__collapse:hover {
  background: var(--color-sidebar-hover);
  color: var(--color-sidebar-fg-strong);
}

.sidebar__collapse .icon {
  transition: var(--transition-transform);
}

/* --- Collapsed state --- */

.app[data-sidebar="collapsed"] .sidebar__brand-text,
.app[data-sidebar="collapsed"] .sidebar__link-label,
.app[data-sidebar="collapsed"] .sidebar__section,
.app[data-sidebar="collapsed"] .sidebar__collapse span,
.app[data-sidebar="collapsed"] .sidebar__badge {
  display: none;
}

.app[data-sidebar="collapsed"] .sidebar__brand,
.app[data-sidebar="collapsed"] .sidebar__link,
.app[data-sidebar="collapsed"] .sidebar__collapse {
  justify-content: center;
  padding-left: var(--space-2);
  padding-right: var(--space-2);
}

.app[data-sidebar="collapsed"] .sidebar__link.is-active::before {
  left: 0;
}

.app[data-sidebar="collapsed"] .sidebar__collapse .icon {
  transform: rotate(180deg);
}

/* Tooltip shown only when collapsed */
.app[data-sidebar="collapsed"] .sidebar__link[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + var(--space-3));
  top: 50%;
  transform: translateY(-50%);
  background: var(--color-gray-900, var(--gray-900));
  color: #fff;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  z-index: var(--z-tooltip);
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

/* ==========================================================================
   Main region
   ========================================================================== */

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

/* ==========================================================================
   Header
   ========================================================================== */

.header {
  flex-shrink: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--page-gutter);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: var(--z-header);
}

.header__menu-btn {
  display: none;
}

.header__titles {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.25;
}

.header__title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
}

.breadcrumb__item {
  transition: var(--transition-colors);
}

.breadcrumb__item[data-href]:hover {
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.breadcrumb__sep {
  color: var(--color-text-subtle);
  user-select: none;
}

.breadcrumb__item:last-child {
  color: var(--color-text);
  font-weight: var(--weight-medium);
}

.header__spacer {
  flex: 1;
  min-width: var(--space-2);
}

.header__search {
  position: relative;
  width: clamp(200px, 26vw, 380px);
}

.header__search-input {
  width: 100%;
  height: 36px;
  padding: 0 var(--space-3) 0 34px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-sunk);
  font-size: var(--text-sm);
  color: var(--color-text);
  transition: var(--transition-colors), var(--transition-shadow);
}

.header__search-input::placeholder {
  color: var(--color-text-subtle);
}

.header__search-input:focus {
  background: var(--color-surface);
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.header__search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-subtle);
  pointer-events: none;
}

.header__search-kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.header__clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.25;
  padding-right: var(--space-2);
  border-right: 1px solid var(--color-border);
  margin-right: var(--space-1);
}

.header__clock-time {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-strong);
  font-variant-numeric: tabular-nums;
}

.header__clock-date {
  font-size: var(--text-2xs);
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* --- Profile --- */

.profile-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2) var(--space-1) var(--space-1);
  border-radius: var(--radius-md);
  transition: var(--transition-colors);
}

.profile-btn:hover {
  background: var(--color-surface-hover);
}

.profile-btn__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.25;
  min-width: 0;
}

.profile-btn__name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-strong);
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-btn__role {
  font-size: var(--text-2xs);
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ==========================================================================
   Content
   ========================================================================== */

.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.view {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--page-gutter);
  padding-bottom: var(--space-16);
}

.view--flush {
  padding: 0;
  max-width: none;
}

/* ---------- Page header --------------------------------------------------- */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

.page-header__text {
  min-width: 0;
}

.page-header__title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  color: var(--color-text-strong);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}

/*
 * The router focuses this heading after every navigation so a screen reader
 * announces the new screen. It carries tabindex="-1", so it is never reached
 * by the Tab key and a focus ring here would only be visual noise on every
 * page load. Keyboard focus rings elsewhere are untouched.
 */
.page-header__title:focus { outline: none; }

.page-header__subtitle {
  margin-top: var(--space-1);
  font-size: var(--text-md);
  color: var(--color-text-muted);
  max-width: 68ch;
}

.page-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* ---------- Section ------------------------------------------------------- */

.section {
  margin-bottom: var(--space-6);
}

.section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}

.section__title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-text-strong);
}

.section__desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ==========================================================================
   Mobile drawer scaffolding
   ========================================================================== */

.scrim {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: var(--z-drawer);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-base) var(--ease-in-out);
}

.scrim.is-open {
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   Loading / boot screens
   ========================================================================== */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--color-bg);
  z-index: var(--z-toast);
  padding: var(--space-6);
}

.boot__inner {
  text-align: center;
  max-width: 460px;
}

.boot__logo {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--color-primary);
  display: grid;
  place-items: center;
  color: #fff;
}

.boot__title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--color-text-strong);
  margin-bottom: var(--space-2);
}

.boot__msg {
  font-size: var(--text-md);
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

.boot__bar {
  width: 200px;
  height: 3px;
  margin: 0 auto;
  border-radius: var(--radius-full);
  background: var(--color-border);
  overflow: hidden;
  position: relative;
}

.boot__bar::after {
  content: "";
  position: absolute;
  inset-block: 0;
  width: 40%;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  animation: boot-slide 1.1s var(--ease-in-out) infinite;
}

@keyframes boot-slide {
  0%   { left: -40%; }
  100% { left: 100%; }
}

.boot__error {
  text-align: left;
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-br);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-danger);
  word-break: break-word;
  max-height: 200px;
  overflow: auto;
}

/* ==========================================================================
   Storage warning banner
   ========================================================================== */

.storage-banner {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--page-gutter);
  background: var(--color-warning-bg);
  border-bottom: 1px solid var(--color-warning-br);
  color: var(--color-warning);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

/* ==========================================================================
   Right contextual panel
   ========================================================================== */

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(480px, 100vw);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-drawer);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--duration-base) var(--ease-out);
}

.side-panel.is-open {
  transform: translateX(0);
}

.side-panel__header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}

.side-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
}

.side-panel__footer {
  flex-shrink: 0;
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}
