:root {
  --bg: #0b1220;
  --panel: #121c2e;
  --line: #22324d;
  --text: #eef4ff;
  --muted: #97a6c2;
  --primary: #3b82f6;
  --good: #16a34a;
  --bad: #dc2626;
}
body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a {
  color: #93c5fd;
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
.page-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wrap {
  max-width: 1560px;
  margin: 0 auto;
  padding: 24px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  overflow-x: auto;
}
.login-card {
  width: 360px;
}
.topbar, .toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
h1, h2 {
  margin: 0 0 8px;
}
.muted {
  color: var(--muted);
}
label {
  display: block;
  margin: 12px 0 6px;
}
input, button {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
form {
  margin: 0;
}
input {
  background: #0f1727;
  color: var(--text);
}
button {
  background: var(--primary);
  color: white;
  cursor: pointer;
  border: none;
}
button.secondary {
  width: auto;
  background: #334155;
}
button.danger {
  width: auto;
  background: var(--bad);
}
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  min-width: 980px;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
}
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}
.badge.up {
  background: rgba(22, 163, 74, 0.15);
  color: #4ade80;
}
.badge.down {
  background: rgba(220, 38, 38, 0.15);
  color: #f87171;
}
.badge.level-info {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
}
.badge.level-warn {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
}
.badge.level-error {
  background: rgba(220, 38, 38, 0.15);
  color: #f87171;
}
.mini-log-list {
  display: grid;
  gap: 8px;
}
.mini-log-item {
  padding: 8px;
  border: 1px solid rgba(151, 166, 194, 0.2);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.35);
  line-height: 1.55;
}


.alert {
  background: rgba(220, 38, 38, 0.15);
  color: #fca5a5;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 12px 0;
}
.alert.success {
  background: rgba(22, 163, 74, 0.15);
  color: #86efac;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 12px;
}
.split-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
}
.section-gap {
  margin-top: 28px;
}
.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 4px 8px 4px 0;
}
.inline-form input {
  width: 140px;
}
.danger-zone {
  display: inline-block;
}
.wrap-text {
  max-width: 420px;
  word-break: break-all;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.stat-card {
  min-height: 96px;
}
.stat-value {
  font-size: 36px;
  font-weight: 700;
  margin-top: 8px;
}
.stat-time {
  font-size: 16px;
  margin-top: 12px;
}
.up-text {
  color: #4ade80;
}
.down-text {
  color: #f87171;
}
.filter-wrap {
  flex-wrap: wrap;
  align-items: flex-end;
}
.filter-wrap > div {
  min-width: 180px;
}
.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
}

.small-text {
  font-size: 12px;
}
.ai-stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 16px;
}
.ai-stat-card {
  min-height: 132px;
}
.dashboard-stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.flow-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.flow-sidebar-panel,
.flow-summary-card,
.flow-timeline-card {
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}
.flow-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.flow-main-head {
  align-items: center;
  margin-bottom: 0;
}
.flow-count-badge,
.device-log-badge,
.flow-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  white-space: nowrap;
}
.flow-count-badge,
.device-log-badge {
  background: rgba(59, 130, 246, 0.16);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.2);
}
.flow-filter-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.flow-filter-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}
.flow-filter-actions {
  display: flex;
  align-items: end;
}
.flow-filter-actions button {
  width: auto;
  min-width: 96px;
}
.device-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 720px;
  overflow-y: auto;
  padding-right: 4px;
}
.device-item {
  display: block;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(15, 23, 39, 0.98), rgba(9, 16, 30, 0.95));
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.device-item:hover {
  text-decoration: none;
  border-color: #35507d;
  transform: translateY(-1px);
}
.device-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35), 0 8px 24px rgba(59, 130, 246, 0.12);
}
.device-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.device-item-title {
  font-weight: 700;
  margin-bottom: 2px;
}
.flow-main-panel {
  min-width: 0;
}
.serial-console {
  margin-top: 16px;
  background: linear-gradient(180deg, #08111f 0%, #09101b 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  min-height: 520px;
  max-height: 720px;
  overflow-y: auto;
  font-family: Consolas, Monaco, monospace;
}
.flow-entry {
  border: 1px solid rgba(71, 85, 105, 0.5);
  border-left: 4px solid #475569;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  background: rgba(15, 23, 39, 0.92);
}
.flow-entry.ok {
  border-left-color: var(--good);
}
.flow-entry.fail {
  border-left-color: var(--bad);
}
.flow-entry-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}
.flow-meta {
  color: #93c5fd;
  font-size: 12px;
  font-weight: 700;
}
.flow-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
.flow-tag {
  background: rgba(148, 163, 184, 0.12);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.15);
}
.flow-tag.muted-tag {
  color: var(--muted);
}
.flow-tag.success-tag {
  background: rgba(22, 163, 74, 0.16);
  color: #86efac;
  border-color: rgba(22, 163, 74, 0.2);
}
.flow-tag.fail-tag {
  background: rgba(220, 38, 38, 0.16);
  color: #fca5a5;
  border-color: rgba(220, 38, 38, 0.2);
}
.flow-content {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  color: #eff6ff;
  margin-bottom: 8px;
}
.flow-extra {
  line-height: 1.6;
}
.flow-error {
  color: #fca5a5;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(220, 38, 38, 0.3);
}
.flow-tag.source-tag {
  background: rgba(59, 130, 246, 0.18);
  color: #bfdbfe;
  border-color: rgba(59, 130, 246, 0.28);
}
.flow-detail,
.flow-ws {
  color: #cbd5e1;
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.12);
  line-height: 1.6;
  word-break: break-word;
}
.flow-ws {
  color: #fcd34d;
  border-color: rgba(245, 158, 11, 0.25);
  background: rgba(120, 53, 15, 0.18);
}
.flow-raw {
  margin-top: 8px;
  color: var(--muted);
}
.flow-raw summary {
  cursor: pointer;
  color: #93c5fd;
}

.flow-copy-btn {
  margin-left: 10px;
  padding: 2px 8px;
  border: 1px solid rgba(147, 197, 253, 0.45);
  border-radius: 999px;
  background: rgba(30, 64, 175, 0.24);
  color: #bfdbfe;
  cursor: pointer;
  font-size: 12px;
}
.flow-copy-btn:hover {
  border-color: rgba(147, 197, 253, 0.8);
  background: rgba(30, 64, 175, 0.42);
}

.flow-raw pre {
  margin: 8px 0 0;
  padding: 10px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.72);
  color: #cbd5e1;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow-y: auto;
}

.empty-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  border: 1px dashed rgba(151, 166, 194, 0.25);
  border-radius: 12px;
  color: var(--muted);
}
@media (max-width: 1100px) {
  .ai-stats-grid,
  .stats-grid,
  .split-grid,
  .flow-shell {
    grid-template-columns: 1fr;
  }
  .flow-filter-grid,
  .flow-entry-head {
    grid-template-columns: 1fr;
  }
  .flow-entry-head,
  .flow-panel-head,
  .device-item-top {
    flex-direction: column;
    align-items: flex-start;
  }
  .flow-tags {
    justify-content: flex-start;
  }
}

.flow-toolbar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.flow-toolbar label {
  margin-top: 0;
}
.flow-toolbar select {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f1727;
  color: var(--text);
}
.flow-toolbar-actions {
  display: flex;
  align-items: end;
}
.flow-toolbar-actions button {
  width: 100%;
}
.flow-toggle-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
}
.toggle-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--text);
}
.toggle-item input {
  width: auto;
  margin: 0;
}
.new-entry {
  animation: flowFlash 8s ease-out;
}
@keyframes flowFlash {
  0% {
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.8), 0 0 24px rgba(59, 130, 246, 0.25);
    background: rgba(24, 53, 102, 0.65);
  }
  100% {
    box-shadow: none;
    background: rgba(15, 23, 39, 0.92);
  }
}
@media (max-width: 1400px) {
  .flow-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 1100px) {
  .flow-toolbar {
    grid-template-columns: 1fr;
  }
  .flow-toggle-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
}
