/* ==========================================================================
   Replica design system
   Inter (self-hosted) · neutral surfaces · indigo accent · light & dark
   ========================================================================== */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/InterVariable-latin.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --font:
    "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans",
    "Noto Sans Devanagari", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-hover: #eef0f4;
  --text: #0f172a;
  --text-2: #344054;
  --muted: #667085;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-text: #ffffff;
  --focus: rgb(79 70 229 / 0.35);

  --ok: #067647;
  --ok-bg: #ecfdf3;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --info: #175cd3;
  --info-bg: #eff8ff;

  --water: #2e90fa;
  --metal: #98a2b3;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.05);
  --shadow: 0 1px 3px rgb(16 24 40 / 0.08), 0 1px 2px rgb(16 24 40 / 0.04);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 0.14);
  --sidebar-w: 264px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b0f17;
    --surface: #111827;
    --surface-2: #172033;
    --surface-hover: #1c2740;
    --text: #e8ebf2;
    --text-2: #c5cbd6;
    --muted: #94a0b4;
    --border: #232e43;
    --border-strong: #2f3c56;

    --accent: #8b93ff;
    --accent-hover: #a5abff;
    --accent-soft: #1d2147;
    --accent-text: #0b0f17;
    --focus: rgb(139 147 255 / 0.4);

    --ok: #47cd89;
    --ok-bg: #0c2a1d;
    --warn: #fdb022;
    --warn-bg: #2e2109;
    --danger: #f97066;
    --danger-bg: #351511;
    --info: #84caff;
    --info-bg: #0f2338;

    --water: #53b1fd;
    --metal: #667085;
    --shadow-sm: none;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 16px 40px rgb(0 0 0 / 0.5);
  }
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  font-feature-settings: "cv11", "ss01", "ss03";
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3 {
  color: var(--text);
  margin: 0;
  letter-spacing: -0.015em;
}

h1 {
  font-size: 1.6rem;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.025em;
}

h2 {
  font-size: 1rem;
  font-weight: 620;
  margin-bottom: 14px;
}

h3 {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 20px 0 10px;
}

p {
  margin: 0 0 12px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

code,
pre {
  font-family: var(--mono);
}

code {
  font-size: 0.85em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

/* ---------- App shell: sidebar + drawer ---------- */

.app {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 40;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.brand-mark svg {
  width: 18px;
  height: 18px;
}

.side-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 12px;
}

.nav-group {
  margin-top: 16px;
}

.nav-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 4px 10px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 0.92rem;
  font-weight: 500;
}

.nav-link svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--muted);
}

.nav-link:hover {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
}

.nav-link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-link[aria-current="page"] svg {
  color: var(--accent);
}

.user-card {
  border-top: 1px solid var(--border);
  padding: 12px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--text);
}

.user-row:hover {
  background: var(--surface-hover);
  text-decoration: none;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 650;
  background: var(--accent-soft);
  color: var(--accent);
}

.user-meta {
  min-width: 0;
  line-height: 1.3;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-sub {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.signout {
  width: 100%;
  margin-top: 8px;
}

.main-col {
  margin-left: var(--sidebar-w);
  min-width: 0;
}

.mobile-bar {
  display: none;
}

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 32px 48px;
  outline: none;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  border: 1px solid transparent;
}

.icon-btn:hover {
  background: var(--surface-hover);
  border-color: transparent;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgb(9 12 20 / 0.5);
  backdrop-filter: blur(2px);
  z-index: 35;
}

.only-mobile {
  display: none;
}

/* Drawer below 1024px */
@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
    width: min(300px, 86vw);
    visibility: hidden;
  }

  body.drawer-open .sidebar {
    transform: translateX(0);
    visibility: visible;
  }

  body.drawer-open {
    overflow: hidden;
  }

  .only-mobile {
    display: inline-grid;
  }

  .main-col {
    margin-left: 0;
  }

  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 30;
    padding: 10px 12px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(8px);
    border-bottom: 1px solid var(--border);
  }

  main {
    padding: 20px 16px 40px;
  }
}

@media (min-width: 1024px) {
  .backdrop {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}

/* Signed-out pages: no sidebar */
body.no-shell .sidebar,
body.no-shell .mobile-bar,
body.no-shell .backdrop {
  display: none;
}

body.no-shell .main-col {
  margin-left: 0;
}

.auth-shell {
  min-height: calc(100vh - 76px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 0;
}

.auth-shell > .brand {
  margin-bottom: 22px;
  font-size: 1.25rem;
}

.auth-shell .narrow {
  margin: 0;
}

/* ---------- Page structure ---------- */

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 22px;
}

.page-head .muted.small {
  margin-top: 4px;
}

.narrow {
  width: 100%;
  max-width: 440px;
  margin: 24px auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Forms ---------- */

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--text-2);
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  font: inherit;
  font-size: 0.93rem;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--focus);
}

select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%23667085' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 8 10 12.5 14.5 8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}

select.auto {
  width: auto;
}

input[type="search"] {
  padding-left: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 11px center;
  background-size: 16px;
}

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

textarea.code {
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
  background-color: var(--surface-2);
}

label.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: 450;
}

.field {
  margin-bottom: 14px;
}

.field .muted.small {
  margin-top: 5px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0 14px;
}

.form .alert {
  margin: 10px 0;
}

/* ---------- Buttons ---------- */

button,
a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 560;
  line-height: 1.2;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
  white-space: nowrap;
}

button:hover,
a.button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  text-decoration: none;
}

button.secondary,
a.button.secondary {
  background: var(--surface);
  color: var(--text-2);
  border-color: var(--border-strong);
}

button.secondary:hover,
a.button.secondary:hover {
  background: var(--surface-hover);
  color: var(--text);
}

button.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
}

button.danger:hover {
  background: var(--danger-bg);
}

button.icon-btn {
  box-shadow: none;
}

button.small,
select.small {
  padding: 5px 10px;
  font-size: 0.82rem;
}

select.small {
  padding-right: 30px;
  background-position: right 8px center;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  margin-top: 10px;
}

.row-actions {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 6px 10px;
  align-items: center;
}

/* ---------- Feedback ---------- */

.alerts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.alert {
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  border: 1px solid transparent;
  border-left-width: 4px;
}

.alert.danger {
  background: var(--danger-bg);
  border-color: color-mix(in srgb, var(--danger) 25%, transparent);
  border-left-color: var(--danger);
}

.alert.warning {
  background: var(--warn-bg);
  border-color: color-mix(in srgb, var(--warn) 25%, transparent);
  border-left-color: var(--warn);
}

.alert.info {
  background: var(--info-bg);
  border-color: color-mix(in srgb, var(--info) 20%, transparent);
  border-left-color: var(--info);
}

.alert.ok {
  background: var(--ok-bg);
  border-color: color-mix(in srgb, var(--ok) 20%, transparent);
  border-left-color: var(--ok);
}

.alert ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
  align-self: flex-start;
  vertical-align: middle;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}

.badge.ok {
  color: var(--ok);
  background: var(--ok-bg);
  border-color: transparent;
}

.badge.warning {
  color: var(--warn);
  background: var(--warn-bg);
  border-color: transparent;
}

.badge.danger {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: transparent;
}

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  max-width: calc(100vw - 32px);
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  animation: toast-in 0.18s ease-out;
}

.toast.ok {
  border-left-color: var(--ok);
}

.toast.warning {
  border-left-color: var(--warn);
}

.toast.danger {
  border-left-color: var(--danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---------- Data display ---------- */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
}

th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}

tbody tr:hover td {
  background: var(--surface-2);
}

tbody tr:last-child td {
  border-bottom: none;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.wrap-cells td,
.wrap-cells th {
  white-space: normal;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.readouts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.readout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.stats .readout {
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.readout .label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.readout .value {
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.stats .readout .value {
  font-size: 1.6rem;
}

.meter {
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  margin-top: 10px;
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 20px;
  margin: 0;
}

.facts dt {
  color: var(--muted);
  font-size: 0.88rem;
}

.facts dd {
  margin: 0;
}

.link-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

.link-row code {
  word-break: break-all;
}

.join-code {
  font-family: var(--mono);
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

pre.code-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.5;
}

.key-box {
  word-break: break-all;
}

/* ---------- Filters & pagination ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.filters input[type="search"] {
  flex: 1 1 240px;
  max-width: 420px;
}

.filters select {
  width: auto;
  min-width: 150px;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 14px;
  margin-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 0.86rem;
  color: var(--muted);
}

.pager-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pager select {
  width: auto;
  padding-top: 5px;
  padding-bottom: 5px;
  font-size: 0.84rem;
}

.paged-body {
  transition: opacity 0.12s;
}

.paged-body.loading {
  opacity: 0.55;
}

.empty {
  text-align: center;
  padding: 28px 12px;
  color: var(--muted);
}

/* ---------- Virtual lab ---------- */

.twin-grid,
.fleet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.twin-card,
.asset-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    transform 0.15s;
}

.twin-card:hover,
.asset-card:hover,
.twin-card:focus-visible,
.asset-card:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  text-decoration: none;
  transform: translateY(-1px);
}

.twin-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.twin-card p {
  margin: 10px 0 0;
  color: var(--text-2);
}

.lab-grid,
.builder-grid,
.twin-grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0 18px;
  align-items: start;
}

@media (min-width: 1180px) {
  .lab-grid {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    grid-template-areas:
      "schematic controls"
      "schematic exercises"
      "chart ask"
      "quiz syllabus";
  }
  .schematic-card {
    grid-area: schematic;
  }
  .controls-card {
    grid-area: controls;
  }
  .chart-card {
    grid-area: chart;
  }
  .ask-card {
    grid-area: ask;
  }
  .syllabus-card {
    grid-area: syllabus;
  }
  .exercises-card {
    grid-area: exercises;
  }
  .quiz-card {
    grid-area: quiz;
  }
  .builder-grid,
  .twin-grid-2 {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  }
}

.param {
  margin-bottom: 16px;
}

.param-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.9rem;
}

.param-head label {
  margin: 0;
}

.param-head output {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  color: var(--accent);
}

.ask-row {
  display: flex;
  gap: 8px;
}

.ask-row input {
  flex: 1;
}

.answer {
  white-space: pre-wrap;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.93rem;
  line-height: 1.6;
}

.schematic {
  width: 100%;
  height: auto;
  display: block;
}

@keyframes bubble {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.6);
  }
  30% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-14px) scale(1.2);
  }
}

.bubble {
  fill: var(--surface);
  stroke: var(--danger);
  stroke-width: 1;
  animation: bubble 0.9s ease-out infinite;
  transform-box: fill-box;
}

@media (prefers-reduced-motion: reduce) {
  .bubble {
    animation: none;
  }
}

.preview .readouts {
  margin-top: 10px;
}

/* ---------- Charts ---------- */

.chart {
  width: 100%;
  height: auto;
  display: block;
  font-family: var(--font);
}

.chart-grid {
  stroke: var(--border);
  stroke-width: 1;
}

.chart-axis {
  stroke: var(--border-strong);
  stroke-width: 1;
}

.chart-tick {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-label {
  fill: var(--muted);
  font-size: 12px;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.25;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-line.predicted {
  stroke: var(--muted);
  stroke-width: 1.75;
  stroke-dasharray: 6 4;
}

.chart-band {
  fill: var(--accent-soft);
  opacity: 0.8;
}

.chart-danger {
  fill: var(--danger-bg);
}

.chart-now {
  stroke: var(--text-2);
  stroke-width: 1;
  stroke-dasharray: 4 3;
}

.chart-dot {
  fill: var(--accent);
  stroke: var(--surface);
  stroke-width: 2;
}

/* ---------- Live twins ---------- */

.health-ok {
  color: var(--ok);
}

.health-warning {
  color: var(--warn);
}

.health-alarm {
  color: var(--danger);
}

.asset-card {
  position: relative;
  overflow: hidden;
}

.asset-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--border-strong);
}

.asset-card.ok::before {
  background: var(--ok);
}

.asset-card.warning::before {
  background: var(--warn);
}

.asset-card.alarm::before {
  background: var(--danger);
}

.score {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  h1 {
    font-size: 1.35rem;
  }

  .card {
    padding: 16px;
    border-radius: 10px;
  }

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

  .stats .readout .value {
    font-size: 1.3rem;
  }

  .pager {
    justify-content: center;
  }
}

/* ---------- Platform console (super-admin) ---------- */

/* A distinct, dark sidebar so it is always obvious you are in the console. */
body.platform-console .sidebar {
  --c-bg: #0f172a;
  --c-text: #cbd5e1;
  --c-muted: #7c8aa5;
  --c-hover: #1e293b;
  --c-active: rgb(129 140 248 / 0.16);
  --c-active-text: #c7d2fe;
  background: var(--c-bg);
  border-right-color: #1e293b;
  color: var(--c-text);
}

body.platform-console .sidebar .brand,
body.platform-console .sidebar .user-name {
  color: #f8fafc;
}

body.platform-console .sidebar .nav-group-label,
body.platform-console .sidebar .user-sub {
  color: var(--c-muted);
}

body.platform-console .sidebar .nav-link {
  color: var(--c-text);
}

body.platform-console .sidebar .nav-link svg {
  color: var(--c-muted);
}

body.platform-console .sidebar .nav-link:hover {
  background: var(--c-hover);
  color: #f8fafc;
}

body.platform-console .sidebar .nav-link[aria-current="page"],
body.platform-console .sidebar .nav-link[aria-current="page"] svg {
  background: var(--c-active);
  color: var(--c-active-text);
}

body.platform-console .sidebar .nav-link[aria-current="page"] svg {
  background: none;
}

body.platform-console .sidebar .user-card {
  border-top-color: #1e293b;
}

body.platform-console .sidebar .signout {
  background: transparent;
  color: var(--c-text);
  border-color: #334155;
}

.console-chip {
  font-size: 0.66rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  color: #fff;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: 0 18px;
}

.grid-2.tight {
  gap: 0 24px;
}

.grid-2 h3 {
  font-size: 0.85rem;
  margin: 0 0 6px;
  color: var(--muted);
  font-weight: 600;
}

.readout.alert {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.meter.full span {
  background: var(--danger);
}

a.more {
  display: inline-block;
  margin-top: 12px;
  font-size: 0.88rem;
  font-weight: 500;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  margin-bottom: 10px;
  color: var(--muted);
}

.back-link svg {
  width: 16px;
  height: 16px;
}

details.disclosure > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
  list-style: none;
}

details.disclosure > summary::before {
  content: "+ ";
  color: var(--accent);
}

details.disclosure[open] > summary {
  margin-bottom: 14px;
}

details.disclosure[open] > summary::before {
  content: "– ";
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}

button.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  font-weight: 550;
  padding: 8px 12px;
  margin-bottom: -1px;
  box-shadow: none;
  white-space: nowrap;
}

button.tab:hover {
  color: var(--text);
  background: none;
}

button.tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.inline-form {
  display: flex;
  gap: 8px;
}

.inline-form input {
  flex: 1;
  min-width: 0;
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 0 18px;
}

.plan-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.plan-head h2 {
  margin: 0;
}

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

.growth-chart {
  width: 100%;
  height: auto;
  display: block;
}

.growth-chart .grid {
  stroke: var(--border);
}

.growth-chart .axis {
  fill: var(--muted);
  font-size: 11px;
}

.growth-chart .users,
.swatch.users {
  fill: #818cf8;
  background: #818cf8;
}

.growth-chart .tenants,
.swatch.tenants {
  fill: #06b6d4;
  background: #06b6d4;
}

.legend {
  display: flex;
  align-items: center;
  gap: 6px 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-left: 6px;
}

/* ---------- AI agents ---------- */

.nav-badge {
  margin-left: auto;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

.agent-tasks {
  display: grid;
  gap: 14px;
}

.agent-task {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: var(--surface);
}

.agent-task.status-needs_review {
  border-color: var(--warn);
  box-shadow: 0 0 0 3px var(--warn-bg);
}

.agent-task.status-failed {
  border-color: var(--danger);
}

.agent-task-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.agent-task-head h3 {
  margin: 0 0 2px;
  font-size: 1rem;
  text-transform: none;
  letter-spacing: -0.01em;
  color: var(--text);
}

.agent-task .badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.agent-summary {
  margin: 10px 0 6px;
}

.agent-task details > summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 550;
  margin: 6px 0;
}

.proposal {
  margin: 8px 0 12px;
}

.proposal h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 12px 0 4px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: 0 18px;
}

.tight-list {
  margin: 0;
  padding-left: 18px;
}

.tight-list li {
  margin: 2px 0;
}

.checks {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
}

.checks li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.check-mark {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.checks .ok .check-mark {
  background: var(--ok-bg);
  color: var(--ok);
}

.checks .bad .check-mark {
  background: var(--warn-bg);
  color: var(--warn);
}

.decision {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.decision input {
  flex: 1 1 220px;
}

.check-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
  cursor: pointer;
}

.check-row input {
  width: auto;
  margin-top: 4px;
}

/* ---------- 3D view ---------- */

.scene3d {
  position: relative;
  height: 400px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 0%, #f8fafc 0%, #e2e8f0 100%);
  margin-bottom: 14px;
}

@media (prefers-color-scheme: dark) {
  .scene3d {
    background: radial-gradient(120% 90% at 50% 0%, #1e293b 0%, #0b1120 100%);
  }
}

@media (max-width: 640px) {
  .scene3d {
    height: 300px;
  }
}

.scene3d canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.scene3d canvas:active {
  cursor: grabbing;
}

.scene3d-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.scene3d-label {
  position: absolute;
  left: 0;
  top: 0;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgb(15 23 42 / 0.78);
  color: #f8fafc;
  font-size: 0.76rem;
  font-weight: 550;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.2);
}

.scene3d-hint {
  position: absolute;
  left: 10px;
  bottom: 8px;
  font-size: 0.72rem;
  color: var(--muted);
  pointer-events: none;
}

.scene3d-label.alert {
  background: #b91c1c;
}

.scene3d-leaders {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.scene3d-leaders line {
  stroke: rgb(15 23 42 / 0.45);
  stroke-width: 1;
}

.scene3d-tools {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.scene3d-btn {
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid rgb(148 163 184 / 0.6);
  background: rgb(255 255 255 / 0.85);
  color: #0f172a;
  box-shadow: none;
  backdrop-filter: blur(6px);
  cursor: pointer;
}

.scene3d-btn[aria-pressed="true"] {
  background: #4f46e5;
  color: #fff;
  border-color: #4f46e5;
}

.scene3d-pop {
  position: absolute;
  max-width: 240px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgb(15 23 42 / 0.9);
  color: #f8fafc;
  font-size: 0.8rem;
  line-height: 1.4;
  pointer-events: none;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.25);
}

.scene3d-pop strong {
  display: block;
  margin-bottom: 2px;
}

.scene3d-ar-overlay {
  position: fixed;
  inset: auto 0 24px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.scene3d-ar-tip {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgb(15 23 42 / 0.8);
  color: #fff;
  font-size: 0.85rem;
}

.scene3d-btn:hover {
  background: #fff;
  color: #0f172a;
  border-color: #64748b;
}

.scene3d-btn[aria-pressed="true"]:hover {
  background: #4338ca;
  color: #fff;
}

/* ---------- Guided experiments and quiz ---------- */

.exercise-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.exercise-list li {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 10px;
  align-items: start;
}

.ex-mark {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.exercise-list li.done .ex-mark {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok);
}

.exercise-list li.done strong {
  color: var(--ok);
}

.quiz-q {
  padding: 12px 0;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 8px;
}

.quiz-options {
  display: grid;
  gap: 4px;
}

.quiz-options .check-row {
  margin: 0;
}

/* ---------- 3D replay ---------- */

.replay-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.replay-slider {
  flex: 1 1 200px;
  min-width: 0;
}
