/* ── Admin Layout ──
   Shell, header, navigation, mobile menu, nav dropdown.
   Split from admin.css (Phase 4, Step B4). */

/* Admin UI Styles */

body {
  overflow-x: hidden;
}

a {
  color: var(--color-primary-dark);
}

.admin-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  max-width: 100vw;
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.admin-nav {
  /* Wider than the 1200px reading measure used for page content: this is a
     dense internal tool bar, not prose, and the extra 200px is the difference
     between one row and two. */
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Audri swirl beside the wordmark (base `.audri-mark` in base.css). */
.admin-brand-mark {
  font-size: 1.6rem;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-primary);
  white-space: nowrap;
}

.admin-brand-badge {
  background: var(--color-primary-bg);
  color: var(--color-primary-dark);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.admin-brand-text {
  /* One line now: the build/version moved into the Internal badge's tooltip
     (spec 2026-08-02 D2), so this no longer stacks a second row. */
  line-height: 1.1;
  white-space: nowrap;
}

.admin-links {
  display: flex;
  flex: 1 1 auto;
  gap: 4px;
  align-items: center;
  /* Deliberately NOT flex-wrap (spec 2026-08-02 D2). Wrapping was the safety
     valve that let this header grow to four rows and ~230px: each new link
     just added another line, so nothing ever felt broken enough to fix. With
     navigation bounded by the registry's group model, a single row is the
     invariant. Below 900px the off-canvas menu takes over (admin-pages.css).

     Do NOT add `overflow-x: auto` here to absorb width pressure. It looks like
     the obvious fix and it breaks every group menu: an `overflow` value other
     than `visible` establishes a clipping context, and the menus are absolutely
     positioned DESCENDANTS of this element, so they get clipped to the nav's
     own box instead of hanging below it. The symptom is a menu that appears to
     replace the nav rather than open under it. The width pressure it was meant
     to solve is handled structurally instead: bounded item count (the registry
     groups), a compact wordmark, a non-shrinking account cluster, and the 900px
     hand-off to the off-canvas menu. */
  flex-wrap: nowrap;
  min-width: 0;
}

/* Practice switcher + Security + user actions. Never shrinks: signing out and
   knowing which practice you are looking at must not depend on nav width. */
.admin-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.admin-link {
  text-decoration: none;
  color: var(--text-secondary);
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  transition: all 0.2s ease;
}

.admin-link:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.admin-link.active {
  background: var(--color-primary-bg);
  color: var(--color-primary-dark);
}

/* Inline-toggle, practice-switcher, user-actions and btn-sm control styles
   moved to shared-components.css (loaded by the admin + clinician shells). */

/* Theme row in mobile menu */
.mobile-menu-theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.mobile-menu-theme-label {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

.admin-main {
  flex: 1;
}

.admin-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}


/* Dark-mode secondary-button contrast, the header practice switcher and the
   .practice-badge moved to shared-components.css (loaded by both shells). */

/* Practice switcher inside the mobile slide-out menu */
.mobile-menu-practice {
  padding: 12px 20px;
  border-top: 1px solid var(--border-color);
}

.mobile-menu-practice .practice-switcher {
  width: 100%;
}

.mobile-menu-practice .practice-switcher select {
  width: 100%;
  max-width: 100%;
  padding: 12px 36px 12px 14px;
  font-size: 1rem;
  min-height: 44px;
}

.mobile-menu-practice .practice-badge {
  display: block;
  max-width: 100%;
  padding: 10px 14px;
  text-align: center;
}

/* ── Nav dropdown ── */
.nav-dropdown {
  position: relative;
}

.nav-dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  /* --text-secondary, matching `.admin-link`. It was --text-tertiary, a MUTED
     token: correct when these were two side dropdowns beside twenty top-level
     links, wrong now that the groups hold 20 of 22 destinations. It rendered
     the primary navigation fainter than the two remaining direct links, and
     measured 3.0:1 against the header — under the 4.5:1 AA floor for body
     text. Promoting an element in the hierarchy means promoting its colour. */
  color: var(--text-secondary);
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  transition: all 0.2s ease;
  cursor: pointer;
  border: none;
  background: none;
  font-size: inherit;
  font-family: inherit;
}

.nav-dropdown-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.nav-dropdown-toggle.active {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.nav-dropdown-toggle .dropdown-arrow {
  font-size: 0.65rem;
  transition: transform 0.2s ease;
}

.nav-dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  padding: 4px 0;
}

.nav-dropdown.open .nav-dropdown-menu {
  display: block;
}

.nav-dropdown-menu a {
  display: block;
  padding: 10px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.nav-dropdown-menu a:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-dropdown-menu a.active {
  color: var(--color-primary-dark);
  background: var(--color-primary-bg);
}

/* POST-only shortcuts render as a <form><button>; make them look exactly
   like the sibling <a> menu items (issue 663). */
.nav-dropdown-form {
  margin: 0;
}

.nav-dropdown-form-button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 16px;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.nav-dropdown-form-button:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-dropdown-form-button.active {
  color: var(--color-primary-dark);
  background: var(--color-primary-bg);
}


/* ── Mobile Responsive (Simulation & Admin) ── */

@media (max-width: 768px) {
  .table-wrapper {
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
  }

  .data-table th,
  .data-table td {
    padding: 10px 8px;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .action-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .action-bar-start,
  .action-bar-end {
    justify-content: center;
  }

  .filters {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group {
    min-width: auto;
    width: 100%;
  }

  .filter-group select,
  .filter-group input {
    width: 100%;
  }

  .filter-actions {
    margin-left: 0;
    display: flex;
    gap: 8px;
  }

  .prompt-diff,
  .expandable-content,
  pre {
    font-size: 0.75rem;
    overflow-x: auto;
  }

  .transcript-bubble {
    max-width: 92%;
  }

  /* Issue #7: Stack heading and CTA on mobile */
  .page-heading-row {
    flex-direction: column;
    gap: 12px;
  }

  .page-heading-row > div:last-child {
    align-self: flex-start;
  }

  /* Issue #4: Prevent meta-value overflow */
  .meta-value {
    word-break: break-word;
    overflow-wrap: break-word;
  }
}

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

  .meta-grid {
    grid-template-columns: 1fr 1fr;
  }

  .meta-grid .meta-item.full-width {
    grid-column: 1 / -1;
  }
}

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


/* ── Command palette (spec 2026-08-02 D5) ──────────────────────────────────
   The grouped header bounded the console's WIDTH; this bounds its DEPTH. Every
   destination is one keystroke away regardless of which menu it lives in, so
   adding a page never costs a click. */

.cmdk-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cmdk-trigger:hover {
  border-color: var(--border-color-strong);
  color: var(--text-secondary);
}

.cmdk-trigger kbd,
.cmdk-hint kbd {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 2px 5px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  border: 1px solid var(--border-color-light);
}

.cmdk {
  position: fixed;
  inset: 0;
  z-index: 200;
  /* A wash, not a blackout: the page behind stays legible, which is the point
     of a palette you open mid-task. */
  background: var(--overlay-scrim);
  display: flex;
  justify-content: center;
  /* Not centred: a dialog that grows downward from a fixed top edge does not
     shift its first result as the list length changes while you type. */
  align-items: flex-start;
  padding-top: 12vh;
}

/* Setting `display` on an element the JS hides via the `hidden` ATTRIBUTE
   silently defeats it: the UA's `display:none` for [hidden] loses to any
   author `display`. Without this rule the palette renders open on every page
   load. (AGENTS.md names this footgun; I still walked into it.) */
.cmdk[hidden] {
  display: none;
}

.cmdk-panel {
  width: min(38rem, 92vw);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.cmdk-input {
  width: 100%;
  padding: 18px 20px;
  border: none;
  border-bottom: 1px solid var(--border-color-light);
  background: transparent;
  color: var(--text-primary);
  font-size: var(--text-lg);
  font-family: inherit;
}

.cmdk-input:focus {
  outline: none;
}

.cmdk-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: 22rem;
  overflow-y: auto;
}

.cmdk-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.cmdk-item.is-active {
  background: var(--color-primary-bg);
}

.cmdk-item-label {
  color: var(--text-primary);
  font-weight: 500;
}

.cmdk-item-group,
.cmdk-empty {
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}

.cmdk-empty {
  padding: 18px 20px;
}

.cmdk-hint {
  display: flex;
  gap: 16px;
  padding: 10px 20px;
  border-top: 1px solid var(--border-color-light);
  background: var(--bg-secondary);
  color: var(--text-tertiary);
  font-size: var(--text-xs);
}

/* The trigger is the first thing to go when width is scarce — the keystroke
   still works, and on a touch device the off-canvas menu is the better shape
   anyway. */
@media (max-width: 900px) {
  .cmdk-trigger {
    display: none;
  }
}
