:root {
  color-scheme: light;
  --bg: #f3f6ef;
  --surface: #ffffff;
  --surface-2: #eaf3ec;
  --text: #1e2b22;
  --muted: #66756d;
  --line: #dbe6d6;
  --green: #1f7a4d;
  --green-dark: #145f3a;
  --amber: #b7791f;
  --red: #b42318;
  --shadow: 0 12px 30px rgba(27, 54, 36, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(31, 122, 77, 0.08), rgba(31, 122, 77, 0)),
    var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 8%, rgba(255, 205, 90, 0.24), transparent 25%),
    linear-gradient(160deg, #0f5b35 0%, #1f7a4d 52%, #d9a441 145%);
}

.login-card {
  width: min(430px, 100%);
  padding: 28px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(11, 45, 28, 0.26);
}

.login-logo {
  width: 82px;
  height: 82px;
  display: block;
  margin-bottom: 16px;
}

.login-card h1 {
  margin: 0 0 18px;
  font-size: 30px;
  color: var(--text);
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  font-size: 13px;
  font-weight: 700;
  color: #385344;
}

.login-form input {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

.login-form button {
  margin-top: 8px;
}

.login-message {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

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

.app-locked {
  display: none;
}

[hidden] {
  display: none !important;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.small-button {
  min-height: 38px;
  padding: 0 12px;
}

body.logged-out {
  background:
    radial-gradient(circle at 50% 8%, rgba(255, 205, 90, 0.24), transparent 25%),
    linear-gradient(160deg, #0f5b35 0%, #1f7a4d 52%, #d9a441 145%);
}

body.logged-out .app-shell {
  min-height: 100vh;
  display: grid;
  align-content: center;
  gap: 16px;
  padding-bottom: 34px;
}

body.logged-out .dashboard-only,
body.logged-out .status-pill {
  display: none !important;
}

body.logged-out .topbar {
  justify-content: center;
  margin-bottom: 0;
  text-align: center;
  color: #fff;
}

body.logged-out .topbar > div:first-child::before {
  content: "";
  display: block;
  width: 86px;
  height: 86px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background:
    radial-gradient(circle, #ffe9a8 0 31%, #f4b63f 32% 48%, transparent 49%),
    conic-gradient(from 0deg, transparent 0 6deg, #ffd36a 6deg 17deg, transparent 17deg 30deg);
  box-shadow: 0 18px 36px rgba(29, 54, 35, 0.22);
}

body.logged-out .eyebrow,
body.logged-out h1 {
  color: #fff;
}

body.logged-out h1 {
  font-size: 34px;
}

body.logged-out .auth-panel {
  width: min(460px, 100%);
  margin: 0 auto;
  box-shadow: 0 22px 60px rgba(11, 45, 28, 0.24);
}

body.logged-out .auth-panel > .section-heading {
  margin-top: 0;
}

body.logged-out .auth-box {
  background: #fff;
}

body.logged-out .app-log-box {
  background: rgba(255, 255, 255, 0.96);
}

body.logged-out {
  background:
    radial-gradient(circle at 50% 8%, rgba(255, 205, 90, 0.24), transparent 25%),
    linear-gradient(160deg, #0f5b35 0%, #1f7a4d 52%, #d9a441 145%);
}

body.logged-out .app-shell {
  min-height: 100vh;
  display: grid;
  align-content: center;
  gap: 16px;
  padding-bottom: 34px;
}

body.logged-out .dashboard-only,
body.logged-out .status-pill {
  display: none !important;
}

body.logged-out .topbar {
  justify-content: center;
  margin-bottom: 0;
  text-align: center;
  color: #fff;
}

body.logged-out .topbar > div:first-child::before {
  content: "";
  display: block;
  width: 86px;
  height: 86px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background:
    radial-gradient(circle, #ffe9a8 0 31%, #f4b63f 32% 48%, transparent 49%),
    conic-gradient(from 0deg, transparent 0 6deg, #ffd36a 6deg 17deg, transparent 17deg 30deg);
  box-shadow: 0 18px 36px rgba(29, 54, 35, 0.22);
}

body.logged-out .eyebrow,
body.logged-out h1 {
  color: #fff;
}

body.logged-out h1 {
  font-size: 34px;
}

body.logged-out .auth-panel {
  width: min(460px, 100%);
  margin: 0 auto;
  box-shadow: 0 22px 60px rgba(11, 45, 28, 0.24);
}

body.logged-out .auth-panel > .section-heading {
  margin-top: 0;
}

body.logged-out .auth-box {
  background: #fff;
}

body.logged-out .app-log-box {
  background: rgba(255, 255, 255, 0.96);
}

button, input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 700;
}

.app-shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--green);
  font-weight: 800;
  font-size: 12px;
  text-transform: uppercase;
}

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

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

.status-pill {
  padding: 8px 11px;
  border-radius: 999px;
  background: #fff7ed;
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
}

.status-pill.online {
  background: #e8f7ef;
  color: var(--green);
}

.status-pill.offline {
  background: #fff1f3;
  color: var(--red);
}

.hero-panel,
.metric-card,
.sensor-card,
.control-panel,
.readiness-panel,
.alerts .alert {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  margin-bottom: 14px;
}

.panel-label,
.label,
.muted,
.section-heading span,
.sensor-card p {
  color: var(--muted);
}

.panel-label,
.label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.prediction-row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-top: 4px;
}

.prediction-row span {
  font-size: 42px;
  font-weight: 850;
  color: var(--green-dark);
}

.prediction-row small,
.fan-ring small {
  color: var(--muted);
  font-weight: 700;
}

.fan-ring {
  width: 104px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  border: 10px solid #d9efe1;
  background: #f8fcf9;
  flex: 0 0 auto;
}

.fan-ring span {
  font-size: 24px;
  font-weight: 850;
  color: var(--green);
}

.grid {
  display: grid;
  gap: 10px;
}

.summary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 22px;
}

.metric-card {
  padding: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 20px 0 10px;
}

.sensor-list {
  display: grid;
  gap: 10px;
}

.sensor-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
}

.sensor-card h3 {
  font-size: 17px;
}

.sensor-card p {
  margin-top: 4px;
  font-size: 13px;
}

.sensor-values {
  text-align: right;
  min-width: 92px;
}

.sensor-values strong,
.sensor-values span {
  display: block;
}

.sensor-values strong {
  font-size: 18px;
}

.sensor-values span {
  margin-top: 4px;
  color: var(--green);
  font-weight: 800;
}

.uno-feed-panel {
  margin-top: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.compact-heading {
  margin: 0 0 10px;
}

.feed-grid {
  display: grid;
  gap: 8px;
}

.feed-item {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff7ed;
}

.feed-item.ok {
  background: #f0fbf4;
}

.feed-item.bad {
  background: #fff7ed;
}

.feed-item strong,
.feed-item span {
  display: block;
}

.feed-item strong {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text);
}

.feed-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.feed-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.feed-status-ok {
  color: var(--green) !important;
  font-weight: 800;
}

.feed-status-bad {
  color: var(--red) !important;
  font-weight: 800;
}

.control-panel {
  padding: 14px;
}

.readiness-panel {
  padding: 14px;
  margin-bottom: 8px;
}

.readiness-meter {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8ece7;
  border: 1px solid var(--line);
}

#readiness-bar {
  width: 0%;
  height: 100%;
  background: var(--green);
  transition: width 240ms ease;
}

#readiness-bar.warn {
  background: var(--amber);
}

.component-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.component {
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fcf9;
}

.component.bad {
  background: #fff7ed;
}

.component strong,
.component span {
  display: block;
}

.component strong {
  font-size: 12px;
  text-transform: uppercase;
}

.component span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.segmented,
.preset-row,
.action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.segmented button,
.preset-row button,
.secondary {
  background: var(--surface-2);
  color: var(--green-dark);
}

.segmented button.active {
  background: var(--green);
  color: white;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  margin: 16px 0 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

#speed-slider {
  width: 100%;
  accent-color: var(--green);
}

.threshold-form {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.threshold-form h3 {
  margin: 0;
  font-size: 15px;
}

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

.threshold-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.threshold-grid input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--text);
  background: #fbfdfb;
  font: inherit;
}

.full-width {
  width: 100%;
  margin-top: 10px;
}

.token-input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: #fbfdfb;
}

.token-button {
  min-height: 32px;
  padding: 0 12px;
  background: var(--surface-2);
  color: var(--green-dark);
  font-size: 12px;
}

.token-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.app-log-box {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
}

.compact-heading {
  margin: 0 0 10px;
}

.public-app-log {
  display: grid;
  gap: 8px;
}

.log-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.log-item strong,
.log-item span,
.log-item small {
  display: block;
}

.log-item strong {
  color: var(--green-dark);
  font-size: 12px;
  text-transform: uppercase;
}

.log-item span {
  margin-top: 3px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.log-item small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.auth-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fcf9;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.auth-tabs button {
  background: var(--surface-2);
  color: var(--green-dark);
}

.auth-tabs button.active {
  background: var(--green);
  color: #fff;
}

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

.password-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.password-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.public-link {
  display: block;
  margin-top: 8px;
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.public-link:focus,
.public-link:hover {
  text-decoration: underline;
}

.auth-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.auth-current strong,
.auth-current span,
.help-text {
  display: block;
}

.auth-current span,
.help-text {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.help-text {
  margin-top: 8px;
}

.biometric-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fcf9;
}

.biometric-box strong,
.biometric-box span {
  display: block;
}

.biometric-box strong {
  font-size: 14px;
  color: var(--text);
}

.biometric-box span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.preset-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 12px 0;
}

.primary {
  background: var(--green);
  color: white;
}

.danger {
  width: 100%;
  margin-top: 10px;
  background: var(--red);
  color: white;
}

.danger-dark {
  background: #7a271a;
}

.dashboard-band {
  margin-top: 18px;
}

.hero-title {
  margin: 0 0 6px;
  font-size: 28px;
}

.ops-grid,
.detail-grid,
.chart-grid {
  display: grid;
  gap: 12px;
}

.ops-panel,
.detail-card,
.chart-panel,
.event-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.ops-panel strong,
.detail-card strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
}

.ops-panel p,
.detail-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.ops-panel a {
  color: var(--green-dark);
  font-weight: 800;
}

.chart-panel {
  overflow: hidden;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
}

.chart-header strong {
  color: var(--text);
}

.chart-panel canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.event-list {
  display: grid;
  gap: 9px;
}

.event-item {
  display: grid;
  gap: 5px;
  box-shadow: none;
}

.event-item span {
  color: var(--muted);
  font-size: 12px;
}

.event-item code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 8px;
  border-radius: 8px;
  background: #f4f8f4;
  color: #25362b;
  font-size: 12px;
}

.full-width {
  width: 100%;
  margin-top: 10px;
}

.alerts {
  display: grid;
  gap: 9px;
}

.user-list {
  display: grid;
  gap: 9px;
}

.user-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fcf9;
}

.user-card strong,
.user-card span {
  display: block;
}

.user-card span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.user-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.user-actions button {
  background: var(--surface-2);
  color: var(--green-dark);
  font-size: 12px;
}

.alert {
  padding: 13px;
  border-left: 5px solid var(--amber);
}

.alert.critical,
.alert.error {
  border-left-color: var(--red);
}

.alert strong {
  display: block;
  margin-bottom: 4px;
  text-transform: uppercase;
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  padding: 13px 14px;
  border-radius: 8px;
  background: #17241c;
  color: white;
  text-align: center;
  box-shadow: var(--shadow);
}

@media (min-width: 760px) {
  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

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

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

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

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