:root {
  --ink: #17202a;
  --muted: #667385;
  --soft: #eef2f6;
  --paper: #f6f7f9;
  --panel: #ffffff;
  --line: #d7dee7;
  --nav: #121821;
  --blue: #2367c7;
  --green: #168257;
  --amber: #b26a00;
  --red: #bd3b3b;
  --shadow: 0 8px 20px rgba(23, 32, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

button {
  min-height: 36px;
  padding: 0 13px;
  font-weight: 750;
  cursor: pointer;
}

button:hover {
  border-color: #aeb9c7;
}

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

.hidden {
  display: none !important;
}

input,
select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
}

.app-topbar {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 24px;
  background: var(--nav);
  color: #fff;
}

.brand-block,
.status-strip,
.section-head,
.lane-head {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #f0f4fa;
  color: var(--nav);
  font-weight: 900;
}

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

.brand-block span,
.status-strip {
  color: #aab5c4;
  font-size: 12px;
}

.status-strip {
  gap: 10px;
}

.status-strip button {
  background: #263242;
  border-color: #364455;
  color: #fff;
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #8793a2;
}

.live-dot.ready {
  background: #28c279;
  box-shadow: 0 0 14px rgba(40, 194, 121, 0.7);
}

.live-dot.error {
  background: #ef6464;
  box-shadow: 0 0 14px rgba(239, 100, 100, 0.55);
}

.workspace {
  padding: 24px;
}

.headline {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(520px, 0.85fr);
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
}

.kicker,
.section-head span,
.lane-head span,
label span,
.meta-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 1px;
  text-transform: uppercase;
}

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

h1 {
  max-width: 780px;
  margin-bottom: 8px;
  font-size: 38px;
  line-height: 1.04;
}

h2 {
  margin-bottom: 8px;
  font-size: 22px;
}

.headline p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 650;
}

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

.metric {
  min-height: 86px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.metric strong {
  font-size: 28px;
}

.command-band {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 210px 210px;
  gap: 12px;
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.mode-tabs button,
.cleanup-actions button {
  background: #fff;
}

.mode-tabs button.active,
.cleanup-actions button.active {
  border-color: var(--nav);
  background: var(--nav);
  color: #fff;
}

label {
  display: grid;
  gap: 6px;
}

.flow-shell {
  display: grid;
  grid-template-columns: 260px minmax(760px, 1fr) 290px;
  gap: 16px;
  align-items: start;
}

.cleanup-shell {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.cleanup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.cleanup-header h2 {
  margin: 3px 0 0;
}

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

.compact-action {
  width: auto;
  min-height: 36px;
}

.danger-action {
  border-color: #e3b4b4;
  background: #fff5f5;
  color: #9b1c1c;
}

.danger-action:hover:not(:disabled) {
  border-color: #c24141;
  background: #ffe7e7;
}

.cleanup-filters {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 220px;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.manage-shell {
  display: grid;
  gap: 16px;
}

.manage-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.manage-layout {
  display: grid;
  grid-template-columns: minmax(460px, 1.15fr) minmax(320px, 0.85fr);
  gap: 14px;
  padding: 14px;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(250px, .85fr) minmax(290px, 1fr) minmax(320px, 1.12fr);
  gap: 14px;
  padding: 14px;
}

.manage-panel,
.editor-panel {
  display: grid;
  grid-template-rows: auto minmax(180px, 30vh) auto;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.manage-panel {
  grid-template-rows: auto auto;
}

.editor-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.editor-panel-head div {
  display: grid;
  gap: 2px;
}

.editor-panel-head span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .8px;
  text-transform: uppercase;
}

.editor-panel-head strong {
  font-size: 16px;
}

.editor-panel-head input {
  max-width: 150px;
  height: 34px;
}

.inherit-badge {
  max-width: 170px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #314158;
  background: #fff;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-list {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 10px;
  overflow: auto;
  border-bottom: 1px solid var(--line);
}

.editor-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  text-align: left;
}

.editor-list-item:hover,
.editor-list-item.selected {
  border-color: #8fb3d8;
  background: #eef6ff;
}

.editor-list-item span {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.editor-list-item strong,
.editor-list-item small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-list-item small,
.editor-list-item em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.floor-editor,
.unassigned-rooms {
  display: grid;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.floor-editor-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.floor-editor-head div {
  display: flex;
  gap: 8px;
  align-items: center;
}

.floor-editor-head strong {
  font-size: 13px;
}

.floor-editor-head span {
  color: var(--muted);
  font-size: 12px;
}

.floor-editor-head button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.floor-list {
  display: grid;
  gap: 6px;
  max-height: 150px;
  overflow: auto;
}

.bulk-room-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.bulk-room-item input {
  width: 18px;
  height: 18px;
}

.bulk-room-item .editor-list-item {
  min-height: 42px;
}

.bulk-assign-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.bulk-assign-bar select {
  min-width: 0;
}

.bulk-assign-bar button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.floor-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) 82px;
  gap: 8px;
}

.floor-form input {
  width: 100%;
}

.floor-form .check-field,
.floor-form button {
  align-self: end;
}

.editor-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
}

.device-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

.editor-form input,
.editor-form select,
.editor-form textarea {
  width: 100%;
}

.device-form input,
.device-form select {
  width: 100%;
}

.editor-form textarea {
  resize: vertical;
}

.wide-field,
.editor-form button {
  grid-column: 1 / -1;
}

.device-form .wide-field,
.device-form button.wide-field {
  grid-column: 1 / -1;
}

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

.model-summary div,
.preview-row {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.model-summary span,
.preview-row span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .7px;
  text-transform: uppercase;
}

.model-summary strong,
.preview-row strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.intake-preview {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.room-device-group {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.room-device-group-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding-bottom: 7px;
  border-bottom: 1px solid #e8edf3;
}

.room-device-group-head span {
  color: var(--muted);
  font-size: 12px;
}

.room-device-list {
  display: grid;
  gap: 6px;
}

.room-device-row {
  display: grid;
  gap: 3px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: #f8fafc;
}

.room-device-row.match {
  border-color: #d5b36f;
  background: #fff8e5;
}

.room-device-row span {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.check-field {
  display: flex;
  gap: 8px;
  align-items: center;
}

.check-field input {
  width: 18px;
  height: 18px;
}

.inherited-field output {
  display: block;
  min-height: 38px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #314158;
  font-size: 13px;
}

.cleanup-table-wrap {
  max-height: calc(100vh - 310px);
  overflow: auto;
}

.cleanup-table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
}

.cleanup-table th,
.cleanup-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.cleanup-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.cleanup-table input,
.cleanup-table select {
  min-width: 130px;
  height: 34px;
  padding: 0 9px;
  font-size: 13px;
}

.cleanup-table input[type="checkbox"] {
  width: 18px;
  min-width: 18px;
  height: 18px;
}

.cleanup-table .editing-row td {
  background: #f8fbff;
}

.cleanup-id,
.cleanup-cell-text {
  color: #344154;
  font-size: 13px;
}

.cleanup-id {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
}

.cleanup-cell-text {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cleanup-row-actions {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.cleanup-row-actions button {
  min-height: 32px;
  font-size: 12px;
}

.location-rail,
.activity-rail,
.lane,
.planner-inner,
.staged-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.section-head,
.lane-head {
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.section-head strong,
.lane-head strong {
  display: block;
  margin-top: 2px;
}

.section-head.compact {
  min-height: 50px;
}

.section-head button {
  min-height: 30px;
  font-size: 12px;
}

.flow-board {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 320px minmax(260px, 1fr);
  gap: 16px;
  align-items: start;
}

.lane-head select {
  max-width: 210px;
}

.inventory-list {
  max-height: calc(100vh - 288px);
  overflow: auto;
  padding: 10px;
  contain: content;
}

.pager {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.pager:empty {
  display: none;
}

.pager div {
  display: flex;
  gap: 6px;
}

.pager button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.item-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #e1e6ee;
  border-radius: 8px;
  background: #fff;
  contain: content;
}

.item-card + .item-card {
  margin-top: 10px;
}

.item-card.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(35, 103, 199, 0.13);
}

.item-card.staged {
  border-color: #d5b36f;
  background: #fffaf0;
}

.item-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.item-title h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.25;
}

.meta {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

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

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.badge.good {
  border-color: #bee3cf;
  background: #effaf4;
  color: var(--green);
}

.badge.warn {
  border-color: #eed59d;
  background: #fff8e5;
  color: var(--amber);
}

.badge.bad {
  border-color: #efc4c4;
  background: #fff1f1;
  color: var(--red);
}

.item-actions {
  display: flex;
  gap: 8px;
}

.item-actions button {
  width: 100%;
}

.primary-action {
  width: 100%;
  min-height: 42px;
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.planner {
  display: grid;
  gap: 16px;
}

.planner-inner {
  display: grid;
  gap: 12px;
  padding: 16px;
  position: sticky;
  top: 18px;
}

.planner-inner p {
  margin-bottom: 0;
  color: var(--muted);
}

.selected-card {
  min-height: 78px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 12px;
  border: 1px dashed #b7c2cf;
  border-radius: 8px;
  background: #f8fafc;
}

.selected-card strong {
  display: block;
}

.read-only-note {
  padding: 10px;
  border-radius: 7px;
  background: #f3f0e7;
  color: #6e5524 !important;
  font-size: 12px;
  line-height: 1.35;
}

.staged-list {
  max-height: 250px;
  overflow: auto;
  padding: 10px;
}

.staged-move {
  display: grid;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.staged-move:last-child {
  border-bottom: 0;
}

.location-tree,
.activity-list {
  max-height: calc(100vh - 220px);
  overflow: auto;
  padding: 10px;
  contain: content;
}

.tree-node {
  width: 100%;
  min-height: 32px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 0;
  background: transparent;
  text-align: left;
}

.tree-all {
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.tree-node:hover,
.tree-node.selected {
  background: var(--soft);
}

.tree-node strong,
.tree-node span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-node small {
  color: var(--muted);
}

.tree-children {
  margin-left: 12px;
  padding-left: 8px;
  border-left: 1px solid #e4e9f0;
}

.tree-room-list {
  margin-left: 10px;
}

.tree-room {
  min-height: 28px;
  color: #344154;
  font-size: 12px;
}

.activity-event {
  display: grid;
  gap: 5px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.activity-event:last-child {
  border-bottom: 0;
}

.activity-event strong {
  font-size: 13px;
}

.empty {
  padding: 22px 12px;
  color: var(--muted);
  text-align: center;
}

.overflow-note {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid #d9e0e9;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid #d0b168;
  border-radius: 8px;
  background: #fff8e5;
  color: #5e4714;
  box-shadow: var(--shadow);
}

@media (max-width: 1280px) {
  .headline,
  .flow-shell,
  .flow-board,
  .manage-layout,
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .planner-inner {
    position: static;
  }

  .inventory-list,
  .location-tree,
  .activity-list,
  .editor-list {
    max-height: none;
  }

  .editor-panel {
    grid-template-rows: auto auto auto;
  }
}

@media (max-width: 760px) {
  .app-topbar,
  .headline,
  .command-band,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .app-topbar {
    height: auto;
    align-items: flex-start;
    padding: 14px;
  }

  .status-strip {
    width: 100%;
    justify-content: space-between;
  }

  .workspace {
    padding: 14px;
  }

  h1 {
    font-size: 30px;
  }

  .lane-head {
    display: grid;
  }

  .lane-head select {
    max-width: none;
  }

  .manage-header,
  .cleanup-header,
  .cleanup-filters {
    grid-template-columns: 1fr;
  }

  .manage-header,
  .cleanup-header {
    display: grid;
  }

  .cleanup-actions {
    justify-content: start;
  }

  .editor-panel-head,
  .editor-form,
  .device-form,
  .model-summary {
    grid-template-columns: 1fr;
  }

  .editor-panel-head {
    display: grid;
  }

  .editor-panel-head input,
  .inherit-badge {
    max-width: none;
    width: 100%;
  }
}
