:root {
  --bg: #0c1017;
  --surface: #151b26;
  --surface2: #1c2433;
  --border: #2a3548;
  --text: #e8edf4;
  --muted: #8b9aaf;
  --accent: #6eb3e8;
  --accent-dim: #4a8ab8;
  --ok: #4caf7a;
  --warn: #e6a23c;
  --err: #e05555;
  --sidebar-w: 240px;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body.admin {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

body.admin.modal-open {
  overflow: hidden;
}

a {
  color: var(--accent);
}

a:hover {
  color: var(--accent-dim);
}

/* ——— App shell (logged-in) ——— */
.admin-shell {
  display: flex;
  min-height: 100vh;
}

.admin-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
}

.sidebar-brand {
  display: block;
  padding: 0.35rem 1.1rem 1rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0 0.5rem;
  flex: 1;
}

.sidebar-link {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.sidebar-link:hover {
  background: var(--surface2);
  color: var(--text);
}

.sidebar-link.active {
  background: rgba(110, 179, 232, 0.12);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-link.logout {
  color: var(--err);
}

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-badge {
  align-self: flex-start;
}

.lang-switcher {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
}

.lang-switcher--login {
  justify-content: center;
  margin-bottom: 0.25rem;
}

.lang-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}

.lang-link:hover {
  color: var(--accent);
}

.lang-link.is-active {
  color: var(--accent);
  text-decoration: underline;
}

.lang-sep {
  color: var(--muted);
  user-select: none;
}

.admin-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topbar-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.admin-content {
  flex: 1;
  padding: 1.25rem 1.5rem 2.5rem;
  max-width: 1200px;
  width: 100%;
}

/* ——— Banners & badges ——— */
.banner {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: 0.92rem;
  border: 1px solid transparent;
}

.banner-warn {
  background: rgba(230, 162, 60, 0.12);
  border-color: rgba(230, 162, 60, 0.45);
  color: #f0d4a8;
}

.banner-scope {
  background: rgba(100, 149, 237, 0.12);
  border-color: rgba(100, 149, 237, 0.4);
  color: #c8d8f8;
}

.badge-scope {
  background: rgba(100, 149, 237, 0.2);
  color: #b4c8f0;
  border: 1px solid rgba(100, 149, 237, 0.35);
}

.banner a {
  color: var(--accent);
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-ok,
.badge.ok {
  background: rgba(76, 175, 122, 0.2);
  color: #9ddeb8;
}

.badge-warn,
.badge.warn {
  background: rgba(230, 162, 60, 0.2);
  color: #f5d08a;
}

.badge-bad,
.badge.bad {
  background: rgba(224, 85, 85, 0.2);
  color: #f5a0a0;
}

.badge-muted,
.badge.muted {
  background: var(--surface2);
  color: var(--muted);
}

.badge-neutral,
.badge.neutral {
  background: var(--border);
  color: var(--text);
}

.panel-warn {
  border-color: rgba(230, 162, 60, 0.4);
}

/* ——— Dashboard ——— */
.dashboard-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  .dashboard-grid {
    grid-template-columns: 1.4fr 1fr;
  }

  .dashboard-grid .panel.panel-full {
    grid-column: 1 / -1;
  }
}

.panel-highlight {
  border-color: rgba(110, 179, 232, 0.35);
  background: linear-gradient(145deg, var(--surface) 0%, #182030 100%);
}

.panel-title {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 650;
  color: var(--text);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
}

.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}

.stat-value {
  display: block;
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.stat-value.stat-ok {
  color: var(--ok);
}

.stat-value.stat-warn {
  color: var(--warn);
}

.stat-value.stat-bad {
  color: var(--err);
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.stat-hint {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.85;
  margin-top: 0.2rem;
}

.panel-subtitle {
  margin: 1.25rem 0 0.65rem;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--muted);
}

.dashboard-coverage-bar {
  margin-top: 1rem;
  max-width: 28rem;
  height: 10px;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  background: var(--border);
}

.dashboard-coverage-bar .seg-ok {
  background: var(--ok);
  height: 100%;
  min-width: 2px;
}

.dashboard-coverage-bar .seg-miss {
  background: var(--warn);
  height: 100%;
  min-width: 2px;
  opacity: 0.65;
}

.dashboard-sync7d-lead {
  margin: 0 0 0.75rem;
  font-size: 0.86rem;
}

.dashboard-coverage-stats {
  margin-top: 0.75rem;
}

.dashboard-coverage-capped-hint {
  margin-top: 0.75rem;
}

.mini-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.mini-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.mini-card span {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
}

.mini-card.subtle span {
  color: var(--muted);
}

.foot-hint {
  margin-top: 2rem;
  font-size: 0.8rem;
}

.foot-hint code {
  font-size: 0.75rem;
  word-break: break-all;
}

/* ——— Cards ——— */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.cards-tight {
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.card strong {
  font-size: 1.45rem;
  font-weight: 700;
}

.card span {
  color: var(--muted);
  font-size: 0.82rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.panel h2 {
  margin: 0 0 1rem;
  font-size: 1.02rem;
  font-weight: 650;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.intro-line {
  margin: 0 0 1rem;
  max-width: 52rem;
}

/* ——— Tables ——— */
.table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  background: var(--surface2);
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.data-table-compact td,
.data-table-compact th {
  padding: 0.45rem 0.55rem;
}

.nowrap {
  white-space: nowrap;
}

.truncate {
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.small {
  max-width: 10rem;
  font-size: 0.8rem;
}

.row-actions {
  white-space: nowrap;
}

.row-actions form.inline {
  display: inline;
}

button.link,
.row-actions button.link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}

button.link.danger {
  color: var(--err);
}

/* ——— Forms ——— */
.btn {
  display: inline-block;
  padding: 0.45rem 0.95rem;
  background: var(--accent);
  color: #0a1018 !important;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 650;
  border: none;
  cursor: pointer;
  line-height: 1.3;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn.secondary {
  background: var(--border);
  color: var(--text) !important;
}

.stacked-form,
.grid-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: 34rem;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  max-width: none;
  align-items: end;
}

.inline-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

label.toggle {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  color: var(--text);
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

label.checkbox {
  flex-direction: row;
  align-items: center;
}

input,
select,
textarea,
button[type="submit"] {
  font: inherit;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

textarea.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
}

button[type="submit"] {
  background: var(--accent);
  color: #0a1018;
  font-weight: 650;
  border: none;
  cursor: pointer;
  width: fit-content;
}

.field-hint {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.field-hint code {
  font-size: 0.78rem;
  color: var(--text);
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.brand-credentials {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  background: var(--surface2);
}

.brand-credentials summary {
  padding: 0.75rem 1rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
}

.brand-credentials summary::-webkit-details-marker {
  display: none;
}

.summary-title {
  flex: 1;
}

.summary-meta {
  font-weight: 400;
}

.settings-cred-form {
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  overflow: auto;
  font-size: 0.75rem;
  max-height: 320px;
  white-space: pre-wrap;
  word-break: break-word;
}

.flash {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.flash.ok {
  background: rgba(76, 175, 122, 0.15);
  border: 1px solid var(--ok);
}

.flash.error {
  background: rgba(224, 85, 85, 0.12);
  border: 1px solid var(--err);
}

.filters a {
  margin-right: 0.75rem;
  color: var(--muted);
}

.filters a.active {
  color: var(--accent);
  font-weight: 600;
}

pre.json-view,
pre.result {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  overflow: auto;
  font-size: 0.8rem;
  max-height: 70vh;
}

/* ——— Login ——— */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-box {
  width: 100%;
  max-width: 380px;
  padding: 1.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.login-box h1 {
  margin: 0 0 1rem;
  font-size: 1.35rem;
  font-weight: 650;
}

.login-box form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

/* ——— Brand slug field ——— */
.slug-field-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.slug-field-block > label[for="brand-slug-input"] {
  font-size: 0.85rem;
  color: var(--muted);
}

.slug-quick-hint {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
}

.slug-quick-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin: 0.25rem 0 0.35rem;
}

.btn-slim {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
}

.slug-preset-btn {
  background: var(--surface2);
  color: var(--accent) !important;
  border: 1px solid var(--border);
}

.slug-preset-btn:hover {
  border-color: var(--accent);
  background: rgba(110, 179, 232, 0.1);
}

.slug-preset-desc {
  margin: 0.25rem 0 0;
  padding-left: 1.2rem;
  font-size: 0.82rem;
  max-width: 36rem;
}

.slug-preset-desc li {
  margin: 0.2rem 0;
}

.slug-preset-desc code {
  font-size: 0.88em;
}

.label-system,
.hint-system {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.88em;
}

.hint-system {
  font-weight: 600;
  color: #9dafc4;
}

.btn-system-prefix {
  display: inline-block;
  margin-right: 0.25rem;
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  background: var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
}

/* ——— MOCO hints (Settings) ——— */
.moco-hint-list {
  margin-top: 0.5rem;
}

.panel-moco-docs .ref-list li {
  margin: 0.35rem 0;
}

/* ——— ID mappings form ——— */
.mapping-intro-panel .mapping-entity-legend {
  margin-top: 0.5rem;
}

.mapping-form.grid-form {
  align-items: start;
}

.mapping-field-span {
  grid-column: 1 / -1;
  max-width: 38rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.mapping-field-span > label {
  margin: 0;
}

.mapping-submit-span {
  grid-column: 1 / -1;
}

.moco-lookup-panel,
.hubspot-lookup-panel {
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
  max-width: 42rem;
}

.moco-lookup-heading,
.hubspot-lookup-heading {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
  font-weight: 650;
}

.moco-lookup-row,
.hubspot-lookup-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}

.moco-lookup-input,
.hubspot-lookup-input {
  flex: 1 1 12rem;
  min-width: 10rem;
}

.moco-lookup-status,
.hubspot-lookup-status {
  margin-top: 0.65rem;
  font-size: 0.88rem;
}

.moco-lookup-status--error,
.hubspot-lookup-status--error {
  color: var(--err);
}

.moco-lookup-results,
.hubspot-lookup-results {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.65rem;
  max-width: 42rem;
}

button.moco-lookup-pick,
button.hubspot-lookup-pick {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.86rem;
  cursor: pointer;
  font-family: inherit;
}

button.moco-lookup-pick:hover,
button.hubspot-lookup-pick:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.mapping-moco-help-panel .mapping-help-sub {
  margin: 1rem 0 0.35rem;
}

.mapping-help-steps {
  margin: 0.35rem 0 0;
  padding-left: 1.35rem;
  max-width: 42rem;
}

.mapping-help-steps li {
  margin: 0.4rem 0;
}

.mapping-json-example {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  font-size: 0.82rem;
  overflow: auto;
  max-width: 32rem;
  margin: 0.5rem 0 0.25rem;
}

/* ——— HubSpot reference (Brands page) ——— */
.reference-hubspot h3 {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 650;
}

.ref-list {
  margin: 0.35rem 0 0;
  padding-left: 1.25rem;
}

.scope-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0 0;
}

.scope-chip {
  font-size: 0.78rem;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: #b8d4f0;
}

.scope-filter-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.75rem 0 0.5rem;
  max-width: 28rem;
}

.scope-filter-input {
  width: 100%;
}

.scope-list-wrap {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  margin-top: 0.35rem;
}

.scope-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem 0.65rem;
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.scope-list li {
  padding: 0.15rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.scope-list li:last-child {
  border-bottom: none;
}

.scope-list code {
  background: transparent;
  color: var(--text);
  font-size: inherit;
}

/* ——— Help toolbar & modals ——— */
.help-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

.btn-help {
  background: var(--surface2);
  color: var(--text) !important;
  border: 1px solid var(--border);
  font-size: 0.84rem;
}

.btn-help:hover {
  border-color: var(--accent);
  color: var(--accent) !important;
}

.panel-heading-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.panel-heading-row h2 {
  margin: 0;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 5000;
  padding: 0;
}

.modal-root[hidden] {
  display: none !important;
}

.modal-root.is-open {
  display: block !important;
}

.modal-surface {
  position: relative;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 16, 0.72);
  cursor: pointer;
}

.modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 42rem;
  max-height: min(88vh, 920px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.modal-card--wide {
  max-width: min(52rem, 96vw);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
  border-radius: 12px 12px 0 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.35;
}

.modal-close {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: var(--surface2);
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.modal-body {
  padding: 1rem 1.15rem 1.25rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-body .panel-title {
  margin-top: 0;
}

.modal-card .scope-list-wrap {
  max-height: min(50vh, 420px);
}

@media (max-width: 768px) {
  .admin-shell {
    flex-direction: column;
  }

  .admin-sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.65rem 0.75rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-brand {
    border: none;
    margin: 0;
    padding: 0.25rem 0.5rem;
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1;
    padding: 0;
    gap: 0.25rem;
  }

  .sidebar-footer {
    flex-direction: row;
    border: none;
    padding: 0;
    width: 100%;
    justify-content: space-between;
    align-items: center;
  }
}
