/* NextMolar tenant console.
   Layout and visual language follow the FirstClock platform console: a dark
   navigation column, a slate canvas, white cards with hairline borders, quiet
   tables and one accent colour. The accent is NextMolar teal. */

:root {
  --ink: #0b1a1d;
  --muted: #5b6b70;
  --line: #e3e9ea;
  --line-soft: #eef3f4;
  --bg: #f5f8f8;
  --surface: #ffffff;
  --surface-soft: #f7fafa;
  --brand: #2aa5b8;
  --brand-btn: #0d7f90;
  --brand-hover: #0a6b79;
  --brand-soft: #e9f7f9;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --warn: #b54708;
  --warn-soft: #fffaeb;
  --ok: #0e7a5f;
  --ok-soft: #ecfdf3;
  --sidebar: #0b2024;
  --sidebar-line: rgba(255, 255, 255, 0.09);
  --sidebar-ink: #c7d7da;
  --sidebar-muted: #89a1a5;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(11, 26, 29, 0.05);
  --shadow-md: 0 16px 40px -28px rgba(11, 26, 29, 0.4);
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.35rem;
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must win over layout rules like `.auth { display: grid }`. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

h1 {
  font-size: var(--text-xl);
  margin: 0;
  letter-spacing: -0.02em;
}

h2 {
  font-size: var(--text-lg);
  letter-spacing: -0.015em;
}

h3 {
  font-size: var(--text-md);
}

p {
  line-height: 1.5;
}

a {
  color: inherit;
}

/* ── focus ──────────────────────────────────────────────────────────────── */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip {
  position: absolute;
  left: 10px;
  top: -60px;
  z-index: 100;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 600;
  text-decoration: none;
}

.skip:focus {
  top: 10px;
}

/* The sign-in card carries the brand itself, so there is no app bar: it only
   ever held a second copy of the logo. */

/* ── shell ──────────────────────────────────────────────────────────────── */
#console {
  --sidebar-w: 236px;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 0.16s ease;
}

body[data-nav="closed"] #console {
  --sidebar-w: 68px;
}

@media (prefers-reduced-motion: reduce) {
  #console,
  .sidebar {
    transition: none;
  }
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 12px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  overflow-y: auto;
  scrollbar-width: thin;
}

.side-top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
}

.side-brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

/* The supplied artwork is dark ink on white, so it sits on a small light plate. */
.side-logo {
  display: block;
  width: 148px;
  height: auto;
  aspect-ratio: 4 / 1;
  object-fit: cover;
  padding: 2px 6px;
  border-radius: 6px;
  background: #fff;
}

body[data-nav="closed"] .side-logo {
  width: 40px;
  aspect-ratio: 1;
  object-fit: contain;
  padding: 3px;
}

body[data-nav="closed"] .nav-toggle {
  display: none;
}

/* The menu names itself: the logo alone does not say which console this is. */
.side-title {
  margin: 2px 10px -6px;
  color: var(--sidebar-muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

body[data-nav="closed"] .side-title {
  display: none;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--sidebar-ink);
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
  text-align: left;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.icon-button svg,
.side-nav svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-toggle {
  padding: 5px 8px;
  font-size: 1rem;
  line-height: 1;
  color: var(--sidebar-muted);
  background: rgba(255, 255, 255, 0.04);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
}

.side-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--sidebar-ink);
  font: inherit;
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
}

.side-nav button:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.side-nav button[aria-selected="true"] {
  background: rgba(42, 165, 184, 0.2);
  color: #fff;
  box-shadow: inset 2px 0 0 var(--brand);
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-count {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.side-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--sidebar-line);
  font-size: 0.82rem;
  color: var(--sidebar-muted);
}

.side-actor {
  padding: 0 10px 6px;
  color: var(--sidebar-ink);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.side-note {
  margin: 6px 10px 0;
  font-size: 0.72rem;
  line-height: 1.4;
}

body[data-nav="closed"] .nav-label,
body[data-nav="closed"] .nav-count,
body[data-nav="closed"] .side-actor,
body[data-nav="closed"] .side-note {
  display: none;
}

body[data-nav="closed"] .side-nav button,
body[data-nav="closed"] .icon-button {
  justify-content: center;
  padding-inline: 0;
}

/* ── content ────────────────────────────────────────────────────────────── */
.content {
  min-width: 0;
  padding: var(--space-6) var(--space-6) 48px;
  /* The tables respond to this column's width, not the window's. */
  container-type: inline-size;
  container-name: panel;
}

.menu-button {
  display: none;
}

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

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: var(--text-sm);
  color: var(--muted);
}

.breadcrumbs [aria-current="page"] {
  color: var(--ink);
}

.page-head h1 {
  margin: 0 0 3px;
}

.page-sub {
  margin: 0;
  max-width: 74ch;
  color: var(--muted);
  font-size: var(--text-sm);
}

.head-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}

/* ── cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

[role="tabpanel"] {
  display: grid;
  gap: var(--space-4);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.card-head h2,
.card-head h3 {
  margin: 0;
}

.hint {
  display: block;
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-sm);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
}

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-value.ok {
  color: var(--ok);
}

.stat-value.warn {
  color: var(--warn);
}

/* ── tables ─────────────────────────────────────────────────────────────── */
.table-wrap {
  margin-top: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: auto;
  max-height: min(62vh, 620px);
  scrollbar-width: thin;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: 10px 12px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: var(--surface-soft);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

td.actions {
  display: table-cell;
  text-align: right;
  white-space: nowrap;
}

td.actions button {
  margin-left: 4px;
}

td.actions button:first-child {
  margin-left: 0;
}

td.actions .hint {
  display: inline-block;
  margin: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand-hover);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge.active {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.suspended {
  background: var(--danger-soft);
  color: var(--danger);
}

td .reason {
  margin-top: 3px;
  padding-left: 10px;
  border-left: 2px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
  white-space: normal;
}

.copy-site {
  opacity: 0;
  transition: opacity 120ms ease-in;
}

tbody tr:hover .copy-site,
.copy-site:focus-visible,
.copy-site.copied {
  opacity: 1;
}

@media (pointer: coarse) {
  .copy-site {
    opacity: 1;
  }
}

/* ── forms ──────────────────────────────────────────────────────────────── */
label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.78rem;
  color: var(--muted);
}

label.inline {
  margin: 0 0 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

input,
select {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
}

input:focus,
select:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
}

.form-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.req,
.opt {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.72rem;
}

.toolbar {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-3);
}

.toolbar > div {
  flex: 1 1 150px;
  min-width: 130px;
}

.toolbar .grow {
  flex: 3 1 240px;
}

/* ── buttons ────────────────────────────────────────────────────────────── */
button {
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  height: 38px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--brand-btn);
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: var(--brand-hover);
}

button.ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

button.ghost:hover {
  background: var(--surface-soft);
  border-color: color-mix(in srgb, var(--line) 60%, var(--muted));
}

button.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--line);
}

button.danger:hover {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.wide {
  width: 100%;
}

button.copied {
  color: var(--ok);
  border-color: var(--ok);
}

td.actions button,
.head-actions button {
  height: 32px;
  padding: 0 12px;
  font-size: 0.82rem;
}

/* ── notices ────────────────────────────────────────────────────────────── */
.status {
  width: fit-content;
  max-width: 100%;
  margin: 0 0 var(--space-4);
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-sm);
}

.status:empty {
  display: none;
}

.status.error {
  border-left-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

/* ── issued keys ────────────────────────────────────────────────────────── */
.issued {
  margin-top: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
}

.issued h3 {
  margin: 0 0 4px;
  font-size: var(--text-md);
}

.issued p {
  margin: 0 0 12px;
  color: var(--warn);
  font-size: var(--text-sm);
}

.issue-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}

.key {
  flex: 1 1 280px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

/* ── empty states ───────────────────────────────────────────────────────── */
.empty {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin: var(--space-3) 0 0;
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
}

.empty-text {
  margin: 0;
}

/* ── facts ──────────────────────────────────────────────────────────────── */
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3) var(--space-5);
  margin: 0;
}

.facts dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.facts dd {
  margin: 2px 0 0;
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

#hub-facts {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.hub-actor {
  margin: var(--space-4) 0 0;
}

.detail-pairs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  color: var(--muted);
}

.detail-pairs b {
  color: var(--ink);
  font-weight: 600;
}

.notes {
  margin: 6px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: var(--text-sm);
}

.notes li + li {
  margin-top: 6px;
}

/* ── drawer ─────────────────────────────────────────────────────────────── */
.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  margin: 0;
  width: min(640px, 100%);
  max-width: 100%;
  height: 100vh;
  max-height: 100vh;
  padding: 0 24px 40px;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

.drawer::backdrop {
  background: rgba(11, 26, 29, 0.45);
}

.drawer .card-head {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 -24px var(--space-4);
  padding: 16px 24px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: var(--space-4);
  margin-top: var(--space-3);
}

#detail-facts {
  margin: var(--space-4) 0;
  padding: var(--space-4) 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* ── dialogs ────────────────────────────────────────────────────────────── */
.dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 30px 70px -34px rgba(11, 26, 29, 0.45);
}

.dialog::backdrop {
  background: rgba(11, 26, 29, 0.45);
}

.dialog h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
}

.dialog-body {
  margin: 0 0 var(--space-4);
  color: var(--muted);
  font-size: var(--text-sm);
}

#register-form label,
#company-form label,
#operator-form label {
  margin-top: var(--space-3);
}

#register-form label:first-of-type,
#company-form label:first-of-type,
#operator-form label:first-of-type {
  margin-top: 0;
}

.dialog-error {
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 0.82rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

/* ── sign-in ────────────────────────────────────────────────────────────── */
.auth {
  display: grid;
  grid-template-columns: 340px 1fr;
  max-width: 800px;
  margin: 6vh auto 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 30px 70px -34px rgba(11, 26, 29, 0.4);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: 30px 26px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
}

.auth-logo {
  display: block;
  width: 150px;
  height: auto;
  aspect-ratio: 4 / 1;
  object-fit: cover;
  padding: 2px 6px;
  border-radius: 6px;
  background: #fff;
}

.auth-brand h1 {
  margin: 0;
  font-size: 1.3rem;
  color: #fff;
  letter-spacing: -0.01em;
}

.auth-lede {
  margin: 0;
  max-width: 30ch;
  font-size: 0.88rem;
  line-height: 1.45;
}

.auth-points {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 9px;
  font-size: 0.84rem;
}

.auth-points li {
  display: flex;
  gap: 8px;
}

.auth-points li::before {
  content: "✓";
  color: var(--brand);
  font-weight: 700;
}

.auth-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 30px 28px;
}

.auth-title {
  margin: 0 0 4px;
  font-size: 1.35rem;
}

.auth-sub {
  margin: 0 0 var(--space-4);
  color: var(--muted);
  font-size: var(--text-sm);
}

.auth-panel label {
  margin-top: var(--space-3);
}

.auth-panel label:first-of-type {
  margin-top: 0;
}

.note {
  margin: var(--space-3) 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}


/* ── responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  /* The rail is fixed here, so a grid would stretch the Menu row to fill the
     viewport and push the content down. Plain flow keeps it tight. */
  #console {
    display: block;
  }

  /* Above the content rather than over it: an expanded menu that covers the
     dashboard would make "expanded by default" a nuisance on a phone. */
  .sidebar {
    position: static;
    width: auto;
    height: auto;
    max-height: none;
    gap: 10px;
    padding: 12px;
    transform: none;
    transition: none;
  }

  .side-nav button {
    padding: 8px 10px;
  }

  /* A row of account controls instead of a column: the expanded menu sits above
     the dashboard, so every vertical pixel costs the page. */
  .side-foot {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }

  .side-actor {
    flex: 1 1 100%;
    padding-bottom: 2px;
  }

  .side-note {
    display: none;
  }

  body[data-nav="closed"] .sidebar {
    display: none;
  }

  /* The rail is a desktop preference; the phone drawer always shows labels. */
  body[data-nav="closed"] .nav-label,
  body[data-nav="closed"] .nav-count,
  body[data-nav="closed"] .side-actor,
  body[data-nav="closed"] .side-note {
    display: inline;
  }

  body[data-nav="closed"] .side-logo {
    width: 148px;
    aspect-ratio: 4 / 1;
  }

  body[data-nav="closed"] .nav-toggle {
    display: inline-flex;
  }

  body[data-nav="open"] .menu-button {
    display: none;
  }

  .menu-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: var(--space-3) var(--space-4) 0;
    height: 40px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    position: sticky;
    top: 8px;
    z-index: 30;
  }

  .menu-button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
  }

  .content {
    padding: 0 var(--space-4) var(--space-8);
  }

  body[data-view="console"] .status {
    position: sticky;
    top: 8px;
    z-index: 25;
    margin: 0 var(--space-4);
  }

  .page-head {
    margin-bottom: var(--space-4);
  }

  .page-head h1 {
    font-size: 1.15rem;
  }

  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@container panel (max-width: 720px) {
  /* The clinic table becomes one card per row, so status and the action are on
     screen without scrolling the table sideways. */
  #clinics-table thead {
    display: none;
  }

  #clinics-table,
  #clinics-table tbody {
    display: block;
    width: 100%;
  }

  #clinics-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "site status"
      "company actions";
    align-items: center;
    gap: 6px 10px;
    height: auto;
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }

  #clinics-table tbody tr:last-child {
    border-bottom: 0;
  }

  #clinics-table td {
    display: block;
    width: auto !important;
    padding: 0;
    border: 0;
    text-align: left;
    white-space: normal;
  }

  #clinics-table td:nth-child(1) {
    grid-area: site;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #clinics-table td:nth-child(2) {
    grid-area: company;
    color: var(--muted);
    font-size: 0.8rem;
  }

  #clinics-table td:nth-child(3) {
    grid-area: status;
    justify-self: end;
  }

  #clinics-table td:nth-child(4),
  #clinics-table td:nth-child(5),
  #clinics-table td:nth-child(6) {
    display: none;
  }

  #clinics-table td:nth-child(7) {
    grid-area: actions;
    text-align: right;
  }

  .table-wrap {
    border: 0;
    max-height: none;
  }
}

/* The drawer and the sign-in card are not inside the content column, so they
   key off the viewport: this must stay a media query, not a container query. */
@media (max-width: 760px) {
  .drawer {
    padding: 0 16px 32px;
  }

  .drawer .card-head {
    margin: 0 -16px var(--space-3);
    padding: 14px 16px 10px;
  }

  .drawer .card-head > div:first-child {
    padding-right: 88px;
  }

  .drawer .card-head {
    position: relative;
  }

  #close-detail {
    position: absolute;
    top: 14px;
    right: 16px;
  }

  .drawer .head-actions {
    flex-wrap: wrap;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .auth {
    grid-template-columns: 1fr;
    margin-top: var(--space-4);
  }

  .auth-brand {
    padding: 22px 20px;
  }

  .auth-points {
    display: none;
  }

  .auth-panel {
    padding: 22px 20px 26px;
  }

  .page-sub {
    display: none;
  }
}

@media (max-width: 480px) {
  .side-nav button {
    padding: 9px 10px;
  }
}

/* Touch targets: 44px is the size a thumb hits reliably. */
@media (pointer: coarse) {
  button,
  .icon-button,
  .side-nav button,
  input,
  select {
    min-height: 44px;
  }

  td.actions button {
    min-height: 38px;
  }
}

/* Phones: a five-column table becomes one card per row, every value carrying
   its column name — the pattern the FirstClock tables use. */
@container panel (max-width: 720px) {
  .table--cards,
  .table--cards tbody {
    display: block;
    width: 100%;
  }

  .table--cards thead {
    display: none;
  }

  .table--cards tbody tr {
    display: block;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
  }

  .table--cards tbody tr:last-child {
    border-bottom: 0;
  }

  .table--cards td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    padding: 4px 0;
    border: 0;
    text-align: right;
    white-space: normal;
  }

  .table--cards td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 0.76rem;
    text-align: left;
  }

  .table--cards td.actions {
    justify-content: flex-end;
    padding-top: 8px;
  }

  .table--cards td.actions::before {
    content: none;
  }
}

/* Small labels above a title (the drawer's "Clinic", the page's section kicker). */
.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.eyebrow + h1,
.eyebrow + h2 {
  margin-top: 0;
}


/* 3. Hub counters: three 95px columns on a phone crowd their labels. */
@media (max-width: 760px) {
  #hub-facts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* 2. The phone menu is a two-column grid instead of a 373px column, and the
   fold control is a full touch target. */
@media (max-width: 600px) {
  .side-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .side-nav button {
    width: auto;
  }

  #sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
  }
}

/* 6. On a phone the sign-in panel keeps the logo and title, not the prose. */
@media (max-width: 760px) {
  .auth-lede {
    display: none;
  }
}

/* 7. A notice that floats over the heading while scrolling is worse than one
   that scrolls away. */
@media (max-width: 900px) {
  body[data-view="console"] .status {
    position: static;
    margin: 0 0 var(--space-3);
  }
}

/* Password reveal beside the field, and the Caps Lock hint under it. */
.field-with-action {
  display: flex;
  gap: 6px;
}

.field-with-action input {
  flex: 1;
}

.field-with-action button {
  flex: 0 0 auto;
  padding: 0 12px;
  font-size: 0.82rem;
  color: var(--muted);
}

.caps {
  margin-top: 6px;
  color: var(--warn);
}

/* ── sign-in refinements ─────────────────────────────────────────────────── */

/* 1. Centre the card instead of anchoring it to the top of the page. */
body[data-view="auth"] main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-5);
}

.auth {
  margin: 0;
}

/* 3. Environment chip beside the heading. */
.auth-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.auth-heading .auth-title {
  margin: 0;
}

.env-badge {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 25%, transparent);
}

/* 6. The checklist fills the bottom of the dark panel instead of floating. */
.auth-points {
  margin: auto 0 0;
}

/* 7. The error takes the subtitle's line, so nothing jumps when it appears. */
#connect.has-error .auth-sub {
  display: none;
}

.auth-error {
  margin: -6px 0 var(--space-4);
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  color: var(--danger);
  font-size: var(--text-sm);
}

/* 8. Show sits inside the password field, so both fields keep one width. */
.field-with-action {
  position: relative;
}

.field-with-action input {
  padding-right: 72px;
}

#toggle-password {
  position: absolute;
  top: 4px;
  right: 4px;
  height: calc(100% - 8px);
  min-height: 0;
  padding: 0 12px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* 2. A field the hub refused is marked, not just described. */
input[aria-invalid="true"] {
  border-color: var(--danger);
}
