:root {
  --ink: #1f2d2a;
  --muted: #66736e;
  --paper: #f7f5ef;
  --surface: #fffdf8;
  --surface-2: #eef4f7;
  --line: #d9dfd8;
  --green: #315f4c;
  --green-2: #e3f0e9;
  --blue: #446984;
  --blue-2: #e7f0f6;
  --amber: #9c6a1d;
  --amber-2: #fff2d8;
  --red: #9f3636;
  --red-2: #f7e3e3;
  --neutral: #53625d;
  --neutral-2: #edf1ee;
  --shadow: 0 18px 48px rgba(32, 46, 42, 0.12);
}

[data-theme="dark"] {
  --ink: #eef7f3;
  --muted: #aab8b1;
  --paper: #101715;
  --surface: #17211e;
  --surface-2: #22302c;
  --line: #31443d;
  --green: #8bc7aa;
  --green-2: #203a31;
  --blue: #9bc6df;
  --blue-2: #213747;
  --amber: #f0c678;
  --amber-2: #3c311f;
  --red: #f1a0a0;
  --red-2: #3b2525;
  --neutral: #aab8b1;
  --neutral-2: #24332e;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eef7f3;
    --muted: #aab8b1;
    --paper: #101715;
    --surface: #17211e;
    --surface-2: #22302c;
    --line: #31443d;
    --green: #8bc7aa;
    --green-2: #203a31;
    --blue: #9bc6df;
    --blue-2: #213747;
    --amber: #f0c678;
    --amber-2: #3c311f;
    --red: #f1a0a0;
    --red-2: #3b2525;
    --neutral: #aab8b1;
    --neutral-2: #24332e;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  color: #fff;
  background: var(--green);
  font-weight: 800;
  cursor: pointer;
}

button.secondary {
  color: var(--green);
  background: var(--green-2);
}

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

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

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 460px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.brand-row img,
.portal-brand img {
  width: 58px;
  height: auto;
}

.brand-row h1,
.topbar h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-form,
.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
}

.form-message {
  min-height: 22px;
  color: var(--red);
  font-weight: 750;
}

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

.sidebar {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.portal-brand {
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  font-size: 20px;
  font-weight: 900;
  text-decoration: none;
}

.nav-list {
  display: grid;
  align-content: start;
  gap: 18px;
}

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

.nav-group-title {
  margin: 0 0 4px;
  padding: 0 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-item {
  min-height: 42px;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 780;
}

.nav-item.active,
.nav-item:hover {
  color: var(--green);
  background: var(--green-2);
}

.nav-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--blue);
  background: var(--blue-2);
  font-size: 13px;
  font-weight: 950;
}

.sidebar-footer {
  display: grid;
  gap: 10px;
}

.sidebar-footer span {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
  font-weight: 800;
}

.workbench {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
}

.topbar-health {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, auto)) auto;
  gap: 10px;
  align-items: stretch;
}

.health-item {
  min-height: 50px;
  display: grid;
  gap: 3px;
  align-content: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.health-item span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.health-item strong {
  font-size: 14px;
}

.status-pill,
.metric-trend,
.tag {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--green);
  background: var(--green-2);
  font-size: 13px;
  font-weight: 900;
}

.status-pill.warn,
.tag.warn {
  color: var(--amber);
  background: var(--amber-2);
}

.status-pill.alert,
.tag.alert {
  color: var(--red);
  background: var(--red-2);
}

.screen-content {
  display: grid;
  gap: 16px;
  padding: 20px 24px 40px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}

.metric-card,
.panel,
.list-item,
.device-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-card {
  min-height: 112px;
  display: grid;
  gap: 10px;
  align-content: space-between;
  padding: 16px;
}

.metric-card.warn {
  border-color: color-mix(in srgb, var(--amber) 36%, var(--line));
}

.metric-card.alert {
  border-color: color-mix(in srgb, var(--red) 36%, var(--line));
}

.metric-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 9px;
  height: 9px;
  display: inline-flex;
  border-radius: 999px;
  background: var(--neutral);
}

.status-dot.ok {
  background: var(--green);
}

.status-dot.warn {
  background: var(--amber);
}

.status-dot.alert {
  background: var(--red);
}

.status-dot.neutral {
  background: var(--blue);
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.metric-value {
  font-size: 32px;
  font-weight: 930;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, 0.7fr);
  gap: 16px;
}

.panel {
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel h2 {
  margin: 0;
  font-size: 18px;
}

.panel-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.text-link {
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.list {
  display: grid;
  gap: 8px;
}

.list-item,
.device-row {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.list-item strong,
.device-row strong {
  font-size: 14px;
}

.muted {
  color: var(--muted);
}

.split-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.device-row {
  grid-template-columns: minmax(190px, 1fr) repeat(4, minmax(110px, 0.5fr));
  align-items: center;
}

.device-main {
  display: grid;
  gap: 4px;
}

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

.field {
  min-height: 64px;
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-2);
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.field strong {
  overflow-wrap: anywhere;
}

.empty {
  min-height: 96px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.5);
  font-weight: 800;
}

.compact-empty {
  min-height: 54px;
}

.dashboard-grid {
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.55fr);
}

.dashboard-primary {
  min-width: 0;
}

.activity-panel {
  align-self: start;
}

.activity-feed {
  display: grid;
  gap: 6px;
}

.activity-item {
  min-height: 48px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.activity-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--blue);
  background: var(--blue-2);
  font-weight: 900;
}

.severity {
  color: var(--blue);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.severity.alert {
  color: var(--red);
}

.ops-table {
  display: grid;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.ops-table-head,
.ops-table-row {
  min-width: 720px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
}

.ops-table-head {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.ops-table-row {
  min-height: 54px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
}

button.ops-table-row {
  width: 100%;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0;
  background: var(--surface);
  font-weight: inherit;
}

button.ops-table-row.selected,
button.ops-table-row:hover {
  background: var(--green-2);
}

.ops-table.compact .ops-table-head,
.ops-table.compact .ops-table-row {
  grid-template-columns: minmax(180px, 1.2fr) 100px repeat(4, minmax(110px, 0.8fr));
}

.filter-bar,
.fleet-actions {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) repeat(3, minmax(150px, 0.7fr)) auto;
  gap: 12px;
  align-items: end;
}

.fleet-grid {
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.6fr);
}

.fleet-actions {
  grid-template-columns: minmax(150px, 0.45fr) minmax(220px, 1fr) auto;
  margin-bottom: 14px;
}

.check-row {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.check-row input {
  width: 20px;
  min-height: 20px;
}

.device-table-head,
.device-table-row {
  min-width: 1040px;
  grid-template-columns: minmax(230px, 1.1fr) 110px 130px 110px 140px 145px 130px;
}

.device-table-row {
  border-radius: 0;
}

.battery-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.battery {
  width: 74px;
  height: 14px;
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
}

.battery span {
  display: block;
  min-width: 4px;
  background: var(--green);
}

.battery.warn span {
  background: var(--amber);
}

.battery.danger span {
  background: var(--red);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 32px));
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-weight: 850;
}

.toast.error {
  color: var(--red);
  background: var(--red-2);
}

.detail-selector .ops-table-head,
.detail-selector .ops-table-row {
  grid-template-columns: minmax(210px, 1.2fr) 100px 120px 120px 130px;
}

.device-detail-grid {
  grid-template-columns: minmax(0, 1fr) minmax(380px, 0.9fr);
}

.device-profile {
  align-self: start;
}

.detail-section {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.detail-section h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  color: var(--muted);
}

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

.timeline {
  display: grid;
  gap: 8px;
}

.timeline-item {
  min-height: 44px;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.managed-form {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

[aria-busy="true"] .screen-content {
  opacity: 0.72;
}

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

  .sidebar {
    min-height: auto;
    position: sticky;
    top: 0;
    z-index: 2;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto;
    align-items: center;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    grid-auto-flow: column;
    overflow-x: auto;
  }

  .nav-item {
    grid-template-columns: 28px max-content;
  }

  .sidebar-footer {
    grid-auto-flow: column;
  }

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

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

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

  .filter-bar,
  .fleet-actions {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .login-panel,
  .screen-content,
  .topbar,
  .sidebar {
    padding: 16px;
  }

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

  .topbar-health {
    width: 100%;
    grid-template-columns: 1fr 1fr;
  }

  .form-grid,
  .metric-grid,
  .field-list,
  .device-row,
  .filter-bar,
  .fleet-actions {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    grid-template-columns: 1fr;
  }

  .nav-list {
    grid-auto-flow: row;
  }
}
