:root {
  color-scheme: light;
  --ink: #1f2526;
  --muted: #697170;
  --line: #d8dedb;
  --panel: #f5f7f5;
  --surface: #ffffff;
  --surface-strong: #e9efeb;
  --accent: #176b63;
  --accent-strong: #0c4d49;
  --accent-soft: #d8ece7;
  --warning: #9a5b1f;
  --shadow: 0 24px 70px rgba(31, 37, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(245, 247, 245, 0.94)),
    radial-gradient(circle at 10% 0%, rgba(23, 107, 99, 0.12), transparent 36%),
    #eef3ef;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell,
.result-view {
  width: min(1180px, calc(100% - 32px));
  min-height: calc(100vh - 48px);
  margin: 24px auto;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
}

.sensor-panel,
.form-stage,
.result-shell {
  border: 1px solid rgba(216, 222, 219, 0.9);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.sensor-panel {
  position: sticky;
  top: 24px;
  display: flex;
  height: calc(100vh - 48px);
  min-height: 680px;
  flex-direction: column;
  gap: 28px;
  padding: 28px;
  border-radius: 8px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-strong);
  color: #fff;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.35rem;
  line-height: 1.1;
}

h2 {
  margin-bottom: 10px;
  font-size: clamp(1.8rem, 3vw, 3.2rem);
  line-height: 1;
}

h3 {
  margin-bottom: 8px;
  font-size: clamp(1.7rem, 3vw, 2.7rem);
  line-height: 1.05;
}

.state-card {
  display: grid;
  place-items: center;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
}

.progress-ring {
  display: grid;
  width: 142px;
  height: 142px;
  margin: 12px 0;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--panel) 56%, transparent 57%),
    conic-gradient(var(--accent) var(--progress, 0%), var(--surface-strong) 0);
}

.progress-ring span {
  font-size: 1.7rem;
  font-weight: 800;
}

.state-card p:last-child,
.panel-note,
#stageDescription {
  color: var(--muted);
  line-height: 1.55;
}

.block-nav {
  display: grid;
  gap: 10px;
}

.block-step {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-weight: 750;
  text-align: left;
}

.block-step span {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.78rem;
}

.block-step.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.block-step.is-complete span {
  background: var(--accent);
  color: #fff;
}

.panel-note {
  margin-top: auto;
  margin-bottom: 0;
  font-size: 0.92rem;
}

.form-stage {
  display: flex;
  min-height: calc(100vh - 48px);
  flex-direction: column;
  border-radius: 8px;
}

.stage-header,
.result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 34px 38px 28px;
  border-bottom: 1px solid var(--line);
}

.stage-header p:last-child {
  max-width: 680px;
  margin-bottom: 0;
}

.ghost-button,
.secondary-button,
.primary-button {
  min-height: 44px;
  border-radius: 8px;
  font-weight: 800;
}

.ghost-button {
  padding: 0 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.secondary-button {
  padding: 0 20px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.primary-button {
  padding: 0 24px;
  border: 1px solid var(--accent-strong);
  background: var(--accent-strong);
  color: #fff;
}

.question-list {
  display: grid;
  gap: 32px;
  padding: 28px 38px;
  scroll-margin-top: 24px;
}

.question-card,
.identity-card {
  min-width: 0;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  scroll-margin-top: 14px;
}

.identity-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.identity-field {
  display: grid;
  gap: 8px;
}

.identity-field:first-child {
  grid-column: 1 / -1;
}

.identity-field span {
  font-size: 0.92rem;
  font-weight: 800;
}

.identity-field input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.identity-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 99, 0.14);
}

.identity-field small {
  display: none;
  color: #a33a2d;
  font-weight: 750;
}

.show-errors .identity-field:has(input:invalid) input {
  border-color: #c86152;
}

.show-errors .identity-field:has(input:invalid) small {
  display: block;
}

.question-card legend {
  display: flex;
  width: 100%;
  align-items: flex-start;
  gap: 12px;
  padding: 0;
  font-size: 1.1rem;
  font-weight: 780;
  line-height: 1.4;
}

.question-card legend span {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 0.85rem;
}

.scale-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 4px;
}

.scale-option {
  position: relative;
  display: grid;
  min-height: 46px;
  align-items: center;
  justify-items: start;
  padding: 8px 38px 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 750;
  text-align: left;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.scale-option::after {
  position: absolute;
  top: 50%;
  right: 11px;
  width: 7px;
  height: 13px;
  border-right: 3px solid var(--accent-strong);
  border-bottom: 3px solid var(--accent-strong);
  opacity: 0;
  transform: translateY(-58%) rotate(45deg);
  content: "";
}

.scale-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.scale-option:hover,
.scale-option:focus-within {
  border-color: var(--accent);
  color: var(--ink);
}

.scale-option.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.scale-option.is-selected::after {
  opacity: 1;
}

.field-error {
  display: none;
  margin: 12px 0 0;
  color: #a33a2d;
  font-size: 0.9rem;
  font-weight: 700;
}

.show-errors .question-card:not(:has(input:checked)) {
  border-color: #c86152;
}

.show-errors .question-card:not(:has(input:checked)) .field-error {
  display: block;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: auto;
  padding: 24px 38px 34px;
  border-top: 1px solid var(--line);
}

.result-view {
  display: grid;
  place-items: center;
}

.result-shell {
  width: min(980px, 100%);
  border-radius: 8px;
}

.profile-band {
  padding: 34px 38px;
  border-bottom: 1px solid var(--line);
  background: var(--accent-strong);
  color: #fff;
}

.profile-band p,
.profile-band span {
  color: rgba(255, 255, 255, 0.78);
}

.profile-band p {
  margin-bottom: 8px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.profile-band h3 {
  margin-bottom: 10px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 28px 38px;
}

.metric-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-card div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.metric-card p {
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 750;
}

.metric-card strong {
  font-size: 1.5rem;
}

.metric-bar {
  display: block;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.metric-bar::before {
  display: block;
  width: var(--metric-value);
  height: 100%;
  background: var(--accent);
  content: "";
}

.interpretation-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 0 38px 38px;
}

.interpretation-grid article {
  min-height: 190px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.interpretation-grid p:last-child {
  margin-bottom: 0;
  color: var(--ink);
  line-height: 1.6;
  white-space: pre-line;
}

.whatsapp-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin: 0 38px 38px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent-soft);
}

.whatsapp-panel h3 {
  margin-bottom: 8px;
  font-size: 1.35rem;
}

.whatsapp-panel p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.whatsapp-button {
  flex: 0 0 auto;
  min-width: 210px;
}

.result-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.save-badge {
  padding: 0 12px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.85rem;
  font-weight: 800;
}

.text-link-button {
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 750;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.auth-view,
.history-view {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto;
}

.single-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 28px 38px;
  border: 1px solid rgba(216, 222, 219, 0.9);
  border-radius: 8px 8px 0 0;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.auth-card {
  padding: 38px;
  border: 1px solid rgba(216, 222, 219, 0.9);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  max-width: 540px;
}

.auth-description {
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 28px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-error {
  font-size: 0.85rem;
  color: #f87171;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: 8px;
  padding: 10px 14px;
  line-height: 1.5;
}

.auth-confirm-text {
  color: var(--muted);
  line-height: 1.6;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent-soft);
}

.history-header-actions {
  display: flex;
  gap: 10px;
}

.history-shell {
  border: 1px solid rgba(216, 222, 219, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.history-shell .single-header {
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--line);
  box-shadow: none;
  backdrop-filter: none;
}

.history-content {
  padding: 38px;
}

.history-email {
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 28px;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-loading,
.history-empty {
  color: var(--muted);
  padding: 24px 0;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.history-item-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  border: none;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.history-item-toggle:hover {
  background: var(--panel);
}

.history-item-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.history-item-band {
  font-size: 0.78rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.history-item-profile {
  font-size: 1rem;
}

.history-item-date {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}

.history-item-scores {
  display: flex;
  gap: 16px;
  color: var(--muted);
  font-size: 0.88rem;
  flex-shrink: 0;
}

.history-item-scores strong {
  color: var(--ink);
}

.history-item-detail {
  padding: 24px 20px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  gap: 24px;
}

.history-detail-estado {
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

.history-metrics {
  display: grid;
  gap: 10px;
}

.history-metric {
  display: grid;
  grid-template-columns: 90px 1fr 48px;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
}

.history-metric-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-strong);
  overflow: hidden;
}

.history-metric-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.history-metric strong {
  font-size: 0.88rem;
  text-align: right;
}

.history-devolutiva {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.history-devolutiva > div {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.history-devolutiva p:last-child {
  color: var(--ink);
  line-height: 1.6;
  font-size: 0.92rem;
  margin: 0;
}

.pre-line {
  white-space: pre-line;
}

[hidden] {
  display: none !important;
}

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

  .sensor-panel {
    position: static;
    height: auto;
    min-height: 0;
  }

  .block-nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .block-step {
    justify-content: center;
  }

  .block-step span {
    display: none;
  }

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

@media (max-width: 720px) {
  .app-shell,
  .result-view {
    width: min(100% - 20px, 1180px);
    margin: 10px auto;
  }

  .stage-header,
  .result-header,
  .form-actions {
    padding-right: 18px;
    padding-left: 18px;
  }

  .stage-header,
  .result-header {
    align-items: stretch;
    flex-direction: column;
  }

  .question-list,
  .metrics-grid,
  .interpretation-grid,
  .profile-band {
    padding-right: 18px;
    padding-left: 18px;
  }

  .block-nav,
  .identity-card,
  .metrics-grid,
  .interpretation-grid {
    grid-template-columns: 1fr;
  }

  .block-step {
    justify-content: flex-start;
  }

  .block-step span {
    display: grid;
  }

  .scale-option {
    padding-left: 14px;
  }

  .whatsapp-panel {
    align-items: stretch;
    flex-direction: column;
    margin-right: 18px;
    margin-left: 18px;
  }

  .whatsapp-button {
    width: 100%;
    min-width: 0;
  }
}
