:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f6f8;
  color: #17202a;
  line-height: 1.45;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
}

button, input, select { font: inherit; }

button {
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  background: #17202a;
  color: white;
  cursor: pointer;
}

button.secondary {
  background: #e8edf2;
  color: #17202a;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid #8db8ff;
  outline-offset: 2px;
}

.shell {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.topbar,
.toolbar,
.row,
.toolbar-actions,
.capabilities {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.7rem, 4vw, 2.5rem); }
h2 { font-size: 1rem; margin-bottom: 1rem; }

.eyebrow {
  margin-bottom: 0.2rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #647180;
}

.panel, .metric {
  background: white;
  border: 1px solid #dde3e9;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(23, 32, 42, 0.05);
}

.panel { padding: 1.15rem; }

.setup-panel {
  display: grid;
  grid-template-columns: 1fr minmax(280px, 420px);
  gap: 1.5rem;
  align-items: end;
}

.identity-form label,
.field label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: #5c6976;
}

.identity-form input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cfd7df;
  border-radius: 10px;
  background: white;
  padding: 0.65rem 0.8rem;
  color: inherit;
}

.identity-form .row input { flex: 1; }
.auth-links { display:flex; gap:0.5rem; flex-wrap:wrap; margin-top:0.5rem; }
.auth-links button { font-size:0.86rem; }
.auth-flow-actions { min-width:0; }
#authFlowStatus { min-height:1.5em; overflow-wrap:anywhere; }
#authFlowResend { margin-top:0.3rem; }


.identity-form { display: grid; gap: 0.5rem; }
.identity-form label { margin-bottom: 0; }
.identity-form button { margin-top: 0.35rem; }
#authMessage:empty { display: none; }
#emptyProducts { margin-top: 1rem; }
#emptyProducts h2 { margin-bottom: 0.4rem; }


.toolbar {
  justify-content: space-between;
  margin-bottom: 1rem;
}

.toolbar .field { min-width: 250px; }

.hero-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.metric {
  padding: 1.3rem;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.metric > span {
  color: #657381;
  font-size: 0.85rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin: 0.15rem 0 0.1rem;
  font-size: clamp(2rem, 5vw, 3.2rem);
  letter-spacing: -0.03em;
}

.metric small { color: #657381; }

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

dl { margin: 0; }

dl div {
  display: grid;
  grid-template-columns: minmax(145px, 1fr) minmax(0, 1.3fr);
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid #edf0f3;
}

dl div:last-child { border-bottom: 0; }
dt { color: #697682; }
dd { margin: 0; text-align: right; font-weight: 650; overflow-wrap: anywhere; }

.badge, .cap {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.good, .cap.good { background: #e6f7ed; color: #176b3a; }
.badge.bad { background: #fdecec; color: #9f2323; }
.badge.neutral, .cap { background: #eef1f4; color: #5d6975; }

.capabilities { flex-wrap: wrap; }
.gate-note { margin: 1rem 0 0; }

.muted {
  color: #697682;
  font-size: 0.86rem;
}

.refresh-device-status {
  min-width: 5.5rem;
  text-align: right;
  white-space: nowrap;
}

.refresh-device-status.good { color: #176b3a; }
.refresh-device-status.bad { color: #9f2323; }
.refresh-device-status.warn { color: #8b5b00; }

.error {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: #fdecec;
  color: #8f1d1d;
}

.hidden { display: none !important; }

@media (max-width: 760px) {
  .setup-panel,
  .hero-grid,
  .grid {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    flex-wrap: wrap;
  }

  .refresh-device-status {
    min-width: 0;
    text-align: left;
  }

  .toolbar .field { min-width: 0; }

  dl div {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  dd { text-align: left; }
}


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

.settings-heading,
.settings-card-head,
.settings-actions,
.check-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.settings-heading,
.settings-card-head {
  justify-content: space-between;
}

.settings-heading {
  margin-bottom: 1rem;
}

.settings-heading h2,
.settings-card h3 {
  margin-bottom: 0.25rem;
}

.settings-global {
  white-space: nowrap;
}

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

.settings-card {
  border: 1px solid #dde3e9;
  border-radius: 14px;
  padding: 1rem;
  background: #fbfcfd;
}

.settings-card h3 {
  font-size: 1rem;
}

.availability {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  background: #eef1f4;
  color: #5d6975;
  font-size: 0.75rem;
  font-weight: 800;
}

.availability.good {
  background: #e6f7ed;
  color: #176b3a;
}

.availability.bad {
  background: #fdecec;
  color: #9f2323;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin: 0.85rem 0;
}

.form-grid label {
  display: block;
  color: #5c6976;
  font-size: 0.8rem;
  font-weight: 700;
}

.form-grid input,
.form-grid select {
  width: 100%;
  min-height: 42px;
  margin-top: 0.35rem;
  border: 1px solid #cfd7df;
  border-radius: 10px;
  background: white;
  padding: 0.6rem 0.7rem;
  color: #17202a;
}

.check-row {
  justify-content: flex-start;
  margin-top: 0.7rem;
  color: #37424d;
  font-size: 0.9rem;
}

.check-row input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.settings-actions {
  justify-content: space-between;
  margin-top: 0.9rem;
}

.settings-action-buttons {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.form-status {
  text-align: right;
}

.helper {
  margin: 0.4rem 0 0;
  color: #697682;
  font-size: 0.8rem;
}

.settings-card.is-disabled {
  opacity: 0.7;
}

.settings-card.is-pending {
  border-color: #aab7c4;
}

.settings-card input:disabled,
.settings-card select:disabled,
.settings-card button:disabled,
.toolbar button:disabled,
.toolbar select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.form-status.good {
  color: #176b3a;
}

.form-status.bad {
  color: #9f2323;
}

.form-status.warn {
  color: #8b5b00;
}

@media (max-width: 760px) {
  .settings-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .settings-heading,
  .settings-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-status {
    text-align: left;
  }
}


/* App-style settings navigation */
.settings-entry {
  margin-top: 1rem;
}

.settings-entry-head,
.app-view-header,
.settings-row,
.settings-row-side {
  display: flex;
  align-items: center;
}

.settings-entry-head {
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.settings-entry-head h2,
.app-view-header h2 {
  margin-bottom: 0.25rem;
  font-size: 1.25rem;
}

.settings-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.settings-summary-item {
  padding: 0.85rem 0.95rem;
  border: 1px solid #e4e9ee;
  border-radius: 12px;
  background: #fbfcfd;
}

.settings-summary-item span {
  display: block;
  margin-bottom: 0.25rem;
  color: #697682;
  font-size: 0.78rem;
  font-weight: 700;
}

.settings-summary-item strong {
  display: block;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.app-view-header {
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 0.25rem 0;
}

.back-button {
  flex: 0 0 auto;
}

.settings-list {
  padding: 0;
  overflow: hidden;
}

.settings-row {
  width: 100%;
  min-height: 78px;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  border-radius: 0;
  border-bottom: 1px solid #edf0f3;
  background: white;
  color: #17202a;
  text-align: left;
}

.settings-row:last-child {
  border-bottom: 0;
}

.settings-row:hover:not(:disabled) {
  background: #f8fafb;
}

.settings-row:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.settings-row-copy {
  min-width: 0;
}

.settings-row-copy strong,
.settings-row-copy small {
  display: block;
}

.settings-row-copy strong {
  margin-bottom: 0.25rem;
}

.settings-row-copy small {
  color: #697682;
  overflow-wrap: anywhere;
}

.settings-row-side {
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 0.5rem;
}

.chevron {
  font-size: 1.7rem;
  line-height: 1;
  color: #84909b;
}

.draft-badge {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  background: #fff4d6;
  color: #835d00;
  font-size: 0.72rem;
  font-weight: 800;
}

.compact-panel {
  margin-top: 0.85rem;
  box-shadow: none;
}

.settings-editor-shell {
  width: min(720px, 100%);
  margin: 0 auto;
}

.editor-card {
  background: white;
  box-shadow: 0 8px 24px rgba(23, 32, 42, 0.05);
}

.editor-card.settings-card {
  padding: 1.25rem;
}

@media (max-width: 760px) {
  .settings-entry-head,
  .app-view-header {
    align-items: stretch;
    flex-direction: column;
  }

  .settings-summary-grid {
    grid-template-columns: 1fr;
  }

  .settings-row {
    min-height: 86px;
    padding: 0.9rem;
  }

  .settings-row-side {
    flex-wrap: wrap;
  }

  .back-button {
    align-self: flex-start;
  }
}


/* Final Gate 2 visual refinement */
.settings-entry {
  border-color: #d7dee6;
}

.settings-entry-head > div {
  min-width: 0;
}

.settings-summary-item {
  transition: border-color 120ms ease, background 120ms ease;
}

.settings-summary-item:hover {
  border-color: #d4dce4;
  background: #f8fafc;
}

.configured-fields {
  margin-top: 0.2rem;
}

.setup-hint {
  margin: 0.75rem 0 0;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  background: #f5f7f9;
  color: #697682;
  font-size: 0.82rem;
}

.device-details {
  margin-top: 1rem;
  padding: 0;
  overflow: hidden;
}

.device-details > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 68px;
  padding: 1rem 1.15rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.device-details > summary::-webkit-details-marker {
  display: none;
}

.device-details > summary:hover {
  background: #f8fafb;
}

.device-details > summary span:first-child {
  min-width: 0;
}

.device-details > summary strong,
.device-details > summary small {
  display: block;
}

.device-details > summary strong {
  margin-bottom: 0.2rem;
}

.device-details > summary small {
  color: #697682;
}

.details-chevron {
  flex: 0 0 auto;
  font-size: 1.55rem;
  line-height: 1;
  color: #84909b;
  transition: transform 120ms ease;
}

.device-details[open] .details-chevron {
  transform: rotate(90deg);
}

.device-details-grid {
  margin: 0;
  padding: 0 1.15rem 1.15rem;
}

.detail-card {
  min-width: 0;
  padding: 1rem;
  border: 1px solid #e4e9ee;
  border-radius: 12px;
  background: #fbfcfd;
}

.detail-card h2 {
  margin-bottom: 0.75rem;
}

.availability.bad {
  max-width: 170px;
  text-align: center;
  line-height: 1.15;
}

@media (max-width: 760px) {
  .device-details-grid {
    grid-template-columns: 1fr;
  }

  .device-details > summary {
    align-items: flex-start;
  }
}


/* Sensor-state cards: quiet status signal, not neon decoration. */
.sensor-card {
  position: relative;
  --sensor-accent: #aeb8c2;
  --sensor-halo: rgba(118, 132, 146, 0.16);
  border-color: var(--sensor-accent);
  box-shadow:
    0 0 0 2px var(--sensor-halo),
    0 8px 24px rgba(23, 32, 42, 0.05);
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.sensor-card::after {
  content: "";
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--sensor-accent);
  box-shadow: 0 0 0 4px var(--sensor-halo);
}

.sensor-state-healthy {
  --sensor-accent: #4aa56b;
  --sensor-halo: rgba(74, 165, 107, 0.15);
}

.sensor-state-warming {
  --sensor-accent: #d8b72f;
  --sensor-halo: rgba(216, 183, 47, 0.17);
}

.sensor-state-warming::after {
  animation: sensor-warming-pulse 1.6s ease-in-out infinite;
}

.sensor-state-warning {
  --sensor-accent: #c47f2c;
  --sensor-halo: rgba(196, 127, 44, 0.17);
}

@keyframes sensor-warming-pulse {
  0%, 100% {
    box-shadow: 0 0 0 4px var(--sensor-halo);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 7px var(--sensor-halo);
    transform: scale(1.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sensor-state-warming::after {
    animation: none;
  }
}

.sensor-state-fault {
  --sensor-accent: #c95151;
  --sensor-halo: rgba(201, 81, 81, 0.17);
}

.sensor-state-offline {
  --sensor-accent: #aeb8c2;
  --sensor-halo: rgba(118, 132, 146, 0.13);
}

.sensor-card small:empty {
  display: none;
}

/* F1-A isolated Add Device; inherits the existing responsive forms. */
.claim-panel { max-width: 560px; margin: 1rem 0; }
.claim-panel .identity-form { margin: 1rem 0; }
.claim-panel #claimStatus { min-height: 1.5rem; overflow-wrap: anywhere; }
.claim-panel #claimBack { margin-top: .6rem; }
