:root {
  --ink: #18201d;
  --muted: #69736e;
  --line: #d9dfdb;
  --surface: #ffffff;
  --canvas: #f4f6f5;
  --green-900: #173f33;
  --green-700: #245e49;
  --green-500: #3b8064;
  --green-100: #e8f1ec;
  --blue-700: #365f79;
  --blue-100: #eaf0f4;
  --amber-700: #8b5b1d;
  --amber-100: #f8efdf;
  --red-700: #9b443c;
  --red-100: #f7e9e7;
  --shadow: 0 8px 24px rgba(20, 35, 29, 0.06);
}

html,
body {
  background: var(--canvas);
}

body {
  color: var(--ink);
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select {
  font-family: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid rgba(54, 95, 121, 0.5);
  outline-offset: 2px;
}

.eyebrow {
  margin-bottom: 7px;
  color: #5d6b64;
  font-size: 11px;
  font-weight: 700;
  text-transform: none;
}

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

.topbar {
  min-height: 68px;
  border-bottom-color: #dfe4e1;
  background: rgba(255, 255, 255, 0.98);
  padding: 0 24px;
  box-shadow: 0 1px 0 rgba(25, 39, 33, 0.03);
}

.brand-mark {
  border-radius: 4px;
  box-shadow: none;
}

.brand-mark.small {
  width: 40px;
  height: 40px;
  background: #f8faf9;
}

.product-name {
  font-size: 18px;
  letter-spacing: 0;
}

.product-subtitle,
.service-status {
  font-size: 12px;
}

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

.sidebar {
  top: 68px;
  height: calc(100vh - 68px);
  border-right-color: #dde3df;
  background: #f7f9f8;
  padding: 26px 16px 18px;
}

.sidebar-label {
  margin: 0 12px 10px;
  color: #7c8781;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
}

.nav-item {
  position: relative;
  min-height: 44px;
  border-radius: 3px;
  color: #4f5c56;
  padding: 10px 12px 10px 17px;
  font-size: 14px;
}

.nav-item:hover {
  background: #eef2f0;
}

.nav-item.active {
  background: #e9efec;
  box-shadow: none;
  color: var(--green-900);
}

.nav-item.active::before {
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 0;
  width: 3px;
  background: var(--green-700);
  content: "";
}

.account-box,
.key-box {
  border-radius: 4px;
  background: #ffffff;
}

.account-box span {
  font-size: 13px;
}

.sidebar-footer {
  font-size: 10px;
}

.main-content {
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 32px clamp(24px, 3vw, 48px) 56px;
}

.page-heading {
  align-items: center;
  margin-bottom: 26px;
}

.page-heading h1 {
  margin-bottom: 6px;
  font-size: 30px;
  font-weight: 700;
}

.heading-date {
  color: #59645f;
  font-size: 13px;
}

.btn,
input,
select {
  min-height: 42px;
  border-radius: 4px;
}

.btn {
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 700;
}

.btn-primary {
  border-color: #235942;
  background: #235942;
}

.btn-primary:hover {
  border-color: #173f33;
  background: #173f33;
}

.btn-quiet {
  border-color: #cdd5d0;
  color: #33413b;
}

.icon-btn {
  border-radius: 4px;
}

.panel,
.kpi-card,
.map-status-strip,
.fleet-summary-strip,
.field-system-workspace,
.map-strategy-band,
.inventory-workspace,
.asset-detail-section {
  border-color: var(--line);
  border-radius: 4px;
  box-shadow: none;
}

.map-status-strip,
.fleet-summary-strip {
  margin-bottom: 18px;
}

.map-status-strip > div,
.fleet-summary-strip > div {
  min-height: 76px;
  padding: 15px 18px;
}

.map-status-strip span,
.fleet-summary-strip span {
  font-size: 11px;
}

.map-status-strip strong,
.fleet-summary-strip strong {
  margin-top: 7px;
  font-size: 22px;
}

.map-system-health {
  background: #f8faf9;
}

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

.map-toolbar {
  min-height: 64px;
  padding: 10px 16px;
}

.map-name-control span,
.map-save-status,
.map-background-source,
.map-legend {
  font-size: 11px;
}

.map-name-control input {
  min-height: 38px;
  background: #f4f6f5;
  font-size: 13px;
}

.mini-btn.inline {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 11px;
}

.topology-tabs {
  min-height: 64px;
  background: #f6f8f7;
}

.topology-tab {
  border-radius: 3px;
  font-size: 12px;
}

.topology-tab.active {
  box-shadow: 0 1px 4px rgba(20, 40, 31, 0.08);
}

.topology-panel-body {
  padding: 14px;
}

.library-device-row {
  min-height: 62px;
}

.library-device-row strong,
.inventory-row strong,
.asset-metric-grid strong {
  font-size: 12px;
}

.library-device-row small,
.inventory-row small,
.asset-metric-grid span {
  font-size: 10px;
}

.map-strategy-band {
  margin-top: 18px;
  padding: 20px;
}

.strategy-row {
  min-height: 108px;
}

.strategy-main h3 {
  font-size: 18px;
}

.strategy-main p,
.strategy-main small {
  font-size: 11px;
}

.inventory-toolbar {
  gap: 10px;
  padding: 14px;
}

.inventory-toolbar input,
.inventory-toolbar select {
  min-height: 42px;
  font-size: 12px;
}

.inventory-header {
  min-height: 46px;
  background: #f7f9f8;
  color: #59645f;
  font-size: 11px;
}

.inventory-row {
  min-height: 78px;
  padding: 11px 14px;
}

.inventory-actions button,
.library-device-row button {
  font-size: 11px;
}

.device-type-mark {
  border-radius: 3px;
}

.asset-detail-heading h1 {
  font-size: 28px;
}

.asset-detail-heading p:last-child {
  font-size: 12px;
}

.asset-command-bar {
  padding-bottom: 2px;
}

.asset-ai-band {
  border-left-width: 3px;
  background: #f7faf8;
}

.asset-detail-section {
  padding: 20px;
}

.asset-metric-grid > div {
  min-height: 66px;
  padding: 11px 12px;
}

.asset-sensor-list > div,
.asset-history-list > div {
  min-height: 50px;
  font-size: 11px;
}

.kpi-grid {
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  min-height: 136px;
  padding: 20px;
}

.kpi-card.accent {
  border-color: #d7e0e5;
  background: #f1f5f7;
}

.kpi-label {
  margin-bottom: 14px;
  font-size: 12px;
}

.kpi-card strong {
  font-size: 30px;
}

.content-grid {
  gap: 18px;
}

.panel {
  padding: 22px;
}

.panel-header h2,
.section-heading h3 {
  font-size: 18px;
}

.device-list {
  gap: 5px;
}

.device-item {
  min-height: 68px;
  border-radius: 3px;
  background: #f7f9f8;
  padding: 12px;
}

.device-item:hover {
  border-color: #cad7d0;
  background: #f1f5f3;
}

.device-item.active {
  border-color: #9fbaac;
  background: #edf4f0;
}

.device-main strong {
  font-size: 13px;
}

.device-main small,
.device-state {
  font-size: 11px;
}

.state-pill,
.count-badge,
.event-level {
  border-radius: 3px;
}

.state-pill {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 11px;
}

.runtime-strip,
.zone-summary,
.sensor-item-card {
  border-radius: 3px;
}

.runtime-strip div,
.zone-field,
.sensor-item-card {
  padding: 13px;
}

.runtime-strip span,
.zone-field span,
.sensor-item-card small,
.sensor-values span {
  font-size: 10px;
}

.runtime-strip strong,
.zone-field strong,
.sensor-item-card h4 {
  font-size: 12px;
}

.event-row {
  min-height: 54px;
  font-size: 12px;
}

.ota-summary > div {
  background: #f6f8f7;
}

.auth-view {
  background: #edf1ef;
}

.auth-layout {
  max-width: 940px;
  min-height: min(640px, calc(100vh - 48px));
  border-radius: 5px;
  box-shadow: 0 18px 48px rgba(18, 39, 30, 0.12);
}

.auth-brand {
  background: #173f33;
}

.auth-brand h1 {
  font-size: 44px;
}

.auth-intro {
  font-size: 15px;
}

.auth-tabs,
.auth-tab {
  border-radius: 3px;
}

.auth-tab.active {
  box-shadow: 0 1px 4px rgba(20, 40, 31, 0.08);
}

@media (max-width: 1020px) {
  .field-system-workspace {
    border-radius: 4px;
  }

  .topology-panel-body {
    max-height: 480px;
  }
}

@media (max-width: 840px) {
  .topbar {
    min-height: 60px;
    padding: 0 14px;
  }

  .mobile-workspace-nav {
    top: 60px;
    min-height: 48px;
    background: rgba(255, 255, 255, 0.98);
  }

  .mobile-workspace-nav button {
    min-height: 48px;
    display: flex;
    justify-content: center;
    border-bottom-width: 2px;
    padding: 6px 4px;
    font-size: 11px;
  }

  .main-content {
    padding: 24px 16px 44px;
  }

  .page-heading {
    margin-bottom: 20px;
  }

  .devices-panel .device-list {
    max-height: min(620px, 70vh);
    overflow: auto;
    overscroll-behavior: contain;
  }
}

@media (max-width: 680px) {
  .product-name {
    font-size: 17px;
  }

  .brand-mark.small {
    width: 36px;
    height: 36px;
  }

  .main-content {
    padding: 22px 12px 40px;
  }

  .page-heading h1 {
    font-size: 24px;
  }

  .page-heading:not(.workspace-heading) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .workspace-actions {
    gap: 8px;
  }

  .map-status-strip > div,
  .fleet-summary-strip > div {
    min-height: 70px;
    padding: 13px 14px;
  }

  .map-toolbar {
    padding: 12px;
  }

  .map-toolbar-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 7px;
  }

  .map-background-source,
  .map-save-status {
    margin-right: 4px;
  }

  .field-map-canvas {
    min-height: 440px;
  }

  .map-strategy-band,
  .panel,
  .asset-detail-section {
    padding: 16px;
  }

  .inventory-toolbar {
    padding: 12px;
  }

  .inventory-row {
    border-radius: 3px;
    padding: 13px;
  }

  .asset-detail-heading h1 {
    font-size: 22px;
  }

  .action-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .action-row .btn {
    min-width: 0;
    padding-right: 8px;
    padding-left: 8px;
  }

  .asset-ai-band {
    padding: 16px;
  }

  .kpi-card {
    min-height: 120px;
    padding: 16px;
  }

  .kpi-card strong {
    font-size: 27px;
  }

  .auth-brand {
    min-height: 230px;
  }

  .auth-brand h1 {
    font-size: 34px;
  }
}

@media (max-width: 560px) {
  .ota-summary {
    grid-template-columns: 1fr;
  }

  .ota-summary strong {
    word-break: break-word;
  }

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

  .ota-actions .btn {
    min-width: 0;
    padding-right: 8px;
    padding-left: 8px;
  }
}

@media (max-width: 380px) {
  .mobile-workspace-nav button {
    font-size: 10px;
  }

  .main-content {
    padding-right: 10px;
    padding-left: 10px;
  }

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

/* Responsive workspace pass: preserve the desktop information density while
   giving tablets and phones a deliberate reading order and touch targets. */
@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 208px minmax(0, 1fr);
  }

  .main-content {
    padding-right: 24px;
    padding-left: 24px;
  }

  .field-system-workspace {
    grid-template-columns: minmax(0, 1fr) 286px;
  }

  .content-grid {
    grid-template-columns: minmax(250px, 0.72fr) minmax(360px, 1.28fr);
  }

  .inventory-header,
  .inventory-row {
    grid-template-columns: minmax(190px, 1.65fr) minmax(100px, 0.8fr) minmax(90px, 0.7fr) minmax(130px, 1fr) minmax(130px, 1fr) 112px;
    gap: 8px;
  }
}

@media (max-width: 980px) {
  .page-heading h1 {
    font-size: 27px;
  }

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

  .devices-panel .device-list {
    max-height: none;
  }

  .detail-panel {
    min-height: 0;
  }

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

  .topology-side-panel {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .topology-panel-body {
    min-height: 0;
    max-height: 360px;
  }

  .inventory-header,
  .inventory-row {
    grid-template-columns: minmax(200px, 1.8fr) minmax(110px, 0.8fr) minmax(100px, 0.7fr) minmax(140px, 1fr) minmax(140px, 1fr) 118px;
  }
}

@media (max-width: 840px) {
  html,
  body {
    overflow-x: hidden;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: 60px;
  }

  .topbar-right {
    gap: 6px;
  }

  .service-status {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .shell {
    display: block;
    min-height: 0;
  }

  .sidebar {
    display: none;
  }

  .mobile-workspace-nav {
    position: sticky;
    top: 60px;
    z-index: 25;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-height: 52px;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 3px 12px rgba(18, 48, 39, 0.06);
  }

  .mobile-workspace-nav button {
    min-width: 0;
    min-height: 52px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .main-content {
    max-width: none;
    padding: 24px 18px 48px;
  }

  .page-heading {
    align-items: flex-start;
  }

  .page-heading h1 {
    font-size: 26px;
  }

  .workspace-actions {
    flex: 0 0 auto;
  }

  .map-status-strip,
  .fleet-summary-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .map-status-strip > div,
  .fleet-summary-strip > div {
    min-height: 72px;
    padding: 12px 13px;
  }

  .map-system-health {
    grid-column: 1 / -1;
    border-top: 1px solid var(--line);
    border-right: 0 !important;
  }

  .field-map-canvas {
    min-height: 0;
    height: clamp(340px, 58vw, 520px);
  }

  .map-toolbar {
    align-items: stretch;
  }

  .map-toolbar-actions {
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .map-toolbar-actions > * {
    flex: 0 0 auto;
  }

  .inventory-toolbar {
    grid-template-columns: minmax(0, 1fr) repeat(3, minmax(132px, 0.45fr));
    overflow-x: auto;
  }

  .inventory-toolbar > * {
    min-width: 132px;
  }

  .inventory-list {
    padding: 12px;
  }

  .inventory-row {
    min-height: 174px;
  }

  .ai-decision-grid,
  .ai-context-grid {
    grid-template-columns: 1fr;
  }

  .ai-decision-grid > div,
  .ai-context-grid > div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .ai-decision-grid > div:last-child,
  .ai-context-grid > div:last-child {
    border-bottom: 0;
  }

  .ai-weather-block {
    border-right: 0;
  }
}

@media (max-width: 600px) {
  .topbar {
    min-height: 56px;
    padding: 0 12px;
  }

  .brand-mark.small {
    width: 34px;
    height: 34px;
  }

  .product-name {
    font-size: 16px;
  }

  .product-subtitle,
  .service-status {
    display: none;
  }

  .topbar-right .text-btn {
    min-height: 36px;
    padding: 6px 8px;
    font-size: 12px;
  }

  .mobile-workspace-nav {
    top: 56px;
    min-height: 48px;
  }

  .mobile-workspace-nav button {
    min-height: 48px;
    font-size: 11px;
  }

  .main-content {
    padding: 18px 12px 36px;
  }

  .page-heading,
  .page-heading:not(.workspace-heading),
  .workspace-heading {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 18px;
  }

  .page-heading h1 {
    font-size: 23px;
  }

  .heading-date {
    font-size: 11px;
  }

  .workspace-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .workspace-actions .btn {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
  }

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

  .map-status-strip > div,
  .fleet-summary-strip > div {
    min-height: 66px;
    padding: 11px 12px;
  }

  .map-status-strip > div:nth-child(2n),
  .fleet-summary-strip > div:nth-child(2n) {
    border-right: 0;
  }

  .map-status-strip > div:nth-last-child(2),
  .fleet-summary-strip > div:nth-last-child(2) {
    border-bottom: 1px solid var(--line);
  }

  .map-status-strip strong,
  .fleet-summary-strip strong {
    font-size: 19px;
  }

  .field-system-workspace,
  .map-strategy-band,
  .inventory-workspace,
  .panel,
  .asset-detail-section {
    border-radius: 6px;
  }

  .map-toolbar {
    padding: 11px;
  }

  .map-name-control {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 8px;
  }

  .map-name-control input {
    width: 100%;
    min-height: 40px;
  }

  .field-map-canvas {
    height: clamp(280px, 75vw, 420px);
  }

  .map-legend {
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 10px 12px;
  }

  .topology-tabs {
    min-height: 50px;
  }

  .topology-panel-body {
    max-height: 310px;
    padding: 10px;
  }

  .map-library-list {
    grid-template-columns: 1fr;
  }

  .map-strategy-band,
  .panel,
  .asset-detail-section {
    padding: 14px;
  }

  .panel-header,
  .section-heading {
    gap: 8px;
  }

  .panel-header h2,
  .section-heading h3 {
    font-size: 16px;
  }

  .device-item {
    min-height: 64px;
    padding: 10px;
  }

  .device-main strong {
    font-size: 12px;
  }

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

  .action-row .btn:first-child {
    grid-column: 1 / -1;
  }

  .action-row .btn {
    min-height: 44px;
    padding: 9px 8px;
  }

  .runtime-strip {
    grid-template-columns: 1fr 1fr;
  }

  .runtime-strip div:last-child {
    grid-column: 1 / -1;
    border-top: 1px solid var(--line);
  }

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

  .zone-field:nth-child(3n) {
    border-right: 1px solid var(--line);
  }

  .zone-field:nth-child(2n) {
    border-right: 0;
  }

  .zone-field:nth-last-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }

  .zone-field:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  .inventory-toolbar {
    grid-template-columns: 1fr;
    overflow: visible;
    gap: 8px;
    padding: 10px;
  }

  .inventory-toolbar > * {
    width: 100%;
    min-width: 0;
  }

  .inventory-list {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .inventory-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-height: 0;
    gap: 8px;
    padding: 12px;
  }

  .inventory-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .inventory-actions button {
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #ffffff;
    padding: 7px 8px;
  }

  .inventory-actions button:last-child {
    color: var(--red-700);
  }

  .inventory-pagination {
    gap: 8px;
    padding: 10px;
  }

  .ai-decision-grid > div,
  .ai-context-grid > div {
    padding: 15px;
  }

  .ai-decision-summary h3 {
    font-size: 21px;
  }

  .ai-weather-list {
    grid-template-columns: 1fr;
  }

  .ai-weather-day {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .ai-weather-day:last-child {
    border-bottom: 0;
  }

  .events-panel .event-row {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .events-panel .event-row > :last-child {
    grid-column: 2;
    text-align: left;
  }

  .config-dialog {
    width: min(94vw, 620px);
    max-height: 90vh;
  }

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

  .form-grid .span-2 {
    grid-column: auto;
  }
}

@media (max-width: 380px) {
  .mobile-workspace-nav button {
    font-size: 10px;
  }

  .main-content {
    padding-right: 9px;
    padding-left: 9px;
  }

  .workspace-actions {
    grid-template-columns: 1fr;
  }

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

  .action-row .btn:first-child {
    grid-column: auto;
  }

  .runtime-strip,
  .zone-summary {
    grid-template-columns: 1fr;
  }

  .runtime-strip div,
  .zone-field {
    border-right: 0 !important;
    border-bottom: 1px solid var(--line) !important;
  }

  .runtime-strip div:last-child,
  .zone-field:last-child {
    border-bottom: 0 !important;
  }
}
