:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #647386;
  --line: #d9e0e8;
  --blue: #1b66d2;
  --blue-dark: #134a9b;
  --green: #14805e;
  --yellow: #f4c542;
  --red: #d84b3c;
  --shadow: 0 18px 40px rgba(31, 45, 61, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 10%, rgba(27, 102, 210, 0.11), transparent 24rem),
    linear-gradient(135deg, #f8fafc 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.site-nav a {
  min-height: 2.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue-dark);
  background: #f8fafc;
  font-size: 0.88rem;
  font-weight: 800;
  padding: 0.5rem 0.7rem;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a.active {
  border-color: var(--blue);
  background: #e7f0fd;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 3vw, 2.2rem);
}

h2 {
  margin-bottom: 0.25rem;
  font-size: 1.2rem;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(18rem, 0.95fr) minmax(20rem, 1.15fr);
  gap: 1rem;
  padding: 1rem;
  max-width: 1420px;
  margin: 0 auto;
}

.content-page {
  display: grid;
  gap: 1rem;
  width: min(1080px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0 2rem;
}

.content-hero {
  padding: clamp(1rem, 4vw, 2rem) 0;
}

.content-hero h2 {
  max-width: 760px;
  margin-bottom: 0.7rem;
  font-size: clamp(1.8rem, 5vw, 3.5rem);
  line-height: 1.05;
}

.content-hero p {
  max-width: 760px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.content-hero a {
  color: var(--blue-dark);
  font-weight: 800;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}

.feature-card {
  min-height: 12rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.feature-card p {
  color: var(--muted);
  line-height: 1.55;
}

.contact-layout {
  grid-template-columns: minmax(0, 0.9fr) minmax(20rem, 1.1fr);
  align-items: start;
}

.contact-panel {
  margin-top: 1rem;
}

.contact-form {
  display: grid;
  gap: 0.85rem;
}

.contact-form .primary-button {
  justify-self: start;
}

.google-button {
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  margin-bottom: 1rem;
}

.google-button:hover {
  background: #f5f8fc;
}

.auth-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.auth-toggle button {
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--blue-dark);
  cursor: pointer;
  font-weight: 900;
}

.auth-toggle button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.error-message {
  color: var(--red);
  font-weight: 800;
}

.dashboard-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.program-list {
  display: grid;
  gap: 1rem;
}

.program-card {
  display: grid;
  gap: 0.85rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.program-card h3,
.program-card p {
  margin-bottom: 0.2rem;
}

.program-card p,
.empty-state {
  color: var(--muted);
}

.program-card textarea {
  min-height: 13rem;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
}

.program-actions,
.import-actions,
.folder-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.import-panel {
  grid-column: 1 / -1;
}

.telemetry-panel {
  grid-column: 1 / -1;
}

.insight-panel {
  grid-column: 1 / -1;
}

.tool-grid,
.run-meta-grid,
.insight-grid,
.calibration-grid,
.telemetry-grid {
  display: grid;
  gap: 0.75rem;
}

.tool-grid,
.run-meta-grid,
.insight-grid,
.telemetry-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.warnings-list {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.warnings-list p {
  margin: 0;
  padding: 0.55rem 0.65rem;
  border: 1px solid #f3d2a1;
  border-radius: 8px;
  background: #fff8ec;
  color: #885600;
  font-weight: 800;
}

.warnings-list .ok-message {
  border-color: #bde5d4;
  background: #f0fbf6;
  color: var(--green);
}

.field-map-wrap {
  min-height: 18rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

#fieldMap {
  display: block;
  width: 100%;
  height: auto;
  cursor: grab;
  touch-action: none;
}

#fieldMap:active {
  cursor: grabbing;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.55rem;
  border-radius: 8px;
  background: #edf3fb;
  color: var(--blue-dark);
  cursor: pointer;
  font-weight: 900;
  padding: 0.6rem 0.8rem;
}

.file-button input {
  display: none;
}

.import-panel textarea {
  min-height: 12rem;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
}

.telemetry-panel textarea {
  min-height: 13rem;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
}

.telemetry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.telemetry-preview {
  margin-top: 1rem;
}

.telemetry-table-wrap {
  max-height: 22rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

#telemetryTable {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
  background: #fff;
  font-size: 0.78rem;
}

#telemetryTable th,
#telemetryTable td {
  border-bottom: 1px solid var(--line);
  padding: 0.45rem 0.55rem;
  text-align: left;
  white-space: nowrap;
}

#telemetryTable th {
  position: sticky;
  top: 0;
  background: #edf3fb;
  color: var(--blue-dark);
  z-index: 1;
}

.hidden-field {
  display: none;
}

.form-note {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 1rem;
}

.code-panel {
  grid-column: 1 / -1;
}

.panel-heading {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 1rem;
}

.panel-heading p {
  color: var(--muted);
  margin-bottom: 0;
}

.code-heading {
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-start;
}

.form-grid,
.item-card,
.step-fields {
  display: grid;
  gap: 0.75rem;
}

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

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--ink);
  padding: 0.55rem 0.65rem;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(27, 102, 210, 0.15);
}

textarea {
  resize: vertical;
}

.primary-button,
.ghost-button,
.segmented button,
.icon-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  background: var(--blue);
  color: #fff;
  padding: 0.7rem 1rem;
}

.primary-button:hover {
  background: var(--blue-dark);
}

.ghost-button,
.segmented button {
  background: #edf3fb;
  color: var(--blue-dark);
  padding: 0.6rem 0.8rem;
}

.ghost-button:hover,
.segmented button:hover {
  background: #dbe9fb;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  background: #f2f5f8;
  color: var(--muted);
}

.icon-button:hover {
  background: #ffe9e7;
  color: var(--red);
}

.subsection {
  margin-top: 1.15rem;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.stack,
.steps {
  display: grid;
  gap: 0.75rem;
}

.item-card {
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  align-items: end;
  padding: 0.8rem;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.segmented,
.run-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.run-tabs button {
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  padding: 0.55rem 0.75rem;
}

.run-tabs button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.run-name-field {
  margin-bottom: 0.75rem;
}

.action-row {
  align-items: flex-start;
}

.danger-button {
  background: #fff0ef;
  color: #a4372b;
}

.danger-button:hover {
  background: #ffd8d4;
}

.step-card {
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  background: #fbfcfe;
}

.step-card.parallel {
  border-left-color: var(--green);
  background: #f5fbf8;
}

.step-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.step-controls {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
}

.step-card.dragging {
  opacity: 0.55;
}

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

.wide {
  grid-column: span 2;
}

.full {
  grid-column: 1 / -1;
}

.comment-field textarea {
  min-height: 4.5rem;
}

.code-output {
  min-height: 24rem;
  max-height: 42rem;
  overflow: auto;
  margin: 0;
  padding: 1rem;
  border-radius: 8px;
  background: #101820;
  color: #d7f7e8;
  font-size: 0.9rem;
  line-height: 1.55;
  tab-size: 4;
}

.robot-visual {
  display: grid;
  place-items: center;
  min-height: 11rem;
  margin-bottom: 1rem;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(27, 102, 210, 0.12) 1px, transparent 1px),
    linear-gradient(rgba(27, 102, 210, 0.1) 1px, transparent 1px),
    #f7fbff;
  background-size: 22px 22px;
  border: 1px solid var(--line);
}

.hub-graphic {
  position: relative;
  width: 10rem;
  height: 7rem;
  border-radius: 8px;
  background: linear-gradient(145deg, #fefefe, #dfe7ef);
  border: 3px solid #2a3542;
  box-shadow: 0 14px 30px rgba(23, 32, 42, 0.18);
}

.screen {
  position: absolute;
  inset: 2rem 3rem;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #17202a;
  color: var(--yellow);
  font-weight: 900;
}

.port {
  position: absolute;
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  font-weight: 900;
  font-size: 0.82rem;
}

.port-a { left: -1rem; top: 0.7rem; }
.port-b { left: -1rem; bottom: 0.7rem; }
.port-c { left: 4.1rem; top: -1rem; }
.port-d { right: -1rem; top: 0.7rem; }
.port-e { right: -1rem; bottom: 0.7rem; }
.port-f { left: 4.1rem; bottom: -1rem; }

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  padding: 0.75rem 0.95rem;
  border-radius: 8px;
  background: #17202a;
  color: #fff;
  box-shadow: var(--shadow);
}

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

  .form-grid,
  .step-fields,
  .item-card,
  .sensor-card,
  .feature-grid,
  .contact-layout,
  .tool-grid,
  .run-meta-grid,
  .insight-grid,
  .calibration-grid,
  .telemetry-grid {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }
}

@media (max-width: 620px) {
  body {
    background: #f8fafc;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 1rem;
  }

  .primary-button {
    width: 100%;
  }

  .header-actions {
    width: 100%;
    flex-direction: column;
  }

  .app-shell {
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .panel {
    padding: 0.85rem;
    box-shadow: none;
  }

  .segmented button,
  .run-tabs button,
  .ghost-button {
    flex: 1 1 9rem;
    min-height: 2.75rem;
  }

  .step-title {
    align-items: flex-start;
  }

  .step-controls {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .step-name {
    overflow-wrap: anywhere;
  }

  .code-output {
    max-height: 26rem;
    min-height: 18rem;
    font-size: 0.78rem;
    overflow-x: auto;
    white-space: pre;
  }

  .section-row,
  .code-heading,
  .site-nav {
    align-items: stretch;
    flex-direction: column;
  }

  .site-nav,
  .site-nav a {
    width: 100%;
  }

  .content-page {
    width: calc(100% - 1.5rem);
    padding-top: 0.75rem;
  }

  .content-hero {
    padding: 0.75rem 0;
  }

  .feature-card {
    min-height: 0;
    box-shadow: none;
  }

  .contact-form .primary-button {
    justify-self: stretch;
  }

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

  .program-card {
    box-shadow: none;
  }

  .program-actions,
  .import-actions,
  .telemetry-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .robot-visual {
    min-height: 9rem;
  }

  .hub-graphic {
    transform: scale(0.86);
  }
}
