:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #eef2f6;
  --line: #d8dee8;
  --text: #1f2937;
  --muted: #64748b;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --amber: #b7791f;
  --blue: #2563eb;
  --red: #b91c1c;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

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

.login-panel {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-brand {
  padding: 0 0 16px;
}

.login-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-panel input,
.login-panel button {
  height: 40px;
  border-radius: 6px;
  border: 1px solid var(--line);
  padding: 0 11px;
  font: inherit;
}

.login-panel button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
}

.login-panel button:hover {
  background: var(--accent-strong);
}

.login-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #17202b;
  color: #f8fafc;
  padding: 24px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #2dd4bf;
  color: #102027;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.brand p {
  margin: 3px 0 0;
  color: #a8b3c3;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
  margin-top: 20px;
}

.nav-item {
  color: #cbd5e1;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 6px;
  font-size: 14px;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.main {
  padding: 24px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.topbar-actions {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--muted);
  font-size: 13px;
}

.user-chip span {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip button {
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  padding: 0 10px;
}

.user-chip button:hover {
  background: var(--surface-muted);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.topbar h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.filters {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.filters label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.filters input,
.filters button {
  height: 38px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  padding: 0 10px;
  font: inherit;
}

.filters button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  min-width: 76px;
}

.filters button:hover {
  background: var(--accent-strong);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.kpi-card,
.panel,
.notice {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.kpi-card strong {
  display: block;
  margin-top: 9px;
  font-size: 28px;
  line-height: 1.1;
}

.kpi-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.4;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 16px;
}

.panel-wide {
  grid-column: span 1;
}

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

.panel-header h3 {
  margin: 0;
  font-size: 16px;
}

.panel-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.status-pill {
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  padding: 5px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
}

.status-badge.online {
  border-color: #86efac;
  background: #dcfce7;
  color: #166534;
}

.status-badge.offline {
  border-color: #fecaca;
  background: #fee2e2;
  color: #991b1b;
}

.trend-chart {
  display: grid;
  gap: 8px;
}

.trend-row {
  display: grid;
  grid-template-columns: 92px 1fr 54px;
  align-items: center;
  gap: 10px;
  min-height: 28px;
  font-size: 12px;
}

.bar-track {
  position: relative;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
  background: var(--accent);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: #fafbfc;
}

td.num {
  font-variant-numeric: tabular-nums;
}

.event-list {
  display: grid;
  gap: 10px;
}

.event-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.event-item strong {
  display: block;
  font-size: 13px;
}

.event-item span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.empty,
.error {
  color: var(--muted);
  background: #fafbfc;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 14px;
  font-size: 13px;
}

.error {
  color: var(--red);
  border-color: #fecaca;
  background: #fff7f7;
}

.notice {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
  box-shadow: none;
}

.notice strong {
  color: var(--amber);
}

.config-section {
  margin-top: 0;
}

.section-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 14px;
}

.section-title h3 {
  margin: 0;
  font-size: 20px;
}

.section-title p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.section-title button,
.inline-form button,
.stack-form button,
.item-action {
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  padding: 0 10px;
}

.section-title button:hover,
.inline-form button:hover,
.stack-form button:hover {
  background: var(--accent-strong);
}

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

.split-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(0, 1.1fr);
  gap: 14px;
}

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

.inline-form {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(120px, 0.8fr) auto;
  gap: 8px;
  margin-bottom: 12px;
}

.stack-form {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.inline-form input,
.inline-form select,
.stack-form input,
.stack-form textarea {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
}

.stack-form textarea {
  min-height: 82px;
  resize: vertical;
}

.compact-list {
  display: grid;
  gap: 8px;
  max-height: 380px;
  overflow: auto;
}

.tall-list {
  max-height: calc(100vh - 300px);
}

#knowledge .compact-list {
  max-height: calc(100vh - 340px);
}

.compact-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #ffffff;
}

.compact-item strong {
  display: block;
  font-size: 13px;
  line-height: 1.35;
}

.compact-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.knowledge-item {
  align-items: start;
}

.knowledge-item span:first-of-type {
  color: var(--text);
  white-space: normal;
}

.item-action {
  border-color: #fecaca;
  background: #fff7f7;
  color: var(--red);
  min-width: 54px;
}

.item-action:hover {
  background: #fee2e2;
}

.item-action.positive {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.item-action.positive:hover {
  background: var(--accent-strong);
}

.list-button {
  display: grid;
  gap: 3px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  padding: 10px;
  text-align: left;
}

.list-button:hover,
.list-button.active {
  border-color: var(--accent);
  background: #f0fdfa;
}

.list-button strong {
  font-size: 13px;
}

.list-button span,
.list-button small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.detail-box {
  display: grid;
  gap: 14px;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.detail-head h3,
.detail-head p,
.detail-section h4,
.detail-section p {
  margin: 0;
}

.detail-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.detail-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.detail-meta div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: #fafbfc;
}

.detail-meta dt {
  color: var(--muted);
  font-size: 12px;
}

.detail-meta dd {
  margin: 4px 0 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.detail-section {
  display: grid;
  gap: 8px;
}

.detail-section h4 {
  font-size: 14px;
}

.detail-section p {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #ffffff;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mini-action {
  height: 30px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  padding: 0 8px;
}

.mini-action.danger {
  border-color: #fecaca;
  background: #fff7f7;
  color: var(--red);
}

.ai-miss-item {
  align-items: start;
}

.ai-miss-item textarea {
  width: 100%;
  min-height: 70px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  padding: 8px 10px;
  resize: vertical;
}

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

  .sidebar {
    padding: 14px;
  }

  .brand {
    padding-bottom: 12px;
  }

  .nav-list {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    margin-top: 12px;
  }

  .nav-item {
    text-align: center;
    padding: 9px 6px;
  }

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

  .topbar-actions {
    align-items: stretch;
    justify-content: flex-start;
  }

  .kpi-grid,
  .dashboard-grid,
  .config-grid,
  .split-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .main {
    padding: 14px;
  }

  .kpi-grid {
    gap: 10px;
  }

  .filters {
    display: grid;
    grid-template-columns: 1fr;
  }

  .filters button {
    width: 100%;
  }

  .trend-row {
    grid-template-columns: 78px 1fr 44px;
  }

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

  .section-title,
  .inline-form {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

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

  .section-title {
    flex-direction: column;
  }
}
