:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1e1e1e;
  --panel: #252526;
  --border: #3c3c3c;
  --text: #cccccc;
  --muted: #858585;
  --accent: #3794ff;
  --ok: #89d185;
  --error: #f48771;
  --gold: #c9a227;
  --item-bg: rgba(0, 0, 0, 0.15);
  --overlay: rgba(0, 0, 0, 0.55);
  --code-bg: rgba(0, 0, 0, 0.25);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f3f3;
  --panel: #ffffff;
  --border: #d4d4d4;
  --text: #1e1e1e;
  --muted: #6e6e6e;
  --accent: #0078d4;
  --ok: #107c10;
  --error: #c72e0f;
  --gold: #a8841c;
  --item-bg: rgba(0, 0, 0, 0.04);
  --overlay: rgba(0, 0, 0, 0.35);
  --code-bg: rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mt { margin-top: 1.25rem; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.brand { font-weight: 600; }
.tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}
.tab.active {
  background: var(--bg);
  border-color: var(--border);
}
.topbar-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover { border-color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-ghost { background: transparent; }
.btn-danger {
  border-color: var(--error);
  color: var(--error);
}
.btn-sm {
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.main {
  flex: 1;
  padding: 1rem 1.25rem 2.5rem;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}
.panel {
  display: none;
  position: relative;
  min-height: 8rem;
}
.panel.active { display: block; }
/* Full block only for hard loading; soft mode keeps the panel interactive */
.panel.is-loading:not(.is-loading-soft) > *:not(.panel-loading) {
  pointer-events: none;
}
.panel-loading {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.5rem;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(1px);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}
.panel.is-loading-soft .panel-loading {
  align-items: flex-start;
  justify-content: center;
  padding-top: 2.5rem;
  background: color-mix(in srgb, var(--bg) 45%, transparent);
}
.panel-loading[hidden] {
  display: none !important;
}
.panel-toolbar h1 {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
}
.panel-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.lead { margin: 0.25rem 0 0; max-width: 48rem; }

/* In-page toast / notification strip */
.status-toast {
  --status-fg: var(--text);
  --status-bg: rgba(55, 148, 255, 0.1);
  --status-border: rgba(55, 148, 255, 0.35);
  --status-icon-bg: rgba(55, 148, 255, 0.18);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0 0 1rem;
  padding: 0.7rem 0.75rem 0.7rem 0.85rem;
  border: 1px solid var(--status-border);
  border-radius: 10px;
  background: var(--status-bg);
  color: var(--status-fg);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  animation: status-toast-in 0.22s ease-out;
}
.status-toast[hidden] {
  display: none !important;
}
.status-toast.ok {
  --status-fg: var(--ok);
  --status-bg: rgba(137, 209, 133, 0.12);
  --status-border: rgba(137, 209, 133, 0.4);
  --status-icon-bg: rgba(137, 209, 133, 0.2);
}
.status-toast.err {
  --status-fg: var(--error);
  --status-bg: rgba(244, 135, 113, 0.12);
  --status-border: rgba(244, 135, 113, 0.42);
  --status-icon-bg: rgba(244, 135, 113, 0.2);
}
.status-toast.info {
  --status-fg: var(--text);
  --status-bg: rgba(55, 148, 255, 0.1);
  --status-border: rgba(55, 148, 255, 0.35);
  --status-icon-bg: rgba(55, 148, 255, 0.18);
}
html[data-theme="light"] .status-toast {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}
html[data-theme="light"] .status-toast.ok {
  --status-bg: rgba(16, 124, 16, 0.08);
  --status-border: rgba(16, 124, 16, 0.28);
  --status-icon-bg: rgba(16, 124, 16, 0.12);
}
html[data-theme="light"] .status-toast.err {
  --status-bg: rgba(199, 46, 15, 0.08);
  --status-border: rgba(199, 46, 15, 0.28);
  --status-icon-bg: rgba(199, 46, 15, 0.12);
}
.status-toast-icon {
  flex-shrink: 0;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--status-icon-bg);
  color: var(--status-fg);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  margin-top: 0.05rem;
}
.status-toast-text {
  flex: 1;
  min-width: 0;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--text);
  word-break: break-word;
}
.status-toast.ok .status-toast-text { color: var(--text); }
.status-toast.err .status-toast-text { color: var(--text); }
.status-toast-dismiss {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  margin: -0.15rem -0.1rem 0 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.status-toast-dismiss:hover {
  color: var(--text);
  background: var(--item-bg);
}
@keyframes status-toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.card h3 { margin: 0; }
.card .stat {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0.25rem 0;
}
.card .btn { margin-top: auto; align-self: flex-start; }

.hint-box {
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(55, 148, 255, 0.08);
  font-size: 0.9rem;
  line-height: 1.45;
}

.split {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.15fr);
  gap: 1rem;
  min-height: 420px;
}
.split.wide-right {
  grid-template-columns: minmax(260px, 0.9fr) minmax(340px, 1.25fr);
}
.list-pane, .detail-pane {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  padding: 0.85rem 1rem;
  overflow: auto;
  max-height: calc(100vh - 160px);
}
.list-pane h2, .detail-pane h2 {
  margin: 0 0 0.65rem;
  font-size: 1rem;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.item-list.compact { max-height: 280px; overflow: auto; }

.settings-preloader,
.skills-preloader {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.settings-preloader[hidden],
.skills-preloader[hidden] {
  display: none !important;
}
.settings-spinner,
.skills-spinner {
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: settings-spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes settings-spin {
  to { transform: rotate(360deg); }
}
.list-loading {
  min-height: 3rem;
}
.dialog-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  color: var(--muted);
  border-radius: inherit;
}
.dialog-loading[hidden] {
  display: none !important;
}
button.linkish {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.panel-toolbar-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}
.panel-toolbar-inline h2 {
  margin: 0;
}
.skills-hygiene-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.65rem 0 0.35rem;
}
.skills-hygiene-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--item-bg);
  padding: 0.75rem 0.9rem;
  margin: 0.5rem 0 0.85rem;
  display: grid;
  gap: 0.55rem;
}
.skills-hygiene-panel[hidden] {
  display: none !important;
}
.skills-hygiene-panel h3 {
  margin: 0;
  font-size: 0.95rem;
}
.skills-dupe-group {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  display: grid;
  gap: 0.25rem;
}
.skills-dupe-group .item-sub {
  margin: 0;
}
.skills-hygiene-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.25rem;
}
.skills-plan-list {
  margin: 0.2rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  background: var(--item-bg);
  display: grid;
  gap: 0.25rem;
}
.item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.item-title { font-weight: 600; }
.item-sub {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}
.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.25rem;
}
.section-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0.65rem 0 0.25rem;
  font-weight: 600;
}

.form-grid {
  display: grid;
  gap: 0.55rem;
}
.form-grid label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.88rem;
}
.form-grid label.full {
  grid-column: 1 / -1;
}
.form-grid input,
.form-grid select,
.form-grid textarea,
.form-row input,
.form-row select,
.hub-search-bar input,
.hub-search-bar select,
.skills-installed-filter input,
.skills-installed-filter select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font: inherit;
}
.form-grid textarea {
  resize: vertical;
  min-height: 4rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
}
.item.selected {
  outline: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--item-bg));
}
.mcp-editor-dialog {
  position: relative;
  width: min(560px, 94vw);
  max-height: 90vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel, var(--bg));
  color: var(--text);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}
.mcp-editor-dialog::backdrop {
  background: var(--overlay, rgba(0, 0, 0, 0.55));
}
.mcp-edit-form {
  padding: 1rem 1.1rem 1rem;
  max-height: 90vh;
  overflow: auto;
}
.mcp-editor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  grid-column: 1 / -1;
  margin-bottom: 0.25rem;
}
.mcp-editor-header h2 {
  margin: 0;
  font-size: 1.15rem;
}
.mcp-editor-header .muted {
  margin: 0.25rem 0 0;
}
.mcp-editor-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.5rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}
.mcp-editor-actions-spacer {
  flex: 1 1 auto;
  min-width: 0.5rem;
}
.mcp-env-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.mcp-env-rows {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.mcp-env-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) auto;
  gap: 0.35rem;
  align-items: center;
}
.mcp-env-row input {
  width: 100%;
  padding: 0.35rem 0.45rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font: inherit;
  font-size: 0.85rem;
}
.mcp-badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--muted);
  margin-left: 0.35rem;
}
.mcp-badge.ok {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 40%, var(--border));
}
.skills-installed-filter {
  margin: 0.35rem 0 0.25rem;
}
.skills-installed-filter select {
  width: auto;
  min-width: 8.5rem;
  flex: 0 0 auto;
}
.skills-installed-filter input {
  flex: 1;
  min-width: 140px;
}
.skills-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.65rem;
  padding: 0.5rem 0.15rem 0.15rem;
  border-top: 1px solid var(--border);
}
.skills-pagination .btn[disabled] {
  opacity: 0.45;
  pointer-events: none;
}
.form-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.form-row input { flex: 1; min-width: 160px; }
.check {
  display: flex !important;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.88rem;
}
.check input { width: auto !important; }

.agent-models {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}
.agent-model-row {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 0.4rem;
  align-items: center;
}
.agent-model-row input {
  padding: 0.35rem 0.45rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font: inherit;
}

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  max-width: 360px;
  text-align: center;
}

.profile-layout {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: 720px;
}
.profile-subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}
.profile-subtab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
}
.profile-subtab:hover {
  border-color: var(--border);
}
.profile-subtab.active {
  background: var(--bg);
  border-color: var(--border);
  font-weight: 600;
}
.profile-subpanel {
  display: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  padding: 1.1rem 1.2rem;
  flex-direction: column;
  gap: 0.65rem;
}
.profile-subpanel.active {
  display: flex;
}
.profile-subpanel h2 {
  margin: 0 0 0.15rem;
  font-size: 1.1rem;
}
.theme-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 0.35rem 0 0.75rem;
}
.theme-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 0.9rem;
  cursor: pointer;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.theme-card:hover { border-color: var(--accent); }
.theme-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.theme-card:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.theme-card-title { font-weight: 600; }
.theme-preview {
  height: 48px;
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
  display: grid;
  grid-template-columns: 18px 1fr;
}
.theme-preview-bar { background: #2d2d2d; }
.theme-preview-main { background: #1e1e1e; }
.theme-preview.light .theme-preview-bar { background: #e8e8e8; }
.theme-preview.light .theme-preview-main { background: #f3f3f3; }
.settings-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.1rem 0 0.85rem;
}
.settings-subheading {
  margin: 0 0 0.15rem;
  font-size: 1rem;
  font-weight: 600;
}
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.settings-group h2 {
  margin: 0 0 0.15rem;
  font-size: 1.05rem;
}
.settings-field {
  display: grid;
  gap: 0.25rem;
  font-size: 0.88rem;
}
.settings-field-label {
  color: var(--muted);
  font-size: 0.8rem;
}
.settings-field-value,
.settings-field-control {
  font: inherit;
}
.settings-field-control,
.settings-group textarea {
  width: 100%;
  padding: 0.4rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font: inherit;
  resize: vertical;
}
.settings-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  word-break: break-all;
}
.admin-only-cards {
  margin-top: 0.5rem;
}
#hub-results.busy {
  opacity: 0.65;
  pointer-events: none;
}
#btn-hub-search.busy {
  opacity: 0.7;
}
.item-readonly {
  opacity: 0.92;
  border-style: dashed;
}

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  flex-shrink: 0;
}
.badge-user {
  color: #7dd3a7;
  border-color: rgba(125, 211, 167, 0.45);
}
.badge-hub {
  color: #9db7ff;
  border-color: rgba(157, 183, 255, 0.45);
}

.skill-editor-dialog {
  position: relative;
  width: min(720px, 94vw);
  max-height: 90vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel, var(--bg));
  color: var(--text);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}
.skill-editor-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.skill-editor-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem 1.1rem 1rem;
  max-height: 90vh;
  overflow: auto;
}
.skill-editor-header h2 {
  margin: 0;
  font-size: 1.15rem;
}
.skill-editor-content-field textarea {
  min-height: 280px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.skill-editor-form input.readonly,
.skill-editor-form textarea.readonly {
  opacity: 0.9;
  background: var(--item-bg, var(--bg));
}
.skill-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
  .split, .split.wide-right {
    grid-template-columns: 1fr;
  }
  .list-pane, .detail-pane {
    max-height: none;
  }
  .agent-model-row {
    grid-template-columns: 1fr;
  }
}
