/* =========================================================================
 * 工业机器人云运维平台 · 样式
 * CSP: style-src 'self' —— 所有样式集中在本文件，不使用内联 style。
 * ========================================================================= */

/* ---------- 变量与基础 ---------- */

:root {
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #182c42;
  background: #f2f5f9;
  font-size: 16px;
  --brand: #d92626;
  --muted: #66788c;
  --line: #e3e9f1;
  --red: #991b1b;
  --orange: #b45309;
  --sidebar: 234px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select {
  outline-offset: 3px;
}

button {
  border: 1px solid #d5deea;
  background: white;
  color: #263c55;
  padding: .6rem .95rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 600;
}

button:hover {
  background: #fef2f2;
  border-color: #fecaca;
}

button:disabled {
  cursor: not-allowed;
  opacity: .45;
}

button.primary {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

button.danger {
  color: #b42318;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

h1 {
  font-size: 1.8rem;
  letter-spacing: -.04em;
  margin-bottom: 0;
}

h2 {
  font-size: 1.2rem;
}

h3 {
  font-size: 1rem;
  margin-bottom: .4rem;
}

.muted {
  color: var(--muted);
  font-size: .875rem;
  line-height: 1.6;
}

.eyebrow {
  display: block;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .14em;
  color: #6684a4;
  margin-bottom: .6rem;
}

.brand {
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: .09em;
}

[hidden] {
  display: none !important;
}

/* ---------- 表单控件 ---------- */

label {
  display: block;
  font-size: .875rem;
  font-weight: 600;
  margin: 1.1rem 0;
  color: #40556c;
}

input,
select {
  display: block;
  width: 100%;
  border: 1px solid #ced9e5;
  border-radius: 7px;
  padding: .7rem .8rem;
  margin-top: .45rem;
  background: white;
  color: #223c54;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%2366788c' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 2rem;
}

input[type=checkbox] {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--brand);
}

/* 复选框行 */
label.check {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin: .8rem 0;
  cursor: pointer;
}

label.check small {
  color: #7d8da0;
  font-weight: 500;
  margin-left: .25rem;
}

/* 客户多选 */
.check-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .4rem 1rem .8rem;
  margin: 1.1rem 0;
  min-width: 0;
}

.check-group legend {
  font-size: .875rem;
  font-weight: 600;
  color: #40556c;
  padding: 0 .4rem;
}

.check-tools {
  display: flex;
  gap: .5rem;
  margin: .4rem 0 .2rem;
}

.check-tools button {
  font-size: .75rem;
  padding: .3rem .6rem;
}

.check-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  column-gap: 1rem;
  max-height: 220px;
  overflow: auto;
}

.check-list label.check {
  margin: .45rem 0;
  font-weight: 500;
  min-width: 0;
  overflow-wrap: anywhere;
}

.wide {
  width: 100%;
  margin-top: .8rem;
}

.error {
  color: #b42318;
  font-size: .875rem;
  line-height: 1.5;
  margin: .8rem 0;
}

.error:empty {
  margin: 0;
}

/* ---------- 登录页 ---------- */

.login {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  min-height: 100vh;
  background: white;
}

.login-art {
  background: #10263d;
  background-image: linear-gradient(135deg, #14181f, #1e242e);
  color: white;
  padding: 4.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.login-art h1 {
  font-size: 3.2rem;
  line-height: 1.3;
  margin-bottom: 1.5rem;
}

.login-art p {
  color: #b6ccdf;
  line-height: 1.8;
}

.login-art .eyebrow {
  color: #fca5a5;
}

.login-art .muted {
  color: #9eb8cf;
}

.login-form {
  display: grid;
  place-items: center;
  padding: 3rem;
}

.login-form form {
  max-width: 360px;
  width: 100%;
}

.login-form h2 {
  font-size: 1.65rem;
  margin-bottom: .7rem;
}

/* ---------- 工作台框架 ---------- */

#workspace {
  display: flex;
  min-height: 100vh;
}

aside {
  width: var(--sidebar);
  flex-shrink: 0;
  background: linear-gradient(160deg, #14181f, #1e242e);
  color: #c8d7e6;
  padding: 2rem 1.15rem;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  overflow-y: auto;
}

aside .brand {
  color: white;
  padding: 0 .8rem;
  font-size: 1.6rem;
}

aside .brand span {
  display: block;
  font-weight: 400;
  font-size: .75rem;
  letter-spacing: .13em;
  color: #9bb2c9;
  margin: .5rem 0 2.5rem;
}

nav {
  display: grid;
  gap: .45rem;
}

nav button {
  text-align: left;
  border: 0;
  color: #adc2d8;
  background: none;
  padding: .9rem 1rem;
}

nav button:hover,
nav button.selected {
  background: #343943;
  color: white;
}

nav b {
  background: #854244;
  color: white;
  border-radius: 4px;
  padding: .1rem .4rem;
  font-size: .75rem;
  margin-left: .7rem;
}

.side-foot {
  margin-top: auto;
  padding: 1rem .8rem 0;
  display: flex;
  flex-direction: column;
  gap: .7rem;
}

.side-foot .who {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  min-width: 0;
}

.side-foot strong {
  font-size: .875rem;
  overflow-wrap: anywhere;
}

.side-foot span {
  font-size: .75rem;
  color: #8fa8c2;
}

.side-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

.side-foot button {
  background: transparent;
  color: #b8cce0;
  border-color: #3a526b;
  font-size: .75rem;
  padding: .4rem .5rem;
}

.side-foot button:hover {
  background: #343943;
  color: white;
}

main {
  margin-left: var(--sidebar);
  width: calc(100% - var(--sidebar));
  min-width: 0;
  padding: 2.2rem 2.5rem;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.header-title {
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: .7rem;
}

footer {
  color: #8292a3;
  font-size: .75rem;
  line-height: 1.7;
  margin: 2rem 0 0;
}

/* ---------- 卡片与面板 ---------- */

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.2rem 0 1.8rem;
}

.stat,
.panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.stat {
  padding: 1.3rem;
  min-width: 0;
}

.stat .label {
  font-size: .875rem;
  color: var(--muted);
}

.stat strong {
  display: block;
  font-size: 2.1rem;
  line-height: 1.5;
  font-weight: 650;
}

.stat small {
  font-size: .75rem;
  color: var(--muted);
}

.stat.warn strong {
  color: #be6505;
}

.panel {
  padding: 1.4rem;
  margin-bottom: 1.3rem;
  min-width: 0;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-title h2 {
  margin: 0;
}

.banner {
  border: 1px solid #b8d5f8;
  background: #eaf3ff;
  color: #2c567d;
  padding: 1rem 1.2rem;
  border-radius: 8px;
  font-size: .875rem;
  line-height: 1.7;
  margin-bottom: 1rem;
}

.banner.amber {
  border-color: #efdab0;
  background: #fff9ec;
  color: #825b16;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 1.2rem;
}

.split > * {
  min-width: 0;
}

.filters {
  display: flex;
  gap: .8rem;
  margin-bottom: 1.3rem;
}

.filters input {
  margin: 0;
  max-width: 340px;
}

.filters select {
  margin: 0;
  max-width: 230px;
}

/* ---------- 表格（含横向滚动阴影提示） ---------- */

.table-wrap {
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* 纯 CSS 滚动阴影：内容可横向滚动时，边缘出现渐变阴影 */
  background:
    linear-gradient(to right, white 30%, rgba(255, 255, 255, 0)),
    linear-gradient(to left, white 30%, rgba(255, 255, 255, 0)) 100% 0,
    radial-gradient(farthest-side at 0 50%, rgba(16, 38, 61, .16), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(16, 38, 61, .16), transparent) 100% 0;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}

.table-wrap table {
  min-width: 600px;
}

.scroll-hint {
  display: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: .875rem;
}

th {
  color: #6e8194;
  font-weight: 500;
  background: #f8fafc;
  white-space: nowrap;
}

th,
td {
  padding: 1rem .8rem;
  border-bottom: 1px solid #edf1f5;
  vertical-align: middle;
}

td.wrap {
  min-width: 140px;
  line-height: 1.6;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tr.row-warn td:first-child {
  box-shadow: inset 3px 0 0 #e59a2f;
}

td strong {
  font-weight: 600;
  display: block;
}

td small {
  display: block;
  color: #7d8da0;
  font-size: .75rem;
  margin-top: .25rem;
}

/* ---------- 标签 ---------- */

.tag {
  display: inline-block;
  padding: .25rem .55rem;
  border-radius: 5px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
  background: #edf1f5;
  color: #66778a;
}

.tag.green {
  background: #dcfce7;
  color: #15803d;
}

.tag.red {
  background: #fef2f2;
  color: var(--red);
}

.tag.orange {
  background: #fff0da;
  color: var(--orange);
}

.tag.orange.outline {
  background: #fffaf2;
  border: 1px dashed #e5a54b;
  padding: .2rem .5rem;
}

.tag.blue {
  background: #eef2f6;
  color: #475569;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
}

.actions {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}

.actions button {
  font-size: .75rem;
  padding: .4rem .6rem;
  white-space: nowrap;
}

/* ---------- 键值、代码、参数 ---------- */

.kv {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 1rem;
  align-items: center;
  font-size: .875rem;
  margin: 1rem 0;
}

.kv > span:nth-child(odd) {
  color: var(--muted);
}

.kv > * {
  min-width: 0;
  overflow-wrap: anywhere;
}

.kv > .tag,
.kv > code {
  justify-self: start;
}

code,
pre {
  font-family: Consolas, monospace;
  overflow-wrap: anywhere;
}

pre {
  white-space: pre-wrap;
  background: #f3f6fa;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 1rem;
  font-size: .875rem;
  line-height: 1.7;
  max-height: 400px;
  overflow: auto;
}

.notes {
  margin: 0 0 1.2rem;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: .8125rem;
  line-height: 1.8;
}

.muted.small {
  font-size: .75rem;
  margin: 0;
}

/* 接入通道并列卡片 */
.transport-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.transport {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 1rem 1.1rem;
  min-width: 0;
  background: #fbfcfe;
}

.transport.recommended {
  border-color: #9fd3b8;
  background: #f5fbf8;
}

.transport-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .5rem;
}

.transport-head h3 {
  margin: 0;
}

.transport .kv {
  grid-template-columns: 76px minmax(0, 1fr);
  gap: .6rem .8rem;
  margin-bottom: .4rem;
}

.section-title {
  margin-top: 1.8rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
  font-size: 1.05rem;
}

.empty {
  padding: 2rem;
  text-align: center;
  color: #7c8fa2;
  font-size: .875rem;
  line-height: 1.8;
}

.metric-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .7rem;
}

.metric {
  background: #f5f8fc;
  border-radius: 7px;
  padding: 1rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: .75rem;
  margin-bottom: .6rem;
}

.metric strong {
  font-size: 1.2rem;
}

/* 历史缓存 / 无效数据：降低视觉权重，避免与实时数据混淆 */
.metric-grid.is-stale .metric {
  background: repeating-linear-gradient(135deg, #fbf7ef, #fbf7ef 8px, #f7f1e4 8px, #f7f1e4 16px);
  border: 1px dashed #e5c48f;
}

.metric-grid.is-stale .metric strong {
  color: #8a7a62;
}

.detail-foot {
  margin: 1rem 0 0;
  font-size: .75rem;
}

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid #edf1f5;
  padding: 1rem 0;
  font-size: .875rem;
}

.list-item:last-child {
  border: 0;
}

.list-item p {
  margin: .3rem 0;
  color: var(--muted);
  font-size: .75rem;
  line-height: 1.6;
}

/* ---------- 弹窗 ---------- */

dialog {
  border: 0;
  border-radius: 12px;
  max-width: 660px;
  width: calc(100% - 2rem);
  max-height: calc(100vh - 2rem);
  padding: 1.8rem;
  box-shadow: 0 24px 80px #00152d44;
  overflow: auto;
}

dialog::backdrop {
  background: #0c213c77;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.dialog-head h2 {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.dialog-head button {
  border: 0;
  font-size: 1.5rem;
  padding: .1rem .5rem;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .7rem;
  margin-top: 1.5rem;
}

.dialog-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

#toast {
  position: fixed;
  top: 1.3rem;
  left: 50%;
  transform: translateX(-50%);
  background: #153c58;
  color: white;
  padding: .9rem 1.3rem;
  border-radius: 8px;
  z-index: 100;
  max-width: 90%;
  box-shadow: 0 5px 20px #0002;
  font-size: .875rem;
  line-height: 1.5;
}

/* ---------- 响应式：平板 ---------- */

@media (max-width: 1050px) {
  main {
    padding: 1.5rem;
  }

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

  .split {
    grid-template-columns: minmax(0, 1fr);
  }

  .header-right .muted {
    display: none;
  }
}

/* ---------- 响应式：手机（≤760px） ---------- */

@media (max-width: 760px) {
  .login {
    grid-template-columns: 1fr;
  }

  .login-art {
    display: none;
  }

  .login-form {
    padding: 2rem 1.25rem;
  }

  #workspace {
    display: block;
  }

  /* 侧栏改为顶部区域 */
  aside {
    position: static;
    width: 100%;
    padding: 1rem;
    overflow: visible;
  }

  aside .brand {
    padding: 0;
    font-size: 1.3rem;
  }

  aside .brand span {
    display: inline;
    margin: 0 0 0 .6rem;
  }

  /* 导航：自动换行网格，所有导航项完整可见、易点选 */
  nav {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: .4rem;
    margin-top: .9rem;
  }

  nav button {
    text-align: center;
    white-space: nowrap;
    padding: .65rem .4rem;
    min-height: 44px;
    background: #2a3039;
  }

  nav b {
    margin-left: .3rem;
  }

  .side-foot {
    margin: .9rem 0 0;
    padding: .8rem 0 0;
    border-top: 1px solid #414852;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }

  .side-foot .who {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .2rem .6rem;
  }

  .side-foot button {
    padding: .45rem .7rem;
  }

  main {
    margin: 0;
    width: 100%;
    padding: 1rem;
  }

  /* 头部：标题与操作区上下排列，不再裁切 */
  header {
    flex-direction: column;
    align-items: stretch;
    gap: .8rem;
    margin-bottom: 1.2rem;
  }

  .header-right {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: .5rem;
  }

  .header-right .muted {
    display: inline;
    font-size: .75rem;
    margin-right: auto;
  }

  .header-right button {
    padding: .5rem .8rem;
  }

  h1 {
    font-size: 1.4rem;
  }

  .panel {
    padding: 1rem;
  }

  .panel-title {
    flex-wrap: wrap;
    gap: .6rem;
  }

  .banner {
    padding: .8rem .9rem;
  }

  .summary {
    gap: .6rem;
    margin: .8rem 0 1.2rem;
  }

  .stat {
    padding: .9rem;
  }

  .stat strong {
    font-size: 1.7rem;
  }

  .filters {
    flex-direction: column;
    gap: .6rem;
  }

  .filters input,
  .filters select {
    max-width: none;
  }

  /* 表格：紧凑间距 + 横向滑动提示 */
  .table-wrap table {
    min-width: 560px;
  }

  th,
  td {
    padding: .7rem .55rem;
  }

  .scroll-hint {
    display: block;
    margin: .4rem 0 0;
    text-align: center;
    color: #8a9bb0;
    font-size: .75rem;
  }

  .kv {
    grid-template-columns: 92px minmax(0, 1fr);
    gap: .7rem .8rem;
  }

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

  pre {
    font-size: .8125rem;
    padding: .8rem;
  }

  dialog {
    width: calc(100% - 1rem);
    max-height: calc(100vh - 1rem);
    padding: 1.2rem 1rem;
  }

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

  .dialog-actions button {
    flex: 1 1 auto;
  }

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

  #toast {
    top: .8rem;
    width: calc(100% - 2rem);
    max-width: none;
    text-align: center;
  }
}

/* 超窄屏（≤380px，如 375px 手机）：导航固定三列 */
@media (max-width: 380px) {
  nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  nav button {
    font-size: .8125rem;
    padding: .6rem .2rem;
  }

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

  .stat strong {
    font-size: 1.5rem;
  }
}

/* 远控配置与现场上报提示 */
.remote-config, .reported-id { margin: 1rem 0; padding: .9rem; border: 1px solid var(--line); border-radius: 7px; background: #f8fafc; overflow-wrap: anywhere; }
.reported-id { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; }
.remote-config pre { margin: .5rem 0; }

/* 奎氪工业品牌 */
.brand-lockup { display: flex; align-items: center; gap: .7rem; color: #fff; min-width: 0; }
.brand-mark { width: 46px; height: 46px; object-fit: contain; flex: 0 0 auto; }
.brand-copy { min-width: 0; }
.brand-copy strong { display: block; font-size: 1.2rem; line-height: 1.2; }
.brand-copy span, aside .brand .brand-copy span { display: block; margin: .35rem 0 0; color: #fff; font-size: .68rem; font-weight: 400; letter-spacing: .03em; white-space: nowrap; }
aside .brand { padding: 0 .3rem; margin-bottom: 2.5rem; }
aside .brand:hover { text-decoration: none; }
.brand-banner { display: block; width: min(100%, 280px); height: auto; margin-bottom: 2.5rem; }
button.primary:hover { background: #b91c1c; border-color: #b91c1c; }
:focus-visible { outline: 2px solid var(--brand); }
nav button.selected { box-shadow: inset 3px 0 var(--brand); }
@media (max-width: 760px) {
  aside .brand { padding: 0; margin-bottom: 0; }
  aside .brand-mark { width: 38px; height: 38px; }
  aside .brand-copy strong { font-size: 1rem; }
}