:root {
  --brand-container: #001c2c;
  --brand-outline: #023751;
  --brand-blue: #009ad8;
  --brand-green: #8df604;
  --brand-text: #f7fbff;
  --brand-muted: rgba(247, 251, 255, 0.68);
  --brand-panel: rgba(0, 28, 44, 0.78);
  --brand-panel-strong: rgba(0, 28, 44, 0.92);
  --brand-border: rgba(0, 154, 216, 0.26);
  --brand-glow: rgba(141, 246, 4, 0.18);
}

html {
  color-scheme: dark;
  background-color: var(--brand-container);
}

html::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background: var(--brand-container);
}

body {
  color: var(--brand-text) !important;
  background-color: var(--brand-container) !important;
  background:
    linear-gradient(180deg, rgba(0, 28, 44, 0.20), rgba(0, 28, 44, 0.82)),
    url("/assets/flosync-background.jpg") center / cover fixed no-repeat,
    var(--brand-container) !important;
}

.wrap,
body > .card:first-of-type,
#loginCard {
  animation: flosync-page-enter 180ms ease-out both;
  will-change: opacity;
}

html.page-transitioning .wrap,
html.page-transitioning body > .card:first-of-type,
html.page-transitioning #loginCard {
  animation: flosync-page-exit 140ms ease-in both;
  pointer-events: none;
}

@keyframes flosync-page-enter {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes flosync-page-exit {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wrap,
  body > .card:first-of-type,
  #loginCard,
  html.page-transitioning .wrap,
  html.page-transitioning body > .card:first-of-type,
  html.page-transitioning #loginCard {
    animation: none !important;
  }
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 80% 18%, rgba(141, 246, 4, 0.13), transparent 23%),
    radial-gradient(circle at 22% 12%, rgba(0, 154, 216, 0.18), transparent 24%);
  z-index: -1;
}

.topbar,
.top-box,
.card,
#loginCard,
.admin-choice {
  background: var(--brand-panel) !important;
  border: 1px solid var(--brand-border) !important;
  border-top: 1px solid rgba(141, 246, 4, 0.42) !important;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28) !important;
  backdrop-filter: blur(20px) saturate(130%) !important;
  -webkit-backdrop-filter: blur(20px) saturate(130%) !important;
}

.topbar { position: relative; }
#loginCard,
body > .card:first-of-type { position: relative; }

.topbar::after,
#loginCard::after,
body > .card:first-of-type::after { display: none !important; }

.topbar::before,
#loginCard::before,
body > .card:first-of-type::before {
  content: "";
  position: absolute;
  left: -1px;
  right: -1px;
  top: -1px;
  height: 5px;
  border-radius: inherit;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  background: linear-gradient(90deg, var(--brand-blue), var(--brand-green));
}

.brand-masthead {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 22px 0 34px;
}

.brand-logo {
  display: block;
  width: clamp(180px, 24vw, 360px);
  height: auto;
  object-fit: contain;
}

.brand-masthead .brand-logo {
  width: clamp(208px, 27.2vw, 416px);
}

.app-top-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: -6px 0 14px;
}

.account-device-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.account-chip {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  max-width: min(360px, 34vw);
  padding: 8px 12px;
  border: 1px solid rgba(0, 154, 216, 0.30);
  border-radius: 8px;
  background: rgba(0, 28, 44, 0.66);
  color: var(--brand-text);
  font-size: 13px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-device-select {
  width: min(280px, 28vw);
  min-height: 38px !important;
  padding: 8px 10px !important;
  border-radius: 8px !important;
  font-size: 13px !important;
}

.account-logout {
  min-height: 38px !important;
  padding: 8px 12px !important;
  border-radius: 8px !important;
  font-size: 13px !important;
}

.admin-account-actions .account-chip {
  grid-column: auto;
}

.compact-nav {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px;
  border: 1px solid rgba(0, 154, 216, 0.28);
  border-radius: 8px;
  background: rgba(0, 11, 20, 0.38);
}

.compact-nav button {
  min-height: 32px !important;
  padding: 7px 10px !important;
  border-radius: 6px !important;
  font-size: 12px !important;
  box-shadow: none !important;
}

.compact-nav button.active {
  background: rgba(141, 246, 4, 0.14) !important;
  color: #caff7a !important;
  border-color: rgba(141, 246, 4, 0.34) !important;
}

.top-control-grid.single-device {
  grid-template-columns: 1fr !important;
}

.brand-logo.auth {
  width: min(100%, 320px);
  margin-bottom: 18px;
  margin-left: auto;
  margin-right: auto;
}

.brand-footer-logo {
  display: block;
  width: min(220px, 46vw);
  height: auto;
  opacity: 0.74;
}

.footer-note,
.brand-copyright {
  display: flex;
  align-items: center;
}

.footer-note { display: none !important; }

.brand-copyright {
  max-width: 1280px;
  margin: 18px auto 0;
  padding: 0 28px 24px;
  gap: 12px;
  color: rgba(247, 251, 255, 0.62);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-copyright img {
  width: 132px;
  height: auto;
  opacity: 0.8;
}

.title,
h1,
h2,
.card-title,
.account-line,
.metric-value {
  color: var(--brand-text) !important;
}

.subtitle,
.small-info,
.footer-note,
label,
.metric-title,
.top-box-title,
.hint,
.muted {
  color: var(--brand-muted) !important;
}

input,
select,
textarea,
.csv-box,
.msg,
.record-control-item,
.serial-monitor {
  background: rgba(0, 28, 44, 0.66) !important;
  border-color: rgba(0, 154, 216, 0.32) !important;
  color: var(--brand-text) !important;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(141, 246, 4, 0.72) !important;
  box-shadow: 0 0 0 4px rgba(141, 246, 4, 0.12) !important;
  background: rgba(0, 28, 44, 0.88) !important;
}

button,
.record-control-item.action.green {
  background: rgba(0, 154, 216, 0.16) !important;
  color: #b7ecff !important;
  border-color: rgba(0, 154, 216, 0.36) !important;
  box-shadow: 0 10px 26px rgba(0, 154, 216, 0.10) !important;
}

button.secondary,
button.light,
.record-control-item.action.secondary {
  background: rgba(0, 28, 44, 0.72) !important;
  color: var(--brand-text) !important;
  border-color: rgba(0, 154, 216, 0.34) !important;
}

button.red,
.record-control-item.action.red {
  background: rgba(255, 96, 86, 0.14) !important;
  color: #ffb4ad !important;
  border-color: rgba(255, 96, 86, 0.32) !important;
}

button.orange,
.record-control-item.action.orange {
  background: rgba(255, 184, 77, 0.14) !important;
  color: #ffd18a !important;
  border-color: rgba(255, 184, 77, 0.32) !important;
}

button.ph-low {
  background: rgba(255, 87, 87, 0.14) !important;
  color: #ffb4ad !important;
  border-color: rgba(255, 87, 87, 0.34) !important;
}

button.ph-mid {
  background: rgba(141, 246, 4, 0.14) !important;
  color: #caff7a !important;
  border-color: rgba(141, 246, 4, 0.34) !important;
}

button.do-zero {
  background: rgba(141, 246, 4, 0.14) !important;
  color: #caff7a !important;
  border-color: rgba(141, 246, 4, 0.34) !important;
}

button.ph-high {
  background: rgba(0, 154, 216, 0.16) !important;
  color: #b7ecff !important;
  border-color: rgba(0, 154, 216, 0.36) !important;
}

.live-trends-panel {
  background:
    linear-gradient(180deg, rgba(0, 37, 58, 0.92), rgba(0, 22, 36, 0.86)) !important;
  border-color: rgba(0, 154, 216, 0.34) !important;
}

.trend-device-bar {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid rgba(0, 154, 216, 0.22);
  border-radius: 8px;
  background: rgba(0, 11, 20, 0.32);
}

#deviceTopBox .trend-device-bar {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 0;
}

.trend-range-control {
  background: rgba(0, 11, 20, 0.46) !important;
  border-color: rgba(0, 154, 216, 0.34) !important;
  box-shadow: inset 0 1px 0 rgba(247, 251, 255, 0.05) !important;
}

.trend-range-control button {
  background: rgba(0, 154, 216, 0.08) !important;
  color: rgba(247, 251, 255, 0.70) !important;
  border: 1px solid transparent !important;
  box-shadow: none !important;
}

.trend-range-control button:hover {
  background: rgba(0, 154, 216, 0.16) !important;
  color: var(--brand-text) !important;
}

.trend-range-control button.active {
  background: rgba(0, 154, 216, 0.28) !important;
  color: #ffffff !important;
  border-color: rgba(141, 246, 4, 0.34) !important;
  box-shadow: 0 0 18px rgba(0, 154, 216, 0.18) !important;
}

.trend-chart-card {
  min-height: 285px !important;
  background: rgba(0, 18, 30, 0.72) !important;
  border-color: rgba(0, 154, 216, 0.28) !important;
  box-shadow:
    inset 0 1px 0 rgba(247, 251, 255, 0.05),
    0 12px 30px rgba(0, 0, 0, 0.16) !important;
}

.trend-chart-box {
  padding: 8px;
  border: 1px solid rgba(0, 154, 216, 0.18);
  border-radius: 8px;
  background: rgba(0, 9, 18, 0.40);
}

.trend-current {
  color: #ffffff !important;
  text-shadow: 0 0 18px rgba(0, 154, 216, 0.22);
}

.control-flow-panel {
  display: none;
}

.trend-subvalue,
.trend-status {
  color: rgba(247, 251, 255, 0.62) !important;
}

.controls-panel {
  overflow: hidden;
}

.panel-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 !important;
  min-height: 0 !important;
  background: transparent !important;
  color: var(--brand-text) !important;
  border: 0 !important;
  text-align: left;
  box-shadow: none !important;
}

.panel-toggle:hover {
  transform: none !important;
  box-shadow: none !important;
}

.controls-content {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.control-section,
.calibration-panel {
  padding: 14px;
  border: 1px solid rgba(0, 154, 216, 0.22);
  border-radius: 8px;
  background: rgba(0, 11, 20, 0.30);
}

.control-section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.serial-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 10px;
  margin-bottom: 8px;
  color: rgba(247, 251, 255, 0.62);
  font-size: 12px;
}

.serial-toolbar label {
  min-width: 150px;
  margin: 0;
}

.serial-empty {
  color: rgba(247, 251, 255, 0.46);
}

.serial-entry {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 2px 0;
}

.serial-time {
  color: rgba(247, 251, 255, 0.46);
}

.serial-label {
  min-width: 44px;
  color: #b7ecff;
  font-weight: 700;
}

.serial-rx .serial-label,
.serial-status .serial-label {
  color: #caff7a;
}

.serial-error .serial-label {
  color: #ffb4ad;
}

.calibration-toggle {
  background: transparent !important;
  color: var(--brand-text) !important;
  border-color: transparent !important;
}

.calibration-toggle:hover {
  background: transparent !important;
}

.calibration-confirm {
  background: rgba(0, 28, 44, 0.92) !important;
  border-color: rgba(141, 246, 4, 0.32) !important;
}

.summary .card,
.table-wrap,
table,
th,
td {
  color: var(--brand-text) !important;
}

.summary .card {
  background: var(--brand-panel) !important;
  border-color: var(--brand-border) !important;
}

.summary .metric-title,
.summary .metric-value,
.table-wrap .muted,
.table-wrap strong,
.table-wrap select,
.table-wrap button {
  color: var(--brand-text) !important;
}

.table-wrap {
  background: rgba(0, 28, 44, 0.72) !important;
}

table {
  background: rgba(0, 28, 44, 0.58) !important;
}

th {
  background: rgba(0, 55, 81, 0.82) !important;
  color: rgba(247, 251, 255, 0.72) !important;
}

td {
  border-bottom-color: rgba(0, 154, 216, 0.18) !important;
  background: rgba(0, 28, 44, 0.42) !important;
}

.theme-toggle {
  display: none !important;
  background: rgba(0, 28, 44, 0.74) !important;
  color: var(--brand-text) !important;
  border-color: rgba(141, 246, 4, 0.36) !important;
}

.status-pill.on,
.msg.ok {
  background: rgba(141, 246, 4, 0.12) !important;
  color: #baff5a !important;
  border-color: rgba(141, 246, 4, 0.32) !important;
}

.msg.error,
.status-pill {
  background: rgba(255, 96, 86, 0.12) !important;
  color: #ffb4ad !important;
  border-color: rgba(255, 96, 86, 0.28) !important;
}

.metric-value {
  text-shadow: 0 0 18px rgba(0, 154, 216, 0.22);
}

a {
  color: #8df604 !important;
}

@media (max-width: 720px) {
  :root {
    --mobile-glass: rgba(3, 20, 32, 0.78);
    --mobile-glass-strong: rgba(4, 27, 43, 0.92);
    --mobile-hairline: rgba(247, 251, 255, 0.12);
    --mobile-shadow: 0 14px 34px rgba(0, 0, 0, 0.26);
  }

  *,
  *::before,
  *::after {
    box-sizing: border-box;
    max-width: 100%;
  }

  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    box-sizing: border-box !important;
    min-height: 100svh;
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
    background:
      linear-gradient(180deg, rgba(5, 31, 47, 0.98), rgba(0, 16, 27, 0.98)),
      url("/assets/flosync-background.jpg") center top / cover scroll no-repeat,
      var(--brand-container) !important;
    background-attachment: scroll !important;
    -webkit-font-smoothing: antialiased;
    text-rendering: geometricPrecision;
  }

  body::before {
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.07), transparent 18%),
      radial-gradient(circle at 86% 0%, rgba(141, 246, 4, 0.12), transparent 24%),
      radial-gradient(circle at 0% 20%, rgba(0, 154, 216, 0.16), transparent 30%);
  }

  body:has(> #loginCard),
  body:has(> .card:first-of-type) {
    align-items: stretch !important;
    justify-content: flex-start !important;
    padding: calc(24px + env(safe-area-inset-top, 0px)) 12px 12px !important;
  }

  .wrap {
    display: flex;
    flex-direction: column;
    width: 100% !important;
    max-width: 100% !important;
    padding: calc(34px + env(safe-area-inset-top, 0px)) 12px 18px !important;
  }

  .wrap > * {
    order: 10;
  }

  body > .card:first-of-type,
  #loginCard {
    box-sizing: border-box !important;
    justify-self: center !important;
    width: 100% !important;
    max-width: min(440px, calc(100vw - 24px)) !important;
    padding: 20px !important;
  }

  .brand-logo {
    width: min(210px, 58vw);
  }

  .brand-masthead {
    order: 1;
    padding: 18px 0 22px;
  }

  .brand-masthead .brand-logo {
    width: min(190px, 50vw);
  }

  .brand-logo.auth {
    width: min(280px, 78vw);
    margin-bottom: 14px;
  }

  .brand-copyright {
    box-sizing: border-box !important;
    width: calc(100vw - 24px);
    max-width: 100%;
    justify-content: flex-start;
    align-items: flex-start;
    padding: 16px 12px 22px;
    text-align: left;
    flex-wrap: wrap;
    gap: 8px;
    line-height: 1.45;
  }

  .brand-copyright img {
    width: 118px;
  }

  .app-top-actions {
    order: 2;
    position: static;
    top: auto;
    z-index: 30;
    align-items: stretch;
    flex-direction: column;
    margin: 0 0 14px;
    gap: 8px;
    padding: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .account-device-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    width: 100%;
    padding: 8px;
    border: 1px solid var(--mobile-hairline);
    border-radius: 8px;
    background: rgba(247, 251, 255, 0.07);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  }

  .account-chip {
    min-height: 40px;
    max-width: 100%;
    justify-content: flex-start;
    grid-column: 1 / -1;
    padding: 9px 10px;
    border-color: rgba(255, 255, 255, 0.10);
    background: rgba(255, 255, 255, 0.07);
    font-size: 12px;
    letter-spacing: 0.01em;
  }

  .admin-account-actions .account-chip {
    grid-column: auto;
  }

  .top-device-select {
    width: 100%;
    min-height: 46px !important;
    font-size: 16px !important;
    background: rgba(255, 255, 255, 0.09) !important;
    border-color: rgba(255, 255, 255, 0.13) !important;
  }

  .account-logout {
    min-height: 46px !important;
    min-width: 82px;
    white-space: nowrap !important;
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.13) !important;
  }

  .compact-nav {
    --nav-corner-radius: clamp(22px, calc(14px + env(safe-area-inset-bottom, 0px)), 38px);
    position: fixed !important;
    left: max(12px, env(safe-area-inset-left, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    top: auto !important;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    z-index: 2147483000;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    width: auto;
    min-width: 0;
    gap: 6px;
    padding:
      8px 10px;
    margin: 0 !important;
    border-radius: var(--nav-corner-radius);
    border-width: 1px;
    border-color: rgba(255, 255, 255, 0.13);
    background: rgba(3, 18, 30, 0.88);
    box-shadow: 0 14px 38px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(22px) saturate(150%);
    -webkit-backdrop-filter: blur(22px) saturate(150%);
  }

  .compact-nav button {
    min-height: 48px !important;
    min-width: 0;
    width: 100%;
    padding: 8px 4px !important;
    border-radius: 8px !important;
    font-size: 10.5px !important;
    font-weight: 720 !important;
    overflow-wrap: anywhere;
    background: transparent !important;
    border-color: transparent !important;
    color: rgba(247, 251, 255, 0.68) !important;
    box-shadow: none !important;
    transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease, color 160ms ease !important;
  }

  .compact-nav button.hidden {
    display: none !important;
  }

  .app-top-actions > .compact-nav {
    flex: none !important;
  }

  .compact-nav button.active {
    background: rgba(0, 154, 216, 0.24) !important;
    border-color: rgba(141, 246, 4, 0.22) !important;
    color: #ffffff !important;
  }

  .compact-nav button:active,
  button:active,
  .record-control-item:active {
    transform: scale(0.985) !important;
  }

  .compact-nav button:nth-last-child(1):nth-child(odd) {
    grid-column: auto;
  }

  .theme-toggle {
    top: 12px;
    right: 12px;
    width: 40px !important;
    min-height: 40px !important;
  }

  .topbar,
  .top-box,
  .card,
  .admin-choice {
    padding: 16px !important;
    margin-bottom: 12px !important;
    border-radius: 8px !important;
    background: var(--mobile-glass) !important;
    border-color: var(--mobile-hairline) !important;
    box-shadow: var(--mobile-shadow) !important;
    backdrop-filter: blur(24px) saturate(145%) !important;
    -webkit-backdrop-filter: blur(24px) saturate(145%) !important;
  }

  .topbar::before,
  #loginCard::before,
  body > .card:first-of-type::before {
    height: 4px;
  }

  h1,
  .title {
    font-size: 30px !important;
    line-height: 1.12 !important;
    letter-spacing: 0 !important;
  }

  h2,
  .card-title {
    font-size: 18px !important;
    line-height: 1.2 !important;
    font-weight: 760 !important;
  }

  .account-line {
    font-size: 18px !important;
    overflow-wrap: anywhere;
  }

  .user-pill {
    width: 100%;
    text-align: left !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  .subtitle,
  .small-info,
  .muted,
  label {
    font-size: 12px !important;
    line-height: 1.5 !important;
  }

  input,
  select,
  textarea {
    min-height: 48px !important;
    font-size: 16px !important;
    max-width: 100% !important;
    border-radius: 8px !important;
    background: rgba(255, 255, 255, 0.075) !important;
    border-color: rgba(255, 255, 255, 0.13) !important;
  }

  button,
  .record-control-item {
    min-height: 48px !important;
    padding: 12px 12px !important;
    border-radius: 8px !important;
    font-size: 13px !important;
    line-height: 1.2 !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  button:disabled,
  .record-control-item:has(input:disabled) {
    opacity: 0.48 !important;
    filter: saturate(0.72);
  }

  .top-control-grid,
  .device-top-grid,
  .trend-device-bar,
  .trend-chart-grid,
  .valve-panel-grid,
  .control-grid,
  .calibration-row,
  .two-col,
  .factory-grid,
  .filter-row,
  .form-grid {
    grid-template-columns: 1fr !important;
  }

  .trend-header,
  .trend-card-top,
  .topline {
    align-items: stretch !important;
    flex-direction: column !important;
    gap: 10px !important;
  }

  .live-trends-panel {
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
  }

  .live-trends-panel .trend-header {
    padding: 16px;
    border: 1px solid var(--mobile-hairline);
    border-radius: 8px;
    background: var(--mobile-glass-strong);
    box-shadow: var(--mobile-shadow);
  }

  .trend-range-control {
    width: 100% !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    padding: 4px !important;
    border-radius: 8px !important;
    background: rgba(255, 255, 255, 0.07) !important;
  }

  .trend-range-control button {
    min-width: 0;
    min-height: 40px !important;
    padding-left: 6px !important;
    padding-right: 6px !important;
    border-radius: 8px !important;
  }

  .actions,
  .actions.three,
  .actions.four,
  .actions.control-actions,
  .calibration-actions,
  .calibration-actions.ph,
  .record-control-row,
  .toolbar {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .actions.one {
    grid-template-columns: 1fr !important;
  }

  .summary,
  .grid-4 {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .summary .card,
  .grid-4 > .card {
    min-height: 78px !important;
    padding: 14px !important;
  }

  .dashboard-summary-grid .status-card,
  .dashboard-control-grid .status-card {
    grid-column: 1 / -1;
  }

  .dashboard-summary-grid .sensor-card,
  .dashboard-control-grid .valve-card {
    min-height: 94px !important;
  }

  .dashboard-summary-grid .sensor-card .metric-value,
  .dashboard-control-grid .valve-card .metric-value {
    font-size: 22px !important;
  }

  .metric-title {
    font-size: 11px !important;
    line-height: 1.28 !important;
    margin-bottom: 6px !important;
    letter-spacing: 0.03em !important;
    text-transform: uppercase !important;
  }

  .metric-value {
    font-size: 23px !important;
    line-height: 1.14 !important;
    overflow-wrap: anywhere;
  }

  .trend-current {
    text-align: left !important;
    white-space: normal !important;
  }

  .trend-chart-card {
    min-height: 270px !important;
    gap: 11px !important;
    padding: 15px !important;
    margin-top: 10px;
    background: var(--mobile-glass-strong) !important;
    border-color: var(--mobile-hairline) !important;
  }

  .trend-chart-box {
    min-height: 178px !important;
    padding: 10px !important;
    border-color: rgba(255, 255, 255, 0.09);
    background: rgba(255, 255, 255, 0.045);
  }

  .trend-chart-box canvas,
  .chart-box canvas {
    max-width: 100% !important;
  }

  .record-control-item {
    height: auto !important;
    justify-content: center;
  }

  .record-control-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .record-control-item.record-all {
    grid-column: 1 / -1;
  }

  .record-control-item.record-sensor {
    grid-column: span 1;
  }

  .record-control-item.record-action {
    grid-column: span 2;
  }

  .record-control-item input,
  .calibration-confirm input {
    flex: 0 0 auto;
  }

  .calibration-toggle {
    align-items: flex-start !important;
  }

  .calibration-confirm {
    align-items: flex-start !important;
    line-height: 1.35 !important;
  }

  .serial-monitor,
  .csv-box {
    font-size: 11px !important;
    line-height: 1.5 !important;
  }

  .serial-monitor {
    max-height: 180px;
  }

  .serial-actions {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px !important;
  }

  .serial-toolbar {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .serial-empty,
  .csv-box:empty,
  td.muted,
  .table-wrap .muted {
    color: rgba(247, 251, 255, 0.58) !important;
  }

  .single-chart-card {
    height: 260px !important;
  }

  .chart-card {
    height: 270px !important;
  }

  .control-flow-panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 12px;
  }

  .flow-step {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 12px;
    border: 1px solid rgba(0, 154, 216, 0.22);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.055);
    box-shadow: inset 0 1px 0 rgba(247, 251, 255, 0.04);
  }

  .flow-step-index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    min-height: 30px;
    border-radius: 999px;
    background: rgba(0, 154, 216, 0.18);
    color: #b7ecff;
    font-size: 11px;
    font-weight: 800;
  }

  .flow-value {
    margin-top: 3px;
    color: var(--brand-text);
    font-size: 18.5px;
    line-height: 1.16;
    font-weight: 750;
    overflow-wrap: anywhere;
  }

  .flow-note {
    margin-top: 4px;
    color: var(--brand-muted);
    font-size: 11px;
    line-height: 1.35;
  }

  .csv-card {
    height: 220px !important;
  }

  .msg,
  .msg.ok,
  .msg.error,
  .msg.warn,
  .msg.show {
    margin-top: 10px !important;
    padding: 11px 12px !important;
    border-radius: 8px !important;
    font-size: 12px !important;
    line-height: 1.45 !important;
    overflow-wrap: anywhere;
    max-height: 220px;
    overflow-y: auto;
  }

  .msg.error {
    border-left: 3px solid rgba(255, 96, 86, 0.76) !important;
  }

  .msg.ok {
    border-left: 3px solid rgba(141, 246, 4, 0.72) !important;
  }

  .msg.warn {
    border-left: 3px solid rgba(255, 184, 77, 0.72) !important;
  }

  .table-wrap {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
    border-radius: 8px !important;
    box-shadow:
      inset -18px 0 18px -20px rgba(247, 251, 255, 0.72),
      0 18px 48px rgba(0, 0, 0, 0.24) !important;
  }

  .table-wrap::before {
    content: "Swipe sideways to view all columns";
    display: block;
    padding: 8px 10px;
    color: var(--brand-muted);
    font-size: 11px;
    line-height: 1.3;
    border-bottom: 1px solid rgba(0, 154, 216, 0.18);
    background: rgba(0, 11, 20, 0.24);
  }

  table {
    width: max-content !important;
    min-width: 760px !important;
    font-size: 12px !important;
  }

  th,
  td {
    padding: 10px 9px !important;
    line-height: 1.4 !important;
  }

  td {
    overflow-wrap: anywhere;
  }

  .generated-item {
    align-items: flex-start !important;
    flex-direction: column;
  }

  .generated-item .copy-btn,
  .table-wrap button,
  .factory-grid button,
  .form-grid button,
  .filter-row button {
    width: 100%;
  }

  .controls-panel,
  .control-section,
  .calibration-panel {
    background: var(--mobile-glass-strong) !important;
    border-color: var(--mobile-hairline) !important;
  }

  .controls-content {
    gap: 12px;
  }

  .panel-toggle {
    padding: 2px 0 !important;
  }

  .calibration-chevron {
    width: 32px;
    min-width: 32px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
  }

  #summaryPanel {
    display: grid;
    gap: 10px;
  }

  #noDeviceMsg {
    text-align: left;
  }

  #deviceTopBox .trend-device-bar {
    padding: 0;
    border: 0;
    background: transparent;
  }
}

@media (max-width: 360px) {
  .summary,
  .grid-4 {
    grid-template-columns: 1fr !important;
  }

  .actions,
  .actions.three,
  .actions.four,
  .actions.control-actions,
  .calibration-actions,
  .calibration-actions.ph,
  .serial-actions {
    grid-template-columns: 1fr !important;
  }
}
