:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #101828;
  background: #f4f7fb;
  line-height: 1.45;
  font-weight: 450;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body { margin: 0; min-height: 100vh; background: linear-gradient(180deg, #f8fafc 0%, #eef3f8 100%); }

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.hidden { display: none !important; }

.app-header {
  min-height: 76px;
  padding: 14px clamp(18px, 4vw, 52px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid #dbe2ea;
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(14px);
}

.brand-lockup, .header-user, .card-actions, .form-actions, .page-heading, .device-card-head, .device-detail-head, .component-card-head {
  display: flex;
  align-items: center;
}

.brand-lockup { gap: 14px; }
.brand-separator { width: 1px; height: 28px; background: #d0d5dd; }
.brand-logo { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -.02em; }
.iotcore-logo { font-size: 1.12rem; }
.ssol-logo { font-size: 1rem; color: #344054; }
.chile-clock {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  white-space: nowrap;
  color: #344054;
  font-size: .88rem;
  font-variant-numeric: tabular-nums;
}
.chile-clock-label { color: #667085; font-size: .75rem; }
#chile-clock { font-weight: 650; font-variant-numeric: tabular-nums; }

.logo-mark { width: 28px; height: 28px; border-radius: 9px; position: relative; display: inline-block; background: #101828; }
.ssol-logo .logo-mark { border-radius: 50%; background: #475467; }
.logo-mark::before, .logo-mark::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: #fff;
}
.logo-mark::before { width: 6px; height: 6px; left: 6px; top: 11px; box-shadow: 10px -7px 0 #fff, 10px 7px 0 #fff; }
.logo-mark::after { width: 13px; height: 2px; left: 8px; top: 13px; transform: rotate(-32deg); box-shadow: 0 7px 0 #fff; opacity: .9; }
.ssol-logo .logo-mark::before { box-shadow: 0 0 0 #fff; width: 8px; height: 8px; left: 10px; top: 10px; }
.ssol-logo .logo-mark::after { display: none; }

.header-user { gap: 12px; }
.user-identity { display: flex; flex-direction: column; align-items: flex-end; min-width: 0; }
.user-label, .eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; color: #667085; }
.user-identity strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }

.shell { width: min(1180px, calc(100% - 32px)); margin: 34px auto 56px; }
.panel { background: rgba(255,255,255,.96); border: 1px solid #dbe2ea; border-radius: 18px; box-shadow: 0 12px 32px rgba(16,24,40,.06); }

.auth-panel { max-width: 460px; margin: 9vh auto 0; padding: 32px; }
.auth-brand h1, .page-heading h1 { margin: 3px 0 8px; letter-spacing: -.035em; }
.auth-brand p { margin: 0 0 24px; }

.form-grid { display: grid; gap: 16px; }
label { display: grid; gap: 7px; font-size: .92rem; font-weight: 650; color: #344054; }
input, select {
  width: 100%; min-height: 46px; padding: 10px 13px;
  border: 1px solid #cfd6df; border-radius: 11px; background: #fff; color: #101828;
}
input:focus, select:focus, button:focus-visible { outline: 3px solid rgba(21,112,239,.18); outline-offset: 1px; }

button {
  min-height: 44px; padding: 10px 16px; border: 0; border-radius: 11px;
  background: #101828; color: #fff; font-weight: 700;
  transition: color .12s ease, background-color .12s ease, border-color .12s ease;
}
button.secondary { background: #f2f4f7; color: #344054; border: 1px solid #d0d5dd; }
button:active:not(:disabled) { color: #175cd3; }
button:not(.secondary):active:not(:disabled) { color: #84adff; }
button.secondary:active:not(:disabled) {
  background: #eaf2ff;
  color: #175cd3;
  border-color: #84adff;
}
button.icon-button { min-width: 42px; padding: 8px 11px; background: transparent; color: #344054; border: 1px solid transparent; font-size: 1.1rem; }

#refresh-button { min-width: 142px; white-space: nowrap; }
#refresh-button:disabled { opacity: 1; }
#refresh-button.is-loading {
  background: #eaf2ff;
  color: #175cd3;
  border: 1px solid #84adff;
  cursor: progress;
}
#refresh-button.is-success {
  background: #ecfdf3;
  color: #067647;
  border: 1px solid #abefc6;
}
#refresh-button.is-error {
  background: #fef3f2;
  color: #b42318;
  border: 1px solid #fecdca;
}

.page-heading { justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.page-heading h1 { font-size: clamp(1.65rem, 3vw, 2.35rem); }
.page-heading p { margin: 0; }

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

.device-card, .component-card, .device-detail { padding: 22px; }
.device-card, .component-card, .device-detail, .card-grid > * { min-width: 0; }
.component-name, .component-resource, .component-measurement-value { overflow-wrap: anywhere; }

.device-card-head, .component-card-head, .device-detail-head { justify-content: space-between; gap: 16px; }
.device-card h2, .device-detail h1, .component-card h3 { margin: 0; letter-spacing: -.025em; }
.device-hardware, .component-type, .component-resource { color: #667085; font-size: .88rem; }
.component-meta:empty { display: none; }
.component-resource { margin: 4px 0 14px; }
.component-resource:empty { display: none; }
.component-owner {
  display: block;
  margin-bottom: 8px;
  color: #667085;
  font-size: .88rem;
  overflow-wrap: anywhere;
}
.device-card-body, .component-meta { padding: 15px 0; }
.device-card-body { min-height: 32px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px;
  border-radius: 999px; background: #eef2f6; color: #344054; font-size: .8rem; font-weight: 750;
  white-space: nowrap;
}
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #98a2b3; }
.status-pill.connected { background: #ecfdf3; color: #067647; }
.status-pill.connected::before { background: #12b76a; }
.status-pill.disconnected { background: #fef3f2; color: #b42318; }
.status-pill.disconnected::before { background: #f04438; }
.status-pill.on { background: #ecfdf3; color: #067647; }
.status-pill.on::before { background: #12b76a; }
.status-pill.off { background: #f2f4f7; color: #475467; }
.status-pill.off::before { background: #667085; }
.status-pill.unknown { background: #fffaeb; color: #b54708; }
.status-pill.actuated { background: #ecfdf3; color: #067647; }
.status-pill.actuated::before { background: #12b76a; }
.status-pill.released { background: #f2f4f7; color: #475467; }
.status-pill.released::before { background: #667085; }

.component-card.component-kind-digital-input {
  border-color: #eabf4a;
  background: linear-gradient(145deg, #fffbeb 0%, #fffdf5 72%);
}
.component-kind-digital-input .component-type,
.component-kind-digital-input .component-resource { color: #946200; }
.component-kind-digital-input .component-state.actuated,
.component-kind-digital-input .component-state.released {
  background: #fef3c7;
  color: #92400e;
}
.component-kind-digital-input .component-state.actuated::before,
.component-kind-digital-input .component-state.released::before { background: #d97706; }

/* BMP280 card palette inspired by the sensor board's purple PCB. */
.component-card.component-kind-sensor-multimeasurement.component-type-bmp280-sensor {
  border-color: #c4b5fd;
  background: linear-gradient(145deg, #f5f0ff 0%, #fcfaff 72%);
}
.component-card.component-type-bmp280-sensor .component-type,
.component-card.component-type-bmp280-sensor .component-resource { color: #6b21a8; }
.component-card.component-type-bmp280-sensor .component-measurements {
  border-color: #ddd6fe;
  background: #faf5ff;
}

.card-actions { justify-content: flex-end; flex-wrap: wrap; gap: 9px; }
.component-actions { justify-content: flex-start; }
.component-card { min-height: 212px; }
.component-card .message { margin: 10px 0 0; }
.component-share-list { display: grid; gap: 8px; margin: 4px 0 12px; }
.component-share-entry {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 11px; border: 1px solid #dbe2ea; border-radius: 10px;
  background: #f8fafc; color: #475467; font-size: .85rem;
}
.component-share-entry button { min-height: 34px; padding: 6px 10px; font-size: .82rem; }

.device-detail { min-height: 380px; }
.device-detail-head { margin-bottom: 22px; }
.device-detail > .card-grid { margin-bottom: 22px; }

.shared-panel { margin-top: 28px; padding: 22px; }
.shared-panel .section-heading { margin-bottom: 16px; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,40,.46);
  display: grid; place-items: center; padding: 22px; z-index: 50;
}
.modal {
  width: min(560px, 100%); min-width: 0; min-height: 0; padding: 24px;
  max-height: calc(100vh - 44px);
  max-height: calc(100dvh - 44px);
  overflow-y: auto;
  overscroll-behavior-y: contain;
}
.modal .section-heading { margin-bottom: 18px; }
.modal .form-actions { justify-content: flex-end; margin-top: 4px; }

.message { min-height: 1.4em; color: #475467; }
.muted { color: #667085; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.logout-button { white-space: nowrap; }

@media (max-width: 720px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px 16px;
  }
  .brand-lockup { min-width: 0; max-width: 100%; gap: 10px; flex-wrap: wrap; }
  .chile-clock { margin-left: 0; }

  .header-user {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    width: 100%;
    min-width: 0;
    gap: 8px;
  }
  .user-identity {
    display: flex;
    grid-column: 1 / -1;
    align-items: flex-start;
    max-width: 100%;
  }
  .user-identity strong {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  #admin-button, #logout-button {
    min-width: 0;
    width: 100%;
    padding-inline: 8px;
    font-size: .88rem;
  }
  .shell { width: min(100% - 20px, 1180px); margin-top: 20px; }
  .page-heading { align-items: flex-start; }
  .card-grid { grid-template-columns: 1fr; }
  .device-card, .component-card, .device-detail { padding: 18px; }
  .device-detail-head, .component-card-head { min-width: 0; flex-wrap: wrap; }
  .device-detail-head > div, .component-card-head > div { min-width: 0; }
  .card-actions { justify-content: stretch; }
  .card-actions button { flex: 1 1 140px; }
}


/* Contract-declared multi-measurement component cards (for example DHT11). */
.component-measurements {
  display: grid;
  gap: 8px;
  margin: 4px 0 14px;
  padding: 12px 14px;
  border: 1px solid #dbe2ea;
  border-radius: 12px;
  background: #f8fafc;
}
.component-measurement-row {
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.component-measurement-label {
  color: #475467;
  font-size: .9rem;
}
.component-measurement-value {
  min-width: 0;
  text-align: right;
  color: #101828;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}
.component-measurement-timestamp {
  margin: 2px 0 0;
  font-size: .78rem;
}


/* DHT11 cards use a cyan identity in both the owner's and observer's dashboards. */
.component-card.component-kind-sensor-multimeasurement {
  border-color: #7dd3fc;
  background: linear-gradient(145deg, #effaff 0%, #f8fdff 72%);
}
.component-kind-sensor-multimeasurement .component-type,
.component-kind-sensor-multimeasurement .component-resource {
  color: #0369a1;
}
.component-kind-sensor-multimeasurement .component-measurements {
  border-color: #bae6fd;
  background: #f0f9ff;
}

/* Wind station: operational green card with readable speeds and compass rose. */
.component-card.component-kind-sensor-multimeasurement.component-type-wind-station {
  border-color: #86c99a;
  background: linear-gradient(145deg, #f0fdf4 0%, #f8fef9 72%);
}
.component-card.component-type-wind-station .component-type,
.component-card.component-type-wind-station .component-resource { color: #166534; }
.component-card.component-type-wind-station .component-measurements.wind-station-telemetry {
  display: block; border-color: #bbf7d0; background: #f0fdf4;
}
/* Use a single column at every viewport width: component cards may be narrow
   even when the overall dashboard is wide and has several cards per row. */
.wind-station-readout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
  gap: 12px;
  width: 100%;
  min-width: 0;
}
.wind-station-speed-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
  min-width: 0;
}
.wind-speed-metric {
  display: grid;
  align-content: center;
  gap: 5px;
  min-width: 0;
  min-height: 72px;
  padding: 8px 6px;
  overflow: hidden;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  background: rgba(255,255,255,.78);
}
.wind-speed-label {
  min-width: 0;
  color: #166534;
  font-size: .72rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.wind-speed-value {
  min-width: 0;
  color: #14532d;
  font-size: clamp(.9rem, 1.2vw, 1.25rem);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.wind-station-direction {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  min-width: 0;
  width: 100%;
}
.wind-direction-caption { color: #166534; font-size: .9rem; font-weight: 650; text-align: center; }
.wind-direction-value { color: #14532d; font-size: 1.6rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.wind-compass-rose {
  display: block;
  width: min(100%, 220px);
  max-width: 100%;
  height: auto;
  overflow: visible;
}


/* Keep device-detail actions within the viewport on narrow screens. */
@media (max-width: 720px) {
  #device-view > .page-heading {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  #device-view > .page-heading > button {
    min-width: 0;
    width: 100%;
    overflow-wrap: anywhere;
  }

  #device-view > .page-heading > #device-delete-button {
    grid-column: 1 / -1;
  }
}



/* Bounded measurement history stays below each sensor card's controls. */
.measurement-history { margin-top: 1rem; border-top: 1px solid #dbe3ef; padding-top: .75rem; }
.measurement-history summary { cursor: pointer; font-weight: 600; }
.history-controls { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.history-controls select, .history-controls input { max-width: 100%; min-width: 0; }
.history-results { overflow-x: auto; font-size: .85rem; }
.history-results table { width: 100%; border-collapse: collapse; }
.history-results th, .history-results td { padding: .4rem; border-bottom: 1px solid #dbe3ef; text-align: left; }
.history-results caption { text-align: left; padding: .5rem 0; }

/* Fixed-height rows: at most ten observations visible, independent of query range. */
.history-table-scroll { --history-row-height: 3.6rem; overflow-x: auto; }
.history-table-scroll table { table-layout: fixed; }
.history-table-scroll thead, .history-table-scroll tbody tr {
  display: table; width: 100%; table-layout: fixed;
}
.history-table-scroll tbody {
  display: block; max-height: calc(10 * var(--history-row-height)); overflow-y: auto;
  scrollbar-gutter: stable;
}
.history-table-scroll td { height: var(--history-row-height); box-sizing: border-box; overflow-wrap: anywhere; }
.history-table-scroll th { overflow-wrap: anywhere; }

.measurement-graphs { margin-top: 1rem; border-top: 1px solid #dbe3ef; padding-top: .75rem; }
.measurement-graphs summary { cursor: pointer; font-weight: 600; }
.measurement-chart { min-width: 0; }
.measurement-chart h4 { margin: .75rem 0 .25rem; font-size: .85rem; }
.measurement-chart svg { display: block; width: 100%; height: auto; }
.measurement-chart svg text { font-size: 10px; fill: #334155; }

/* Eight per-instance ADC captures remain usable in the owner configurator. */
.adc-calibration-row { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.adc-calibration-row > label { flex: 1; min-width: 90px; }
.adc-calibration-row > button { flex: 2; min-width: 150px; overflow-wrap: anywhere; }
.configuration-fields fieldset { min-width: 0; margin: 0; border: 1px solid #d5dfed; border-radius: 8px; }
.configuration-fields fieldset p { font-size: .85rem; color: #52627a; }

.wind-aeronautical-statistics > button { margin-top: 12px; }
.wind-aero-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.wind-aero-metric { display: flex; flex-direction: column; gap: 4px; padding: 12px; border: 1px solid #bbf7d0; border-radius: 8px; }
.wind-aero-metric strong { font-size: 1.25rem; }
.wind-aero-note, .wind-aero-metric small { font-size: .8rem; color: #52627a; }
.wind-aero-table-scroll { max-width: 100%; overflow-x: auto; }
.wind-aero-runways { width: 100%; border-collapse: collapse; font-size: .85rem; }
.wind-aero-runways th, .wind-aero-runways td { padding: 8px; text-align: left; border-bottom: 1px solid #dbe3ef; overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .wind-aero-grid { grid-template-columns: minmax(0, 1fr); }
}
/* Level 2: one column, measured values first, inline formula disclosure. */
.composite-list { display: grid; gap: 20px; margin: 20px 0; }
.status-pill.partial { background: #fff7ed; color: #9a3412; }
.composite-card { border: 1px solid var(--border, #d7deea); border-radius: 14px; padding: 20px; min-width: 0; width: 100%; max-width: 900px; margin-inline: auto; }
.composite-card h2 { margin: 0; font-size: 1.2rem; }
.composite-card h3 { margin: 20px 0 8px; font-size: .95rem; }
.composite-card > .section-heading { min-height: 2.5rem; }
.composite-status { flex: 0 0 8rem; font-size: .75rem; text-align: right; }
.composite-row { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 7.5rem 30px; gap: 8px 12px; align-items: baseline; padding: 6px 0 14px; border-bottom: 1px solid var(--border, #e4e9f0); }
.composite-row > strong { white-space: nowrap; text-align: right; }
.composite-row-status { position: absolute; bottom: 1px; left: 0; font-size: .7rem; line-height: 12px; }
.composite-row-status:empty { display: none; }
.composite-formula { display: contents; }
.composite-formula::details-content { display: contents; }
.composite-formula:not([open]) > div { display: none; }
.composite-formula > summary { grid-column: 3; grid-row: 1; list-style: none; cursor: pointer; text-align: center; border: 1px solid var(--border, #d7deea); border-radius: 50%; width: 26px; height: 26px; }
.composite-formula > summary::-webkit-details-marker { display: none; }
.composite-formula[open] > div { grid-column: 1 / -1; padding: 12px; border-radius: 8px; background: var(--surface, #f5f7fa); overflow-wrap: anywhere; font-size: .85rem; }
.composite-formula p { margin: 4px 0 10px; }
.composite-sources { margin: 16px 0; font-size: .85rem; overflow-wrap: anywhere; }
.composite-options { border-top: 1px solid var(--border, #d7deea); padding-top: 16px; margin-top: 16px; }
#individual-components > summary { cursor: pointer; margin: 16px 0; }
.composite-card .card-actions { margin-top: 16px; }
@media (max-width: 480px) {
  .composite-card { padding: 12px; }
  .composite-row { grid-template-columns: minmax(0, 1fr) 6rem 26px; gap: 6px; font-size: .85rem; }
}
