:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1c2733;
  --muted: #64748b;
  --line: #dbe2ea;
  --brand: #2f6df6;
  --danger: #c2410c;
  --ok: #0f7b4f;
  --ml-yellow: #ffe600;
  --ml-blue: #3483fa;
  --ml-dark-blue: #2d3277;
  --ml-bg: #f5f6fa;
  --ml-border: #e5e7eb;
  --ml-success-bg: #dcfce7;
  --ml-success-text: #166534;
  --ml-warning-bg: #fef3c7;
  --ml-warning-text: #92400e;
  --ml-danger-bg: #fee2e2;
  --ml-danger-text: #991b1b;
  --ml-info-bg: #dbeafe;
  --ml-info-text: #1e40af;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--ml-yellow);
  border-bottom: 1px solid rgba(0, 0, 0, .08);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h1 { color: var(--ml-dark-blue); display: flex; align-items: center; gap: 10px; }
.topbar .subtitle { color: #4b5563; }
.topbar-badge {
  background: var(--ml-dark-blue);
  color: #fff;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: .5px;
}
.topbar .badge { background: rgba(255, 255, 255, .7); color: var(--ml-dark-blue); }
.topbar .badge.connected { background: #fff; color: var(--ok); }
.topbar .button { background: rgba(255, 255, 255, .75); border-color: rgba(0, 0, 0, .12); color: var(--ml-dark-blue); }
.topbar .button.active { background: var(--ml-dark-blue); border-color: var(--ml-dark-blue); color: #fff; }

h1 { font-size: 19px; margin: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
.subtitle, .hint { color: var(--muted); margin: 3px 0 0; font-size: 12px; }
code { background: #eef2f7; padding: 1px 4px; border-radius: 4px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* App shell + left navigation */
.app-shell {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  min-height: 100vh;
}
.app-main { min-width: 0; }
.app-nav {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100vh;
  padding: 18px 14px;
  overflow-y: auto;
  background: var(--ml-dark-blue);
  color: #e5e7ff;
}
.app-nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .18);
}
.app-nav-logo {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--ml-yellow);
  color: var(--ml-dark-blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .5px;
}
.app-nav-brand strong { display: block; color: #fff; font-size: 14px; }
.app-nav-brand small { color: #c3c8f2; font-size: 11px; }
.app-nav-group { display: flex; flex-direction: column; gap: 4px; }
.app-nav-title {
  margin: 0 0 2px;
  padding: 0 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #a8aee6;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #e5e7ff;
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.nav-link::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
  opacity: .5;
}
.nav-link:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav-link.active {
  background: var(--ml-yellow);
  color: var(--ml-dark-blue);
  font-weight: 700;
}
.nav-link.active::before { opacity: 1; }


.badge {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
}
.badge.connected { background: #e4f5ec; color: var(--ok); }
.badge.error { background: #fdece7; color: var(--danger); }

.layout {
  display: grid;
  grid-template-columns: 230px minmax(420px, 1fr) 360px;
  gap: 14px;
  padding: 14px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

.sidebar, .inspector { position: sticky; top: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-head h2 { margin: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-head h2 { margin-bottom: 8px; }

.button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}
.button:hover { border-color: #9fb2c9; }
.button:disabled { opacity: .55; cursor: not-allowed; }
.button.small { padding: 5px 9px; font-size: 12px; }
.button.subtle { background: #f7f9fb; }
.button.primary { background: var(--brand); border-color: var(--brand); color: white; }
.button.danger { color: var(--danger); }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.span-2 { grid-column: 1 / -1; }
.field > span { font-size: 12px; color: var(--muted); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 9px;
  font: inherit;
  color: var(--ink);
  background: white;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfd3ff; border-color: var(--brand); }
.inline { display: flex; gap: 6px; }
.inline input { min-width: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; }
.checks label { display: flex; align-items: center; gap: 5px; }
.checks input { width: auto; }

.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}
.row.picture { grid-template-columns: minmax(0, 1fr) 130px auto; }
.row.attr { grid-template-columns: 110px minmax(0, 1fr) 130px auto; }
.row input { min-width: 0; }
.row button { padding: 6px 8px; }

.category-info {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #cfe0ff;
  border-radius: 8px;
  background: #f4f8ff;
  font-size: 12px;
}
.category-info strong { display: block; font-size: 13px; }
.category-info ul { margin: 8px 0 0; padding-left: 16px; }
.category-info li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 0; }

.draft-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.draft-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  background: white;
}
.draft-item:hover, .draft-item.active { border-color: var(--brand); background: #f4f8ff; }
.draft-item strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-item small { color: var(--muted); }
.draft-actions { display: flex; gap: 4px; margin-top: 6px; }

.validation { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 14px; }
.message { padding: 8px 10px; border-radius: 7px; font-size: 12px; }
.message.ok { background: #e4f5ec; color: var(--ok); }
.message.error { background: #fdece7; color: var(--danger); }
.message.warn { background: #fff5df; color: #8a5a00; }
.message ul { margin: 5px 0 0; padding-left: 18px; }

.action-stack { display: flex; flex-direction: column; gap: 8px; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.payload {
  margin: 0;
  max-height: 420px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  padding: 11px 14px;
  border-radius: 8px;
  background: #1c2733;
  color: white;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .25);
  z-index: 10;
}

.hidden { display: none !important; }
.app-locked .app-shell { display: none; }

.button.active { background: #e4f5ec; border-color: #9ad3b4; color: var(--ok); }

/* Applications dashboard */
.dashboard-view {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 20px 40px;
}
.apps-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.apps-toolbar-title { font-size: 18px; text-transform: none; letter-spacing: normal; color: #111827; margin: 0; }
.apps-toolbar .search-input { max-width: 260px; }
.apps-toolbar select { max-width: 90px; }
.apps-dashboard { display: flex; flex-direction: column; gap: 20px; }

.hero-card, .dash-card, .kpi-card {
  background: #fff;
  border: 1px solid var(--ml-border);
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, .05), 0 2px 4px -2px rgba(0, 0, 0, .05);
}
.hero-card {
  padding: 22px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.hero-left { display: flex; align-items: center; gap: 18px; min-width: 0; }
.app-avatar {
  width: 68px;
  height: 68px;
  border-radius: 14px;
  object-fit: cover;
  border: 1px solid var(--ml-border);
  background: #f9fafb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--ml-dark-blue);
  font-size: 18px;
  flex: 0 0 auto;
}
.app-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.app-title-row h3 { font-size: 22px; margin: 0; color: #111827; }
.app-subtitle { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.app-meta-inline { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.app-meta-inline strong { color: var(--text-main); }
.badges-group, .tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; }
.dashboard-view .badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: var(--ml-success-bg); color: var(--ml-success-text); }
.badge-warning { background: var(--ml-warning-bg); color: var(--ml-warning-text); }
.badge-danger { background: var(--ml-danger-bg); color: var(--ml-danger-text); }
.badge-info { background: var(--ml-info-bg); color: var(--ml-info-text); }
.badge-neutral { background: #f3f4f6; color: #374151; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.kpi-card { padding: 18px 20px; }
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 4px; color: #111827; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); gap: 20px; }
.dash-card { padding: 20px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ml-border);
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  color: #111827;
  text-transform: none;
  letter-spacing: normal;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.kv-list { display: flex; flex-direction: column; gap: 10px; }
.kv-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 9px;
  border-bottom: 1px dashed #f3f4f6;
  font-size: 13px;
}
.kv-item:last-child { border-bottom: 0; padding-bottom: 0; }
.kv-key { color: var(--muted); font-weight: 500; min-width: 150px; }
.kv-val { font-weight: 600; text-align: right; word-break: break-word; }
.kv-val a { color: var(--ml-blue); text-decoration: none; }

.url-block { background: #f9fafb; border: 1px solid var(--ml-border); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.url-block:last-child { margin-bottom: 0; }
.url-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.url-actions { display: flex; gap: 6px; }
.btn-mini {
  border: 1px solid var(--ml-border);
  border-radius: 6px;
  background: #fff;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  color: var(--ink);
  font-weight: 500;
}
.btn-mini:hover { background: #f3f4f6; border-color: #d1d5db; }
.code-text { font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: #1f2937; word-break: break-all; }

.tag-chip {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  color: #374151;
  padding: 5px 10px;
  border-radius: 6px;
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.tag-chip.scope-write { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.tag-chip.scope-read { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }

.table-wrap { overflow: auto; margin-top: 10px; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-wrap th {
  text-align: left;
  padding: 10px 12px;
  background: #f9fafb;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--ml-border);
}
.table-wrap td { padding: 11px 12px; border-bottom: 1px solid #f3f4f6; }
.table-wrap tr:last-child td { border-bottom: 0; }
.table-wrap code { white-space: nowrap; }

.progress-bar { width: 100%; height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; background: #16a34a; border-radius: 999px; }
.trace-title { font-weight: 700; color: #111827; margin-bottom: 4px; }
.trace-box {
  background: #f9fafb;
  border-left: 3px solid var(--ml-blue);
  padding: 12px 14px;
  border-radius: 0 8px 8px 0;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted);
}
.trace-box:last-child { margin-bottom: 0; }

.raw-card summary { cursor: pointer; font-weight: 600; color: var(--ml-dark-blue); }
.raw-card[open] summary { margin-bottom: 12px; }
.apps-pager { justify-content: center; margin-top: 4px; }

/* Users dashboard */
.users-filters {
  background: #fff;
  border: 1px solid var(--ml-border);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 18px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, .05), 0 2px 4px -2px rgba(0, 0, 0, .05);
}
.filter-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill-btn {
  background: #f3f4f6;
  border: 1px solid var(--ml-border);
  color: #374151;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.pill-btn:hover { background: #e5e7eb; }
.pill-btn.active { background: var(--ml-dark-blue); color: #fff; border-color: var(--ml-dark-blue); }

.user-card {
  background: #fff;
  border: 1px solid var(--ml-border);
  border-radius: 14px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, .05), 0 2px 4px -2px rgba(0, 0, 0, .05);
  overflow: hidden;
  margin-bottom: 22px;
}
.user-header {
  padding: 20px 22px;
  background: linear-gradient(135deg, #fff 0%, #f9fafb 100%);
  border-bottom: 1px solid var(--ml-border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.user-identity { display: flex; align-items: center; gap: 16px; min-width: 0; }
.avatar {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--ml-yellow);
  background: var(--ml-dark-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  flex: 0 0 auto;
}
.nickname-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.nickname-row h3 { font-size: 20px; margin: 0; color: #111827; }
.user-realname { font-size: 13px; color: var(--muted); margin-top: 2px; }
.user-meta { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.user-meta strong { color: var(--text-main); }
.badges-wrap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.badge-gold { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }
.badge-silver { background: #f3f4f6; color: #374151; border: 1px solid #d1d5db; }

.user-body {
  padding: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 20px;
}
.sub-panel {
  background: #fafafa;
  border: 1px solid var(--ml-border);
  border-radius: 10px;
  padding: 16px 18px;
}
.sub-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--ml-dark-blue);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--ml-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.sub-title small { font-size: 11px; color: var(--muted); font-weight: 500; text-transform: none; }
.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed #e5e7eb;
  font-size: 12px;
}
.kv-row:last-child { border-bottom: 0; }
.kv-k { color: var(--muted); flex-shrink: 0; }
.kv-v { font-weight: 600; color: var(--text-main); text-align: right; word-break: break-word; }

.thermometer { display: flex; gap: 4px; margin: 10px 0 14px; }
.thermo-bar { flex: 1; height: 8px; border-radius: 4px; opacity: .22; }
.thermo-bar.active { opacity: 1; height: 11px; margin-top: -1.5px; box-shadow: 0 0 0 2px #fff, 0 0 0 3px #16a34a; }
.metrics-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 10px; }
.metric-box { background: #fff; border: 1px solid var(--ml-border); border-radius: 8px; padding: 10px; }
.m-label { font-size: 11px; color: var(--muted); }
.m-val { font-size: 16px; font-weight: 700; color: #111827; margin-top: 2px; }
.m-sub { font-size: 11px; color: var(--muted); }
.rating-bar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: #e5e7eb; margin: 8px 0 6px; }
.r-pos { background: #16a34a; }
.r-neu { background: #9ca3af; }
.r-neg { background: #dc2626; }

.status-chips, .tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag-item {
  background: #fff;
  border: 1px solid #d1d5db;
  padding: 3px 8px;
  border-radius: 5px;
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #374151;
}
.btn-link { display: inline-block; margin-top: 10px; color: var(--ml-blue); font-size: 12px; font-weight: 600; text-decoration: none; }
.btn-link:hover { text-decoration: underline; }
.btn-copy {
  background: #fff;
  border: 1px solid var(--ml-border);
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 11px;
  cursor: pointer;
  margin-left: 6px;
}
.btn-copy:hover { background: #f3f4f6; }

@media (max-width: 540px) {
  .grid-2 { grid-template-columns: 1fr; }
  .hero-card { align-items: flex-start; }
  .kv-item { flex-direction: column; align-items: flex-start; gap: 2px; }
  .kv-val { text-align: left; }
  .user-body { grid-template-columns: 1fr; }
  .user-header { align-items: flex-start; }
  .kv-row { flex-direction: column; gap: 2px; }
  .kv-v { text-align: left; }
}

/* Categories tree (neobrutalist dashboard) */
.categories-view {
  --cat-bg: #f7f7f7;
  --cat-surface: #ffffff;
  --cat-orange: #ff6b00;
  --cat-yellow: #f5d300;
  --cat-pink: #ff66b3;
  --cat-green: #00d26a;
  --cat-border: 3px solid #1c1c1c;
  --cat-shadow: 5px 5px 0 #1c1c1c;
  --cat-shadow-sm: 3px 3px 0 #1c1c1c;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  background: var(--cat-bg);
  color: #1c1c1c;
  line-height: 1.4;
  padding: 20px;
}

.cat-topbar {
  background: var(--cat-yellow);
  border: var(--cat-border);
  box-shadow: var(--cat-shadow);
  padding: 18px 22px;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.cat-topbar h1 {
  font-size: 21px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -.5px;
  color: #1c1c1c;
}
.cat-topbar small { font-size: 11px; font-weight: 700; }
.cat-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.cat-badge {
  background: var(--cat-surface);
  border: 2px solid #1c1c1c;
  box-shadow: 2px 2px 0 #1c1c1c;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
}
.cat-badge.orange { background: var(--cat-orange); color: #fff; }
.cat-badge.pink { background: var(--cat-pink); }
.cat-badge.green { background: var(--cat-green); }
.cat-badge.red { background: #ff5b5b; color: #fff; }

.cat-message {
  border: var(--cat-border);
  box-shadow: var(--cat-shadow-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-weight: 700;
  background: #fff;
}
.cat-message.error { background: #fee2e2; }

.cat-controls {
  display: grid;
  grid-template-columns: 2fr repeat(4, auto);
  gap: 12px;
  margin-bottom: 12px;
}
@media (max-width: 1080px) {
  .cat-controls { grid-template-columns: 1fr 1fr; }
  .cat-controls input { grid-column: 1 / -1; }
}
@media (max-width: 620px) {
  .cat-controls { grid-template-columns: 1fr; }
  .cat-controls input { grid-column: auto; }
}

.cat-controls input[type="text"], .cat-btn {
  background: var(--cat-surface);
  border: var(--cat-border);
  box-shadow: var(--cat-shadow-sm);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: #1c1c1c;
  outline: none;
}
.cat-controls input[type="text"]:focus { background: #fffdf0; border-color: var(--cat-orange); }
.cat-btn {
  cursor: pointer;
  background: var(--cat-orange);
  color: #fff;
  text-transform: uppercase;
  white-space: nowrap;
}
.cat-btn:active { transform: translate(3px, 3px); box-shadow: none; }
.cat-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: var(--cat-shadow-sm); }
.cat-btn.secondary { background: var(--cat-surface); color: #1c1c1c; }
.cat-btn.yellow { background: var(--cat-yellow); color: #1c1c1c; }

.cat-meta {
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cat-meta span { border: 2px solid #1c1c1c; background: #fff; padding: 3px 8px; }

.cat-workspace {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 1024px) {
  .cat-workspace { grid-template-columns: 1fr; }
}

.cat-tree-panel, .cat-inspector, .cat-history {
  background: var(--cat-surface);
  border: var(--cat-border);
  box-shadow: var(--cat-shadow);
  padding: 18px;
}
.cat-tree-panel { max-height: calc(100vh - 260px); overflow-y: auto; }
.cat-inspector { position: sticky; top: 20px; max-height: calc(100vh - 260px); overflow-y: auto; }
.cat-loading, .cat-empty { font-weight: 700; color: #555; padding: 20px; text-align: center; }

.cat-tree, .cat-tree-children { list-style: none; }
.cat-tree-children {
  margin-left: 22px;
  padding-left: 14px;
  border-left: 3px solid #1c1c1c;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cat-tree-children.collapsed { display: none; }
.cat-node { margin-bottom: 6px; }
.cat-node-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--cat-bg);
  border: 2px solid #1c1c1c;
  padding: 8px 10px;
  cursor: pointer;
}
.cat-node-row:hover { background: #fffdf0; }
.cat-node-row.selected { background: var(--cat-yellow); box-shadow: var(--cat-shadow-sm); }
.cat-node-row.highlight-match { border-color: var(--cat-orange); border-width: 3px; }
.cat-node-left, .cat-node-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cat-node-right { flex-shrink: 0; }
.cat-toggle {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  background: #1c1c1c;
  color: #fff;
  border: 0;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cat-toggle.leaf { background: var(--cat-green); color: #1c1c1c; cursor: default; }
.cat-toggle.reference { background: var(--cat-pink); color: #1c1c1c; cursor: help; }
.cat-id { background: #1c1c1c; color: #fff; padding: 2px 6px; font-size: 11px; font-weight: 800; flex-shrink: 0; }
.cat-name { font-size: 12px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-pill {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border: 1.5px solid #1c1c1c;
  background: #fff;
}
.cat-pill.leaf { background: var(--cat-green); }
.cat-pill.count { background: #eaeaea; }
.cat-copy {
  background: var(--cat-orange);
  color: #fff;
  border: 1.5px solid #1c1c1c;
  padding: 2px 6px;
  font: inherit;
  font-size: 10px;
  font-weight: 900;
  cursor: pointer;
}

.cat-inspector h2 { font-size: 19px; font-weight: 900; margin: 8px 0 4px; color: #1c1c1c; text-transform: none; letter-spacing: 0; }
.cat-section { margin-top: 16px; border: 2px solid #1c1c1c; background: var(--cat-bg); padding: 12px; }
.cat-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  background: #1c1c1c;
  color: #fff;
  display: inline-block;
  padding: 2px 8px;
  margin-bottom: 10px;
}
.cat-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 11px; }
.cat-kv-item { background: #fff; border: 1.5px solid #1c1c1c; padding: 6px 8px; word-break: break-word; }
.cat-kv-item span { display: block; font-size: 10px; color: #555; }
.cat-children { list-style: none; max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.cat-child {
  background: #fff;
  border: 2px solid #1c1c1c;
  padding: 7px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
}
.cat-child.clickable { cursor: pointer; }
.cat-child.clickable:hover { background: var(--cat-yellow); }
.cat-thumb { width: 48px; height: 48px; object-fit: contain; border: 2px solid #1c1c1c; background: #fff; padding: 4px; }
.cat-path { font-size: 11px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.cat-path button {
  border: 0;
  background: none;
  color: var(--cat-orange);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  padding: 0;
}
.cat-change { border: 1.5px solid #1c1c1c; background: #fff; padding: 6px 8px; font-size: 10px; margin-bottom: 6px; }
.cat-change code { display: block; background: #f3f3f3; padding: 2px 4px; margin-top: 3px; white-space: pre-wrap; word-break: break-word; }

.cat-attrs { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.cat-attr { background: #fff; border: 1.5px solid #1c1c1c; padding: 8px 10px; font-size: 11px; }
.cat-attr-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cat-attr-meta { color: #555; margin-top: 3px; }
.cat-attr-hint { margin-top: 4px; background: #fffdf0; border-left: 3px solid var(--cat-orange); padding: 4px 6px; }
.cat-attr-values { margin-top: 5px; }
.cat-attr-values summary { cursor: pointer; font-weight: 800; }
.cat-attr-values-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.cat-attr-value { background: #f3f3f3; border: 1px solid #bbb; padding: 2px 5px; font-size: 10px; }

.cat-history { margin-top: 20px; }
.cat-history-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.cat-history-head h2 { margin: 0 0 10px; color: #1c1c1c; font-size: 14px; font-weight: 900; text-transform: uppercase; }
.cat-filter-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.cat-pill-btn {
  background: #f3f4f6;
  border: 2px solid #1c1c1c;
  padding: 4px 10px;
  font: inherit;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}
.cat-pill-btn.active { background: var(--cat-yellow); }
.cat-history-item { border: 2px solid #1c1c1c; background: var(--cat-bg); padding: 10px 12px; margin-bottom: 10px; }
.cat-history-item header { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 11px; font-weight: 900; }
.cat-history-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin-top: 8px; }
.cat-history-group { background: #fff; border: 1.5px solid #1c1c1c; padding: 8px; font-size: 10px; max-height: 180px; overflow-y: auto; }
.cat-history-group strong { display: block; margin-bottom: 4px; text-transform: uppercase; }
.cat-history-row { border-bottom: 1px dashed #bbb; padding: 3px 0; }
.cat-history-row:last-child { border-bottom: 0; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #eef2f7;
}
.login-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .10);
}
.login-card h1 { font-size: 20px; }
.login-card .button { margin-top: 4px; }

dialog { border: 1px solid var(--line); border-radius: 10px; padding: 20px; max-width: 460px; }
dialog::backdrop { background: rgba(15, 23, 42, .4); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 200px 1fr; }
  .inspector { position: static; grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar, .inspector { position: static; }
  .grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: auto; }
  .topbar { flex-wrap: wrap; }
}

.references-view { padding: 22px; background: var(--cat-bg); min-height: calc(100vh - 96px); }
.references-view .cat-controls select {
  border: 2px solid #1c1c1c;
  background: #fff;
  color: #1c1c1c;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 10px;
  box-shadow: var(--cat-shadow-sm);
}
.ref-table-wrap {
  border: 2px solid #1c1c1c;
  background: #fff;
  box-shadow: var(--cat-shadow-sm);
  overflow: auto;
  max-height: 60vh;
}
.ref-table { border-collapse: collapse; width: 100%; font-size: 11px; }
.ref-table th, .ref-table td {
  border: 1px solid #1c1c1c;
  padding: 7px 9px;
  text-align: left;
  vertical-align: top;
  max-width: 360px;
  overflow-wrap: anywhere;
}
.ref-table th { background: #1c1c1c; color: #fff; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; }
.ref-table tbody tr:nth-child(even) { background: #f7f7f7; }
.ref-table code { font-size: 10px; }
.ref-json { max-width: 420px; max-height: 130px; overflow: auto; white-space: pre-wrap; font-size: 10px; }
.logs-table-wrap { max-height: 68vh; }
.logs-table th:first-child { width: 150px; }
.logs-table th:nth-child(2) { width: 110px; }
.log-time { color: #6b7280; white-space: nowrap; font-size: 10px; }
.log-message { white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10px; line-height: 1.45; }
.logs-view .cat-controls label.inline { width: auto; white-space: nowrap; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-nav {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    padding: 10px 12px;
    overflow: visible;
  }
  .app-nav-brand { padding: 0 6px 0 0; border-bottom: 0; }
  .app-nav-brand small { display: none; }
  .app-nav-group { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px; }
  .app-nav-title { display: none; }
  .nav-link { width: auto; padding: 6px 10px; font-size: 12px; }
}
