:root {
  --bg: #f5f7fc; --surface: #ffffff; --surface2: #f7f9fd; --surface3: #edf2fb; --border: #e1e7f2;
  --accent: #3568e8; --accent2: #7457dc; --text: #17233b; --text2: #71809a;
  --danger: #d94b5e; --ok: #168667; --sidebar-w: 248px;
  --shadow-soft: 0 2px 5px rgb(25 45 85 / 0.025), 0 8px 20px -14px rgb(30 55 100 / 0.14);
  --shadow-card: 0 2px 5px rgb(25 45 85 / 0.025), 0 18px 35px -24px rgb(40 66 124 / 0.26);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: radial-gradient(circle at 78% -14%, #e9edff 0, transparent 28rem), var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

#admin-app { min-height: 100vh; display: flex; }
#admin-sidebar { width: var(--sidebar-w); min-width: var(--sidebar-w); background: rgb(255 255 255 / .74); border-right: 1px solid rgb(219 227 241 / .82); padding: 18px 14px 14px; display: flex; flex-direction: column; gap: 6px; backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 9px; font-size: 17px; font-weight: 820; letter-spacing: -.025em; color: #263c79; margin: 2px 5px 17px; }
.brand::before { content: ''; width: 11px; height: 11px; border-radius: 4px; background: linear-gradient(135deg, #3e70ef, #805ee2); box-shadow: 0 5px 12px -4px rgb(74 91 215 / .8); }
.nav-btn { width: 100%; text-align: left; border: 1px solid transparent; border-radius: 10px; padding: 10px 12px; background: transparent; color: var(--text2); font-weight: 650; transition: background .16s ease, color .16s ease, border-color .16s ease, transform .16s ease; }
.nav-btn:hover { background: rgb(239 243 252 / .8); border-color: #e4eaf6; color: #30436d; transform: translateX(2px); }
.nav-btn.active { background: linear-gradient(118deg, #3971ec, #6d59dc); border-color: rgb(255 255 255 / .28); color: #fff; box-shadow: 0 10px 21px -12px rgb(58 87 210 / .8); }
.sidebar-spacer { flex: 1; }
#admin-user-line { color: var(--text2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 7px 8px; }

#admin-main { flex: 1; min-width: 0; padding: 20px 22px 26px; }
#admin-topbar { min-height: 58px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 15px; }
h1 { font-size: 26px; line-height: 1.15; letter-spacing: -.045em; }
h2 { font-size: 13px; font-weight: 780; letter-spacing: .01em; color: #415273; margin: 0 0 8px 2px; }
#page-subtitle, #admin-status { color: var(--text2); font-size: 13px; margin-top: 4px; }
#admin-status.error { color: var(--danger); }

.admin-pane { max-width: none; }
.two-col, .split-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.stats-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card, .data-row, .form, .clawhub-box { background: rgb(255 255 255 / .88); border-radius: 14px; border: 1px solid rgb(226 232 243 / .92); box-shadow: var(--shadow-soft); }
.stat-card { padding: 12px 14px; display: grid; gap: 7px; grid-column: span 2; min-height: 84px; overflow: hidden; position: relative; transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.stat-card::after { content: ''; position: absolute; inset: 0 0 auto; height: 2px; background: linear-gradient(90deg, #4b7bec, #9170e7); opacity: .7; }
.stat-card:hover { transform: translateY(-2px); border-color: #d4def5; box-shadow: var(--shadow-card); }
.stat-card.is-lg { grid-column: span 2; min-height: 82px; }
.stat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-label { color: #7b89a2; font-size: 11px; font-weight: 650; letter-spacing: .02em; }
.stat-value { font-size: clamp(23px, 1.8vw, 30px); line-height: 1; font-weight: 830; color: #254fb8; letter-spacing: -.04em; }
.stat-delta { font-size: 10px; font-weight: 760; padding: 3px 7px; border-radius: 999px; width: fit-content; }
.stat-delta.up { color: #137558; background: #e1f8ed; }
.stat-delta.down { color: #c34055; background: #fff0f2; }
.stat-delta.neutral { color: #536482; background: #edf1f8; }
.dashboard-band { margin-bottom: 14px; }
.chart-card { background: rgb(255 255 255 / .88); border: 1px solid rgb(226 232 243 / .92); border-radius: 14px; padding: 14px; min-height: 230px; box-shadow: var(--shadow-card); }
.mini-trend-list, .mini-model-list { display: grid; gap: 10px; }
.chart-legend { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; color: var(--text2); font-size: 12px; margin-bottom: 4px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 999px; background: linear-gradient(90deg, var(--accent), #8d86ea); box-shadow: inset 0 0 0 1px rgba(255,255,255,.45); }
.legend-swatch.warn { background: linear-gradient(90deg, #f59e0b, #fcd34d); }
.trend-row, .rank-row, .model-row { display: grid; gap: 6px; }
.trend-head, .rank-head, .model-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.trend-label, .rank-label, .model-label { font-weight: 650; }
.trend-meta, .rank-meta, .model-meta { color: var(--text2); font-size: 12px; }
.bar-track { width: 100%; height: 8px; border-radius: 999px; background: var(--surface2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), #8d86ea); }
.bar-fill.alt { background: linear-gradient(90deg, #22c55e, #86efac); }
.bar-fill.warn { background: linear-gradient(90deg, #f59e0b, #fcd34d); }

.data-list { display: grid; gap: 7px; }
.data-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 10px 11px; }
.data-row.rich-row { transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, background .16s ease; }
.data-row.rich-row:hover { transform: translateY(-1px); border-color: #d5e0f6; background: #fff; box-shadow: var(--shadow-card); }
.data-row.expandable { align-items: start; }
.row-main { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.4);
}
.row-title { font-weight: 720; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { color: #8a98b0; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; flex-wrap: wrap; }
.row-action-fade { opacity: 0; pointer-events: none; transform: translateX(6px); transition: opacity .16s ease, transform .16s ease; }
.data-row.rich-row:hover .row-action-fade,
.data-row.rich-row:focus-within .row-action-fade { opacity: 1; pointer-events: auto; transform: translateX(0); }
.stack-fields { display: grid; gap: 8px; margin-top: 8px; max-width: 360px; }
.conversation-detail { grid-column: 1 / -1; border-top: 1px solid var(--border); margin-top: 10px; padding-top: 12px; display: grid; gap: 10px; }
.conversation-summary { display: flex; gap: 10px; flex-wrap: wrap; color: var(--text2); font-size: 12px; }
.message-timeline { display: grid; gap: 8px; }
.message-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.message-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.message-role { font-size: 12px; font-weight: 700; color: var(--accent2); text-transform: uppercase; }
.message-meta { color: var(--text2); font-size: 12px; }
.message-content { white-space: pre-wrap; word-break: break-word; line-height: 1.55; font-size: 13px; }
.message-error { margin-top: 8px; color: var(--danger); font-size: 12px; white-space: pre-wrap; word-break: break-word; }
.toolbar { margin-bottom: 10px; }

.form { padding: 16px; display: grid; gap: 11px; }
.field { display: grid; gap: 6px; }
label { color: var(--text2); font-size: 12px; }
.input, select, textarea { width: 100%; background: #f8faff; color: var(--text); border: 1px solid #e1e7f2; border-radius: 9px; padding: 10px 12px; outline: none; transition: background .16s ease, border-color .16s ease, box-shadow .16s ease; }
textarea { resize: vertical; }
.input:focus, select:focus, textarea:focus { background: #fff; border-color: #7e9ef0; box-shadow: 0 0 0 3px rgb(78 118 230 / .1); }
.short-input { max-width: 80px; }
.inline-row, .toolbar { display: flex; gap: 8px; align-items: center; }
.inline-row .input, .toolbar .input { flex: 1; min-width: 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
.primary, .secondary, .link-btn { border-radius: 9px; padding: 9px 12px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; font-weight: 680; transition: transform .16s ease, box-shadow .16s ease, background .16s ease, border-color .16s ease; }
.primary { background: linear-gradient(135deg, #3d72ea, #6257d5); color: white; border: 0; box-shadow: 0 9px 16px -11px rgb(59 88 207 / .8); }
.primary:hover { transform: translateY(-1px); box-shadow: 0 12px 20px -12px rgb(59 88 207 / .9); }
.secondary { background: rgb(255 255 255 / .7); color: #61708b; border: 1px solid #dfe6f2; }
.secondary:hover { background: #f5f8fe; border-color: #ccd9f0; color: #354664; }
.danger { color: var(--danger); }
.check-row { display: flex; align-items: center; gap: 6px; color: var(--text); }
.field-status, .attachment-preview { color: var(--text2); font-size: 12px; }
.attachment-preview, #clawhub-results { background: #f7f9fd; border: 1px solid #e1e7f2; border-radius: 9px; padding: 8px 10px; }
.clawhub-box { padding: 14px; display: grid; gap: 8px; margin-bottom: 12px; }
.clawhub-result-item, .skill-file-item { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.clawhub-result-item:last-child, .skill-file-item:last-child { border-bottom: 0; }
.clawhub-result-slug, .skill-file-path { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clawhub-result-desc { color: var(--text2); font-size: 12px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skill-files-list { grid-column: 1 / -1; border-top: 1px solid var(--border); padding-top: 8px; display: grid; gap: 4px; }
.empty-state { min-height: 120px; display: grid; place-items: center; color: var(--text2); background: rgb(255 255 255 / .7); border: 1px dashed #d7e0ef; border-radius: 12px; }

@media (max-width: 860px) {
  #admin-app { display: block; }
  #admin-sidebar { width: 100%; min-width: 0; border-right: 0; border-bottom: 1px solid var(--border); }
  #admin-main { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card { grid-column: span 1; }
  .stat-card.is-lg { grid-column: span 2; }
  .two-col, .split-layout { grid-template-columns: 1fr; }
  .data-row { grid-template-columns: 1fr; }
  .row-actions { justify-content: flex-start; }
  .row-action-fade { opacity: 1; pointer-events: auto; transform: none; }
}
