/* ==========================================================================
   App Core — reset, layout shell, typography, components, utilities
   ========================================================================== */

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

html {
  -webkit-font-smoothing: antialiased;
}

img,
svg {
  max-width: 100%;
  height: auto;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -.01em;
  margin: 0 0 .35em;
  color: var(--text-primary);
}

a {
  color: inherit;
  text-decoration: none;
}

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

::selection {
  background: var(--accent);
  color: #fff;
}

/* scrollbars */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
  border: 2.5px solid var(--bg);
}

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

/* ---------- App Shell ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  height: 100vh;
  border-right: 1px solid var(--sidebar-border);
  z-index: 1030;
  transition: transform var(--dur) var(--ease), width var(--dur) var(--ease);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.25rem 1.25rem .75rem;
}

.sidebar-brand .mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #9B8CFF);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand span {
  font-family: var(--font-display);
  font-weight: 700;
  color: #fff;
  font-size: 1.02rem;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: .5rem .75rem;
}

.sidebar-section-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #565963;
  padding: 1rem .6rem .35rem;
  font-weight: 600;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .5rem .6rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: .87rem;
  font-weight: 500;
  margin-bottom: 2px;
  position: relative;
}

.nav-link i,
.nav-link svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  opacity: .85;
}

.nav-link:hover {
  background: rgba(255, 255, 255, .06);
  color: #fff;
}

.nav-link.active {
  background: rgba(109, 94, 240, .16);
  color: var(--sidebar-text-active);
}

.nav-link.active::before {
  content: "";
  position: absolute;
  left: -.75rem;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
}

.nav-link .badge-count {
  margin-left: auto;
  font-size: .68rem;
  background: rgba(255, 255, 255, .1);
  padding: .1rem .4rem;
  border-radius: 99px;
}

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

.main-wrap {
  margin-left: 248px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin var(--dur) var(--ease);
}

body.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
}

body.sidebar-collapsed .main-wrap {
  margin-left: 0;
}

.topbar {
  height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1020;
}

.topbar-search {
  position: relative;
  max-width: 340px;
  flex: 1;
}

.topbar-search input {
  width: 100%;
  background: var(--surface-sunken);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: .45rem .7rem .45rem 2.1rem;
  font-size: .85rem;
  color: var(--text-primary);
}

.topbar-search input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

.topbar-search i {
  position: absolute;
  left: .65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: .85rem;
}

.topbar-search kbd {
  position: absolute;
  right: .5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: .68rem;
  color: var(--text-tertiary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .05rem .35rem;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  border: 1px solid transparent;
  background: transparent;
  position: relative;
}

.icon-btn:hover {
  background: var(--surface-sunken);
  color: var(--text-primary);
}

.icon-btn .dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--bg);
}

.page-body {
  padding: 1.75rem 2rem 3rem;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.page-eyebrow {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: .3rem;
}

.page-title {
  font-size: 1.5rem;
  margin: 0;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: .88rem;
  margin-top: .25rem;
}

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

  .sidebar {
    width: min(86vw, 320px);
  }

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

  .topbar {
    height: auto;
    padding: .8rem 1rem;
    flex-wrap: wrap;
  }

  .page-body {
    padding: 1rem .95rem 2rem;
  }

  .page-header {
    margin-bottom: 1.25rem;
  }

  .card-header,
  .card-body {
    padding: .9rem 1rem;
  }
}

@media (max-width: 575.98px) {
  .topbar {
    gap: .6rem;
  }

  .page-title {
    font-size: 1.2rem;
    line-height: 1.25;
  }

  .page-subtitle {
    font-size: .8rem;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: .4rem;
  }
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: .83rem;
  border-radius: var(--radius-sm);
  padding: .5rem 1rem;
  border: 1px solid transparent;
  transition: all var(--dur) var(--ease);
}

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

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .05);
}

.btn-primary:hover {
  background: #5B4CE0;
  color: #fff;
}

.btn-outline-secondary {
  border-color: var(--border-strong);
  color: var(--text-primary);
  background: var(--surface);
}

.btn-outline-secondary:hover {
  background: var(--surface-sunken);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--surface-sunken);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: .32rem .7rem;
  font-size: .78rem;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
  font-family: var(--font-display);
  font-weight: 600;
}

.card-body {
  padding: 1.25rem;
}

.card-hover:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.stat-card {
  padding: 1.1rem 1.25rem;
}

.stat-card .stat-label {
  font-size: .78rem;
  color: var(--text-secondary);
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 700;
  margin-top: .3rem;
}

.stat-card .stat-delta {
  font-size: .76rem;
  font-weight: 600;
  margin-top: .35rem;
  display: inline-flex;
  align-items: center;
  gap: .25rem;
}

.stat-delta.up {
  color: var(--success);
}

.stat-delta.down {
  color: var(--danger);
}

.stat-card .stat-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  opacity: .9;
}

/* ---------- Badges / Status ---------- */
.badge-status {
  font-size: .72rem;
  font-weight: 600;
  padding: .28rem .6rem;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}

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

.badge-status.success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-status.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-status.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-status.info {
  background: var(--info-soft);
  color: var(--info);
}

.badge-status.render {
  background: var(--render-soft);
  color: var(--render);
}

.badge-status.render::before {
  animation: pulse-dot 1.4s infinite;
}

.badge-status.neutral {
  background: var(--surface-sunken);
  color: var(--text-secondary);
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: .35;
  }
}

/* ---------- Table ---------- */
.table-wrap {
  overflow-x: auto;
}

.table-app {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

.table-app thead th {
  text-align: left;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-tertiary);
  font-weight: 600;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table-app tbody td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-primary);
}

.table-app tbody tr {
  transition: background var(--dur) var(--ease);
}

.table-app tbody tr:hover {
  background: var(--surface-sunken);
}

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

/* ---------- Forms ---------- */
.form-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: .35rem;
}

.form-control,
.form-select {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-size: .87rem;
  padding: .5rem .75rem;
}

.form-control:focus,
.form-select:focus {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 94, 240, .15);
}

.form-text {
  color: var(--text-tertiary);
  font-size: .78rem;
}

.form-control.is-invalid {
  border-color: var(--danger);
}

.invalid-feedback {
  color: var(--danger);
  font-size: .78rem;
}

.form-check-input:checked {
  background-color: var(--accent);
  border-color: var(--accent);
}

/* ---------- Progress ---------- */
.progress {
  height: 7px;
  background: var(--surface-sunken);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar {
  background: var(--accent);
  transition: width .5s var(--ease);
}

.progress-bar.render {
  background: var(--render);
}

.progress-bar.success {
  background: var(--success);
}

.progress-bar.danger {
  background: var(--danger);
}

/* ---------- Empty / Loading ---------- */
.empty-state {
  text-align: center;
  padding: 3.5rem 1.5rem;
  color: var(--text-secondary);
}

.empty-state .empty-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: 16px;
  background: var(--surface-sunken);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  font-size: 1.4rem;
}

.empty-state h3 {
  font-size: 1rem;
  color: var(--text-primary);
}

.empty-state p {
  font-size: .85rem;
  max-width: 340px;
  margin: .25rem auto 1rem;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-sunken) 25%, var(--border) 37%, var(--surface-sunken) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
  0% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0 50%;
  }
}

/* ---------- Pipeline Stepper (signature element) ---------- */
.pipeline-stepper {
  display: flex;
  align-items: flex-start;
  gap: 0;
  overflow-x: auto;
  padding: .5rem 0 1rem;
}

.pipeline-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 104px;
  position: relative;
}

.pipeline-step .node {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-tertiary);
  font-size: .85rem;
  z-index: 1;
}

.pipeline-step .label {
  margin-top: .55rem;
  font-size: .76rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-align: center;
}

.pipeline-step .sub {
  font-size: .68rem;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

.pipeline-step::after {
  content: "";
  position: absolute;
  top: 19px;
  left: 50%;
  width: 100%;
  height: 2px;
  background: var(--border-strong);
  z-index: 0;
}

.pipeline-step:last-child::after {
  display: none;
}

.pipeline-step.done .node {
  border-color: var(--success);
  background: var(--success);
  color: #fff;
}

.pipeline-step.done .label {
  color: var(--text-primary);
}

.pipeline-step.done::after {
  background: var(--success);
}

.pipeline-step.active .node {
  border-color: var(--render);
  color: var(--render);
  animation: node-pulse 1.5s infinite;
}

.pipeline-step.active .label {
  color: var(--text-primary);
}

.pipeline-step.error .node {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.pipeline-step.error .label {
  color: var(--danger);
}

@keyframes node-pulse {

  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(242, 169, 59, .35);
  }

  50% {
    box-shadow: 0 0 0 6px rgba(242, 169, 59, 0);
  }
}

/* ---------- Toast ---------- */
.toast-stack {
  position: fixed;
  top: 1.1rem;
  right: 1.1rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  width: 320px;
}

.toast-app {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: .8rem .9rem;
  display: flex;
  gap: .65rem;
  align-items: flex-start;
  animation: toast-in .22s var(--ease);
}

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

  to {
    opacity: 1;
    transform: none;
  }
}

.toast-app .icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.toast-app.success .icon {
  background: var(--success-soft);
  color: var(--success);
}

.toast-app.danger .icon {
  background: var(--danger-soft);
  color: var(--danger);
}

.toast-app.info .icon {
  background: var(--info-soft);
  color: var(--info);
}

.toast-app.warning .icon {
  background: var(--warning-soft);
  color: var(--warning);
}

.toast-app .msg {
  font-size: .83rem;
  flex: 1;
}

.toast-app .msg strong {
  display: block;
  font-size: .85rem;
  margin-bottom: .1rem;
}

.toast-app .close {
  opacity: .5;
  cursor: pointer;
}

.toast-app .close:hover {
  opacity: 1;
}

/* ---------- Modal ---------- */
.modal-content {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.modal-header {
  border-bottom: 1px solid var(--border);
}

.modal-footer {
  border-top: 1px solid var(--border);
}

/* ---------- Dropdown / misc ---------- */
.dropdown-menu {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: .4rem;
}

.dropdown-item {
  border-radius: var(--radius-sm);
  font-size: .85rem;
  padding: .45rem .6rem;
  color: var(--text-primary);
}

.dropdown-item:hover {
  background: var(--surface-sunken);
  color: var(--text-primary);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: .8rem;
}

/* ---------- Utilities ---------- */
.text-secondary-app {
  color: var(--text-secondary) !important;
}

.text-tertiary {
  color: var(--text-tertiary) !important;
}

.surface-sunken {
  background: var(--surface-sunken);
}

.fade-in {
  animation: fade-in .3s var(--ease);
}

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

  to {
    opacity: 1;
    transform: none;
  }
}

.divider {
  height: 1px;
  background: var(--border);
  border: none;
  margin: 1.25rem 0;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}