:root {
  --bg: #f6faf7;
  --surface: #ffffff;
  --surface-soft: #eef8f0;
  --sidebar: #f8fcf9;
  --text: #142218;
  --muted: #69776d;
  --brand: #1f8f49;
  --brand-dark: #126b35;
  --brand-soft: #dff4e5;
  --ok: #138a3d;
  --bad: #c7392f;
  --warn: #a96700;
  --chip-bg-ok: #e4f6ea;
  --chip-bg-bad: #fde9e7;
  --border: #dce8df;
  --shadow: 0 12px 28px rgba(20, 60, 35, 0.08);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  z-index: 20;
}

.brand {
  display: grid;
  grid-template-columns: 44px 1fr;
  column-gap: 12px;
  align-items: center;
}

.logo {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.logo-img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

.name {
  color: var(--brand-dark);
  font-weight: 800;
  line-height: 1.15;
}

.subname {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.navlinks {
  display: grid;
  gap: 8px;
}

.navlinks a {
  color: var(--text);
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
  font-weight: 700;
}

.navlinks a:hover,
.navlinks a.active {
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.app-shell {
  min-height: 100vh;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.page-kicker {
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.page-title {
  margin: 2px 0 0;
  font-size: 24px;
  line-height: 1.2;
}

.actions,
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sensor-select,
.logout {
  min-height: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  outline: none;
  font: inherit;
}

.sensor-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 143, 73, 0.12);
}

.logout {
  text-decoration: none;
  color: var(--brand-dark);
  font-weight: 700;
}

.container {
  width: 100%;
  max-width: 1220px;
  margin: 0 auto;
  padding: 24px 28px 36px;
}

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

.section-head h1 {
  margin: 0;
  font-size: 22px;
}

.refresh-status {
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.card.full { grid-column: 1 / -1; margin-top: 16px; }
.card.warn { border-color: #f2b8b5; background: #fffaf9; }

.card-head {
  min-height: 34px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-weight: 800;
}

.target,
.muted {
  color: var(--muted);
}

.target {
  font-size: 12px;
  white-space: nowrap;
}

.card.full .target {
  white-space: normal;
  text-align: right;
}

.metric {
  font-size: 36px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  margin-top: 8px;
}

.chip.ok { background: var(--chip-bg-ok); color: var(--ok); }
.chip.bad { background: var(--chip-bg-bad); color: var(--bad); }
.chip.warning { background: #fff3d8; color: #a96700; }
.chip.critical { background: var(--chip-bg-bad); color: var(--bad); }

.battery-help {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.list { margin: 0; padding-left: 18px; }

.table-card {
  overflow: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  background: var(--surface-soft);
}

tr:last-child td { border-bottom: 0; }

.alert-row-high td {
  background: #fff0f0;
  border-bottom-color: #f6c7c7;
}

.alert-row-low td {
  background: #fff7e8;
  border-bottom-color: #f0d5a8;
}

.alert-level {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-right: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.alert-level.alert-row-high {
  background: #e53935;
  color: #fff;
}

.alert-level.alert-row-low {
  background: #f2991f;
  color: #241600;
}

.alert-suggestion {
  margin-top: 5px;
  color: var(--text);
  font-weight: 700;
}

.footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  color: var(--muted);
  background: var(--surface);
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

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

.metric-block {
  min-width: 0;
}

.metric-block .metric-small {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.15;
}

.metric-block .label {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.target-inline {
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
  margin-top: 5px;
}

.warning-text {
  color: var(--warn);
}

.threshold-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.threshold-card {
  box-shadow: none;
}

.threshold-ok {
  border-color: #b7e5c4;
  background: #f3fbf6;
}

.threshold-warning {
  border-color: #f2d09b;
  background: #fff9ec;
}

.threshold-critical {
  border-color: #f2b8b5;
  background: #fff5f4;
}

.battery-cards {
  margin-bottom: 16px;
}

.battery-card.battery-ok {
  border-color: #b7e5c4;
}

.battery-card.battery-warning {
  border-color: #f2d09b;
}

.battery-card.battery-critical {
  border-color: #f2b8b5;
}

.battery-row-ok td {
  background: #f8fdf9;
}

.battery-row-warning td {
  background: #fff8e8;
  border-bottom-color: #f0d5a8;
}

.battery-row-critical td {
  background: #fff0f0;
  border-bottom-color: #f6c7c7;
}

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 800;
  border: 1px solid var(--brand);
  cursor: pointer;
}

.btn:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--surface); color: var(--brand-dark); }
.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.pagination-bar {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pagination-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.page-numbers {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.page-number {
  min-width: 38px;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--brand-dark);
  font-weight: 800;
  cursor: pointer;
}

.page-number:hover,
.page-number.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.page-gap {
  color: var(--muted);
  padding: 0 2px;
  font-weight: 800;
}

.info-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  gap: 24px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 18px;
}

.info-copy h1 {
  margin: 0 0 12px;
  font-size: 34px;
  line-height: 1.15;
}

.info-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.eyebrow {
  color: var(--brand) !important;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 8px !important;
}

.info-image {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--surface-soft);
}

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

.info-card h2 {
  margin: 0 0 10px;
  font-size: 20px;
}

.info-card p,
.info-list {
  color: var(--muted);
  line-height: 1.65;
}

.info-list {
  margin: 10px 0 0;
  padding-left: 18px;
}

.threshold-table {
  min-width: 0;
}

canvas {
  width: 100% !important;
  height: 280px !important;
  max-height: 280px;
}

.chart-status {
  min-height: 24px;
  margin: 4px 0 10px;
}

.compact-table {
  box-shadow: none;
}

.compact-table table {
  min-width: 640px;
}

@media (max-width: 980px) {
  .sidebar {
    position: static;
    width: 100%;
    padding: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

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

  .navlinks a {
    text-align: center;
  }

  .app-shell {
    margin-left: 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .container {
    padding: 18px 16px 28px;
  }

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

  .metric-row {
    grid-template-columns: 1fr;
  }

  .pagination-bar,
  .pagination-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .threshold-grid,
  .info-hero,
  .info-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .navlinks {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .sensor-select,
  .logout,
  .btn {
    width: 100%;
  }

  .actions,
  .controls {
    width: 100%;
  }
}
