:root {
  --bg: #f3f5fa;
  --text: #1e2a4d;
  --muted: #59658a;
  --surface: rgba(255, 255, 255, 0.84);
  --surface-strong: #ffffff;
  --line: #c7d1e7;
  --brand: #253668;
  --brand-deep: #1b274b;
  --accent: #f96714;
  --warn: #f96714;
  --good: #253668;
  --radius: 18px;
  --shadow: 0 14px 45px rgba(37, 54, 104, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 16% -10%, #dbe4f8 0%, transparent 42%),
    radial-gradient(circle at 85% 0%, #ffd9c3 0%, transparent 34%),
    var(--bg);
}

h1,
h2,
h3,
.nav-item,
.brand-kicker {
  font-family: 'Space Grotesk', sans-serif;
}

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

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(65px);
  z-index: 0;
  opacity: 0.55;
  pointer-events: none;
}

.bg-orb-a {
  width: 280px;
  height: 280px;
  background: #9ba9d4;
  top: -120px;
  left: -70px;
}

.bg-orb-b {
  width: 320px;
  height: 320px;
  background: #f96714;
  top: 8%;
  right: -140px;
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

body:not(.authenticated) .app-shell {
  display: none;
}

body.authenticated .login-page {
  display: none;
}

.sidebar {
  border-right: 1px solid rgba(37, 54, 104, 0.28);
  background: linear-gradient(165deg, rgba(27, 39, 75, 0.96) 0%, rgba(37, 54, 104, 0.92) 100%);
  color: #f3f6ff;
  padding: 1.6rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.brand {
  background: rgba(20, 31, 64, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  padding: 1rem;
  animation: rise 320ms ease-out;
}

.brand h1 {
  font-size: 1.7rem;
  letter-spacing: 0.02em;
}

.brand-kicker {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: #d7e1ff;
}

.brand-copy {
  margin-top: 0.55rem;
  color: #e1e8ff;
  font-size: 0.9rem;
  line-height: 1.45;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.nav-item {
  border: 1px solid transparent;
  color: #ecfffd;
  background: transparent;
  text-align: left;
  padding: 0.8rem 0.9rem;
  border-radius: 13px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease, border-color 150ms ease;
}

.nav-item:hover {
  transform: translateX(2px);
  border-color: rgba(249, 103, 20, 0.35);
  background: rgba(249, 103, 20, 0.14);
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.44);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 0.7rem;
}

.pill {
  display: inline-flex;
  width: fit-content;
  padding: 0.38rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#userBadge {
  display: block;
  width: 100%;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  text-transform: none;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.content {
  padding: 1.35rem 1.4rem;
  display: grid;
  gap: 1.1rem;
  grid-template-rows: auto 1fr;
}

@media (min-width: 981px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    height: 100vh;
    overflow: hidden;
  }

  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
  }

  .content {
    min-height: 0;
    overflow-y: auto;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(37, 54, 104, 0.22);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  animation: rise 300ms ease-out;
}

.eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--muted);
  margin-bottom: 0.28rem;
}

.topbar h2 {
  font-size: 1.42rem;
}

.topbar-controls {
  display: grid;
  gap: 0.38rem;
}

.topbar-controls label {
  font-size: 0.76rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.topbar-controls select,
input,
textarea,
select {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  padding: 0.62rem 0.72rem;
}

.multi-select-dropdown {
  position: relative;
}

.multi-select-trigger {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  padding: 0.62rem 0.72rem;
  text-align: left;
  cursor: pointer;
}

.multi-select-trigger::after {
  content: '▾';
  float: right;
  color: var(--muted);
}

.multi-select-dropdown.open .multi-select-trigger::after {
  content: '▴';
}

.multi-select-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  z-index: 20;
  display: none;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 16px 36px rgba(13, 56, 49, 0.16);
}

.multi-select-dropdown.open .multi-select-menu {
  display: block;
}

.settings-shell {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.config-shell {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.settings-user-shell {
  display: grid;
  align-content: start;
}

.settings-account-card {
  max-width: 720px;
}

.card-divider {
  height: 1px;
  margin: 1rem 0;
  background: #e2e9e5;
}

.settings-tablist {
  display: inline-flex;
  align-items: center;
  align-self: start;
  width: fit-content;
  gap: 0.3rem;
  padding: 0.25rem;
  border: 1px solid rgba(37, 54, 104, 0.26);
  border-radius: 14px;
  background: rgba(37, 54, 104, 0.08);
}

.config-tablist {
  display: inline-flex;
  align-items: center;
  align-self: start;
  width: fit-content;
  gap: 0.3rem;
  padding: 0.25rem;
  border: 1px solid rgba(37, 54, 104, 0.26);
  border-radius: 14px;
  background: rgba(37, 54, 104, 0.08);
}

.settings-tablist .ghost-btn {
  border: none;
  background: transparent;
  padding: 0.6rem 1rem;
}

.config-tablist .ghost-btn {
  border: none;
  background: transparent;
  padding: 0.6rem 1rem;
}

.settings-tablist .ghost-btn.active {
  color: #f4fffd;
  background: linear-gradient(130deg, var(--brand) 0%, var(--brand-deep) 100%);
}

.config-tablist .ghost-btn.active {
  color: #f4fffd;
  background: linear-gradient(130deg, var(--brand) 0%, var(--brand-deep) 100%);
}

.settings-panel {
  display: none;
  gap: 1rem;
}

.settings-panel.active {
  display: grid;
  align-content: start;
}

.config-panel {
  display: none;
  gap: 1rem;
}

.config-panel.active {
  display: grid;
  align-content: start;
}

textarea {
  resize: vertical;
}

.view {
  display: none;
  gap: 1rem;
  animation: fadeIn 220ms ease;
}

.view.active {
  display: grid;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.metrics {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.card {
  background: var(--surface);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(37, 54, 104, 0.18);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}

.workflows-hero {
  padding: 0.95rem 1.1rem;
}

.workflows-hero-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.workflows-grid {
  grid-template-columns: minmax(320px, 1.15fr) minmax(320px, 0.85fr);
}

.workflows-attach-form {
  gap: 0.55rem;
  justify-content: flex-end;
}

.workflows-attach-form label {
  display: grid;
  gap: 0.32rem;
  font-size: 0.85rem;
  min-width: 240px;
}

.workflow-studio {
  display: grid;
  align-content: start;
  gap: 0.75rem;
}

.workflow-mode-toggle {
  display: inline-flex;
  width: fit-content;
  border: 1px solid rgba(37, 54, 104, 0.26);
  border-radius: 12px;
  padding: 0.25rem;
  background: rgba(37, 54, 104, 0.08);
}

.workflow-mode-toggle .ghost-btn {
  border: none;
  background: transparent;
  padding: 0.45rem 0.8rem;
}

.workflow-mode-toggle .ghost-btn.active {
  color: #f4fffd;
  background: linear-gradient(130deg, var(--brand) 0%, var(--brand-deep) 100%);
}

.workflow-mode-panel {
  display: grid;
  gap: 0.55rem;
}

.metric-card {
  padding: 1rem;
}

.metric-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.metric-value {
  margin-top: 0.35rem;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.62rem;
  font-weight: 700;
}

.metric-value.good {
  color: var(--good);
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.7rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  text-align: left;
  padding: 0.56rem;
  border-bottom: 1px solid #e5ece9;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.79rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status {
  display: inline-block;
  border-radius: 999px;
  padding: 0.2rem 0.52rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status.success {
  color: #253668;
  background: #dce4f8;
}

.status.failed {
  color: #8b2911;
  background: #ffe2da;
}

.status.never {
  color: #59658a;
  background: #e7ebf6;
}

.stack {
  display: grid;
  gap: 0.6rem;
}

.item-row {
  border: 1px solid #e2e9e5;
  background: #ffffff;
  border-radius: 12px;
  padding: 0.75rem;
  display: grid;
  gap: 0.3rem;
}

.item-row-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.item-row p,
.helper {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.project-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.project-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.52rem;
  border-radius: 999px;
  border: 1px solid rgba(37, 54, 104, 0.25);
  background: rgba(37, 54, 104, 0.1);
  color: var(--brand-deep);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.checkbox-list {
  max-height: 14rem;
  overflow-y: auto;
  display: grid;
  gap: 0.3rem;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.35rem 0.4rem;
  border-radius: 10px;
  font-size: 0.92rem;
}

.checkbox-list label:hover {
  background: rgba(37, 54, 104, 0.08);
}

.checkbox-list input[type='checkbox'] {
  margin: 0;
  width: 1rem;
  height: 1rem;
}

.form-stack {
  display: grid;
  gap: 0.7rem;
  margin-top: 0.7rem;
}

.form-stack label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.inline-form {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.primary-btn,
.ghost-btn {
  font: inherit;
  border-radius: 11px;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 0.56rem 0.86rem;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

.primary-btn {
  color: #f4fffd;
  background: linear-gradient(130deg, var(--brand-deep) 0%, var(--brand) 62%, var(--accent) 138%);
}

.primary-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
}

.ghost-btn {
  color: var(--brand-deep);
  border-color: rgba(37, 54, 104, 0.32);
  background: rgba(37, 54, 104, 0.08);
}

.sidebar .ghost-btn {
  color: #f3f6ff;
  border-color: rgba(226, 234, 255, 0.32);
  background: rgba(255, 255, 255, 0.08);
}

.sidebar .ghost-btn:hover {
  border-color: rgba(249, 103, 20, 0.62);
  background: rgba(249, 103, 20, 0.22);
}

.json-output {
  width: 100%;
  margin: 0;
  border: 1px solid #e2e9e5;
  border-radius: 10px;
  background: #f7fbf9;
  color: var(--text);
  font-family: 'IBM Plex Sans', monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  padding: 0.65rem;
  white-space: pre-wrap;
  word-break: break-word;
}

code {
  font-family: 'IBM Plex Sans', monospace;
  background: #f0f5f3;
  border-radius: 6px;
  padding: 0.1rem 0.3rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 90;
  color: #1f2d56;
  background: #e4eaf8;
  border: 1px solid #b8c4e4;
  border-radius: 12px;
  padding: 0.65rem 0.82rem;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 130ms ease, transform 130ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-page {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  width: 100%;
  display: none;
  place-items: center;
  padding: 1.2rem;
}

.login-page.show {
  display: grid;
}

.login-page::before,
.login-page::after {
  content: '';
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
}

.login-page::before {
  width: 420px;
  height: 420px;
  top: 18%;
  left: -180px;
  border: 1px solid rgba(47, 70, 125, 0.2);
}

.login-page::after {
  width: 560px;
  height: 560px;
  right: -280px;
  bottom: -260px;
  background: radial-gradient(circle at 35% 35%, rgba(255, 193, 159, 0.32) 0%, rgba(255, 193, 159, 0) 72%);
}

.login-shell {
  width: min(920px, 100%);
  display: grid;
  justify-items: center;
  gap: 1.2rem;
  position: relative;
  z-index: 1;
}

.login-branding {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 0.6rem;
}

.login-logo-link {
  display: block;
  text-decoration: none;
}

.login-logo-card {
  width: 188px;
  height: 150px;
  border-radius: 26px;
  border: 1px solid rgba(188, 198, 224, 0.95);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 34px rgba(98, 112, 156, 0.2);
  display: grid;
  align-content: center;
  justify-items: center;
  overflow: hidden;
}

.login-logo-image {
  width: 86%;
  max-height: 76%;
  object-fit: contain;
  display: block;
}

.login-brand-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(2rem, 3.1vw, 2.8rem);
  font-weight: 700;
  line-height: 1.1;
  color: #253668;
}

.login-brand-subtitle {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(1.52rem, 2.4vw, 2.05rem);
  font-weight: 600;
  color: #f96714;
}

.login-ai-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.42rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(165, 173, 204, 0.9);
  background: rgba(255, 255, 255, 0.66);
  font-weight: 700;
  font-size: 1.03rem;
  color: #f96714;
}

.login-ai-badge::before {
  content: '✧';
  font-size: 1.05rem;
  margin-right: 0.45rem;
  color: #f96714;
}

.login-brand-copy {
  color: #59658a;
  font-size: 1.06rem;
}

.login-card {
  width: min(500px, 100%);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(6px);
  border-radius: 30px;
  border: 1px solid rgba(150, 165, 204, 0.65);
  box-shadow: 0 28px 60px rgba(80, 94, 133, 0.2);
  padding: 2rem 2rem 1.8rem;
  display: grid;
  gap: 0.88rem;
}

.login-card h2 {
  font-family: 'Space Grotesk', sans-serif;
  text-align: center;
  color: #253668;
  font-size: clamp(2rem, 3vw, 2.5rem);
}

.login-chip {
  margin: 0 auto 0.9rem;
  width: fit-content;
  padding: 0.48rem 0.92rem;
  border-radius: 12px;
  background: rgba(224, 229, 241, 0.68);
  color: #253668;
  font-weight: 600;
  font-size: 1.02rem;
}

.login-card label {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.1rem;
  font-size: 1.02rem;
  font-weight: 600;
  color: #253668;
}

.login-card input {
  border: 2px solid rgba(37, 54, 104, 0.35);
  border-radius: 14px;
  padding: 0.72rem 0.78rem;
  background: rgba(247, 250, 255, 0.72);
}

.login-card .primary-btn {
  margin-top: 0.7rem;
  justify-self: end;
  min-width: 140px;
  border-radius: 12px;
  background: linear-gradient(125deg, #1b274b 0%, #253668 62%, #f96714 140%);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid rgba(37, 54, 104, 0.24);
    padding-bottom: 0.9rem;
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .nav-item {
    flex: 1 0 calc(50% - 0.45rem);
    text-align: center;
  }

  .sidebar-footer {
    margin-top: 0.4rem;
  }
}

@media (max-width: 640px) {
  .content {
    padding: 0.9rem;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.7rem;
  }
  .config-tablist {
    width: 100%;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .config-tablist .ghost-btn {
    flex: 1 1 100%;
    width: 100%;
    text-align: center;
  }

  .card-grid,
  .metrics {
    grid-template-columns: 1fr;
  }

  .inline-form {
    flex-direction: column;
    align-items: stretch;
  }

  .workflows-hero-head {
    align-items: stretch;
    flex-direction: column;
  }

  .workflows-attach-form {
    justify-content: stretch;
  }

  .workflows-attach-form label {
    min-width: 0;
  }

  .login-card {
    padding: 1.35rem 1.05rem;
    border-radius: 22px;
  }

  .login-brand-copy {
    font-size: 0.96rem;
  }

  .login-card .primary-btn {
    width: 100%;
    justify-self: stretch;
  }
}

@media (max-width: 1100px) {
  .workflows-grid {
    grid-template-columns: 1fr;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
