:root {
  color-scheme: dark;
  --bg: #0c111b;
  --bg-elevated: #121a27;
  --bg-elevated-2: #1a2639;
  --bg-soft: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f5f7fb;
  --text-soft: #afbbcf;
  --text-muted: #8794ab;
  --brand: #53c7a8;
  --brand-strong: #2aa57f;
  --danger: #ff6b6b;
  --warning: #f6c85f;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.32);
  --radius: 22px;
  --radius-sm: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top right, rgba(83, 199, 168, 0.18), transparent 28%),
    radial-gradient(circle at top left, rgba(58, 143, 255, 0.12), transparent 24%),
    linear-gradient(180deg, #0c111b 0%, #0f1723 40%, #121724 100%);
  color: var(--text);
  font-family: "SF Pro Display", "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  padding:
    calc(1rem + env(safe-area-inset-top))
    1rem
    calc(2rem + env(safe-area-inset-bottom));
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin-bottom: 1rem;
  backdrop-filter: blur(16px);
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(14, 21, 33, 0.82);
  box-shadow: var(--shadow);
}

.topbar__nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
}

.topbar__nav form {
  margin: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand__mark {
  display: inline-grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--brand) 0%, #72ddff 100%);
  color: #071018;
  font-size: 0.9rem;
}

.page-shell {
  display: grid;
  gap: 1rem;
}

.hero,
.card,
.widget-card,
.form-panel,
.empty-state {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(18, 26, 39, 0.96) 0%, rgba(14, 21, 33, 0.98) 100%);
  box-shadow: var(--shadow);
}

.hero,
.form-panel,
.empty-state {
  padding: 1.25rem;
}

.hero {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.hero--compact {
  margin-bottom: 0.5rem;
}

.hero__copy {
  max-width: 62ch;
  color: var(--text-soft);
  line-height: 1.6;
}

.hero__actions,
.card-actions,
.widget-card__actions,
.form-actions,
.history-form__actions,
.field__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: clamp(2rem, 5vw, 3rem);
}

h2 {
  font-size: clamp(1.2rem, 3vw, 1.5rem);
}

.button,
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.8rem;
  padding: 0.7rem 1rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-strong) 100%);
  color: #081018;
  font-weight: 700;
  transition: transform 120ms ease, opacity 120ms ease, border-color 120ms ease;
}

.button:hover,
.chip:hover {
  transform: translateY(-1px);
}

.button--ghost,
.chip {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
  color: var(--text);
}

.button--danger {
  background: rgba(255, 107, 107, 0.16);
  border-color: rgba(255, 107, 107, 0.35);
  color: #ffd7d7;
}

.button--small,
.chip {
  min-height: 2.3rem;
  padding: 0.55rem 0.85rem;
  font-size: 0.92rem;
}

.messages {
  display: grid;
  gap: 0.65rem;
}

.message,
.notice {
  padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.message--success {
  background: rgba(83, 199, 168, 0.12);
  border-color: rgba(83, 199, 168, 0.25);
}

.message--error,
.notice--error {
  background: rgba(255, 107, 107, 0.12);
  border-color: rgba(255, 107, 107, 0.25);
}

.dashboard-list,
.widget-stack {
  display: grid;
  gap: 1rem;
}

.dashboard-card {
  position: relative;
  display: grid;
  gap: 1rem;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease,
    background 140ms ease;
}

.dashboard-card__link {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
}

.dashboard-card__content {
  position: relative;
  z-index: 2;
  pointer-events: none;
}

.dashboard-card .card-actions {
  position: relative;
  z-index: 3;
}

.dashboard-card:hover,
.dashboard-card:focus-within {
  transform: translateY(-2px);
  border-color: rgba(83, 199, 168, 0.28);
  box-shadow:
    0 28px 70px rgba(0, 0, 0, 0.38),
    0 0 0 1px rgba(83, 199, 168, 0.12);
  background: linear-gradient(180deg, rgba(24, 48, 64, 0.98) 0%, rgba(18, 36, 54, 1) 100%);
}

.dashboard-card:active {
  transform: scale(0.992);
  border-color: rgba(83, 199, 168, 0.42);
  background: linear-gradient(180deg, rgba(20, 41, 58, 1) 0%, rgba(15, 31, 46, 1) 100%);
}

.dashboard-card__link:focus-visible {
  outline: none;
}

.card,
.widget-card {
  padding: 1rem;
}

.dashboard-card__meta,
.widget-card__meta,
.widget-feedback,
.widget-status__text,
.summary-pill__label,
.field__help {
  color: var(--text-soft);
}

.widget-card__header,
.widget-statusline,
.field-grid {
  display: grid;
  gap: 0.9rem;
}

.widget-card__body {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.widget-controls,
.history-form {
  display: grid;
  gap: 0.8rem;
}

.chip-row,
.widget-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.summary-pill {
  min-width: 6rem;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.summary-pill strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge--live {
  background: rgba(83, 199, 168, 0.18);
  color: #91f0d5;
}

.badge--history {
  background: rgba(246, 200, 95, 0.18);
  color: #ffd98a;
}

.badge--muted {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-soft);
}

.chart-host {
  min-height: 280px;
  position: relative;
}

.apexcharts-tooltip,
.apexcharts-xaxistooltip,
.apexcharts-yaxistooltip {
  border: 1px solid rgba(255, 255, 255, 0.14) !important;
  border-radius: 14px !important;
  background: rgba(12, 17, 27, 0.96) !important;
  color: var(--text) !important;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.34) !important;
}

.apexcharts-tooltip.apexcharts-theme-dark,
.apexcharts-xaxistooltip.apexcharts-theme-dark,
.apexcharts-yaxistooltip.apexcharts-theme-dark {
  background: rgba(12, 17, 27, 0.96) !important;
  color: var(--text) !important;
}

.apexcharts-tooltip-title,
.apexcharts-xaxistooltip-text,
.apexcharts-yaxistooltip-text {
  border-color: rgba(255, 255, 255, 0.08) !important;
  background: rgba(255, 255, 255, 0.04) !important;
  color: var(--text) !important;
}

.apexcharts-tooltip-text,
.apexcharts-tooltip-text-y-label,
.apexcharts-tooltip-text-y-value,
.apexcharts-tooltip-text-z-label,
.apexcharts-tooltip-text-z-value,
.apexcharts-tooltip-text-goals-label,
.apexcharts-tooltip-text-goals-value,
.apexcharts-tooltip-series-group,
.apexcharts-tooltip-series-group span {
  color: var(--text) !important;
}

.apexcharts-tooltip-text-y-label,
.apexcharts-tooltip-text-z-label,
.apexcharts-tooltip-text-goals-label {
  color: var(--text-soft) !important;
}

.apexcharts-xaxistooltip:before,
.apexcharts-xaxistooltip:after,
.apexcharts-yaxistooltip:before,
.apexcharts-yaxistooltip:after {
  border-bottom-color: rgba(12, 17, 27, 0.96) !important;
}

.sensor-tooltip {
  display: grid;
  gap: 0.52rem;
  min-width: 0;
}

.sensor-tooltip--floating {
  position: absolute;
  z-index: 8;
  pointer-events: none;
  width: min(236px, calc(100% - 16px));
  padding: 0.72rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: rgba(12, 17, 27, 0.96);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(12px);
}

.sensor-tooltip--floating > .sensor-tooltip {
  min-width: 0;
}

.sensor-tooltip__title {
  padding-bottom: 0.45rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.3;
}

.sensor-tooltip__row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: start;
}

.sensor-tooltip__marker {
  width: 0.72rem;
  height: 0.72rem;
  margin-top: 0.2rem;
  border-radius: 999px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.sensor-tooltip__content {
  display: grid;
  gap: 0.12rem;
  min-width: 0;
}

.sensor-tooltip__topline {
  display: flex;
  justify-content: space-between;
  gap: 0.85rem;
  align-items: baseline;
}

.sensor-tooltip__name {
  color: var(--text);
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sensor-tooltip__value {
  color: var(--text);
  font-size: 0.92rem;
  white-space: nowrap;
}

.sensor-tooltip__meta {
  color: var(--text-soft);
  font-size: 0.72rem;
  line-height: 1.25;
}

.gauge-grid {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.gauge-tile {
  padding: 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
}

.gauge-chart {
  position: relative;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}

.gauge-chart__svg {
  display: block;
  width: 100%;
  height: auto;
}

.gauge-chart__value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-top: 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  pointer-events: none;
}

.gauge-tile__label {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  color: var(--text);
}

.gauge-tile__timestamp {
  margin: 0.45rem 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
}

.empty-state p {
  max-width: 48ch;
  margin: 0.65rem auto 1rem;
  color: var(--text-soft);
  line-height: 1.6;
}

.form-layout {
  display: grid;
}

.form-panel {
  display: grid;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.45rem;
}

.field label {
  font-weight: 600;
}

.field__label {
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 3rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(7, 12, 19, 0.65);
  color: var(--text);
}

select[multiple] {
  min-height: 12rem;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
.button:focus,
.chip:focus {
  outline: 2px solid rgba(83, 199, 168, 0.45);
  outline-offset: 2px;
}

.field-grid {
  grid-template-columns: 1fr;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text);
}

.checkbox input[type="checkbox"] {
  width: 1.1rem;
  min-width: 1.1rem;
  min-height: 1.1rem;
  height: 1.1rem;
  margin: 0;
  padding: 0;
  accent-color: var(--brand);
}

.dashboard-checklist {
  display: grid;
  gap: 0.75rem;
}

.tag-alias-list {
  display: grid;
  gap: 0.8rem;
}

.tag-alias-item {
  display: grid;
  gap: 0.55rem;
  padding: 0.9rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(7, 12, 19, 0.58);
}

.tag-alias-item__value {
  font-weight: 700;
  color: var(--text);
  word-break: break-all;
}

.dashboard-checklist__item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(7, 12, 19, 0.58);
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.dashboard-checklist__item:hover {
  border-color: rgba(83, 199, 168, 0.3);
  background: rgba(16, 25, 38, 0.92);
}

.dashboard-checklist__item input[type="checkbox"] {
  width: 1.2rem;
  min-width: 1.2rem;
  min-height: 1.2rem;
  height: 1.2rem;
  margin: 0;
  accent-color: var(--brand);
}

.dashboard-checklist__name {
  font-weight: 600;
}

.dashboard-checklist__item:has(input:checked) {
  border-color: rgba(83, 199, 168, 0.45);
  background: rgba(83, 199, 168, 0.12);
}

.chip.is-active {
  background: rgba(83, 199, 168, 0.16);
  border-color: rgba(83, 199, 168, 0.35);
  color: #91f0d5;
}

.widget-feedback[data-state="error"] {
  color: #ffb4b4;
}

.widget-feedback[data-state="muted"] {
  color: var(--text-muted);
}

@media (min-width: 720px) {
  body {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }

  .hero {
    flex-direction: row;
    align-items: end;
    justify-content: space-between;
  }

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

  .history-form {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: end;
  }
}

@media (min-width: 980px) {
  .widget-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .widget-card[data-widget-type="line_chart"] {
    grid-column: 1 / -1;
  }
}
