@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap");

:root {
  color-scheme: dark;
  --bg: #080b14;
  --bg-soft: #0d1120;
  --surface: rgba(18, 24, 42, 0.88);
  --surface-solid: #12182a;
  --surface-raised: #182038;
  --surface-hover: #1d2743;
  --border: rgba(155, 173, 212, 0.14);
  --border-strong: rgba(155, 173, 212, 0.24);
  --text: #f5f7fc;
  --text-soft: #b2bdd4;
  --text-muted: #7f8ba6;
  --primary: #7c6cf2;
  --primary-bright: #9587ff;
  --primary-soft: rgba(124, 108, 242, 0.14);
  --success: #4fd1a5;
  --success-soft: rgba(79, 209, 165, 0.12);
  --danger: #ff7f96;
  --danger-soft: rgba(255, 127, 150, 0.12);
  --warning: #f9c86b;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  --shadow-soft: 0 8px 28px rgba(0, 0, 0, 0.18);
  font-family: "DM Sans", Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 92% 0%, rgba(93, 73, 199, 0.12), transparent 32rem),
    radial-gradient(circle at 0% 100%, rgba(52, 104, 170, 0.08), transparent 34rem),
    var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: var(--primary-bright);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  color: var(--text);
  line-height: 1.16;
  letter-spacing: -0.025em;
}

h1 {
  margin-bottom: 0.65rem;
  font-size: clamp(2rem, 4vw, 3.2rem);
  font-weight: 700;
}

h2 {
  margin-bottom: 0.75rem;
  font-size: 1.18rem;
  font-weight: 650;
}

p {
  color: var(--text-soft);
}

code {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.2rem 0.55rem;
  color: #c7beff;
  background: var(--primary-soft);
  border: 1px solid rgba(149, 135, 255, 0.16);
  border-radius: 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
}

/* Authentication */
.layout-auth:has(.auth-shell) {
  display: grid;
  place-items: center;
  padding: clamp(1.25rem, 5vw, 4rem);
}

.auth-shell {
  display: grid;
  width: 100%;
  min-height: calc(100vh - clamp(2.5rem, 10vw, 8rem));
  place-items: center;
}

.auth-card {
  position: relative;
  width: min(100%, 470px);
  padding: clamp(2rem, 6vw, 3.25rem);
  overflow: hidden;
  background: linear-gradient(145deg, rgba(24, 31, 54, 0.96), rgba(14, 19, 34, 0.96));
  border: 1px solid var(--border-strong);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.auth-card::before {
  position: absolute;
  top: -6rem;
  right: -5rem;
  width: 14rem;
  height: 14rem;
  background: rgba(124, 108, 242, 0.16);
  border-radius: 50%;
  filter: blur(24px);
  content: "";
  pointer-events: none;
}

.brand-mark {
  position: relative;
  display: grid;
  width: 3.25rem;
  height: 3.25rem;
  margin-bottom: 2rem;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--primary-bright), #5e4bc8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 15px;
  box-shadow: 0 12px 30px rgba(92, 73, 194, 0.28);
  font-weight: 700;
  letter-spacing: -0.04em;
}

.auth-heading {
  position: relative;
  margin-bottom: 2rem;
}

.auth-heading p:last-child {
  max-width: 35rem;
  margin-bottom: 0;
}

.eyebrow {
  margin-bottom: 0.65rem;
  color: var(--primary-bright);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.auth-form {
  display: grid;
  gap: 1.1rem;
}

.auth-note {
  margin: 1.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
}

/* Application shell */
.layout-dashboard {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 260px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
}

.app-sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  height: 100vh;
  padding: 1.75rem 1.25rem;
  flex-direction: column;
  grid-row: 1 / -1;
  background: rgba(10, 14, 26, 0.94);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.sidebar-brand {
  display: flex;
  min-height: 3.5rem;
  margin-bottom: 2.25rem;
  padding: 0 0.7rem;
  align-items: center;
  gap: 0.8rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}

.sidebar-brand .brand-mark {
  width: 2.6rem;
  height: 2.6rem;
  margin: 0;
  flex: 0 0 auto;
  border-radius: 12px;
  font-size: 0.85rem;
}

.sidebar-nav {
  display: grid;
  gap: 0.45rem;
}

.sidebar-nav a {
  display: flex;
  min-height: 2.85rem;
  padding: 0.7rem 0.85rem;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 11px;
  text-decoration: none;
  transition: 160ms ease;
}

.sidebar-nav a:hover,
.sidebar-nav a[aria-current="page"] {
  color: var(--text);
  background: var(--primary-soft);
  border-color: rgba(149, 135, 255, 0.12);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.app-topbar,
.layout-dashboard > nav {
  display: flex;
  min-height: 78px;
  padding: 0 clamp(1.5rem, 4vw, 3.5rem);
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: rgba(8, 11, 20, 0.72);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.app-topbar h1 {
  margin: 0;
  font-size: 1.15rem;
}

.app-topbar p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.dashboard-main {
  width: 100%;
  max-width: 1500px;
  padding: clamp(2rem, 5vw, 4.5rem) clamp(1.5rem, 4vw, 3.5rem) 5rem;
}

/* Graceful layout for the previous, non-shell dashboard markup. */
.layout-dashboard > .flash,
.layout-dashboard > .grid,
.layout-dashboard > article {
  width: calc(100% - clamp(3rem, 8vw, 7rem));
  max-width: 1420px;
  margin-right: auto;
  margin-left: auto;
  grid-column: 2;
}

.layout-dashboard > .flash {
  margin-top: 2rem;
  margin-bottom: 0;
}

.layout-dashboard > .grid {
  margin-top: clamp(2rem, 4vw, 3.5rem);
}

.layout-dashboard > article {
  margin-top: 2rem;
  margin-bottom: 5rem;
}

.page-heading {
  display: flex;
  margin-bottom: 2.25rem;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
}

.page-heading h1 {
  margin-bottom: 0.45rem;
  font-size: clamp(1.8rem, 3vw, 2.45rem);
}

.page-heading p {
  max-width: 42rem;
  margin-bottom: 0;
  color: var(--text-muted);
}

/* Cards and instance overview */
.grid,
.instance-grid,
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 1.25rem;
}

article,
.panel,
.instance-card,
.stat-card {
  background: linear-gradient(145deg, rgba(21, 28, 48, 0.95), rgba(15, 20, 35, 0.95));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}

article,
.panel {
  padding: clamp(1.4rem, 3vw, 2rem);
}

.grid > article,
.instance-card {
  position: relative;
  display: flex;
  min-height: 275px;
  padding: 1.6rem;
  flex-direction: column;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.grid > article:hover,
.instance-card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.24);
  transform: translateY(-2px);
}

.grid > article > p:nth-of-type(1) {
  color: var(--text-muted);
  font-size: 0.84rem;
}

.grid > article > p:nth-of-type(2) {
  display: inline-flex;
  width: fit-content;
  margin-bottom: 1.5rem;
  padding: 0.35rem 0.7rem;
  align-items: center;
  gap: 0.45rem;
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid rgba(79, 209, 165, 0.16);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.grid > article > p:nth-of-type(2)::before {
  width: 0.4rem;
  height: 0.4rem;
  background: currentColor;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(79, 209, 165, 0.12);
  content: "";
}

.grid > article > p:has(.button) {
  margin-top: auto;
  margin-bottom: 1rem;
}

.stat-card {
  padding: 1.5rem;
}

.stat-card .value {
  margin: 0.4rem 0 0;
  color: var(--text);
  font-size: 2rem;
  font-weight: 700;
}

/* Forms */
form {
  margin: 0;
}

article > form:not(.actions),
.config-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.15rem 1.5rem;
}

label {
  display: grid;
  min-width: 0;
  gap: 0.5rem;
  color: var(--text-soft);
  font-size: 0.84rem;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 3.1rem;
  padding: 0.78rem 0.95rem;
  color: var(--text);
  background: rgba(7, 10, 19, 0.62);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

input::placeholder,
textarea::placeholder {
  color: #59647d;
}

input:hover,
select:hover,
textarea:hover {
  border-color: rgba(155, 173, 212, 0.35);
}

input:focus,
select:focus,
textarea:focus {
  background: rgba(8, 11, 21, 0.9);
  border-color: var(--primary-bright);
  box-shadow: 0 0 0 4px rgba(124, 108, 242, 0.14);
}

fieldset {
  min-width: 0;
  margin: 0.6rem 0;
  padding: 1.35rem;
  grid-column: 1 / -1;
  background: rgba(8, 11, 21, 0.36);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

fieldset label:not(.check) {
  margin-bottom: 1rem;
}

fieldset label:not(.check):last-child {
  margin-bottom: 0;
}

legend {
  padding: 0 0.6rem;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}

.check {
  display: inline-flex;
  min-height: 2.6rem;
  margin: 0.25rem 0.65rem 0.25rem 0;
  padding: 0.45rem 0.75rem;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  transition: 150ms ease;
}

.check:hover {
  color: var(--text);
  background: var(--surface-raised);
  border-color: var(--border-strong);
}

.check input {
  width: 1rem;
  min-height: 1rem;
  margin: 0;
  padding: 0;
  accent-color: var(--primary);
}

/* Buttons and actions */
button,
.button,
.button-primary,
.button-secondary {
  display: inline-flex;
  min-height: 2.75rem;
  padding: 0.68rem 1rem;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  color: #f7f5ff;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: none;
  cursor: pointer;
  font-weight: 650;
  text-decoration: none;
  transition: background 150ms ease, border-color 150ms ease, transform 150ms ease,
    box-shadow 150ms ease;
}

button:hover,
.button:hover,
.button-secondary:hover {
  color: #fff;
  background: var(--surface-hover);
  border-color: rgba(155, 173, 212, 0.34);
}

button:focus-visible,
.button:focus-visible {
  outline: 3px solid rgba(149, 135, 255, 0.38);
  outline-offset: 2px;
}

button:active,
.button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.button-primary,
article > form:not(.actions) > button:last-child {
  color: #fff;
  background: linear-gradient(135deg, var(--primary-bright), #6b59dc);
  border-color: transparent;
  box-shadow: 0 10px 24px rgba(92, 73, 194, 0.24);
}

.button-primary:hover,
article > form:not(.actions) > button:last-child:hover {
  background: linear-gradient(135deg, #a094ff, #7562e5);
  border-color: transparent;
  box-shadow: 0 12px 30px rgba(92, 73, 194, 0.32);
}

.button-block {
  width: 100%;
}

article > form:not(.actions) > button:last-child {
  width: fit-content;
  min-width: 9rem;
  margin-top: 0.5rem;
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  padding: 0;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: transparent;
  border: 0;
}

.actions + .actions {
  margin-top: 0.55rem;
}

.actions button {
  min-height: 2.35rem;
  padding: 0.5rem 0.72rem;
  color: var(--text-muted);
  font-size: 0.76rem;
  text-transform: capitalize;
}

nav form,
.app-topbar form,
.sidebar-footer form {
  padding: 0;
  background: transparent;
  border: 0;
}

/* Feedback */
.flash,
.error {
  position: relative;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.flash {
  color: #a8ead3;
  background: var(--success-soft);
  border: 1px solid rgba(79, 209, 165, 0.2);
}

.error {
  color: #ffafbd;
  background: var(--danger-soft);
  border: 1px solid rgba(255, 127, 150, 0.2);
}

.empty-state {
  padding: 4rem 2rem;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 900px) {
  .layout-dashboard {
    display: block;
  }

  .app-sidebar {
    position: static;
    width: 100%;
    height: auto;
    min-height: 0;
    padding: 1rem 1.25rem;
    flex-direction: row;
    align-items: center;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-brand {
    min-height: 0;
    margin: 0;
    padding: 0;
  }

  .sidebar-nav {
    display: flex;
    margin-left: auto;
  }

  .sidebar-footer {
    margin: 0 0 0 0.5rem;
    padding: 0;
    border: 0;
  }

  .app-topbar,
  .layout-dashboard > nav {
    padding: 0 1.5rem;
  }

  .layout-dashboard > .flash,
  .layout-dashboard > .grid,
  .layout-dashboard > article {
    width: calc(100% - 3rem);
    grid-column: auto;
  }

  .dashboard-main {
    padding-right: 1.5rem;
    padding-left: 1.5rem;
  }
}

@media (max-width: 640px) {
  .app-sidebar {
    flex-wrap: wrap;
    gap: 0.8rem;
  }

  .sidebar-nav {
    width: 100%;
    order: 3;
    overflow-x: auto;
  }

  .sidebar-nav a {
    min-width: max-content;
  }

  .page-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  article > form:not(.actions),
  .config-form {
    grid-template-columns: 1fr;
  }

  fieldset,
  article > form:not(.actions) > button:last-child {
    grid-column: auto;
  }

  .grid,
  .instance-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .grid > article,
  .instance-card {
    min-height: 0;
  }

  .auth-card {
    padding: 1.65rem;
    border-radius: 20px;
  }
}

/* Routed dashboard pages */
.page-heading,
.instance-hero {
  display: flex;
  min-height: 132px;
  padding: clamp(1.5rem, 3vw, 2.25rem);
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  background: linear-gradient(135deg, rgba(25, 33, 57, 0.96), rgba(14, 20, 36, 0.96));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.page-heading h2,
.instance-hero h2 {
  margin-bottom: 0.45rem;
  font-size: clamp(1.55rem, 3vw, 2.2rem);
}

.page-heading p:last-child,
.instance-hero p:last-child { margin-bottom: 0; color: var(--text-muted); }
.panel { padding: clamp(1.35rem, 2.5vw, 1.8rem); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-soft); }
.panel > h3 { margin-bottom: .55rem; font-size: 1.05rem; }
.panel > p:not(.eyebrow) { color: var(--text-muted); font-size: .86rem; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 1.25rem; }
.subnav { display: flex; padding: .4rem; gap: .35rem; overflow-x: auto; background: rgba(15,20,35,.72); border: 1px solid var(--border); border-radius: 13px; }
.subnav a { min-width: max-content; padding: .65rem 1rem; color: var(--text-muted); border-radius: 9px; font-size: .8rem; font-weight: 650; text-decoration: none; }
.subnav a:hover,.subnav a[aria-current="page"] { color: var(--text); background: var(--primary-soft); }
.list-stack { display: grid; gap: .65rem; }
.list-row,.message-row { display: flex; min-width: 0; padding: .85rem; align-items: center; gap: .8rem; color: var(--text); background: rgba(7,10,19,.36); border: 1px solid var(--border); border-radius: 11px; text-decoration: none; }
.list-row > span:nth-child(2),.message-row > span:first-child { display: grid; min-width: 0; margin-right: auto; }
.list-row strong,.message-row strong { overflow: hidden; font-size: .82rem; text-overflow: ellipsis; white-space: nowrap; }
.list-row small,.message-row small { color: var(--text-muted); font-size: .68rem; }
.message-row > span:last-child { color: var(--primary-bright); font-size: .72rem; }
.message-row.is-disabled { color: var(--text-muted); cursor: not-allowed; opacity: .58; }
.message-row.is-disabled > span:last-child { color: var(--text-muted); }
.account-card { display: flex; padding: .65rem; align-items: center; gap: .7rem; }
.account-card > div { display: grid; min-width: 0; }
.account-card strong { overflow: hidden; font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }
.account-card small { color: var(--text-muted); font-size: .64rem; }
.account-avatar { display: grid; width: 2.15rem; height: 2.15rem; flex: 0 0 auto; place-items: center; color: #d6d0ff; background: var(--primary-soft); border: 1px solid rgba(149,135,255,.2); border-radius: 9px; font-size: .65rem; font-weight: 750; }
.message-layout { display: grid; grid-template-columns: minmax(0,1.45fr) minmax(300px,.75fr); align-items: start; gap: 1.25rem; }
.content-column { display: grid; gap: 1.25rem; }
.stack-form { display: grid; gap: 1rem; }
.stack-form .button { width: fit-content; }
textarea { width: 100%; min-height: 8rem; padding: .85rem 1rem; resize: vertical; color: var(--text); background: rgba(7,10,19,.62); border: 1px solid var(--border-strong); border-radius: 10px; outline: none; }
textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,108,242,.12); }
.access-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); align-items: start; gap: 1.25rem; }
.user-list { grid-column: 1/-1; }
.empty-state.compact { padding: 1.25rem; }
.system-message-layout { padding-top: 1.25rem; border-top: 1px solid var(--border); }
.system-editor { overflow: hidden; }
.system-embed { display: grid; gap: 1rem; }
.system-field { display: grid; padding: 1rem; gap: .8rem; background: rgba(7,10,19,.3); border: 1px solid var(--border); border-radius: 10px; }
.banner-editor { display: grid; gap: 1rem; }
.banner-preview { display: grid; overflow: hidden; background: rgba(7,10,19,.42); border: 1px solid var(--border); border-radius: 12px; }
.banner-preview img { display: block; width: 100%; max-height: 260px; object-fit: contain; background: #080b14; }
.banner-preview > div { display: grid; padding: .85rem 1rem; gap: .2rem; }
.banner-preview strong { color: var(--text-soft); font-size: .8rem; }
.banner-preview small { color: var(--text-muted); font-size: .68rem; line-height: 1.5; }
.banner-empty { min-height: 96px; place-items: center; text-align: center; border-style: dashed; }
.check-row { display: flex; min-height: 2.4rem; margin: 0; align-items: center; gap: .65rem; color: var(--text-muted); font-size: .75rem; }
.check-row input { width: 1rem; min-height: 1rem; margin: 0; accent-color: var(--primary); }
.color-input { min-height: 3rem; padding: .35rem; cursor: pointer; }
input[type="file"] { padding: .65rem; color: var(--text-muted); }
input[type="file"]::file-selector-button { margin-right: .75rem; padding: .5rem .7rem; color: var(--text-soft); background: var(--surface-raised); border: 1px solid var(--border-strong); border-radius: 8px; cursor: pointer; }
.system-install-row { margin: 0; }
.system-install-row .button { margin-left: auto; }

/* Message studio */
.message-studio { display: grid; gap: 1.5rem; }
.system-navigation { padding: 1.35rem; }
.system-navigation .section-header { margin-bottom: 1rem; }
.system-template-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: .7rem; }
.system-template-card { min-height: 78px; padding: .85rem .95rem; }
.system-template-card.is-active { background: var(--primary-soft); border-color: rgba(149,135,255,.5); box-shadow: inset 3px 0 0 var(--primary-bright); }
.system-nav-actions,.studio-header-actions { display: flex; align-items: center; gap: .65rem; }
.system-create-panel { display: grid; margin-top: 1rem; padding: 1.1rem; grid-template-columns: minmax(220px,.65fr) minmax(0,1.35fr); align-items: end; gap: 1.25rem; background: rgba(255,255,255,.025); border: 1px dashed var(--border-strong); border-radius: 13px; }
.system-create-panel h4 { margin: .15rem 0 .25rem; }
.system-create-panel p:last-child { margin: 0; color: var(--text-muted); font-size: .75rem; }
.system-create-form { display: grid; grid-template-columns: minmax(180px,1fr) minmax(200px,1fr) auto; align-items: end; gap: .75rem; }
.system-create-form label { margin: 0; }
.system-message-meta { background: rgba(124,77,255,.035); }
.studio-panel { overflow: hidden; background: linear-gradient(145deg,rgba(20,27,47,.98),rgba(11,16,29,.98)); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); }
.studio-header { display: flex; padding: 1.6rem 1.75rem; align-items: flex-start; justify-content: space-between; gap: 1.5rem; background: rgba(255,255,255,.018); border-bottom: 1px solid var(--border); }
.studio-header h3 { margin: .15rem 0 .4rem; font-size: 1.3rem; }
.studio-header p:last-child { max-width: 720px; margin: 0; color: var(--text-muted); font-size: .8rem; }
.editor-section { padding: 1.6rem 1.75rem; border-bottom: 1px solid var(--border); }
.editor-section-heading { display: flex; margin-bottom: 1.25rem; align-items: flex-start; justify-content: space-between; gap: 1.25rem; }
.editor-section-heading > div:first-child { display: grid; grid-template-columns: auto 1fr; column-gap: .75rem; }
.editor-section-heading .section-number { display: grid; width: 2rem; height: 2rem; grid-row: 1/3; place-items: center; color: var(--primary-bright); background: var(--primary-soft); border: 1px solid rgba(149,135,255,.2); border-radius: 8px; font-size: .67rem; font-weight: 800; }
.editor-section-heading h4 { margin: 0; color: var(--text); font-size: 1rem; }
.editor-section-heading p { margin: .2rem 0 0; color: var(--text-muted); font-size: .74rem; }
.banner-actions { display: grid; margin-top: 1rem; grid-template-columns: minmax(0,1fr) auto; align-items: end; gap: 1rem; }
.embed-builder-actions { display: flex; align-items: center; gap: .65rem; }
.embed-builder-actions .section-count strong { color: var(--text-soft); }
.embed-list { display: grid; gap: 1rem; }
.embed-add-bar { display: grid; margin-top: 1rem; padding: 1rem; grid-template-columns: minmax(210px,.7fr) auto minmax(220px,1fr); align-items: end; gap: 1rem; background: rgba(255,255,255,.025); border: 1px dashed var(--border-strong); border-radius: 13px; }
.embed-add-bar label { margin: 0; }
.embed-add-bar small { align-self: center; color: var(--text-muted); font-size: .7rem; }
.embed-card { overflow: hidden; background: rgba(7,10,19,.42); border: 1px solid var(--border); border-radius: 13px; }
.embed-card.is-banner { border-color: rgba(52,152,219,.32); }
.embed-card.is-new { animation: embed-arrive .22s ease-out; border-color: rgba(149,135,255,.42); }
.embed-card-header { display: grid; padding: .85rem 1rem; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: .85rem; background: rgba(255,255,255,.025); border-bottom: 1px solid var(--border); }
.embed-order { display: grid; min-width: 2.2rem; height: 2.2rem; padding: 0 .45rem; place-items: center; color: var(--primary-bright); background: var(--primary-soft); border-radius: 8px; font-size: .64rem; font-weight: 800; }
.embed-card-header > div { display: grid; min-width: 0; }
.embed-card-header strong { color: var(--text-soft); font-size: .8rem; }
.embed-card-header small { color: var(--text-muted); font-size: .65rem; }
.embed-card-body { display: grid; padding: 1.15rem; gap: 1rem; }
.button-danger { color: #ffb4c1; background: var(--danger-soft); border-color: rgba(255,127,150,.22); }
.button-danger:hover { color: #ffd1d9; border-color: rgba(255,127,150,.45); }
.message-publish-bar { position: sticky; bottom: 0; z-index: 8; display: flex; padding: 1rem 1.75rem; align-items: center; justify-content: space-between; gap: 1.25rem; background: rgba(10,14,25,.94); border-top: 1px solid var(--border-strong); backdrop-filter: blur(16px); }
.message-publish-bar > div { display: grid; }
.message-publish-bar strong { color: var(--text-soft); font-size: .8rem; }
.message-publish-bar small { color: var(--text-muted); font-size: .68rem; }
.confirm-toast { position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 100; display: flex; width: min(520px,calc(100vw - 2rem)); padding: 1rem; align-items: center; justify-content: space-between; gap: 1rem; color: var(--text); background: rgba(28,20,30,.98); border: 1px solid rgba(255,127,150,.38); border-radius: 13px; box-shadow: 0 22px 60px rgba(0,0,0,.55); animation: toast-arrive .18s ease-out; }
.confirm-toast[hidden] { display: none; }
.confirm-toast > div { display: grid; gap: .15rem; }
.confirm-toast > div:last-child { display: flex; grid-auto-flow: column; gap: .5rem; }
.confirm-toast strong { font-size: .82rem; }
.confirm-toast span { color: var(--text-muted); font-size: .7rem; }
.studio-empty { padding: 3rem; text-align: center; }
.studio-empty p:last-child { max-width: 560px; margin-right: auto; margin-left: auto; }
.secondary-publishing { display: grid; gap: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.compact-heading { margin: 0; }
.compact-heading h2 { font-size: 1.25rem; }
.secondary-message-grid { display: grid; grid-template-columns: minmax(0,1.45fr) minmax(300px,.75fr); align-items: start; gap: 1.25rem; }
.managed-message-panel { position: sticky; top: 105px; }
@keyframes embed-arrive { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-arrive { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1050px) {
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .message-layout { grid-template-columns: 1fr; }
  .system-template-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .secondary-message-grid { grid-template-columns: 1fr; }
  .system-create-panel { grid-template-columns: 1fr; }
  .system-create-form { grid-template-columns: 1fr 1fr; }
  .system-create-form .button { grid-column: 1/-1; }
  .managed-message-panel { position: static; }
}

@media (max-width: 720px) {
  .page-heading,.instance-hero { align-items: flex-start; flex-direction: column; }
  .detail-grid,.access-grid { grid-template-columns: 1fr; }
  .user-list { grid-column: auto; }
  .stack-form .button { width: 100%; }
  .system-template-grid { grid-template-columns: 1fr; }
  .studio-header,.editor-section-heading,.message-publish-bar,.banner-actions { align-items: stretch; grid-template-columns: 1fr; flex-direction: column; }
  .system-nav-actions,.studio-header-actions { align-items: stretch; flex-direction: column; }
  .system-create-form { grid-template-columns: 1fr; }
  .system-create-form .button { grid-column: auto; }
  .embed-add-bar { grid-template-columns: 1fr; align-items: stretch; }
  .studio-header,.editor-section,.message-publish-bar { padding-right: 1rem; padding-left: 1rem; }
  .embed-builder-actions { width: 100%; justify-content: space-between; }
  .embed-card-header { grid-template-columns: auto minmax(0,1fr); }
  .embed-card-header .js-remove-embed { grid-column: 1/-1; }
  .confirm-toast { right: 1rem; bottom: 1rem; align-items: stretch; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* Dashboard shell markup */
.layout-dashboard{display:block}.app-shell{display:grid;grid-template-columns:270px minmax(0,1fr);min-height:100vh}.sidebar{position:sticky;top:0;display:flex;height:100vh;padding:1.75rem 1.25rem;flex-direction:column;background:rgba(10,14,26,.96);border-right:1px solid var(--border);z-index:20}.sidebar-brand>span:last-child{display:grid;gap:.15rem}.sidebar-brand small,.system-indicator small{color:var(--text-muted);font-size:.75rem;font-weight:500}.nav-label{margin:0 .85rem .55rem;color:var(--text-faint);font-size:.7rem;font-weight:750;letter-spacing:.12em;text-transform:uppercase}.nav-item>span:first-child{display:grid;width:1.55rem;height:1.55rem;place-items:center}.nav-item.is-active{color:var(--text);background:var(--primary-soft);border-color:rgba(149,135,255,.15)}.nav-count{min-width:1.5rem;margin-left:auto;padding:.15rem .4rem;text-align:center;background:rgba(255,255,255,.07);border-radius:999px;font-size:.72rem}.system-indicator{display:flex;align-items:center;gap:.7rem}.system-indicator>span{width:.65rem;height:.65rem;background:var(--success);border-radius:50%;box-shadow:0 0 0 5px var(--success-soft)}.system-indicator div{display:grid;gap:.12rem}.app-main{min-width:0}.topbar{position:sticky;top:0;z-index:15;display:flex;min-height:82px;padding:0 clamp(1.5rem,4vw,3.5rem);align-items:center;justify-content:space-between;gap:1rem;background:rgba(8,11,20,.82);border-bottom:1px solid var(--border);backdrop-filter:blur(18px)}.topbar h1{margin:0;font-size:1.3rem}.topbar .eyebrow{margin-bottom:.2rem}.logout-form{margin-left:auto}.menu-button{display:none}.dashboard-content{width:100%;max-width:1540px;margin:0 auto;padding:clamp(2rem,4vw,3.75rem) clamp(1.5rem,4vw,3.5rem) 5rem}.welcome-panel{display:flex;margin-bottom:1.5rem;padding:clamp(1.6rem,3vw,2.5rem);align-items:center;justify-content:space-between;gap:2rem;background:linear-gradient(135deg,rgba(124,77,255,.2),rgba(21,28,48,.9));border:1px solid rgba(149,135,255,.18);border-radius:var(--radius-lg);box-shadow:var(--shadow-soft)}.welcome-panel h2{margin:.15rem 0 .5rem;font-size:clamp(1.6rem,3vw,2.25rem)}.welcome-panel p:last-child{margin:0;color:var(--text-muted)}.stats-grid{grid-template-columns:repeat(4,minmax(0,1fr));margin-bottom:clamp(2.5rem,5vw,4rem)}.stat-card{display:flex;min-height:130px;padding:1.35rem;align-items:center;gap:1rem}.stat-icon{display:grid;width:2.8rem;height:2.8rem;flex:0 0 auto;place-items:center;color:var(--primary-light);background:var(--primary-soft);border-radius:12px}.stat-icon-success{color:var(--success);background:var(--success-soft)}.stat-card div{display:grid;gap:.15rem}.stat-card p,.stat-card small{margin:0;color:var(--text-muted)}.stat-card strong{font-size:1.65rem}.dashboard-section{margin-bottom:clamp(3rem,6vw,5rem)}.section-header,.editor-header,.section-heading{display:flex;margin-bottom:1.5rem;align-items:flex-start;justify-content:space-between;gap:1.5rem}.section-header h2,.editor-header h2,.section-heading h3{margin:.15rem 0 .4rem}.section-header p:last-child,.editor-header p:last-child,.section-heading p:last-child{margin:0;color:var(--text-muted)}.section-count{padding:.45rem .75rem;color:var(--text-muted);background:var(--surface);border:1px solid var(--border);border-radius:999px;font-size:.8rem}.instances-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,340px),1fr));gap:1.35rem}.instance-card{display:block;min-height:0;padding:1.45rem}.instance-card.is-selected{border-color:rgba(149,135,255,.55);box-shadow:0 0 0 3px rgba(124,77,255,.09)}.instance-card-header{display:flex;align-items:center;gap:.85rem}.instance-avatar{display:grid;width:2.8rem;height:2.8rem;flex:0 0 auto;place-items:center;color:white;background:linear-gradient(135deg,var(--primary),#a86cff);border-radius:12px;font-weight:800}.instance-title{min-width:0}.instance-title h3{margin:0;font-size:1rem}.instance-title p{margin:.2rem 0 0;color:var(--text-muted);font-size:.78rem}.status-badge{display:inline-flex;margin-left:auto;padding:.4rem .65rem;align-items:center;gap:.45rem;border-radius:999px;font-size:.74rem;font-weight:700}.status-badge i{width:.45rem;height:.45rem;background:currentColor;border-radius:50%}.status-online{color:var(--success);background:var(--success-soft)}.status-muted{color:var(--text-muted);background:rgba(255,255,255,.06)}.instance-meta{display:grid;margin:1.4rem 0;grid-template-columns:1fr 1fr;gap:.8rem}.instance-meta div{min-width:0;padding:.75rem;background:rgba(255,255,255,.025);border:1px solid var(--border);border-radius:10px}.instance-meta dt{margin-bottom:.25rem;color:var(--text-faint);font-size:.7rem;text-transform:uppercase}.instance-meta dd{margin:0;overflow:hidden;text-overflow:ellipsis;font-size:.78rem}.instance-card-actions{display:flex;align-items:center;gap:.65rem}.instance-card-actions form{margin-left:auto}.runtime-controls{margin-top:1rem;padding-top:1rem;border-top:1px solid var(--border)}.runtime-controls summary{color:var(--text-muted);cursor:pointer;font-size:.8rem}.runtime-controls .button-group{display:flex;margin-top:.8rem;flex-wrap:wrap;gap:.45rem}.button-compact{padding:.48rem .7rem;font-size:.75rem}.editor-panel{overflow:hidden;background:linear-gradient(145deg,rgba(21,28,48,.98),rgba(12,17,30,.98));border:1px solid var(--border);border-radius:var(--radius-lg);box-shadow:var(--shadow-soft)}.editor-header{margin:0;padding:clamp(1.5rem,3vw,2.25rem);border-bottom:1px solid var(--border)}.instance-form{padding:0}.form-section{padding:clamp(1.5rem,3vw,2.25rem);border-bottom:1px solid var(--border)}.section-step{margin:0;color:var(--primary-light)!important;font-size:.7rem;font-weight:800;letter-spacing:.1em;text-transform:uppercase}.form-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1.15rem 1.35rem}.form-grid label{margin:0}.field-span{grid-column:1/-1}.feature-grid{display:grid;padding:0;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:.75rem;border:0}.feature-option{display:flex;margin:0;padding:1rem;align-items:center;gap:.8rem;background:rgba(255,255,255,.025);border:1px solid var(--border);border-radius:12px;cursor:pointer}.feature-option:has(input:checked){background:var(--primary-soft);border-color:rgba(149,135,255,.35)}.feature-option input{width:1.05rem;height:1.05rem;min-height:0}.feature-option span{display:grid;gap:.2rem}.feature-option small{color:var(--text-muted)}.mapping-group{margin-top:1.25rem;padding:1.25rem;border:1px solid var(--border);border-radius:14px}.mapping-group legend{padding:0 .5rem;color:var(--text);font-weight:750}.form-footer{display:flex;padding:1.5rem clamp(1.5rem,3vw,2.25rem);align-items:center;justify-content:space-between;gap:1.5rem}.toggle{display:flex;margin:0;align-items:center;gap:.8rem}.toggle>input{position:absolute;opacity:0}.toggle-track{position:relative;width:2.8rem;height:1.55rem;background:#30384d;border-radius:999px;transition:.2s}.toggle-track:after{position:absolute;top:.2rem;left:.2rem;width:1.15rem;height:1.15rem;background:white;border-radius:50%;content:'';transition:.2s}.toggle input:checked+.toggle-track{background:var(--primary)}.toggle input:checked+.toggle-track:after{transform:translateX(1.25rem)}.toggle>span:last-child{display:grid}.toggle small{color:var(--text-muted)}.form-footer-actions{display:flex;gap:.7rem}.empty-icon{display:grid;width:3rem;height:3rem;margin:0 auto 1rem;place-items:center;background:var(--primary-soft);border-radius:50%;font-size:1.5rem}.flash{display:flex;margin-bottom:1.5rem;align-items:center;gap:.8rem}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}

@media(max-width:1100px){.stats-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.app-shell{grid-template-columns:230px minmax(0,1fr)}}
@media(max-width:800px){.app-shell{display:block}.sidebar{position:static;width:100%;height:auto;padding:1rem 1.25rem;border-right:0;border-bottom:1px solid var(--border)}.sidebar-brand{margin:0}.sidebar-nav{display:flex;margin-top:1rem;overflow-x:auto}.nav-label,.sidebar-footer{display:none}.nav-item{min-width:max-content}.topbar{position:static}.menu-button{display:none}.dashboard-content{padding:1.5rem 1rem 4rem}.welcome-panel,.form-footer{align-items:flex-start;flex-direction:column}.form-footer-actions{width:100%}.form-footer-actions .button{flex:1}.form-grid{grid-template-columns:1fr}.field-span{grid-column:auto}}
@media(max-width:560px){.stats-grid{grid-template-columns:1fr}.welcome-panel>.button{width:100%}.section-header,.editor-header,.section-heading{flex-direction:column}.instance-card-header{align-items:flex-start;flex-wrap:wrap}.status-badge{margin-left:0}.instance-meta{grid-template-columns:1fr}.instance-card-actions{align-items:stretch;flex-direction:column}.instance-card-actions form,.instance-card-actions button,.instance-card-actions .button{width:100%;margin:0;text-align:center}.feature-grid{grid-template-columns:1fr}.topbar{padding:0 1rem}.topbar .eyebrow{display:none}}

/* Dashboard semantic shell */
.layout-dashboard {
  display: block;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 264px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  height: 100vh;
  padding: 1.5rem 1.15rem;
  flex-direction: column;
  background: rgba(9, 13, 24, 0.96);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.sidebar-brand > span:last-child {
  display: grid;
  line-height: 1.25;
}

.sidebar-brand small {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
}

.sidebar .sidebar-nav {
  margin: 0;
}

.nav-label {
  margin: 0 0 0.6rem;
  padding: 0 0.85rem;
  color: #66728d;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.sidebar-nav .nav-item {
  font-size: 0.86rem;
  font-weight: 600;
}

.sidebar-nav .nav-item > span:first-child {
  display: grid;
  width: 1.25rem;
  height: 1.25rem;
  place-items: center;
  color: var(--primary-bright);
  font-size: 1rem;
}

.sidebar-nav .nav-item.is-active {
  color: var(--text);
  background: var(--primary-soft);
  border-color: rgba(149, 135, 255, 0.12);
}

.nav-count {
  min-width: 1.5rem;
  margin-left: auto;
  padding: 0.08rem 0.4rem;
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  font-size: 0.68rem;
  text-align: center;
}

.system-indicator {
  display: flex;
  padding: 0.7rem;
  align-items: center;
  gap: 0.65rem;
}

.system-indicator > span {
  width: 0.52rem;
  height: 0.52rem;
  flex: 0 0 auto;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--success-soft);
}

.system-indicator div {
  display: grid;
  line-height: 1.3;
}

.system-indicator strong {
  font-size: 0.76rem;
}

.system-indicator small {
  color: var(--text-muted);
  font-size: 0.66rem;
}

.app-main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  min-height: 82px;
  padding: 0 clamp(1.5rem, 4vw, 3.5rem);
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: rgba(8, 11, 20, 0.78);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.topbar h1 {
  margin: 0;
  font-size: 1.22rem;
}

.topbar .eyebrow {
  margin-bottom: 0.2rem;
  font-size: 0.6rem;
}

.menu-button {
  display: none;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0.72rem;
  flex-direction: column;
  border-color: var(--border);
}

.menu-button span {
  width: 100%;
  height: 2px;
  background: var(--text-soft);
  border-radius: 2px;
}

.logout-form {
  margin-left: auto;
}

.dashboard-content {
  width: min(100%, 1540px);
  margin: 0 auto;
  padding: clamp(2rem, 4vw, 3.5rem) clamp(1.5rem, 4vw, 3.5rem) 5rem;
}

.dashboard-content > * + * {
  margin-top: clamp(2rem, 4vw, 3.5rem);
}

.welcome-panel {
  position: relative;
  display: flex;
  min-height: 210px;
  padding: clamp(1.75rem, 4vw, 2.75rem);
  overflow: hidden;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  background:
    radial-gradient(circle at 88% 12%, rgba(149, 135, 255, 0.2), transparent 20rem),
    linear-gradient(135deg, rgba(27, 35, 61, 0.98), rgba(15, 21, 38, 0.98));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.welcome-panel > div {
  position: relative;
  max-width: 620px;
}

.welcome-panel h2 {
  margin-bottom: 0.65rem;
  font-size: clamp(1.65rem, 3vw, 2.3rem);
}

.welcome-panel p:last-child {
  margin-bottom: 0;
  color: var(--text-muted);
}

.welcome-panel > .button {
  position: relative;
  flex: 0 0 auto;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat-card {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 1rem;
}

.stat-icon {
  display: grid;
  width: 2.9rem;
  height: 2.9rem;
  flex: 0 0 auto;
  place-items: center;
  color: var(--primary-bright);
  background: var(--primary-soft);
  border: 1px solid rgba(149, 135, 255, 0.15);
  border-radius: 12px;
  font-weight: 700;
}

.stat-icon-success {
  color: var(--success);
  background: var(--success-soft);
  border-color: rgba(79, 209, 165, 0.15);
}

.stat-icon-info {
  color: #6eb9ff;
  background: rgba(70, 153, 230, 0.12);
  border-color: rgba(70, 153, 230, 0.16);
}

.stat-icon-muted {
  color: var(--text-muted);
  background: rgba(128, 140, 167, 0.08);
  border-color: var(--border);
}

.stat-card > div {
  min-width: 0;
}

.stat-card p,
.stat-card small {
  display: block;
  margin: 0;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-card strong {
  display: block;
  margin: 0.1rem 0;
  color: var(--text);
  font-size: 1.55rem;
  line-height: 1.2;
}

.dashboard-section {
  scroll-margin-top: 110px;
}

.section-header,
.editor-header,
.section-heading,
.form-footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
}

.section-header {
  margin-bottom: 1.35rem;
  align-items: flex-end;
}

.section-header h2,
.editor-header h2,
.section-heading h3 {
  margin-bottom: 0.4rem;
}

.section-header p:last-child,
.editor-header p:last-child,
.section-heading p:last-child {
  margin-bottom: 0;
  color: var(--text-muted);
  font-size: 0.86rem;
}

.section-count {
  padding: 0.35rem 0.65rem;
  flex: 0 0 auto;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.instances-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr));
  gap: 1.25rem;
}

.instance-card {
  min-height: 0;
  padding: 1.45rem;
}

.instance-card.is-selected {
  border-color: rgba(149, 135, 255, 0.48);
  box-shadow: 0 0 0 1px rgba(149, 135, 255, 0.14), var(--shadow-soft);
}

.instance-card-header {
  display: grid;
  margin-bottom: 1.4rem;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.8rem;
}

.instance-avatar {
  display: grid;
  width: 2.8rem;
  height: 2.8rem;
  place-items: center;
  color: #d6d0ff;
  background: var(--primary-soft);
  border: 1px solid rgba(149, 135, 255, 0.2);
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 700;
}

.instance-title {
  min-width: 0;
}

.instance-title h3,
.instance-title p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.instance-title h3 {
  margin: 0;
  font-size: 0.98rem;
}

.instance-title p {
  margin: 0.18rem 0 0;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.7rem;
}

.status-badge {
  display: inline-flex;
  min-height: 1.75rem;
  padding: 0.25rem 0.55rem;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
}

.status-badge i {
  width: 0.38rem;
  height: 0.38rem;
  background: currentColor;
  border-radius: 50%;
}

.status-online {
  color: var(--success);
  background: var(--success-soft);
  border-color: rgba(79, 209, 165, 0.18);
}

.status-muted {
  color: var(--text-muted);
  background: rgba(128, 140, 167, 0.08);
  border-color: var(--border);
}

.instance-meta {
  display: grid;
  margin: 0 0 1.35rem;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.instance-meta div {
  min-width: 0;
  padding: 0.75rem;
  background: rgba(7, 10, 19, 0.38);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.instance-meta dt {
  margin-bottom: 0.2rem;
  color: var(--text-muted);
  font-size: 0.64rem;
  font-weight: 600;
}

.instance-meta dd {
  margin: 0;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.instance-card-actions,
.form-footer-actions,
.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.instance-card-actions form {
  display: contents;
}

.button-ghost {
  color: var(--text-muted);
  background: transparent;
  border-color: var(--border);
}

.button-compact {
  min-height: 2.15rem;
  padding: 0.4rem 0.65rem;
  font-size: 0.7rem;
}

.runtime-controls {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.runtime-controls summary {
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
}

.runtime-controls[open] summary {
  margin-bottom: 0.75rem;
}

.editor-panel {
  scroll-margin-top: 110px;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(21, 28, 48, 0.96), rgba(14, 19, 34, 0.96));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.editor-header {
  padding: clamp(1.5rem, 3vw, 2.25rem);
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.instance-form {
  display: block;
}

.form-section {
  padding: clamp(1.5rem, 3vw, 2.25rem);
  border-bottom: 1px solid var(--border);
}

.section-heading {
  margin-bottom: 1.5rem;
  align-items: center;
}

.section-step {
  margin-bottom: 0.35rem !important;
  color: var(--primary-bright) !important;
  font-size: 0.63rem !important;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.2rem 1.4rem;
}

.field-span {
  grid-column: 1 / -1;
}

label small {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 400;
}

.feature-grid {
  display: grid;
  margin: 0;
  padding: 0;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  background: transparent;
  border: 0;
}

.feature-option {
  display: flex;
  min-height: 4.35rem;
  padding: 0.9rem;
  align-items: center;
  gap: 0.75rem;
  background: rgba(7, 10, 19, 0.4);
  border: 1px solid var(--border);
  border-radius: 11px;
  cursor: pointer;
  transition: 150ms ease;
}

.feature-option:hover {
  background: var(--surface-raised);
  border-color: var(--border-strong);
}

.feature-option:has(input:checked) {
  background: var(--primary-soft);
  border-color: rgba(149, 135, 255, 0.3);
}

.feature-option input {
  width: 1.05rem;
  min-height: 1.05rem;
  margin: 0;
  accent-color: var(--primary);
}

.feature-option > span {
  display: grid;
  line-height: 1.3;
}

.feature-option strong {
  color: var(--text-soft);
  font-size: 0.79rem;
}

.feature-option small {
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 400;
}

.mapping-group {
  margin-top: 1.25rem;
}

.mapping-group .form-grid {
  margin-top: 0.3rem;
}

.form-footer {
  padding: 1.35rem clamp(1.5rem, 3vw, 2.25rem);
  align-items: center;
  background: rgba(7, 10, 19, 0.24);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.toggle > input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.toggle-track {
  position: relative;
  width: 2.55rem;
  height: 1.45rem;
  flex: 0 0 auto;
  background: #30394e;
  border-radius: 999px;
  transition: 150ms ease;
}

.toggle-track::after {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.05rem;
  height: 1.05rem;
  background: #f2f4fa;
  border-radius: 50%;
  content: "";
  transition: 150ms ease;
}

.toggle input:checked + .toggle-track {
  background: var(--primary);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(1.1rem);
}

.toggle input:focus-visible + .toggle-track {
  box-shadow: 0 0 0 4px rgba(124, 108, 242, 0.18);
}

.toggle > span:last-child {
  display: grid;
  line-height: 1.3;
}

.toggle strong {
  color: var(--text-soft);
  font-size: 0.78rem;
}

.toggle small {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 400;
}

.flash {
  display: flex;
  margin-bottom: 1.75rem;
  align-items: center;
  gap: 0.7rem;
}

.flash p {
  margin: 0;
  color: inherit;
}

.flash > span {
  display: grid;
  width: 1.45rem;
  height: 1.45rem;
  flex: 0 0 auto;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
}

.flash-error {
  color: #ffafbd;
  background: var(--danger-soft);
  border-color: rgba(255, 127, 150, 0.2);
}

.empty-state {
  grid-column: 1 / -1;
  background: rgba(15, 20, 35, 0.6);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.empty-icon {
  display: grid;
  width: 3rem;
  height: 3rem;
  margin: 0 auto 1rem;
  place-items: center;
  color: var(--primary-bright);
  background: var(--primary-soft);
  border-radius: 13px;
  font-size: 1.3rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1120px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 0.85rem 1.25rem;
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar .sidebar-brand {
    min-width: max-content;
    margin: 0;
    padding: 0;
  }

  .sidebar .sidebar-nav {
    display: flex;
    margin-left: auto;
    overflow-x: auto;
  }

  .sidebar .nav-label,
  .sidebar .sidebar-footer,
  .sidebar-nav .nav-item > span:first-child,
  .sidebar-nav .nav-item:nth-of-type(3) {
    display: none;
  }

  .sidebar-nav .nav-item {
    min-width: max-content;
    min-height: 2.45rem;
    padding: 0.55rem 0.7rem;
  }

  .topbar {
    position: static;
  }

  .dashboard-content {
    padding-top: 2rem;
  }
}

@media (max-width: 640px) {
  .sidebar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .sidebar .sidebar-nav {
    width: 100%;
    margin: 0;
    order: 2;
  }

  .topbar {
    min-height: 70px;
    padding: 0 1.15rem;
  }

  .topbar h1 {
    font-size: 1.05rem;
  }

  .dashboard-content {
    padding-right: 1rem;
    padding-bottom: 3.5rem;
    padding-left: 1rem;
  }

  .welcome-panel,
  .section-header,
  .editor-header,
  .section-heading,
  .form-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .welcome-panel {
    min-height: 0;
    padding: 1.5rem;
  }

  .welcome-panel > .button,
  .section-heading > .button {
    width: 100%;
  }

  .stats-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .field-span {
    grid-column: auto;
  }

  .instance-card-header {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .instance-card-header .status-badge {
    width: fit-content;
    grid-column: 1 / -1;
  }

  .form-footer-actions {
    width: 100%;
  }

  .form-footer-actions .button {
    flex: 1;
  }
}

/* Keep the message studio out of the legacy two-column article form grid. */
.studio-panel > form {
  display: block;
}

.studio-panel > form > *,
.embed-list,
.embed-card {
  width: 100%;
  grid-column: 1 / -1;
}
