/**
 * NUART UI compatibility layer
 *
 * The application currently uses vanilla CSS rather than Tailwind/daisyUI.
 * These semantic tokens and component contracts keep the existing render
 * fragments stable while applying the daisyUI 5 visual language consistently.
 */

:root {
  --color-base-100: var(--surface-base);
  --color-base-200: var(--surface-elevated);
  --color-base-300: var(--color-rule-strong);
  --color-base-content: var(--color-ink);
  --color-primary: var(--brand-primary);
  --color-primary-content: #fff;
  --color-secondary: var(--brand-indigo);
  --color-secondary-content: #fff;
  --color-neutral: var(--color-ink-2);
  --color-neutral-content: var(--color-paper);
  --color-info: var(--brand-blue);
  --color-error: var(--color-danger);
  --color-focus-ring: var(--color-focus);
  --radius-selector: 4px;
  --radius-field: 6px;
  --radius-box: 8px;
  --size-control: 36px;
  --border-width: 1px;
}

/* Shared component contract: button, badge, card, stats, table, form. */
.bt,
.btn {
  min-height: var(--size-control);
  border-width: var(--border-width);
  border-radius: var(--radius-field);
  border-color: var(--color-base-300);
  background: var(--color-base-100);
  color: var(--color-base-content);
  box-shadow: none;
  transition: background-color var(--duration-short), color var(--duration-short), border-color var(--duration-short), transform var(--duration-short);
}

.bt:hover,
.btn:hover {
  border-color: var(--color-base-content);
  background: var(--surface-card-hover);
  color: var(--color-base-content);
}

.bt:active,
.btn:active {
  transform: translateY(1px);
}

.bt.bt-p,
.btn.btn-primary,
.bt.btn-primary {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: var(--color-primary-content);
  box-shadow: none;
}

.bt.bt-p:hover,
.btn.btn-primary:hover,
.bt.btn-primary:hover {
  border-color: var(--brand-primary-hover);
  background: var(--brand-primary-hover);
  color: var(--color-primary-content);
}

.bt.bt-d,
.btn.btn-error {
  border-color: var(--color-error);
  background: transparent;
  color: var(--color-error);
}

.bt.bt-g,
.btn.btn-success {
  border-color: var(--color-success);
  background: transparent;
  color: var(--color-success);
}

.bt.bt-s,
.btn.btn-sm {
  min-height: 30px;
  border-radius: var(--radius-selector);
}

.table-action {
  min-height: 32px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-selector);
  color: var(--color-primary);
  text-decoration: none;
  transition: background-color var(--duration-short), color var(--duration-short), border-color var(--duration-short);
}

.table-action:hover {
  border-color: color-mix(in srgb, var(--color-primary) 28%, transparent);
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
  color: var(--color-primary);
  text-decoration: none;
}

.table-action.danger-action,
.table-action[aria-label*="删除"] {
  color: var(--color-error);
}

.quality-chip,
.badge,
.tag {
  min-height: 24px;
  border-radius: var(--radius-selector);
  border-width: var(--border-width);
  font-weight: 650;
}

.status-text {
  min-height: 22px;
  padding: 0 6px;
  border-radius: var(--radius-selector);
  background: color-mix(in srgb, currentColor 9%, transparent);
}

.card,
.pn,
.tbw,
.metering-panel,
.metering-scope-builder,
.catalog-section,
.integration-section,
.live-chart-panel,
.meter-card {
  border: 1px solid var(--color-base-300);
  border-radius: var(--radius-box);
  box-shadow: var(--shadow-card);
}

.card-body {
  padding: var(--space-md);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  border: 1px solid var(--color-base-300);
  border-radius: var(--radius-box);
  background: var(--color-base-100);
}

.stat {
  min-width: 0;
  padding: var(--space-md);
}

.stat + .stat {
  border-left: 1px solid var(--color-base-300);
}

.stat-title,
.stat-desc {
  color: var(--color-neutral);
  font-size: var(--text-xs);
}

.stat-value {
  color: var(--color-base-content);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea,
.input,
.select,
.textarea {
  border: 1px solid var(--color-base-300);
  border-radius: var(--radius-field);
  background: var(--color-base-100);
  color: var(--color-base-content);
}

input:not([type="checkbox"]):not([type="radio"]):focus-visible,
select:focus-visible,
textarea:focus-visible,
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible,
.bt:focus-visible,
.btn:focus-visible,
.table-action:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--color-focus-soft);
}

/* Explicit states prevent color alone from carrying operational meaning. */
.alert,
.provider-import-status,
.system-link-feedback,
.comm-password-error {
  border-radius: var(--radius-field);
}

.alert-info {
  border: 1px solid color-mix(in srgb, var(--color-info) 30%, transparent);
  background: color-mix(in srgb, var(--color-info) 8%, var(--color-base-100));
  color: var(--color-info);
}

.alert-success {
  border: 1px solid color-mix(in srgb, var(--color-success) 30%, transparent);
  background: color-mix(in srgb, var(--color-success) 8%, var(--color-base-100));
  color: var(--color-success);
}

.alert-warning {
  border: 1px solid color-mix(in srgb, var(--color-warning) 30%, transparent);
  background: color-mix(in srgb, var(--color-warning) 8%, var(--color-base-100));
  color: var(--color-warning);
}

.alert-error {
  border: 1px solid color-mix(in srgb, var(--color-error) 30%, transparent);
  background: color-mix(in srgb, var(--color-error) 8%, var(--color-base-100));
  color: var(--color-error);
}

.skeleton {
  min-height: 1rem;
  border-radius: var(--radius-selector);
  background: color-mix(in srgb, var(--color-base-300) 65%, transparent);
  animation: ui-skeleton-pulse 1.4s ease-in-out infinite;
}

@keyframes ui-skeleton-pulse {
  50% { opacity: .55; }
}

@media (max-width: 640px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat + .stat {
    border-left: 0;
  }

  .stat:nth-child(n + 3) {
    border-top: 1px solid var(--color-base-300);
  }

  .bt,
  .btn {
    min-height: 40px;
  }

  .bt.bt-s,
  .btn.btn-sm {
    min-height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

/* Guided commissioning workbench */
.operation-flow-card {
  margin: 0 0 18px;
  border: 1px solid var(--color-base-300);
  border-radius: var(--radius-box);
  background: var(--color-base-100);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .06);
}

.operation-flow-card .card-body {
  gap: 14px;
  padding: clamp(16px, 2vw, 22px);
}

.operation-flow-head,
.operation-flow-progress,
.operation-flow-step-head,
.operation-flow-expert-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.operation-flow-head {
  align-items: flex-start;
}

.operation-flow-kicker,
.operation-flow-step-index {
  color: var(--color-neutral);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 10px;
  letter-spacing: .08em;
}

.operation-flow-head h2 {
  margin: 5px 0 4px;
  color: var(--color-base-content);
  font-size: clamp(18px, 2vw, 24px);
  line-height: 1.15;
}

.operation-flow-head p,
.operation-flow-step p,
.operation-flow-expert-note span {
  margin: 0;
  color: var(--color-neutral);
  font-size: 12px;
  line-height: 1.6;
}

.operation-flow-mode {
  flex: 0 0 auto;
}

.operation-flow-mode .btn {
  min-width: 88px;
}

.operation-flow-progress {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 34%);
  align-items: flex-end;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--color-base-300);
  border-radius: var(--radius-field);
  background: var(--color-base-200);
}

.operation-flow-progress > div {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  column-gap: 9px;
}

.operation-flow-progress span,
.operation-flow-progress small {
  color: var(--color-neutral);
  font-size: 11px;
}

.operation-flow-progress strong {
  color: var(--color-primary);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 20px;
}

.operation-flow-progress small {
  grid-column: 1 / -1;
}

.operation-flow-progress .progress {
  width: 100%;
  height: 8px;
}

.operation-flow-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: visible;
  list-style: none;
  gap: 0;
}

.operation-flow-step {
  position: relative;
  display: grid;
  align-content: start;
  justify-items: start;
  min-width: 0;
  padding: 0 16px 0 0;
  text-align: left;
}

.operation-flow-step + .operation-flow-step {
  padding-left: 16px;
  border-left: 1px solid var(--color-base-300);
}

.operation-flow-step::after {
  color: var(--color-base-300);
}

.operation-flow-step.is-complete::after {
  color: var(--color-success, #16805a);
}

.operation-flow-step.is-attention::after {
  color: var(--color-error, #bb3b3b);
}

.operation-flow-step-head {
  width: 100%;
  justify-content: flex-start;
  margin-bottom: 10px;
}

.operation-flow-step-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--color-base-300);
  border-radius: 50%;
  background: var(--color-base-100);
  color: var(--color-neutral);
}

.operation-flow-step-icon svg {
  width: 15px;
  height: 15px;
}

.operation-flow-step.is-complete .operation-flow-step-icon {
  border-color: color-mix(in srgb, var(--color-success, #16805a) 45%, var(--color-base-300));
  color: var(--color-success, #16805a);
}

.operation-flow-step.is-attention .operation-flow-step-icon {
  border-color: color-mix(in srgb, var(--color-error, #bb3b3b) 45%, var(--color-base-300));
  color: var(--color-error, #bb3b3b);
}

.operation-flow-status {
  margin-left: auto;
  border: 1px solid var(--color-base-300);
  background: var(--color-base-100);
  color: var(--color-neutral);
  font-size: 10px;
  font-weight: 600;
}

.operation-flow-step.is-complete .operation-flow-status {
  border-color: color-mix(in srgb, var(--color-success, #16805a) 35%, var(--color-base-300));
  color: var(--color-success, #16805a);
}

.operation-flow-step.is-attention .operation-flow-status {
  border-color: color-mix(in srgb, var(--color-error, #bb3b3b) 35%, var(--color-base-300));
  color: var(--color-error, #bb3b3b);
}

.operation-flow-step > strong {
  color: var(--color-base-content);
  font-size: 14px;
}

.operation-flow-step > p {
  min-height: 38px;
  margin-top: 4px;
}

.operation-flow-step-action {
  width: fit-content;
  margin-top: 7px;
  border-color: var(--color-base-300);
  color: var(--color-base-content);
}

.operation-flow-step-action:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.operation-flow-expert {
  display: grid;
  gap: 16px;
}

.operation-flow-expert-note {
  align-items: flex-start;
  justify-content: flex-start;
  flex-direction: column;
  gap: 3px;
}

.operation-flow-expert-note strong {
  color: var(--color-base-content);
  font-size: 14px;
}

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

.operation-flow-expert-link {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 72px;
  gap: 10px;
  padding: 12px;
  text-align: left;
}

/* Keep the access workflow and its surrounding controls on one component scale. */
.integration-page-head .bt,
.integration-page-head .btn,
.access-overview .bt,
.access-overview .btn,
.access-source-block .bt,
.access-source-block .btn,
.meter-install-gateway .bt,
.meter-install-gateway .btn {
  min-height: var(--size-control);
  height: auto;
  padding-inline: 12px;
}

.integration-page-head + .operation-flow-card {
  margin-top: 0;
}

.access-overview,
.access-source-block,
.meter-install-gateway {
  border-color: var(--color-base-300);
  border-radius: var(--radius-box);
  box-shadow: var(--shadow-card);
  background: var(--color-base-100);
}

.operation-flow-expert-link > svg:first-child {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
}

.operation-flow-expert-link > svg:last-child {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin-left: auto;
}

.operation-flow-expert-link span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.operation-flow-expert-link strong,
.operation-flow-expert-link small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.operation-flow-expert-link strong {
  color: var(--color-base-content);
  font-size: 12px;
}

.operation-flow-expert-link small {
  color: var(--color-neutral);
  font-size: 10px;
  font-weight: 400;
}

@media (max-width: 900px) {
  .operation-flow-steps {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 14px;
  }

  .operation-flow-step::before,
  .operation-flow-step::after {
    display: none;
  }

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

@media (max-width: 560px) {
  .operation-flow-head {
    display: grid;
  }

  .operation-flow-mode {
    width: 100%;
  }

  .operation-flow-mode .btn {
    flex: 1 1 0;
  }

  .operation-flow-progress {
    display: grid;
    grid-template-columns: 1fr;
    align-items: center;
  }

  .operation-flow-progress .progress {
    width: 100%;
  }

  .operation-flow-steps,
  .operation-flow-expert-grid {
    grid-template-columns: 1fr;
  }

  .operation-flow-step {
    padding-right: 0;
  }

  .operation-flow-step + .operation-flow-step {
    padding-left: 0;
    border-left: 0;
  }
}

/* Dashboard object-first selection */
.dashboard-object-switch {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--color-base-300);
  border-radius: var(--radius-box);
  background: var(--color-base-100);
}

.dashboard-object-switch-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.dashboard-object-switch-head strong {
  color: var(--color-base-content);
  font-size: 11px;
  white-space: nowrap;
}

.dashboard-object-switch-head span {
  min-width: 0;
  overflow: hidden;
  color: var(--color-neutral);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-object-tabs {
  display: flex;
  width: 100%;
}

.dashboard-object-tab {
  min-width: 0;
  flex: 1 1 0;
  border-color: var(--color-base-300);
  color: var(--color-neutral);
  font-size: 10px;
  white-space: nowrap;
}

.dashboard-object-tab.is-active {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: var(--color-primary-content);
}

.dashboard-device-context {
  max-width: 46%;
  overflow: hidden;
  color: var(--color-neutral);
  font-size: 9px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-object-switch + .precision-search-box {
  margin-top: 2px;
}

@media (max-width: 640px) {
  .dashboard-object-switch-head {
    display: block;
  }

  .dashboard-object-switch-head span {
    display: block;
    margin-top: 2px;
  }

  .dashboard-device-context {
    display: none;
  }
}
