:root {
  color-scheme: light;
  --ink: #15242d;
  --muted: #657080;
  --line: #dce4ee;
  --soft-line: #e7edf3;
  --panel: #ffffff;
  --canvas: #f6f8f5;
  --sidebar: #111c34;
  --sidebar-soft: #22304a;
  --blue: #00146f;
  --teal: #1aa46f;
  --green: #2eb872;
  --amber: #f5bf24;
  --red: #e04f5f;
  --radius: 8px;
  --shadow: 0 10px 28px rgba(28, 42, 68, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 14px/1.45 Inter, Segoe UI, Roboto, Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

input,
select {
  min-width: 0;
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  outline: 0;
  padding: 0 11px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.12;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(0, 20, 111, 0.95), rgba(47, 57, 72, 0.92)),
    var(--sidebar);
}

.login-card {
  width: min(100%, 410px);
  padding: 26px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.20);
}

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

.login-brand {
  margin-bottom: 26px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(245, 191, 36, 0.92) 0 34%, transparent 34%),
    linear-gradient(135deg, var(--blue), #273b86);
  color: #ffffff;
  font-weight: 900;
}

.login-brand strong,
.login-brand span,
.brand strong,
.brand span {
  display: block;
}

.login-brand span,
.brand span {
  color: var(--muted);
  font-size: 12px;
}

.login-copy {
  margin-bottom: 18px;
}

.login-copy p:not(.eyebrow) {
  margin-bottom: 0;
  color: var(--muted);
}

.login-card label {
  margin-bottom: 13px;
}

.remember-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 12px;
}

.remember-line input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  accent-color: var(--blue);
}

.login-error,
.form-message {
  min-height: 18px;
  margin: 0 0 10px;
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
}

.login-button {
  width: 100%;
}

.text-button {
  width: 100%;
  min-height: 36px;
  margin-top: 10px;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 900;
}

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

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 18px 14px;
  background: var(--sidebar);
  color: #dce7f7;
}

.brand {
  min-height: 44px;
}

.brand span {
  color: #aebbd1;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-item {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: #c5d2e6;
  text-decoration: none;
}

.nav-item svg {
  width: 17px;
  height: 17px;
}

.nav-item.active,
.nav-item:hover {
  background: var(--sidebar-soft);
  color: #ffffff;
}

.nav-item.active {
  border-left: 3px solid var(--amber);
}

.side-status {
  margin-top: auto;
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
}

.side-status strong,
.side-status span {
  display: block;
}

.side-status span {
  color: #aebbd1;
  font-size: 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(245, 165, 36, 0.16);
  flex: 0 0 auto;
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(46, 184, 114, 0.16);
}

.status-dot.offline {
  background: var(--red);
  box-shadow: 0 0 0 5px rgba(224, 79, 95, 0.16);
}

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

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 2px 14px;
}

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

.user-pill,
.sync-pill {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.user-pill svg {
  width: 16px;
  height: 16px;
  color: var(--green);
}

.icon-button,
.primary-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  background: var(--blue);
  color: #ffffff;
  font-weight: 800;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.icon-button.soft,
.secondary-action {
  background: #edf3fb;
  color: var(--blue);
}

.icon-button svg,
.primary-button svg {
  width: 17px;
  height: 17px;
}

.primary-button {
  padding: 0 14px;
}

.view-stack {
  display: grid;
  gap: 12px;
}

.summary-band,
.panel,
.stat-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.summary-band {
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-left: 4px solid var(--amber);
}

.summary-band p:not(.eyebrow) {
  margin-bottom: 0;
  color: var(--muted);
}

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

.stat-card {
  min-height: 98px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 14px;
}

.stat-card span,
.stat-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stat-card strong {
  color: var(--ink);
  font-size: 30px;
  line-height: 1;
}

.stat-card.good strong {
  color: #16834f;
}

.stat-card.warn strong {
  color: #a96700;
}

.stat-card.danger strong {
  color: #b72d3d;
}

.panel {
  min-width: 0;
  padding: 14px;
}

.panel-heading {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.panel-chip {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(46, 184, 114, 0.12);
  color: #16834f;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.panel-chip.danger {
  background: rgba(224, 79, 95, 0.12);
  color: #b72d3d;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th,
td {
  padding: 10px 8px;
  border-top: 1px solid var(--soft-line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

td {
  font-weight: 700;
}

td strong,
td span {
  display: block;
}

td span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.selected-row {
  background: #f6f9ff;
}

.row-status {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
}

.row-status.online {
  background: rgba(46, 184, 114, 0.12);
  color: #16834f;
}

.row-status.offline {
  background: rgba(224, 79, 95, 0.12);
  color: #b72d3d;
}

.row-status.warn {
  background: rgba(245, 165, 36, 0.14);
  color: #9a5f00;
}

.action-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mini-button,
.table-select {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
}

.mini-button {
  padding: 0 11px;
  color: var(--blue);
  font-weight: 900;
}

.table-select {
  min-width: 170px;
  padding: 0 10px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
}

.detail-grid > div {
  min-height: 70px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: var(--radius);
  background: #f8fbff;
}

.detail-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.detail-grid strong {
  font-size: 16px;
  word-break: break-word;
}

.detail-wide {
  grid-column: 1 / -1;
}

.parameter-board {
  display: grid;
  gap: 12px;
}

.parameter-heading {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--soft-line);
}

.parameter-heading strong {
  color: var(--blue);
  font-size: 13px;
}

.parameter-section {
  display: grid;
  gap: 8px;
}

.parameter-section h3 {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
}

.parameter-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 8px;
}

.parameter-row {
  min-height: 52px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 9px 10px;
  border: 1px solid var(--soft-line);
  border-radius: var(--radius);
  background: #ffffff;
}

.parameter-row strong {
  font-size: 14px;
}

.fault-list,
.alarm-detail {
  display: grid;
  gap: 8px;
}

.fault-item {
  display: grid;
  gap: 3px;
  min-height: 46px;
  padding: 10px;
  border: 1px solid var(--soft-line);
  border-radius: var(--radius);
  background: #fffaf0;
}

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

.device-add-form,
.oem-form,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

.device-add-form {
  grid-template-columns: minmax(210px, 1.1fr) minmax(180px, 1fr) minmax(190px, 1fr) minmax(170px, 0.8fr) auto;
}

.settings-grid {
  grid-template-columns: minmax(260px, 1fr) 180px auto;
}

.settings-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.2fr);
  gap: 12px;
}

.chart-box {
  min-height: 320px;
  border: 1px solid var(--soft-line);
  border-radius: var(--radius);
  background: #fbfdff;
}

.empty-state {
  min-height: 42px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
}

.edit-dialog {
  width: min(94vw, 520px);
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
}

.add-device-dialog {
  width: min(94vw, 560px);
}

.edit-dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.edit-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  background: #ffffff;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .brand div:not(.brand-mark),
  .nav-item span,
  .side-status div {
    display: none;
  }

  .brand,
  .nav-item {
    justify-content: center;
  }

  .side-status {
    justify-content: center;
    padding: 12px 0;
  }

  .stat-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

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

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

  .device-add-form,
  .oem-form,
  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 10px;
  }

  .brand,
  .side-status {
    display: none;
  }

  .nav-list {
    display: flex;
    gap: 4px;
  }

  .nav-item {
    width: 60px;
    height: 50px;
    flex: 0 0 60px;
    flex-direction: column;
    gap: 3px;
    padding: 5px 3px;
    border-left: 0;
    border-bottom: 3px solid transparent;
  }

  .nav-item span {
    display: block;
    margin: 0;
    font-size: 9px;
    line-height: 1;
  }

  .nav-item.active {
    border-left: 0;
    border-bottom-color: var(--amber);
  }

  .workspace {
    padding: 12px;
  }

  .topbar,
  .summary-band {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .detail-grid,
  .parameter-list,
  .device-add-form,
  .oem-form,
  .settings-grid {
    grid-template-columns: 1fr;
  }

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

  .panel-heading {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .table-wrap {
    overflow: visible;
  }

  table {
    min-width: 0;
  }

  table thead {
    display: none;
  }

  table tbody,
  table tr,
  table td {
    display: block;
    width: 100%;
  }

  table tbody tr {
    display: grid;
    padding: 7px 0;
    border-top: 1px solid var(--line);
  }

  table tbody td[data-label] {
    min-width: 0;
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    padding: 7px 0;
    border: 0;
    white-space: normal;
  }

  table tbody td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
  }

  table tbody td[colspan] {
    padding: 8px 0;
    border: 0;
    white-space: normal;
  }

  table td strong,
  table td span {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .selected-row {
    box-shadow: inset 3px 0 var(--blue);
  }

  .row-status {
    justify-self: start;
  }

  .table-select {
    width: 100%;
    min-width: 0;
  }

  .row-actions .action-buttons {
    min-width: 0;
    justify-content: flex-start;
  }

  h1 {
    font-size: 22px;
  }

  .chart-box {
    min-height: 280px;
  }
}
