:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f1f2f5;
  --ink: #141821;
  --ink-soft: #5f6673;
  --accent: #f21f2f;
  --accent-2: #a8001a;
  --ring: rgba(242, 31, 47, 0.28);
  --radius: 18px;
  --shadow: 0 16px 38px rgba(20, 24, 33, 0.14);
  --accent-bright: #ff2738;
  --accent-deep: #8f0017;
  --accent-soft: #ffe4e7;
  --charcoal: #11141b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 8% 14%, rgba(242, 31, 47, 0.14) 0, transparent 46%),
    radial-gradient(circle at 88% 82%, rgba(168, 0, 26, 0.1) 0, transparent 40%),
    linear-gradient(135deg, #f7f8fa 0%, var(--bg) 100%);
  font-family: "Manrope", sans-serif;
  color: var(--ink);
}

.bg-shape {
  position: fixed;
  pointer-events: none;
  z-index: 0;
  border-radius: 999px;
  filter: blur(38px);
  opacity: 0.32;
}

.bg-shape-a {
  width: 300px;
  height: 300px;
  background: #f21f2f;
  top: -70px;
  right: -80px;
}

.bg-shape-b {
  width: 260px;
  height: 260px;
  background: #8f0017;
  bottom: -80px;
  left: -60px;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  min-height: 100vh;
}

.panel {
  background: color-mix(in srgb, var(--surface) 84%, white 16%);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(20, 24, 33, 0.08);
}

.app-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  width: 88px;
  height: auto;
  flex-shrink: 0;
  display: block;
}

.header-actions {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.admin-cog-btn {
  border: 1px solid rgba(20, 24, 33, 0.14);
  background: #fff;
  color: var(--ink);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  font-size: 1.12rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.admin-cog-btn:hover {
  background: var(--surface-2);
}

.kicker {
  margin: 0;
  color: var(--accent-2);
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  font-size: 0.74rem;
}

h1,
h2 {
  font-family: "Space Grotesk", sans-serif;
  margin: 0;
}

h1 {
  margin-top: 6px;
  font-size: 1.55rem;
}

h2 {
  font-size: 1.08rem;
  margin-bottom: 10px;
}

.app-header p {
  color: var(--ink-soft);
  line-height: 1.5;
  margin: 8px 0 0;
}

.app-version {
  display: inline-flex;
  align-items: center;
  margin-top: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(20, 24, 33, 0.14);
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  font-weight: 700;
}

.stepper {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.step-indicator {
  border-radius: 999px;
  border: 1px solid rgba(20, 24, 33, 0.14);
  background: #fff;
}

.step-indicator-btn {
  border: 0;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  background: transparent;
  box-shadow: none;
  transform: none;
}

.step-indicator-btn:hover:not(:disabled) {
  transform: none;
}

.step-indicator-btn:disabled {
  opacity: 0.55;
}

.step-indicator-btn:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.step-indicator.active {
  border-color: transparent;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
}

.step-indicator.active .step-indicator-btn {
  color: white;
}

.page {
  display: none;
  padding: 16px;
}

.page.active {
  display: block;
}

.page-columns {
  display: grid;
  grid-template-columns: minmax(300px, 520px) 1fr;
  gap: 14px;
  min-height: calc(100vh - 210px);
}

.card {
  background: #fff;
  border: 1px solid rgba(20, 24, 33, 0.1);
  border-radius: 14px;
  padding: 14px;
}

.section-copy {
  color: var(--ink-soft);
  margin: 4px 0 14px;
}

.job-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.upload-progress {
  margin-top: 14px;
  border: 1px solid rgba(20, 24, 33, 0.14);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px;
}

.upload-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.upload-progress-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.upload-progress-header h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.98rem;
}

.upload-progress-header p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.upload-cancel-btn {
  padding: 6px 10px;
  font-size: 0.76rem;
  white-space: nowrap;
}

.upload-retry-btn {
  padding: 6px 10px;
  font-size: 0.76rem;
  white-space: nowrap;
}

.upload-progress-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.upload-progress-item {
  border: 1px solid rgba(20, 24, 33, 0.12);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
}

.upload-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.upload-progress-name {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-progress-state {
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.upload-progress-item progress {
  width: 100%;
  height: 8px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  padding: 0;
}

input,
select,
button {
  font: inherit;
}

.mode-toggle-group {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.mode-toggle-group legend {
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.mode-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid rgba(20, 24, 33, 0.14);
}

.mode-toggle-option {
  display: block;
  cursor: pointer;
}

.mode-toggle-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-toggle-option span {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  text-align: center;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid transparent;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease,
    box-shadow 140ms ease;
}

.mode-toggle-option input:checked + span {
  color: white;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  border-color: transparent;
  box-shadow: 0 10px 22px rgba(168, 0, 26, 0.2);
}

.mode-toggle-option input:focus-visible + span {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

input[type="file"],
select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid rgba(20, 24, 33, 0.14);
  border-radius: 12px;
  padding: 10px 12px;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, box-shadow 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(20, 24, 33, 0.12);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#run-btn,
#publish-btn {
  background: linear-gradient(120deg, #ff2738, var(--accent-2));
  color: white;
}

#publish-btn {
  background: linear-gradient(120deg, #1d2330, #0d1017);
}

.ghost-btn {
  border: 1px solid rgba(20, 24, 33, 0.16);
  background: #fff;
  color: var(--ink);
}

.status {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(242, 31, 47, 0.08);
  border: 1px solid rgba(242, 31, 47, 0.18);
  color: var(--ink-soft);
  font-size: 0.84rem;
  font-weight: 600;
}

.client-admin {
  margin-top: 12px;
}

.client-admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.client-admin-header h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1rem;
}

.client-admin-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.client-admin-status.error {
  color: #b1001b;
}

.client-admin-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 10px;
}

.client-admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.telemetry-panel {
  margin-top: 16px;
  border: 1px solid rgba(20, 24, 33, 0.12);
  border-radius: 12px;
  background: var(--surface-2);
  padding: 12px;
}

.telemetry-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.telemetry-panel-header h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1rem;
}

.telemetry-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.upload-telemetry-status {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.upload-telemetry-status.error {
  color: #b1001b;
}

.upload-telemetry-refresh-btn {
  padding: 6px 10px;
  font-size: 0.76rem;
}

.telemetry-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.telemetry-grid div {
  border: 1px solid rgba(20, 24, 33, 0.12);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
}

.telemetry-grid dt {
  margin: 0;
  font-size: 0.74rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.telemetry-grid dd {
  margin: 5px 0 0;
  font-size: 1rem;
  font-weight: 800;
  color: var(--ink);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 16, 23, 0.56);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 30;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  width: min(680px, 100%);
  background: #fff;
  border-radius: 16px;
  border: 1px solid rgba(20, 24, 33, 0.12);
  box-shadow: 0 24px 56px rgba(13, 16, 23, 0.3);
  padding: 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.modal-close-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(20, 24, 33, 0.14);
  background: #fff;
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.logs-title-group {
  display: grid;
  gap: 4px;
}

.card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.log-view {
  margin: 8px 0 0;
  min-height: 320px;
  max-height: calc(100vh - 300px);
  overflow: auto;
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(20, 24, 33, 0.14);
  background: #11141b;
  color: #ffd6da;
  padding: 12px;
  font-family: "Courier New", monospace;
  font-size: 0.82rem;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  overscroll-behavior: contain;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
}

.preview-layout {
  height: calc(100vh - 220px);
  display: grid;
  grid-template-columns: minmax(220px, 290px) 1fr;
  gap: 16px;
}

.preview-layout.full {
  min-height: calc(100vh - 240px);
}

.tree-panel,
.iframe-panel {
  background: #fff;
  border: 1px solid rgba(20, 24, 33, 0.1);
  border-radius: 14px;
  padding: 14px;
  overflow: auto;
}

.logs-card,
.page-columns > *,
.preview-layout > * {
  min-width: 0;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.list li button,
.list li a {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid rgba(20, 24, 33, 0.1);
  border-radius: 10px;
  padding: 9px 10px;
  text-decoration: none;
  display: inline-block;
}

.list li button:hover,
.list li a:hover {
  outline: 2px solid var(--ring);
}

.list li button.preview-page-active {
  border-color: rgba(242, 31, 47, 0.5);
  background: color-mix(in srgb, var(--surface-2) 58%, #ffe1e5 42%);
  box-shadow: inset 3px 0 0 var(--accent-2);
  font-weight: 700;
}

#preview-frame {
  width: 100%;
  height: calc(100% - 28px);
  border: 1px solid rgba(31, 37, 44, 0.15);
  border-radius: 10px;
  background: white;
}

@media (max-width: 1040px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .brand-block {
    width: 100%;
  }

  .brand-logo {
    width: 72px;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
    align-items: center;
  }

  .page-columns,
  .preview-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .log-view {
    max-height: 42vh;
  }

  #preview-frame {
    min-height: 60vh;
  }

  .modal-overlay {
    padding: 10px;
    align-items: flex-end;
  }

  .modal-card {
    width: 100%;
    max-height: 85vh;
    overflow: auto;
  }

  .telemetry-panel-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .telemetry-panel-actions {
    width: 100%;
    justify-content: space-between;
  }

  .telemetry-grid {
    grid-template-columns: 1fr;
  }
}