:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #edf2ef;
  --ink: #1d2522;
  --muted: #68736f;
  --line: #d8dfdb;
  --brand: #167c74;
  --brand-dark: #105f59;
  --accent: #c28a21;
  --danger: #bd3d34;
  --danger-dark: #983028;
  --ok: #2f8f55;
  --shadow: 0 12px 30px rgba(30, 39, 36, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-box {
  display: grid;
  gap: 15px;
  width: min(390px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-box p {
  margin: -6px 0 4px;
  color: var(--muted);
}

.login-message {
  min-height: 20px;
  color: var(--danger);
  font-size: 0.88rem;
  font-weight: 700;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  background: #18211f;
  color: #f4faf7;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand,
.topbar,
.status-header,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  display: block;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 1.45rem;
}

h2 {
  font-size: 1.55rem;
}

h3 {
  font-size: 1rem;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.sidebar label {
  color: #b9c8c3;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(22, 124, 116, 0.12);
}

.sidebar input {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar input::placeholder {
  color: #94a6a1;
}

.inline-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.device-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 4px;
}

.device-item {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #f4faf7;
  text-align: left;
}

.device-item.active,
.device-item:hover {
  border-color: rgba(194, 138, 33, 0.7);
  background: rgba(255, 255, 255, 0.12);
}

.device-item strong,
.device-item span {
  display: block;
  overflow-wrap: anywhere;
}

.device-item span {
  margin-top: 4px;
  color: #b9c8c3;
  font-size: 0.78rem;
}

.workspace {
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 28px;
  min-width: 0;
}

.topbar {
  padding-bottom: 2px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

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

.metric {
  padding: 15px;
  min-width: 0;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.status-band {
  display: block;
  overflow: visible;
}

.status-content {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px;
}

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

.status-pill {
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

.status-pill span,
.history-result span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-pill strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 12px 14px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  border-color: var(--brand);
  color: var(--ink);
}

.panel {
  padding: 18px;
}

.form-grid,
.history-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

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

.config-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.compartment {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 16px;
}

.compartment legend {
  padding: 0 7px;
  font-weight: 900;
}

.toggle-row,
.check-group label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
}

.toggle-row input,
.check-group input {
  width: 18px;
  min-height: 18px;
}

.check-group {
  display: flex;
  align-items: end;
  gap: 14px;
}

.form-actions {
  grid-column: 1 / -1;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.form-actions.split {
  justify-content: space-between;
}

.primary-button,
.secondary-button,
.danger-button,
.compact-button,
.icon-button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 900;
}

.full-button {
  width: 100%;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.primary-button:hover {
  background: var(--brand-dark);
}

.secondary-button,
.compact-button,
.icon-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.danger-button {
  background: var(--danger);
  color: #fff;
}

.danger-button:hover {
  background: var(--danger-dark);
}

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

.sidebar .compact-button,
.sidebar .icon-button {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 1.1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 900;
}

.badge.neutral {
  background: #e8ece9;
  color: #53605b;
}

.badge.ok {
  background: #def3e6;
  color: var(--ok);
}

.badge.warn {
  background: #fff1cf;
  color: #8a5f09;
}

.badge.danger {
  background: #fae0de;
  color: var(--danger);
}

.history-result {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-2);
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  border-radius: 8px;
  padding: 13px 15px;
  background: #1d2522;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    min-height: auto;
  }

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

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

@media (max-width: 760px) {
  .workspace,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .brand,
  .status-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .device-list,
  .summary-grid,
  .status-grid,
  .form-grid,
  .form-grid.compact,
  .config-layout,
  .history-layout {
    grid-template-columns: 1fr;
  }
}
