:root {
  --bg: #edf4f6;
  --bg-deep: #dfeaec;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --panel-soft: #f4f8f9;
  --ink: #10242b;
  --muted: #687c84;
  --brand: #245b59;
  --brand-dark: #153c3b;
  --brand-ink: #0f3032;
  --cyan: #1597b8;
  --cyan-soft: #d7f2fb;
  --amber: #f1a72b;
  --coral: #d85f55;
  --success: #16855d;
  --line: #d1dee2;
  --line-strong: #a9c0c7;
  --input: #d6f0fb;
  --shadow: 0 18px 42px rgba(14, 40, 47, 0.14);
  --shadow-soft: 0 10px 28px rgba(14, 40, 47, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(21, 151, 184, 0.14), transparent 38%),
    linear-gradient(315deg, rgba(241, 167, 43, 0.12), transparent 34%),
    linear-gradient(180deg, #f8fbfc 0%, var(--bg) 42%, var(--bg-deep) 100%);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 15px;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(360px, 0.98fr) minmax(360px, 1.06fr) minmax(340px, 0.96fr);
  gap: 10px;
  align-items: stretch;
  padding: 8px 18px;
  background: rgba(239, 247, 248, 0.82);
  border-bottom: 1px solid rgba(160, 185, 191, 0.55);
  backdrop-filter: blur(18px);
  box-shadow: 0 12px 36px rgba(20, 46, 52, 0.08);
}

.company-branding {
  position: absolute;
  top: 2px;
  right: 135px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 22px rgba(20, 46, 52, 0.1);
  color: var(--brand-dark);
  font-size: 0.82rem;
  font-weight: 700;
  z-index: 1;
}

.company-branding img {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  object-fit: cover;
}

.connection-hint {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 2000;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 280px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(20, 50, 56, 0.08);
  box-shadow: 0 14px 32px rgba(20, 46, 52, 0.12);
}

.connection-hint.hidden {
  display: none;
}

.connection-hint img {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
}

.connection-hint-text {
  flex: 1;
  min-width: 0;
}

.connection-hint-text strong {
  display: block;
  color: var(--brand-dark);
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.connection-hint-text p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.hint-cancel {
  border: none;
  background: #e5eff0;
  color: var(--brand-ink);
  border-radius: 999px;
  width: 30px;
  height: 30px;
  line-height: 1;
  padding: 0;
  font-size: 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.hint-cancel:hover:not(:disabled) {
  background: #d1e5e7;
}

.connection-panel,
.status-panel,
.system-panel {
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid rgba(190, 207, 212, 0.92);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  position: relative;
}

.status-panel {
  position: relative;
}

.connection-panel {
  padding: 8px 11px;
}

.connection-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.connection-panel label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.mode-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(54px, 1fr));
  gap: 2px;
  min-width: 116px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #dfeaec;
}

.mode-toggle button {
  min-height: 24px;
  border-radius: 7px;
  padding: 0 9px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 950;
  box-shadow: none;
}

.mode-toggle button:hover:not(:disabled) {
  transform: none;
  box-shadow: none;
}

.mode-toggle button.active {
  background: linear-gradient(180deg, #2f6c69 0%, var(--brand) 100%);
  color: #fff;
}

.connection-controls {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  min-width: 0;
}

.connection-controls select {
  flex: 1 1 0;
  width: 0;
}

.connection-controls button {
  flex: 0 0 auto;
  min-width: 94px;
  min-height: 34px;
  border-radius: 9px;
  padding: 0 11px;
  font-size: 13px;
}

select,
input {
  min-width: 0;
  min-height: 40px;
  border-radius: 10px;
  color: var(--ink);
  outline: none;
}

select {
  width: 100%;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #eef6f7 100%);
  box-shadow: inset 0 -1px 0 rgba(20, 50, 56, 0.04);
}

input {
  width: 100%;
  padding: 0 14px;
  border: 2px solid #2098d3;
  background: linear-gradient(180deg, #d9f3ff 0%, var(--input) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

input:focus,
select:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 4px rgba(241, 167, 43, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  padding: 0 16px;
  font-weight: 850;
  color: var(--brand-ink);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease, opacity 0.14s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(20, 42, 45, 0.17);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.primary-button,
.icon-button {
  background: linear-gradient(180deg, #2f6c69 0%, var(--brand) 100%);
  color: #fff;
}

.primary-button:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  background: linear-gradient(180deg, #275f5c 0%, var(--brand-dark) 100%);
}

.ghost-button,
.utility-button {
  background: #e5eff0;
  color: var(--brand-ink);
}

.utility-button:hover:not(:disabled),
.ghost-button:hover:not(:disabled) {
  background: #d8e7e8;
}

.zero-button {
  min-width: 126px;
  background: linear-gradient(180deg, #25333a 0%, #172229 100%);
  color: #fff;
}

.zero-button.active {
  background: linear-gradient(180deg, #e27066 0%, var(--coral) 100%);
}

.status-panel {
  padding: 9px 14px;
}

.status-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  font-weight: 900;
}

.status-heading > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state-badge {
  flex: 0 0 auto;
  min-width: 82px;
  border-radius: 999px;
  padding: 5px 10px;
  text-align: center;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.state-badge.idle {
  background: #697c84;
}

.state-badge.running {
  background: var(--amber);
  color: #281b05;
}

.state-badge.finished {
  background: var(--success);
}

.state-badge.failed {
  background: var(--coral);
}

.status-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce8eb;
  box-shadow: inset 0 1px 3px rgba(14, 42, 49, 0.18);
}

.status-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #21a6c8 0%, #29a981 52%, var(--brand) 100%);
  transition: width 0.22s ease;
}

.status-panel p {
  margin: 7px 0 0;
  min-height: 16px;
  color: #57717a;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.system-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  min-width: 0;
  padding: 8px 12px;
}

.system-metrics {
  display: grid;
  grid-template-columns: minmax(122px, 0.42fr) minmax(220px, 1fr);
  gap: 8px;
  min-width: 0;
}

.baud-box,
.pic-id-box {
  display: grid;
  gap: 3px;
  min-width: 0;
  min-height: 46px;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f1f7f8 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92);
}

.baud-box span,
.pic-id-box span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 950;
  text-transform: uppercase;
}

.baud-box strong,
.pic-id-box strong {
  min-width: 0;
  color: var(--brand-dark);
  line-height: 1.12;
}

.baud-box strong {
  font-size: 18px;
}

.pic-id-box strong {
  display: block;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
}

.pic-id-box {
  gap: 1px;
  padding: 4px 8px;
}

.id-row {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.id-row span {
  font-size: 9px;
  line-height: 1;
  white-space: nowrap;
}

.id-row strong,
.id-row input {
  min-width: 0;
  width: 100%;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 11px;
  line-height: 1.05;
}

.id-row input {
  height: 15px;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0 4px;
  color: var(--brand-dark);
  background: rgba(255, 255, 255, 0.72);
  outline: none;
}

.id-row input:focus {
  border-color: #2098d3;
  background: #ffffff;
}

.id-row input.dirty {
  border-color: #d68c16;
  background: #fff7e8;
}

.table-wrap {
  overflow: auto;
  padding: 18px 24px 94px;
}

.parameter-table {
  width: 100%;
  display: grid;
  gap: 9px;
}

.parameter-row {
  display: grid;
  grid-template-columns: 84px repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.row-identifier {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 45px;
  border-radius: 10px;
  background: linear-gradient(180deg, #f5f8f9 0%, #e7eef0 100%);
  color: var(--brand-dark);
  font-weight: 900;
  letter-spacing: 0.04em;
  font-size: 0.86rem;
  border: 1px solid rgba(148, 171, 176, 0.82);
}

.parameter-field {
  display: grid;
  grid-template-columns: minmax(122px, 1.05fr) minmax(84px, 0.95fr);
  gap: 6px;
  align-items: stretch;
  min-width: 0;
}

.parameter-field span {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 45px;
  padding: 0 9px;
  border-radius: 10px;
  background: linear-gradient(180deg, #2e615f 0%, #255453 100%);
  color: #fff;
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.parameter-field.selected span {
  background: linear-gradient(180deg, #183d3d 0%, #113333 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.32), 0 0 0 3px rgba(21, 151, 184, 0.18);
}

.parameter-field input {
  min-height: 45px;
  font-weight: 800;
}

.parameter-field.parameter-readonly input {
  border-color: var(--line-strong);
  background: linear-gradient(180deg, #f5f8f9 0%, #e7eef0 100%);
  color: #526970;
  cursor: default;
}

.parameter-field.read-updated input {
  background: linear-gradient(180deg, #dff6ff 0%, #c8efff 100%);
  border-color: #2298d1;
}

.parameter-field.dirty input {
  background: linear-gradient(180deg, #fff0bf 0%, #ffe49a 100%);
  border-color: var(--amber);
}

.parameter-field.write-updated input {
  background: linear-gradient(180deg, #ffe39b 0%, #ffd06a 100%);
  border-color: #d08b12;
}

.parameter-field.zero-updated input {
  background: linear-gradient(180deg, #dcf6d2 0%, #c5efba 100%);
  border-color: #55a63d;
}

.actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  border-top: 1px solid rgba(184, 202, 207, 0.85);
  background: rgba(250, 253, 253, 0.88);
  backdrop-filter: blur(18px);
  box-shadow: 0 -16px 38px rgba(14, 40, 47, 0.13);
}

.selection-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 320px;
  max-width: min(520px, 38vw);
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 16px;
  background: var(--panel-solid);
  box-shadow: var(--shadow-soft);
}

.selection-pill span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.selection-pill strong {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.action-buttons {
  display: flex;
  gap: 11px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.action-buttons button {
  min-width: 108px;
  min-height: 48px;
}

@media (max-width: 1360px) {
  .topbar {
    grid-template-columns: minmax(340px, 0.96fr) minmax(340px, 1.04fr) minmax(330px, 1fr);
    padding-inline: 18px;
  }
}

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

  .parameter-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  .table-wrap,
  .actionbar {
    padding-inline: 12px;
  }

  .table-wrap {
    padding-top: 12px;
    padding-bottom: 160px;
  }

  .connection-controls button,
  .connection-controls select {
    flex-basis: calc(50% - 5px);
    width: auto;
  }

  .connection-controls {
    flex-wrap: wrap;
  }

  .system-metrics {
    grid-template-columns: 1fr;
  }

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

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

  .selection-pill {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .action-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .action-buttons button {
    min-width: 0;
  }
}
