:root {
  --bg: #f3efe7;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-strong: #ffffff;
  --text: #1f2521;
  --muted: #5f675f;
  --line: rgba(31, 37, 33, 0.1);
  --brand: #155e63;
  --brand-soft: #d8efec;
  --ok: #1f7a4f;
  --warn: #b36a18;
  --shadow: 0 14px 40px rgba(22, 34, 34, 0.08);
  --radius: 20px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(21, 94, 99, 0.12), transparent 28%),
    radial-gradient(circle at top right, rgba(179, 106, 24, 0.10), transparent 22%),
    linear-gradient(180deg, #f7f4ed 0%, #efe8dc 100%);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}
a { color: inherit; text-decoration: none; }
.container { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }
.topbar {
  position: sticky;
  top: 0;
  backdrop-filter: blur(12px);
  background: rgba(243, 239, 231, 0.82);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}
.topbar-inner {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-weight: 800; letter-spacing: 0.08em; }
.nav { display: flex; gap: 18px; align-items: center; }
.link-button {
  border: 0;
  padding: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
  color: inherit;
}
.hero, .panel, .auth-card, .metric-card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.hero {
  margin: 28px 0;
  padding: 42px;
  min-height: 360px;
  display: grid;
  place-items: center start;
}
.hero h1, .page-head h1 { font-size: clamp(2rem, 4vw, 3.5rem); line-height: 0.98; margin: 0 0 12px; }
.lead { color: var(--muted); max-width: 70ch; }
.lead.compact { margin-top: 0; margin-bottom: 18px; max-width: 88ch; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.18em; font-size: 0.8rem; color: var(--brand); font-weight: 700; }
.actions, .status-line { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 700;
}
.button.primary { background: var(--brand); color: white; }
.button.secondary { background: var(--brand-soft); color: var(--brand); }
.button.danger { background: #8e2618; color: white; }
.button.small { min-height: 36px; padding: 0 14px; font-size: 0.92rem; }
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: end; margin: 28px 0 20px; }
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.metric-card { padding: 18px; }
.metric-label { display: block; color: var(--muted); margin-bottom: 10px; }
.metric-value { font-size: 2rem; line-height: 1; }
.metric-value.small { font-size: 1.15rem; line-height: 1.2; }
.panel { padding: 20px; margin-bottom: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.range-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.range-button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.range-button.active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}
.device-list { display: grid; gap: 12px; }
.device-row {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.55);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}
.device-meta { display: flex; flex-direction: column; align-items: end; gap: 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}
.badge.ok { background: rgba(31, 122, 79, 0.12); color: var(--ok); }
.badge.warn { background: rgba(179, 106, 24, 0.12); color: var(--warn); }
.muted { color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.auth-card {
  width: min(420px, 100%);
  margin: 48px auto;
  padding: 28px;
}
.stack { display: grid; gap: 16px; }
label span { display: block; margin-bottom: 8px; font-weight: 600; }
input {
  width: 100%;
  min-height: 46px;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 0 14px;
  font: inherit;
}
.flash-stack { margin: 20px 0; display: grid; gap: 10px; }
.flash { padding: 14px 16px; border-radius: 14px; }
.flash-danger { background: rgba(179, 37, 24, 0.12); color: #8e2618; }
.flash-success { background: rgba(31, 122, 79, 0.12); color: #1f7a4f; }
.chart-stack {
  display: grid;
  gap: 18px;
}
.chart-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.42);
}
.chart-card h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}
.chart-card canvas {
  width: 100%;
  height: 240px !important;
}
.empty-state { color: var(--muted); padding: 14px 0; }
.register-form {
  display: grid;
  grid-template-columns: 1.2fr 1fr auto;
  gap: 14px;
  align-items: end;
}
.inline-edit-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.inline-edit-form input {
  min-width: 180px;
}

@media (max-width: 720px) {
  .page-head, .device-row { flex-direction: column; align-items: start; }
  .device-meta { align-items: start; }
  .hero { padding: 28px; min-height: 280px; }
  .register-form { grid-template-columns: 1fr; }
}
