:root {
  --bg: #f4f9ff;
  --panel: #ffffff;
  --panel-soft: #eef7ff;
  --line: #d7e8f8;
  --line-strong: #bad7ef;
  --text: #16324f;
  --muted: #6b8298;
  --blue: #1d8fe6;
  --blue-dark: #0b6db6;
  --cyan: #47c4e8;
  --green: #1ca97a;
  --yellow: #d8931d;
  --red: #df4b5f;
  --shadow: 0 18px 50px rgba(29, 102, 164, .12);
  color-scheme: light;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: .04em;
}

.brand strong {
  display: block;
  font-size: 16px;
}

.brand span,
.topbar p,
.panel-head span {
  color: var(--muted);
}

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

.nav-item,
.logout {
  height: 42px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: var(--panel-soft);
  color: var(--blue-dark);
}

.logout {
  margin-top: auto;
  border: 1px solid var(--line);
}

.workspace {
  padding: 26px;
  min-width: 0;
}

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

.topbar h1 {
  margin: 0 0 5px;
  font-size: 26px;
  letter-spacing: 0;
}

.topbar p {
  margin: 0;
}

.toolbar {
  display: flex;
  gap: 10px;
}

.toolbar select {
  width: 310px;
}

.toolbar button,
.command-form button,
.login-form button {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  min-height: 40px;
  padding: 0 16px;
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 14px;
}

.metric,
.panel,
.object-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span {
  color: var(--muted);
  display: block;
  margin-bottom: 10px;
}

.metric strong {
  font-size: 30px;
  line-height: 1;
}

.metric.warn strong {
  color: var(--yellow);
}

.metric.danger strong {
  color: var(--red);
}

.panel {
  overflow: hidden;
}

.panel-head {
  min-height: 62px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
}

.panel-head input {
  height: 38px;
  min-width: 300px;
  padding: 0 12px;
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  background: #f8fbff;
}

tbody tr:hover {
  background: #f8fbff;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--panel-soft);
  color: var(--blue-dark);
}

.badge.green {
  background: #e9f8f1;
  color: var(--green);
}

.badge.red {
  background: #fff0f2;
  color: var(--red);
}

.badge.yellow {
  background: #fff7e7;
  color: var(--yellow);
}

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

.cards-grid {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.object-card {
  padding: 16px;
}

.object-link {
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}

.object-link:hover {
  border-color: var(--blue);
  transform: translateY(-1px);
}

.object-card h3 {
  margin: 0 0 8px;
}

.object-card p {
  margin: 0 0 14px;
  color: var(--muted);
}

.object-card dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.object-card dt {
  color: var(--muted);
  font-size: 12px;
}

.object-card dd {
  margin: 3px 0 0;
  font-weight: 800;
}

.object-card button {
  margin-top: 14px;
  min-height: 34px;
  padding: 0 12px;
  background: #eef8ff;
  border-color: #cfe8fb;
  color: var(--blue-dark);
  font-weight: 700;
}

.split-panel {
  padding-bottom: 10px;
}

#readingsChart {
  width: 100%;
  display: block;
  padding: 10px 18px 18px;
}

.command-form {
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(220px, 1.4fr) 160px 140px auto;
  gap: 12px;
  align-items: end;
}

.command-form label,
.login-form label {
  display: grid;
  gap: 6px;
}

.command-form span,
.login-form span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.command-form input,
.command-form select,
.report-filters input,
.report-filters select,
.login-form input {
  height: 40px;
  padding: 0 10px;
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.report-filters {
  display: grid;
  grid-template-columns: minmax(240px, 2fr) repeat(3, minmax(120px, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

.report-filters label,
.filter-groups label {
  display: grid;
  gap: 6px;
}

.report-filters span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-groups {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 16px;
}

.filter-groups fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.filter-groups legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.filter-groups label {
  grid-auto-flow: column;
  align-items: center;
  color: var(--text);
  font-size: 13px;
}

.filter-groups input {
  width: 16px;
  height: 16px;
}

.totals-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.totals-strip span {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: #eef8ff;
  border: 1px solid #cfe8fb;
  border-radius: 8px;
  color: var(--blue-dark);
  font-size: 13px;
}

.login-page {
  background:
    radial-gradient(circle at 20% 20%, rgba(71, 196, 232, .24), transparent 32%),
    linear-gradient(135deg, #f7fbff, #eaf6ff);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 30px;
}

.login-panel .brand-mark {
  margin-bottom: 18px;
}

.login-panel h1 {
  margin: 0 0 6px;
  font-size: 30px;
}

.login-panel p {
  margin: 0 0 22px;
  color: var(--muted);
}

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

.alert {
  padding: 10px 12px;
  margin-bottom: 16px;
  border: 1px solid #ffd0d7;
  background: #fff0f2;
  color: var(--red);
  border-radius: 8px;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow: auto;
  }

  .nav {
    display: flex;
  }

  .logout {
    margin-top: 0;
    margin-left: auto;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .command-form {
    grid-template-columns: 1fr 1fr;
  }

  .report-filters,
  .filter-groups {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  .sidebar {
    flex-wrap: wrap;
  }

  .toolbar select,
  .panel-head input {
    min-width: 0;
    width: 100%;
  }

  .metric-grid,
  .command-form,
  .report-filters,
  .filter-groups {
    grid-template-columns: 1fr;
  }
}

@media print {
  .sidebar,
  .topbar,
  .view:not(#reports),
  #reports > .panel:first-child {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .workspace {
    padding: 0;
  }

  .view {
    display: block !important;
  }

  .panel {
    border: 0;
    box-shadow: none;
  }
}
