:root {
  --bg: #e7edf3;
  --panel: #f7f9fc;
  --panel-head: #eef3f8;
  --border: #c3d0dc;
  --border-strong: #9aafc0;
  --text: #1c2a38;
  --muted: #5b6b7c;
  --accent: #1a6f9a;
  --accent-soft: #d7ebf5;
  --ok: #1f9d64;
  --danger: #c44536;
  --input: #ffffff;
  --nav: #14324d;
  --nav-text: #d7e6f2;
  --shadow: 0 1px 2px rgba(20, 50, 77, 0.06);
  --radius: 8px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
}

html {
  height: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-width: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
}

.app-shell {
  background:
    radial-gradient(1200px 400px at 0% 0%, rgba(26, 111, 154, 0.08), transparent 55%),
    var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  background: var(--nav);
  border-bottom: 1px solid #0c2438;
  min-height: 58px;
}

.app-nav-brand {
  display: flex;
  align-items: center;
  padding: 0 20px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  text-decoration: none;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}

.app-nav-brand:hover {
  color: #fff;
}

.app-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  flex: 0 0 auto;
  padding: 8px 14px 7px;
  color: var(--nav-text);
  text-decoration: none;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 12px;
  gap: 3px;
  white-space: nowrap;
}

.app-nav-item i {
  font-size: 18px;
  line-height: 1;
}

.app-nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.app-nav-item.active {
  background: #1a6f9a;
  color: #fff;
  font-weight: 600;
  box-shadow: inset 0 -3px 0 #7ad0f0;
}

.app-nav-item.logout {
  background: transparent;
  color: #f3c4be;
  border-right: 0;
  min-width: 88px;
  margin-left: 0;
}

.app-nav-item.logout:hover {
  background: var(--danger);
  color: #fff;
}

.app-nav-end {
  display: flex;
  align-items: stretch;
  margin-left: auto;
}

.app-user {
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 12px;
  color: #9fb6c9;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}

.app-main {
  padding: clamp(8px, 1.2vw, 16px) clamp(8px, 1.4vw, 18px) 20px;
  min-width: 0;
  max-width: 100%;
}

.page-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.lv-box {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius);
  padding: 0 14px 14px;
  position: relative;
  height: auto;
  min-width: 0;
  box-shadow: var(--shadow);
}

.lv-box > .lv-legend {
  position: static;
  display: block;
  margin: 0 -14px 12px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #f4f8fb 0%, #eef3f8 100%);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: 13px;
  font-weight: 700;
  color: #16324a;
  letter-spacing: 0.02em;
}

.lv-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
}

.lv-label {
  min-width: 72px;
  color: var(--muted);
  white-space: nowrap;
  text-align: left;
}

.field-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  margin-bottom: 10px;
}

.field-stack .lv-label {
  min-width: 0;
  width: 100%;
  text-align: left;
}

.field-stack .lv-textarea,
.field-stack .lv-input,
.field-stack .lv-select {
  width: 100%;
}

.lv-input,
.lv-select,
.lv-textarea {
  background: var(--input);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  height: 30px;
  padding: 0 8px;
  font-size: 12px;
  line-height: 28px;
  color: var(--text);
}

.lv-input:focus,
.lv-select:focus,
.lv-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(26, 111, 154, 0.18);
}

.lv-input.num {
  width: min(88px, 100%);
  min-width: 64px;
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: #12324a;
  font-weight: 600;
}

.lv-input.num-wide {
  width: min(110px, 100%);
}

.lv-input.grow,
.lv-select.grow,
.lv-textarea.grow {
  flex: 1;
  width: 100%;
}

.lv-select.meter-name {
  color: var(--danger);
  font-weight: 700;
}

.lv-select-wide {
  min-width: min(220px, 100%);
  width: 100%;
  max-width: 320px;
}

.lv-textarea {
  height: auto;
  min-height: 72px;
  padding: 8px;
  resize: vertical;
}

.lv-check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  margin-right: 10px;
  color: var(--muted);
}

.lv-btn {
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  border-radius: 5px;
  padding: 5px 12px;
  font-size: 13px;
  line-height: 1.3;
}

.lv-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.lv-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.lv-btn-primary:hover {
  background: #155d82;
  color: #fff;
}

.lv-btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: #9d372c;
}

.lv-btn-danger:hover {
  background: #a8372c;
  color: #fff;
}

.lv-btn-lg {
  min-width: 120px;
  padding: 8px 18px;
  font-size: 14px;
}

.lv-warn {
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
}

.led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid #146b44;
  background: var(--ok);
  box-shadow: 0 0 6px rgba(31, 157, 100, 0.7);
  flex-shrink: 0;
}

.led.bad {
  background: var(--danger);
  border-color: #8d2e26;
  box-shadow: 0 0 6px rgba(196, 69, 54, 0.7);
}

.sampling-top,
.sampling-mid,
.sampling-bottom {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  min-width: 0;
}

.sampling-top {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.1fr) minmax(0, 2.2fr);
}

.sampling-mid {
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.6fr) minmax(0, 0.9fr);
}

.sampling-bottom {
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  min-height: clamp(280px, 42vh, 520px);
}

.agc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px 10px;
}

.gas-sampling-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px 10px;
}

.gas-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}

.gas-item label {
  min-width: 58px;
  margin: 0;
  color: var(--muted);
}

.meter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 6px 14px;
}

.meter-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  min-width: 0;
}

.channel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
}

.charts-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  height: 100%;
  min-height: clamp(280px, 42vh, 520px);
  min-width: 0;
}

.chart-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px 4px;
  display: flex;
  flex-direction: column;
  min-height: 160px;
  min-width: 0;
}

.chart-box h3 {
  font-size: 12px;
  margin: 0 0 2px;
  text-align: center;
  font-weight: 700;
  color: var(--accent);
}

.chart-box canvas {
  flex: 1;
  min-height: 120px;
  width: 100% !important;
}

.data-table-wrap {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  height: 100%;
  min-width: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table-wrap table {
  font-size: 11px;
  margin: 0;
  white-space: nowrap;
  width: 100%;
}

.data-table-wrap thead th {
  position: sticky;
  top: 0;
  background: #eef4f8;
  color: var(--muted);
  font-weight: 700;
  z-index: 1;
}

.data-table-tall {
  height: min(520px, 70vh);
  min-height: 280px;
}

.data-table-mid {
  height: auto;
  min-height: 120px;
  max-height: min(320px, 40vh);
}

.sampling-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.settings-page {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 90px);
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1.05fr) minmax(300px, 1.2fr) minmax(260px, 0.9fr);
  gap: 14px;
  align-items: start;
}

.settings-left,
.settings-center,
.settings-right {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.gas-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
}

.gas-set-item {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(72px, 0.9fr);
  align-items: center;
  gap: 8px;
  font-size: 12px;
  min-width: 0;
  padding: 4px 6px;
  border-radius: 6px;
  background: #f6f9fb;
}

.gas-set-item span {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gas-set-item .lv-input {
  width: 100%;
}

.notice-warn {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #fff6e8;
  color: #8a5a12;
  font-size: 12px;
  line-height: 1.45;
}

.mode-pills {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 10px;
  padding: 3px;
  background: #eef3f8;
  border-radius: 999px;
}

.mode-pills .lv-check {
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
}

.mode-pills input:checked + span,
.mode-pills .lv-check:has(input:checked) {
  background: #fff;
  color: var(--accent);
  font-weight: 700;
  box-shadow: var(--shadow);
}

.comm-tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.comm-tab {
  padding: 5px 14px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-bottom: 0;
  background: #e4ebf1;
  color: var(--muted);
  cursor: pointer;
  margin-right: 4px;
  border-radius: 6px 6px 0 0;
}

.comm-tab.active {
  background: #fff;
  color: var(--accent);
  font-weight: 700;
}

.comm-pane {
  display: none;
}

.comm-pane.active {
  display: block;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: auto;
  padding: 12px 0 4px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(231, 237, 243, 0), var(--bg) 28%);
}

.user-mini-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.user-mini-form .lv-select,
.user-mini-form .lv-input {
  width: 100%;
}

.user-mini-form > .lv-select {
  grid-column: 1 / -1;
}

.user-mini-actions {
  display: flex;
  gap: 8px;
  grid-column: 1 / -1;
  justify-content: flex-end;
}

.stat-card {
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.stat-label {
  color: var(--muted);
  font-size: 0.875rem;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    radial-gradient(900px 500px at 20% 10%, rgba(122, 208, 240, 0.18), transparent 50%),
    linear-gradient(160deg, #10283d 0%, #1a6f9a 58%, #0f3a52 100%);
}

.login-card {
  width: min(420px, 100%);
  border: 0;
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(8, 24, 40, 0.28);
}

.badge-source {
  font-weight: 500;
}

.table td, .table th {
  vertical-align: middle;
}

.flash-stack {
  margin-bottom: 10px;
}

.flash-stack .alert {
  border-radius: 6px;
  border: 0;
  box-shadow: var(--shadow);
}

.container .lv-box,
.container .card {
  border-color: var(--border);
  border-radius: var(--radius);
}

.page-toolbar form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

@media (max-width: 1599px) {
  .sampling-top {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .sampling-top > :last-child {
    grid-column: 1 / -1;
  }
  .settings-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .settings-right {
    grid-column: 1 / -1;
  }
}

@media (max-width: 1199px) {
  .sampling-top,
  .sampling-mid,
  .sampling-bottom,
  .settings-layout {
    grid-template-columns: 1fr;
  }
  .sampling-top > :last-child {
    grid-column: auto;
  }
  .charts-grid {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    min-height: 0;
  }
  .chart-box {
    min-height: 220px;
  }
  .sampling-bottom {
    min-height: 0;
  }
  .data-table-wrap {
    min-height: 240px;
  }
}

@media (max-width: 767px) {
  .app-nav-brand {
    width: 100%;
    border-right: 0;
    padding: 10px 14px;
  }
  .app-nav-end {
    width: 100%;
    margin-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }
  .app-nav-item {
    flex: 1 1 auto;
    min-width: 72px;
  }
  .app-user {
    flex: 1;
    border-left: 0;
  }
  .lv-label {
    min-width: 56px;
  }
  .agc-grid,
  .channel-grid,
  .meter-grid {
    grid-template-columns: 1fr;
  }
  .lv-btn-lg {
    min-width: 0;
    flex: 1 1 140px;
  }
  .gas-settings {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1920px) {
  .app-main {
    max-width: 1920px;
    margin: 0 auto;
  }
}
