:root {
  --ink: #1a2332; --ink-muted: #5a6578; --cream: #f5f0eb; --teal: #0d6e73;
  --teal-light: #e6f3f4; --border: #dde2ea; --white: #fff;
  --red: #b42318; --green: #067647;
  --font-display: 'Instrument Sans', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --panel-width: 380px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-body); font-size: 14px; color: var(--ink); background: var(--cream); min-height: 100vh; }
body.panel-open { overflow: hidden; }
.wrap { max-width: 960px; margin: 0 auto; padding: 28px 20px 40px; }
.header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 8px; }
.brand { font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.brand span { color: var(--teal); }
.byline { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
.nav {
  display: flex; gap: 4px; margin-bottom: 0; border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.admin-main { margin-top: 20px; }
.nav a {
  padding: 10px 14px; font-size: 13px; font-weight: 600; color: var(--ink-muted);
  text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.nav a:hover { color: var(--ink); }
.nav a.active { color: var(--teal); border-bottom-color: var(--teal); }
.page-header {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin-bottom: 16px;
}
h1 { font-family: var(--font-display); font-size: 1.35rem; }
h2 { font-family: var(--font-display); font-size: 1.05rem; margin-bottom: 12px; }
.card {
  background: var(--white); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; margin-bottom: 20px;
}
.card--flush { padding: 0; overflow: visible; }
.flash {
  padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px;
}
.flash.success { background: #ecfdf3; color: var(--green); border: 1px solid #abefc6; }
.flash.error { background: #fef3f2; color: var(--red); border: 1px solid #fecdca; }
label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
input, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; font: inherit; font-size: 13px;
}
.field { margin-bottom: 12px; }
.btn {
  display: inline-block; padding: 8px 14px; background: var(--teal); color: white;
  border: none; border-radius: 8px; font-family: var(--font-display); font-weight: 600;
  font-size: 13px; cursor: pointer; text-decoration: none;
}
.btn:hover { background: #095459; }
.btn.secondary { background: var(--white); color: var(--ink); border: 1px solid var(--border); }
.btn.danger { background: var(--red); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.ghost { background: transparent; color: var(--ink-muted); border: 1px solid transparent; }
.btn.ghost:hover { background: var(--teal-light); color: var(--teal); }
.logout-form { display: inline; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-muted); }
tr:last-child td { border-bottom: none; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
}
.badge.active { background: #ecfdf3; color: var(--green); }
.badge.revoked, .badge.inactive { background: #f2f4f7; color: var(--ink-muted); }
.badge.expired { background: #fff7e6; color: #8a5a00; }
.badge.ready { background: #ecfdf3; color: var(--green); }
.badge.failed { background: #fef3f2; color: var(--red); }
.badge.pending, .badge.processing { background: var(--teal-light); color: var(--teal); }
.muted { color: var(--ink-muted); font-size: 12px; }
.code { font-family: ui-monospace, monospace; font-size: 12px; }
.code-copy {
  font-family: ui-monospace, monospace; font-size: 12px;
  background: none; border: none; padding: 0; color: var(--teal);
  cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px;
}
.code-copy:hover { color: #095459; }
.partner-name-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.partner-code-mobile {
  display: none; margin-top: 2px; padding: 2px 8px; border-radius: 6px;
  background: var(--teal-light); border: 1px solid #c5e3e5; font-size: 12px;
}
@media (max-width: 720px) {
  .partner-code-mobile { display: inline-block; }
}
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.split-btn { display: inline-flex; position: relative; align-items: stretch; }
.split-btn .split-btn-primary {
  border-top-right-radius: 0; border-bottom-right-radius: 0; border-right: none;
}
a.split-btn-primary {
  display: inline-flex; align-items: center; text-decoration: none;
}
.split-btn .split-btn-caret {
  border-top-left-radius: 0; border-bottom-left-radius: 0;
  min-width: 28px; padding-left: 6px; padding-right: 6px; line-height: 1;
}
.menu-wrap { position: relative; }
.menu-wrap.open { z-index: 5; }
tr:has(.menu-wrap.open) { position: relative; z-index: 4; }
.menu-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 4px);
  min-width: 170px; background: var(--white); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(26, 35, 50, 0.12); z-index: 50; padding: 4px;
}
.menu-wrap.drop-up .menu-dropdown {
  top: auto; bottom: calc(100% + 4px);
}
.menu-wrap.open .menu-dropdown { display: block; }
.menu-dropdown.is-fixed {
  position: fixed; right: auto; bottom: auto; z-index: 60;
}
.menu-item {
  display: block; width: 100%; text-align: left; border: none; background: none;
  padding: 8px 10px; font: inherit; font-size: 13px; border-radius: 6px; cursor: pointer;
  color: var(--ink);
}
.menu-item:hover { background: var(--teal-light); }
.menu-item.danger { color: var(--red); }
.menu-item.danger:hover { background: #fef3f2; }
.menu-form { margin: 0; }
.filter-form {
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 10px; align-items: end;
  margin-bottom: 16px;
}
.filter-form-auto {
  grid-template-columns: 2fr 1fr 1fr 1fr;
}
@media (max-width: 800px) {
  .filter-form { grid-template-columns: 1fr 1fr; }
  .filter-form-auto { grid-template-columns: 1fr 1fr; }
  .filter-form .field.full { grid-column: 1 / -1; }
  .filter-form .field.actions { grid-column: 1 / -1; }
}
.filter-form .field { margin-bottom: 0; }
.filter-form .btn { font-size: 13px; }
.combo-input { font-size: 13px; }
.reports-results.is-loading { opacity: 0.55; }
.asset-link {
  border: none; background: none; padding: 0; font: inherit; font-size: 13px;
  color: var(--teal); cursor: pointer; text-decoration: underline dotted;
  text-underline-offset: 2px; text-align: left;
}
.asset-link:hover { color: #095459; }
.asset-grid { display: flex; flex-direction: column; gap: 14px; }
.asset-card {
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  background: #f7f8fa;
}
.asset-preview {
  display: block; width: 100%; max-height: 220px; background: #1a2332;
  object-fit: contain;
}
.asset-preview--image { background: var(--white); }
.asset-preview--file {
  display: grid; place-items: center; min-height: 96px; font-size: 28px;
  background: var(--teal-light); color: var(--teal);
}
.asset-thumb-link { display: block; }
.asset-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; background: var(--white); border-top: 1px solid var(--border);
}
.asset-filename {
  min-width: 0; font-size: 12px; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.radio-option {
  display: flex; align-items: flex-start; gap: 8px; font-size: 13px; font-weight: 600;
}
.radio-option input { width: auto; margin-top: 2px; }
.radio-option + .muted { margin: 4px 0 0 22px; }
.pagination {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-top: 1px solid var(--border); font-size: 13px;
}
.pagination .muted { margin: 0; }
.page-header h1 { margin: 0; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric { background: var(--white); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.metric .value { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; color: var(--teal); }
.metric .label { font-size: 12px; color: var(--ink-muted); margin-top: 4px; }
.panel-backdrop {
  position: fixed; inset: 0; background: rgba(26, 35, 50, 0.35);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 100;
}
.panel-backdrop.open { opacity: 1; pointer-events: auto; }
.panel {
  position: fixed; top: 0; right: 0; width: min(var(--panel-width), 100vw); height: 100vh;
  background: var(--white); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform 0.25s ease; z-index: 101;
  display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(26, 35, 50, 0.08);
}
.panel.open { transform: translateX(0); }
.panel.panel--assets { width: min(480px, 100vw); --panel-width: 480px; }
.panel.panel--wide { width: min(480px, 100vw); --panel-width: 480px; }
.status-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.error-tag {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  border: none; background: #fef3f2; color: var(--red);
  font: inherit; font-size: 11px; font-weight: 600; cursor: pointer;
}
.error-tag:hover { background: #fde8e6; }
.error-tag--static { cursor: default; }
.error-tag--static:hover { background: #fef3f2; }
.error-link {
  border: none; background: none; padding: 0; font: inherit; font-size: 12px;
  color: var(--red); cursor: pointer; text-decoration: underline dotted;
  text-underline-offset: 2px;
}
.error-link:hover { color: #912018; }
.error-detail {
  margin: 10px 0 0; padding: 14px; border-radius: 10px; border: 1px solid var(--border);
  background: #f7f8fa; color: var(--ink); font-family: ui-monospace, monospace;
  font-size: 12px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
  max-height: 320px; overflow: auto;
}
.error-hint {
  margin-top: 12px; padding: 10px 12px; border-radius: 8px;
  background: #fff7e6; border: 1px solid #f5d08a; color: #8a5a00;
  font-size: 13px; line-height: 1.45;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 20px; border-bottom: 1px solid var(--border);
}
.panel-header h2 { margin: 0; font-size: 1.1rem; }
.panel-body { flex: 1; overflow-y: auto; padding: 20px; }
.panel-section { margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.panel-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.panel-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-muted); margin-bottom: 10px; }
.panel-actions { display: flex; flex-direction: column; gap: 8px; }
.panel-meta { font-size: 13px; line-height: 1.5; }
.panel-meta dt { color: var(--ink-muted); font-size: 11px; margin-top: 8px; }
.panel-meta dd { margin: 2px 0 0; }
.checkbox-grid {
  display: grid; gap: 8px;
}
.checkbox-option {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 13px; line-height: 1.4; cursor: pointer;
}
.checkbox-option input { margin-top: 2px; flex-shrink: 0; }
.combo { position: relative; }
.combo-input-wrap { position: relative; }
.combo-input { padding-right: 30px; }
.combo-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: none; background: none; color: var(--ink-muted); font-size: 18px;
  line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.combo-clear:hover { color: var(--ink); background: var(--teal-light); }
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 220px; overflow-y: auto; margin: 0; padding: 4px; list-style: none;
  background: var(--white); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(26, 35, 50, 0.12); z-index: 30;
}
.combo.open .combo-list { display: block; }
.combo-list[hidden] { display: none; }
.combo-option {
  padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.combo-option:hover, .combo-option.active { background: var(--teal-light); }
.combo-empty {
  padding: 8px 10px; font-size: 13px; color: var(--ink-muted);
}

.model-chain-source { margin-top: 12px; }
.model-chain-toolbar {
  display: flex; gap: 10px; align-items: flex-end; margin-bottom: 16px;
}
.model-chain-list {
  list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px;
}
.model-chain-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--white);
}
.model-chain-rank {
  width: 24px; height: 24px; border-radius: 999px; background: var(--teal-light);
  color: var(--teal); display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.model-chain-info {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px;
}
.model-chain-info strong { font-size: 14px; }
.model-chain-info .muted { font-size: 12px; }
.model-chain-info .badge { align-self: flex-start; margin-top: 4px; }
.model-chain-actions { display: flex; gap: 4px; flex-shrink: 0; }
.model-chain-footer {
  display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap;
}
.danger-text { color: var(--red); }
.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;
}

.admin-table-wrap { width: 100%; overflow: visible; }
.admin-table { min-width: 0; }
.admin-table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.admin-table .col-actions .row-actions { justify-content: flex-end; }

@media (max-width: 720px) {
  .wrap { padding: 16px 12px 32px; }
  .header { flex-wrap: wrap; gap: 10px; }
  .nav {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap; margin-left: -12px; margin-right: -12px; padding: 0 12px;
  }
  .nav a { white-space: nowrap; flex-shrink: 0; padding: 10px 12px; }
  .page-header {
    flex-direction: column; align-items: stretch; gap: 10px;
  }
  .page-header .btn { align-self: flex-start; }
  .card { padding: 14px; }
  .filter-form,
  .filter-form-auto { grid-template-columns: 1fr; }
  .pagination {
    flex-direction: column; align-items: flex-start; gap: 10px;
    padding: 12px;
  }
  .admin-table .col-mobile-hide { display: none; }
  .admin-table th,
  .admin-table td { padding: 10px 8px; }
  .admin-table .col-patient { min-width: 0; }
  .admin-table .col-actions { padding-right: 4px; }
  .admin-table .col-actions .split-btn-caret { min-width: 24px; padding-left: 4px; padding-right: 4px; }
  .model-chain-item { flex-wrap: wrap; }
  .model-chain-actions { width: 100%; justify-content: flex-end; }
}
