@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap");

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-muted: #f8fbff;
  --text: #1f2937;
  --muted: #667085;
  --line: #e9eef5;
  --line-soft: #f2f6fb;
  --primary: #111827;
  --primary-dark: #030712;
  --accent: #1d4ed8;
  --accent-soft: #f4f9ff;
  --accent-line: #d8e8fb;
  --success: #0f9f6e;
  --warning: #b7791f;
  --danger: #b42318;
  --radius-xl: 8px;
  --radius-lg: 6px;
  --radius-md: 6px;
  --shadow: none;
  --shadow-soft: none;
  --page-gutter: clamp(8px, 1vw, 16px);
  --topbar-height: 64px;
  --sidebar-width: 236px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", sans-serif;
}

body {
  position: relative;
  overflow-x: hidden;
  background: linear-gradient(180deg, #ffffff 0, #fdfefe 220px, #ffffff 100%);
}

body.admin-sidebar-open {
  overflow: hidden;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
}

.admin-table-select {
  min-width: 7.5rem;
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
}

code {
  padding: 0 0.28rem;
  border-radius: 4px;
  background: #f2f6fb;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.92em;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.note {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.error {
  color: var(--danger);
  font-size: 0.92rem;
}

.success {
  color: var(--success);
}

.warning {
  color: var(--warning);
}

.admin-page,
.admin-login {
  min-height: 100vh;
  padding: 0;
}

.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 120;
  min-height: var(--topbar-height);
  margin: 0;
  padding: 10px var(--page-gutter);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.admin-topbar > div {
  min-width: 0;
}

.admin-topbar-copy {
  flex: 1;
  min-width: 0;
}

.admin-topbar h1,
.admin-card h2,
.login-card h1,
.login-side h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.06;
}

.admin-topbar h1 {
  margin-top: 4px;
  font-size: clamp(1.45rem, 2vw, 1.95rem);
}

.admin-topbar .muted:first-child {
  margin-bottom: 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.admin-topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.admin-org-scope {
  display: grid;
  min-width: 180px;
}

.admin-org-scope-select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line-soft);
  background: #fff;
  color: #334155;
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.admin-profile-menu {
  position: relative;
}

.admin-menu-toggle {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.admin-menu-toggle span,
.admin-menu-toggle span::before,
.admin-menu-toggle span::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: #0f172a;
  content: "";
}

.admin-menu-toggle span {
  position: relative;
}

.admin-menu-toggle span::before {
  position: absolute;
  top: -6px;
  left: 0;
}

.admin-menu-toggle span::after {
  position: absolute;
  top: 6px;
  left: 0;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-brand-logo {
  width: 38px;
  height: 30px;
  object-fit: contain;
  flex: 0 0 auto;
}

.admin-brand-copy {
  display: grid;
  gap: 1px;
}

.admin-brand-caption {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.admin-user-pill {
  margin: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  color: #334155;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.admin-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f4f9ff;
  color: #1d4ed8;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.admin-profile-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 220px;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  z-index: 200;
}

.admin-profile-summary {
  display: block;
  padding: 6px 10px 10px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 6px;
}

.admin-profile-summary strong {
  font-size: 0.92rem;
}

.admin-profile-language {
  display: grid;
  gap: 8px;
  padding: 2px 10px 10px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 6px;
}

.admin-profile-dropdown .admin-org-scope {
  min-width: 0;
  width: 100%;
  padding: 2px 10px 10px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 6px;
}

.admin-profile-language-label {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.admin-language-select-wrap {
  display: block;
}

.admin-language-select {
  width: 100%;
  border: 1px solid var(--line-soft);
  background: #fff;
  color: #334155;
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.admin-profile-menu.open .admin-profile-dropdown {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.admin-profile-action {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: #991b1b;
  border-radius: var(--radius-lg);
  text-align: left;
  padding: 9px 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
}

.admin-profile-action:hover {
  background: #fff5f5;
}

.admin-shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-height));
}

.admin-nav {
  width: var(--sidebar-width);
  min-height: calc(100vh - var(--topbar-height));
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #fff;
  border-right: 1px solid var(--line-soft);
  position: sticky;
  top: var(--topbar-height);
  align-self: start;
}

body.admin-sidebar-collapsed .admin-nav {
  width: 64px;
  padding-inline: 6px;
}

.admin-nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-nav-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.admin-nav-link {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: #334155;
  border-radius: var(--radius-lg);
  text-align: left;
  padding: 9px 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.admin-nav-link:hover {
  background: #f8fbff;
  color: #111827;
}

.admin-nav-link.active {
  background: #f4f9ff;
  color: #111827;
  border-color: #d8e8fb;
}

.admin-nav-sublist {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 0 4px 34px;
}

.admin-nav-sublink {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  color: #475569;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-nav-sublink:hover {
  background: #f8fbff;
  color: #111827;
}

.admin-nav-sublink.active {
  background: #f4f9ff;
  color: #111827;
  border-color: #d8e8fb;
}

.admin-nav-link svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.9;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.admin-nav-link .sidebar-icon,
.admin-nav-link svg {
  flex: 0 0 auto;
}

.admin-nav-link .admin-nav-label,
.admin-nav-sublink .admin-nav-label {
  min-width: 0;
  margin-right: auto;
}

.admin-nav-pill {
  padding: 2px 8px;
  border-radius: 999px;
  background: #f4f9ff;
  border: 1px solid #d8e8fb;
  color: #1d4ed8;
  font-size: 0.74rem;
  line-height: 1.2;
  font-weight: 700;
}

body.admin-sidebar-collapsed .admin-nav-head,
body.admin-sidebar-collapsed .admin-nav-link .admin-nav-label,
body.admin-sidebar-collapsed .admin-nav-link .admin-nav-pill {
  display: none;
}

body.admin-sidebar-collapsed .admin-nav-link {
  justify-content: center;
  padding-inline: 0;
}

body.admin-sidebar-collapsed .admin-nav-sublist {
  display: none;
}

.admin-main {
  min-width: 0;
  padding: 12px var(--page-gutter) 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-card,
.login-card,
.login-side {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-soft);
}

.admin-card {
  min-width: 0;
  padding: 12px;
}

.admin-card h2 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.admin-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.admin-toolbar-main {
  flex: 1;
  min-width: 0;
}

.admin-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-toolbar-actions > label {
  min-width: min(220px, 100%);
}

.admin-master-detail {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
}

.admin-list-panel,
.admin-detail-panel {
  min-width: 0;
}

.admin-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 10px;
}

.admin-panel-head h2,
.admin-panel-head h3 {
  margin-bottom: 4px;
}

.admin-meta-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-empty-state {
  border: 1px dashed var(--line);
  background: #fbfdff;
  padding: 18px;
  text-align: center;
  color: var(--muted);
}

.admin-table-button {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.admin-table-button-compact {
  padding: 4px 8px;
  font-size: 0.76rem;
  line-height: 1.2;
}

.admin-inline-assess-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.admin-ai-pending-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  color: var(--accent);
}

.admin-ai-pending-dots {
  display: inline-block;
  width: 1.4em;
  animation: admin-ai-thinking-dots 900ms infinite ease-in-out;
}

@keyframes admin-ai-thinking-dots {
  0% { opacity: 0.25; }
  50% { opacity: 1; }
  100% { opacity: 0.25; }
}

.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;
}

.button.admin-icon-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.button.admin-table-icon-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.admin-icon-button .icon-tabler,
.admin-table-icon-button .icon-tabler {
  width: 18px;
  height: 18px;
  display: block;
  stroke: currentColor;
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.admin-icon-button .icon-tabler {
  width: 22px;
  height: 22px;
}

.admin-table-icon-button .icon-tabler {
  width: 22px;
  height: 22px;
}

.button.admin-icon-button:hover,
.button.admin-table-icon-button:hover {
  color: #1e40af;
  background: #e3efff;
  border-color: #bfd3f6;
}

.admin-inline-filter-button {
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 700;
}

.admin-table tbody tr {
  cursor: pointer;
}

.admin-table tbody tr.admin-row-active {
  background: #f4f9ff;
}

.admin-table-cell-title {
  display: grid;
  gap: 4px;
}

.admin-kv {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.admin-kv-item {
  border: 1px solid var(--line-soft);
  background: #fbfdff;
  padding: 10px;
}

.admin-kv-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.admin-kv-value {
  display: block;
  margin-top: 4px;
  font-weight: 600;
}

.admin-json-block {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: #fbfdff;
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.84rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
}

.admin-chip-link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  font: inherit;
}

.admin-chip-link[disabled] {
  color: var(--muted);
  cursor: not-allowed;
  text-decoration: none;
}

.admin-chip-readings-wrap {
  max-height: 58vh;
  overflow: auto;
}

.admin-chip-readings-synthetic-row td {
  background: #f8fbff;
}

.admin-chip-readings-add-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 0.9fr) minmax(130px, 0.7fr) minmax(120px, 0.6fr) auto;
  gap: 8px;
  align-items: end;
  margin-top: 10px;
}

.admin-chip-readings-add-meta {
  margin-top: 6px;
}

.admin-chip-result-toggle {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  margin: 0 0 6px 0;
  font: inherit;
}

.admin-chip-result-block {
  margin-top: 10px;
}

.admin-section-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-table-action-col {
  width: 1%;
  white-space: nowrap;
}

.admin-table th.admin-table-action-col,
.admin-table td.admin-table-action-col {
  text-align: right;
  padding-right: 0;
}

.admin-table-action-col .admin-inline-actions {
  justify-content: flex-end;
  flex-wrap: nowrap;
  align-items: center;
}

.admin-table-wrap {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-table-wrap .admin-table {
  min-width: 760px;
}

.admin-form-submit-row {
  align-self: end;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.admin-tab-button {
  border: 1px solid var(--line-soft);
  background: #fff;
  color: #334155;
  padding: 8px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.admin-tab-button.active {
  background: #f4f9ff;
  border-color: #d8e8fb;
  color: #111827;
}

.admin-tab-panel.hidden {
  display: none;
}

.admin-chip-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-chip-item {
  border: 1px solid var(--line-soft);
  background: #fbfdff;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  width: 100%;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.admin-chip-item.admin-row-active {
  background: #f4f9ff;
  border-color: #d8e8fb;
}

.admin-chip-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.admin-chat-layout {
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
}

.admin-chat-toolbar-actions {
  align-items: flex-end;
  flex-wrap: wrap;
}

.admin-chat-sessions {
  max-height: 540px;
  overflow: auto;
}

.admin-chat-session {
  width: 100%;
}

.admin-chat-threads-modal {
  width: min(760px, 100%);
}

.admin-chat-threads-modal .admin-chat-sessions {
  max-height: calc(100vh - 220px);
}

.admin-chat-feed {
  min-height: 280px;
  max-height: none;
  height: clamp(280px, 52vh, 720px);
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: #fbfdff;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-chat-message {
  max-width: min(640px, 92%);
  border-radius: 12px;
  border: 1px solid var(--line-soft);
  padding: 10px 12px;
  background: #fff;
}

.admin-chat-message-text {
  white-space: normal;
  line-height: 1.5;
}

.admin-chat-message-text p {
  margin: 0 0 8px;
}

.admin-chat-message-text p:last-child {
  margin-bottom: 0;
}

.admin-chat-message-text h1,
.admin-chat-message-text h2,
.admin-chat-message-text h3,
.admin-chat-message-text h4,
.admin-chat-message-text h5,
.admin-chat-message-text h6 {
  margin: 0 0 8px;
  line-height: 1.25;
  letter-spacing: 0;
}

.admin-chat-message-text h1 { font-size: 1.1rem; }
.admin-chat-message-text h2 { font-size: 1.04rem; }
.admin-chat-message-text h3 { font-size: 1rem; }
.admin-chat-message-text h4,
.admin-chat-message-text h5,
.admin-chat-message-text h6 { font-size: 0.95rem; }

.admin-chat-message-text ul,
.admin-chat-message-text ol {
  margin: 0 0 8px 20px;
  padding: 0;
}

.admin-chat-message-text li {
  margin-bottom: 4px;
}

.admin-chat-message-text blockquote {
  margin: 0 0 8px;
  padding: 6px 10px;
  border-left: 3px solid #c7d2fe;
  background: #f8faff;
  color: #374151;
}

.admin-chat-message-text pre {
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
  overflow: auto;
}

.admin-chat-message-text pre code {
  display: block;
  padding: 0;
  background: transparent;
  line-height: 1.45;
}

.admin-chat-message-text a {
  color: #1d4ed8;
  text-decoration: underline;
}

.admin-chat-message-user {
  align-self: flex-end;
  background: #f4f9ff;
  border-color: #d8e8fb;
}

.admin-chat-message-assistant {
  align-self: flex-start;
}

.admin-chat-message-system {
  align-self: center;
  background: #f8fafc;
  color: var(--muted);
}

.admin-chat-message-meta {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.admin-chat-status {
  padding: 10px 12px;
  border: 1px solid #d8e8fb;
  border-radius: var(--radius-lg);
  background: #f4f9ff;
  color: #1e3a8a;
  font-size: 0.9rem;
}

.admin-chat-trace {
  margin-top: 8px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: #fcfdff;
  padding: 10px 12px;
}

.admin-chat-trace-head {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-chat-trace-list {
  display: grid;
  gap: 8px;
}

.admin-chat-trace-empty {
  color: var(--muted);
  font-size: 0.85rem;
}

.admin-chat-trace-item {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
}

.admin-chat-trace-running {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.admin-chat-trace-done {
  border-color: #d1fae5;
  background: #f0fdf4;
}

.admin-chat-trace-fallback {
  border-color: #fde68a;
  background: #fffbeb;
}

.admin-chat-trace-error {
  border-color: #fecaca;
  background: #fef2f2;
}

.admin-chat-trace-title {
  font-size: 0.86rem;
  font-weight: 700;
  color: #1f2937;
}

.admin-chat-trace-detail {
  margin-top: 2px;
  font-size: 0.84rem;
  color: #334155;
}

.admin-chat-trace-meta {
  margin-top: 4px;
  font-size: 0.76rem;
  color: var(--muted);
}

.admin-chat-card {
  position: relative;
}

.admin-chat-composer {
  position: sticky;
  bottom: 0;
  z-index: 20;
  margin-top: 12px;
  padding-top: 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.92) 24%, #fff 52%);
}

.admin-chat-composer textarea {
  min-height: 72px;
}

.admin-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.admin-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.24);
}

.admin-modal-card {
  position: relative;
  width: min(720px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  z-index: 1;
}

.admin-chip-readings-modal {
  width: min(90vw, 1400px);
}

.admin-form,
.stack,
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.admin-checkbox-row,
.admin-checkbox-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 8px;
}

.admin-checkbox-list label,
.admin-checkbox-row label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.admin-search-field {
  width: 100%;
}

.admin-search-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.admin-search-control .admin-icon-button {
  flex: 0 0 auto;
}

.admin-selectors {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.admin-form label,
.admin-selectors label,
.login-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (max-width: 980px) {
  .admin-chip-readings-add-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .admin-chip-readings-add-form .button {
    width: 100%;
  }
}

.admin-form label > div,
.admin-selectors label > div,
.login-form label > div {
  font-size: 0.84rem;
  font-weight: 600;
  color: #334155;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  font: inherit;
  color: inherit;
  background: #fff;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #94a3b8;
  box-shadow: 0 0 0 1px #94a3b8;
}

textarea {
  resize: vertical;
  min-height: 96px;
}

.button,
.login-form button,
.admin-ghost-button {
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.button,
.login-form button {
  background: var(--primary);
  color: #fff;
  box-shadow: none;
}

.button:hover,
.login-form button:hover {
  background: var(--primary-dark);
}

.admin-ghost-button {
  background: #fff;
  color: #1f2937;
  border-color: var(--line-soft);
}

.admin-ghost-button:hover {
  background: #f8fbff;
}

.button:active,
.login-form button:active,
.admin-ghost-button:active {
  transform: translateY(1px);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th,
.admin-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.admin-table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  vertical-align: top;
}

.admin-table td {
  vertical-align: middle;
}

.admin-table tbody tr:hover {
  background: #f8fbff;
}

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

.admin-timing-scope-card .stats-grid {
  margin-top: 10px;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
}

.admin-timing-scope-card #summaryMeta {
  margin-top: 6px;
}

.stat-card,
.history-item {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: 10px;
  background: var(--surface-muted);
}

.stat-card strong {
  display: block;
  font-size: 1.55rem;
  margin-top: 6px;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge {
  padding: 6px 10px;
  border-radius: 999px;
  background: #f4f9ff;
  color: #1d4ed8;
  border: 1px solid #d8e8fb;
  font-weight: 700;
  font-size: 0.8rem;
}

.admin-login {
  display: grid;
  place-items: center;
  padding: 16px;
}

.admin-login-shell {
  width: min(520px, 100%);
  display: grid;
  grid-template-columns: minmax(320px, 1fr);
  justify-items: stretch;
}

.login-card,
.login-side {
  padding: 24px;
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.login-brand-logo {
  width: 64px;
  height: 48px;
}

.login-card h1 {
  margin: 0 0 12px;
  font-size: clamp(1.8rem, 3vw, 2.7rem);
  text-align: center;
}

.login-intro,
.login-side p,
.login-side li {
  color: var(--muted);
  line-height: 1.7;
}

.login-intro {
  text-align: center;
}

.login-form {
  margin-top: 18px;
  display: grid;
  gap: 14px;
}

.login-form button {
  justify-self: end;
}

.login-build-meta {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.admin-sidebar-backdrop {
  position: fixed;
  inset: var(--topbar-height) 0 0 0;
  background: rgba(15, 23, 42, 0.18);
  z-index: 140;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

body.admin-sidebar-open .admin-sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

body.admin-sidebar-open #adminNav {
  transform: translateX(0) !important;
}

@media (max-width: 980px) {
  .admin-shell,
  .admin-login-shell,
  .admin-selectors,
  .admin-master-detail {
    grid-template-columns: 1fr;
  }

  .admin-nav {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    z-index: 160;
    width: min(84vw, 320px);
    min-height: auto;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: none;
  }

  body.admin-sidebar-open .admin-nav {
    transform: translateX(0);
  }

  .admin-main {
    padding: 10px;
  }
}

@media (max-width: 780px) {
  .admin-topbar {
    gap: 10px;
    padding-inline: 14px;
  }

  .admin-topbar h1 {
    font-size: 1.28rem;
  }

  .admin-topbar-copy .muted {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .admin-topbar-actions {
    justify-content: flex-end;
    min-width: 0;
  }

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

  .admin-toolbar-actions {
    width: 100%;
  }

  .admin-toolbar-actions > label {
    flex: 1 1 180px;
  }

  .admin-org-scope {
    min-width: 130px;
  }

  .admin-form-grid,
  .admin-login-shell,
  .admin-kv {
    grid-template-columns: 1fr;
  }

  .admin-user-pill {
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .admin-brand-copy,
  .admin-user-pill {
    display: none;
  }

  .admin-card,
  .login-card,
  .login-side {
    border-radius: var(--radius-xl);
  }

  .admin-modal {
    align-items: flex-start;
    overflow: auto;
    padding: 12px;
  }

  .admin-modal-card {
    max-height: calc(100dvh - 24px);
  }

  .admin-chip-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-chip-item > .admin-inline-actions {
    width: 100%;
  }

  .admin-table {
    display: block;
    overflow-x: auto;
  }

  .admin-table-wrap .admin-table {
    display: table;
    overflow-x: visible;
  }

  .admin-table .admin-col-secondary {
    display: none;
  }

  .admin-table-wrap .admin-col-secondary {
    display: table-cell;
  }

  .admin-table th.admin-table-action-col,
  .admin-table td.admin-table-action-col {
    position: sticky;
    right: 0;
    z-index: 1;
    background: #fff;
  }
}

@media (max-width: 520px) {
  .admin-table .admin-col-tertiary {
    display: none;
  }
}
