/* ════════════════════════════════════════════════════════════════
   FlexRank Admin Dashboard
   Re-implements jl-engines admin_dashboard gem class contract
   using FlexRank tokens (design_tokens.css extends fyf_theme).
   ════════════════════════════════════════════════════════════════ */

:root {
  --admin-sidebar-w: 240px;
  --admin-topbar-h: 56px;
  --admin-radius: 8px;
  --admin-radius-lg: 12px;
}

*, *::before, *::after { box-sizing: border-box; }
.admin-body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.admin-body a { color: var(--accent); text-decoration: none; }
.admin-body a:hover { color: var(--accent-hover); }

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--admin-topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px; color: var(--text);
  letter-spacing: -0.01em;
}
.topbar-brand:hover { color: var(--text); }
.topbar-sep { width: 1px; height: 22px; background: var(--border); }
.topbar-title {
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-link {
  padding: 6px 12px; border-radius: 6px;
  font-size: 13px; color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.topbar-link:hover { background: var(--surface-2); color: var(--text); }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: var(--admin-topbar-h); left: 0; bottom: 0;
  width: var(--admin-sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px 12px;
  overflow-y: auto; z-index: 90;
  display: flex; flex-direction: column;
}
.sidebar-section { margin-bottom: 22px; }
.sidebar-label {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-dim);
  padding: 0 12px; margin-bottom: 6px;
}
.sidebar-nav { list-style: none; padding: 0; margin: 0; }
.sidebar-nav li { margin: 0; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px; border-radius: 6px;
  font-size: 13px; font-weight: 500;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
}
.sidebar-nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar-nav a.active {
  background: var(--accent-bg); color: var(--accent);
}
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px; border-radius: 6px;
  font-size: 13px; font-weight: 500; color: var(--text-muted);
}
.sidebar-link:hover { background: var(--surface-2); color: var(--text); }
.sidebar-link.active { background: var(--accent-bg); color: var(--accent); }
.sidebar-badge {
  margin-left: auto;
  font-size: 11px; padding: 1px 6px; border-radius: 10px;
  background: var(--surface-3); color: var(--text-dim);
}
.sidebar-foot {
  margin-top: auto; padding: 12px;
  border-top: 1px solid var(--border-subtle);
  font-size: 11px; color: var(--text-dim);
}

/* ── Main content ───────────────────────────────────────────── */
.layout-main {
  margin-left: var(--admin-sidebar-w);
  margin-top: var(--admin-topbar-h);
  min-height: calc(100vh - var(--admin-topbar-h));
}
.content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 32px 64px;
}

/* ── Page header ────────────────────────────────────────────── */
.page-header { margin-bottom: 24px; }
.page-header h1 {
  font-size: 22px; font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.page-header p { color: var(--text-muted); font-size: 14px; margin: 0; }

/* ── Breadcrumbs ────────────────────────────────────────────── */
.breadcrumbs {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-muted);
  margin-bottom: 18px;
}
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--text); }
.breadcrumbs .sep { opacity: 0.4; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--admin-radius-lg);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h2 {
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0;
}
.card-body { padding: 18px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-grid .full-width { grid-column: 1 / -1; }

/* ── Stats grid ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--admin-radius-lg);
  padding: 18px;
}
.stat-card .stat-label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.stat-card .stat-label svg { opacity: 0.55; }
.stat-card .stat-value {
  font-size: 28px; font-weight: 700; line-height: 1;
  color: var(--text);
}
.stat-card .stat-value.is-accent { color: var(--accent); }
.stat-card .stat-value.is-success { color: var(--green); }
.stat-card .stat-value.is-warn    { color: var(--orange); }
.stat-card .stat-value.is-info    { color: var(--blue); }
.stat-card .stat-value.is-muted   { color: var(--text-muted); }
.stat-card .stat-value.is-danger  { color: var(--red); }
.stat-card .stat-sub {
  font-size: 12px; color: var(--text-dim); margin-top: 6px;
}

/* ── Engine grid (config index) ─────────────────────────────── */
.engine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.engine-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--admin-radius-lg);
  padding: 18px;
  transition: border-color 0.18s, box-shadow 0.18s;
  display: flex; flex-direction: column; gap: 12px;
  text-decoration: none; color: inherit;
}
.engine-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-bg);
  color: inherit;
}
.engine-card-top {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.engine-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.engine-name { font-weight: 600; font-size: 15px; color: var(--text); }
.engine-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.engine-meta {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: auto;
}
.engine-mount {
  font-family: var(--mono);
  font-size: 12px; color: var(--text-muted);
  background: var(--surface-2);
  padding: 2px 8px; border-radius: 4px;
}

/* ── Category headers ───────────────────────────────────────── */
.category-header {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 28px 0 12px;
  display: flex; align-items: center; gap: 10px;
}
.category-header:first-child { margin-top: 0; }
.category-line { flex: 1; height: 1px; background: var(--border); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 500;
  padding: 3px 9px; border-radius: 6px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-green  { background: var(--green-bg);  color: var(--green);  border-color: var(--green-bg); }
.badge-red    { background: var(--red-bg);    color: var(--red);    border-color: var(--red-bg); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); border-color: var(--yellow-bg); }
.badge-blue   { background: var(--blue-bg);   color: var(--blue); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-muted  { background: var(--surface-3); color: var(--text-muted); }

.status-dot {
  width: 7px; height: 7px; border-radius: 50%; display: inline-block;
}
.status-dot.on   { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.off  { background: var(--red); opacity: 0.6; }
.status-dot.warn { background: var(--yellow); }

/* ── Config table (gem partials) ────────────────────────────── */
.config-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.config-table th {
  text-align: left; padding: 10px 14px;
  font-weight: 600; color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
}
.config-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.config-table tr:last-child td { border-bottom: none; }
.config-table tr:hover td { background: var(--surface-2); }
.config-table .attr-name  { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.config-table .attr-value { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.config-table .attr-type  { font-size: 11px; color: var(--text-dim); }

/* ── Route + env lists ──────────────────────────────────────── */
.route-list, .env-list { list-style: none; padding: 0; margin: 0; }
.route-list li, .env-list li {
  display: flex; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
}
.route-list li:last-child, .env-list li:last-child { border-bottom: none; }
.route-list li { align-items: baseline; }
.env-list li   { align-items: center; }
.route-verb {
  font-family: var(--mono);
  font-size: 10px; font-weight: 700;
  padding: 3px 8px; border-radius: 4px;
  min-width: 48px; text-align: center; flex-shrink: 0;
}
.route-verb.get          { background: var(--blue-bg);   color: var(--blue); }
.route-verb.post         { background: var(--green-bg);  color: var(--green); }
.route-verb.put,
.route-verb.patch        { background: var(--yellow-bg); color: var(--yellow); }
.route-verb.delete       { background: var(--red-bg);    color: var(--red); }
.route-path { font-family: var(--mono); font-size: 12px; color: var(--text); }
.route-desc { color: var(--text-dim); font-size: 12px; margin-left: auto; }
.env-name   { font-family: var(--mono); font-size: 12px; color: var(--text); }

/* ── Provider grid + demo + dependencies ────────────────────── */
.provider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.provider-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 14px; text-align: center;
}
.provider-card .name   { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.provider-card .status { font-size: 11px; }
.demo-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--admin-radius);
  padding: 18px; margin-top: 14px;
}
.demo-section h3 {
  font-size: 14px; font-weight: 600; margin: 0 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.dep-chain { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dep-arrow { color: var(--text-dim); font-size: 11px; }

/* ── Code blocks ────────────────────────────────────────────── */
pre, .query-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-family: var(--mono);
  font-size: 12px; line-height: 1.6;
  overflow-x: auto;
  color: var(--text-muted);
  margin: 0;
}
pre .comment, .query-box .comment { color: var(--text-dim); font-style: italic; }
pre .key,     .query-box .key     { color: var(--accent); }
pre .str,     .query-box .str     { color: var(--green); }
pre .num,     .query-box .num     { color: var(--orange); }
.query-box { white-space: pre; }

/* ── Librarian filters ──────────────────────────────────────── */
.librarian-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filter-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px; font-family: var(--mono);
  color: var(--text-muted);
}
.filter-chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}

/* ── Modal ──────────────────────────────────────────────────── */
.louie-modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
html[data-theme="dark"] .louie-modal-backdrop { background: rgba(0,0,0,0.65); }
.louie-modal-backdrop.hidden { display: none; }
.louie-modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--admin-radius-lg);
  max-width: 560px; width: 100%;
  max-height: 80vh; overflow-y: auto;
  padding: 22px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
}

/* ── Flash toasts ───────────────────────────────────────────── */
.louie-flash {
  padding: 12px 16px;
  border-radius: var(--admin-radius);
  font-size: 13px;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px;
  min-width: 280px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
  animation: admin-flash-in 0.25s ease-out;
}
.louie-flash.notice { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-bg); }
.louie-flash.alert  { background: var(--red-bg);   color: var(--red);   border: 1px solid var(--red-bg); }
.louie-flash .dismiss-btn {
  margin-left: auto; background: none; border: none; color: inherit;
  cursor: pointer; opacity: 0.6; font-size: 16px; padding: 0 4px;
}
.louie-flash .dismiss-btn:hover { opacity: 1; }
@keyframes admin-flash-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ── Show fields (resource detail) ──────────────────────────── */
.show-fields { display: grid; grid-template-columns: 1fr; gap: 0; }
.show-field {
  display: flex; padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.show-field:last-child { border-bottom: none; }
.show-field dt {
  width: 200px; flex-shrink: 0;
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-dim);
}
.show-field dd { flex: 1; font-size: 14px; color: var(--text); margin: 0; }

/* ── Custom action button success state ─────────────────────── */
[data-custom-action].action-done {
  background: var(--green-bg);
  color: var(--green);
  border-color: var(--green-bg);
}

/* ════════════════════════════════════════════════════════════
   Host additions (used by analytics + consensus polish)
   ════════════════════════════════════════════════════════════ */

/* ── Pill nav (period + tab nav) ────────────────────────────── */
.pill-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.pill-nav a {
  padding: 6px 12px; font-size: 13px; font-weight: 500;
  border-radius: var(--admin-radius);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.pill-nav a:hover { border-color: var(--border-hover); color: var(--text); }
.pill-nav a.active {
  border-color: var(--accent); color: var(--accent); background: var(--accent-bg);
}

/* ── Tab nav (underline style) ──────────────────────────────── */
.tab-nav {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.tab-nav a {
  padding: 10px 16px; font-size: 13px; font-weight: 500;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}
.tab-nav a:hover { color: var(--text); }
.tab-nav a.active { border-bottom-color: var(--accent); color: var(--accent); }

/* ── Data table (analytics + consensus tables) ──────────────── */
.data-table-wrap { overflow-x: auto; }
.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.data-table thead th {
  text-align: left; padding: 8px 10px;
  font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-subtle);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .muted { color: var(--text-muted); }
.data-table .accent { color: var(--accent); font-weight: 600; }
.data-table .success { color: var(--green); }
.data-table .warn { color: var(--orange); }
.data-table tr.status-ok   { border-left: 3px solid var(--green); }
.data-table tr.status-warn { border-left: 3px solid var(--orange); }
.data-table tr.status-err  { border-left: 3px solid var(--red); }
.data-table tr.status-mute { border-left: 3px solid var(--border); }

/* ── Action buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center;
  padding: 8px 16px;
  font-size: 13px; font-weight: 600;
  border-radius: var(--radius);
  border: none; cursor: pointer;
  transition: background 0.15s;
}
.btn-accent  { background: var(--accent); color: #fff; }
.btn-accent:hover  { background: var(--accent-hover); }
.btn-success { background: var(--green); color: #fff; }
.btn-link {
  background: none; border: none;
  color: var(--accent); font-size: 12px; font-weight: 500;
  cursor: pointer; padding: 0;
}
.btn-sm  { padding: 4px 10px; font-size: 11px; }
.btn-md  { padding: 6px 14px; font-size: 12px; }

/* Card status borders (consensus source cards etc.) */
.card.status-ok   { border-left: 4px solid var(--green); }
.card.status-warn { border-left: 4px solid var(--orange); }
.card.status-err  { border-left: 4px solid var(--red); }
.card.status-mute { border-left: 4px solid var(--border); }

/* ── Inline note (decision-gate callout etc) ────────────────── */
.admin-note {
  margin-top: 16px; padding: 12px 16px;
  background: var(--surface-2);
  border-radius: var(--admin-radius);
  font-size: 12px; color: var(--text-muted);
  line-height: 1.55;
}

/* ── Empty state ────────────────────────────────────────────── */
.admin-empty {
  color: var(--text-muted); font-size: 13px;
  padding: 16px 0;
}

/* ── Position group (consensus unmatched players) ──────────── */
.position-group { margin-bottom: 12px; }
.position-group-summary {
  cursor: pointer; padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 8px;
  list-style: none;
}
.position-group-summary::-webkit-details-marker { display: none; }
.position-group[open] .position-group-summary {
  border-bottom-left-radius: 0; border-bottom-right-radius: 0;
}
.position-group-body {
  margin-top: 0;
  border-top-left-radius: 0; border-top-right-radius: 0;
  border-top: none;
  overflow: visible;
}

/* Row layout used inside grouped lists (e.g. position groups, log lists) */
.row-divided {
  padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.row-divided.last { border-bottom: none; }
.row-rank { font-size: 12px; color: var(--text-dim); font-family: var(--mono); min-width: 28px; }
.row-name { font-weight: 600; font-size: 14px; color: var(--text); }
.row-team { font-size: 12px; color: var(--text-muted); }
.row-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; margin-left: 38px; }

/* ── Match-search popup (consensus matching UI) ─────────────── */
.match-details { position: relative; }
.match-popup {
  margin-top: 8px; padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 280px;
  position: absolute; z-index: 10; right: 0;
}
.match-popup-input {
  width: 100%; padding: 6px 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  margin-bottom: 8px;
}
.match-popup-results { max-height: 200px; overflow-y: auto; }
.match-popup-empty { font-size: 12px; color: var(--text-dim); padding: 8px; }
.match-popup-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px solid var(--border); margin: 0;
}
.match-popup-row:last-child { border-bottom: none; }
.match-popup-row .name   { font-size: 13px; color: var(--text); font-weight: 600; }
.match-popup-row .meta   { color: var(--text-dim); font-size: 11px; font-weight: 400; }
.match-popup-row .link-btn {
  padding: 3px 10px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 600; border-radius: var(--radius);
  border: none; cursor: pointer;
}
.match-summary {
  font-size: 12px; font-weight: 500; color: var(--accent);
  cursor: pointer; list-style: none;
}
.match-summary::-webkit-details-marker { display: none; }


/* ── Theme toggle override (consistent with reader/editor) ──── */
.theme-toggle {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { background: var(--surface-3); color: var(--text); }
.theme-toggle .theme-icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .theme-icon-sun  { display: none; }
html[data-theme="dark"] .theme-toggle .theme-icon-moon { display: inline-block; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .layout-main { margin-left: 0; }
  .content { padding: 20px 16px 48px; }
  .engine-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
