:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef4f8;
  --ink: #172033;
  --muted: #64748b;
  --line: #dbe3ee;
  --blue: #2563eb;
  --teal: #0f766e;
  --amber: #b7791f;
  --red: #b42318;
  --green: #15803d;
  --shadow: 0 14px 34px rgba(15, 23, 42, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Inter", "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

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

.auth-locked .app-shell {
  display: block;
}

.auth-locked .sidebar,
.auth-locked .topbar,
.auth-locked #content {
  display: none !important;
}

.auth-locked .main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.auth-locked #message {
  position: fixed;
  left: 50%;
  top: 18px;
  width: min(420px, calc(100vw - 32px));
  transform: translateX(-50%);
  z-index: 10;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 14px;
  background: #111827;
  color: #e5eefb;
  border-right: 1px solid #0b1220;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #38bdf8, #14b8a6);
  color: white;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #9fb1c9;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  text-align: left;
  color: #cbd5e1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  color: white;
  background: rgba(255, 255, 255, .08);
  border-color: rgba(255, 255, 255, .12);
}

.side-meta {
  margin-top: auto;
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  color: #9fb1c9;
  font-size: 12px;
}

.main {
  min-width: 0;
  padding: 22px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: 26px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
}

h3 {
  margin: 12px 0 8px;
  font-size: 14px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search,
input,
select,
textarea {
  height: 38px;
  min-width: 0;
  padding: 0 11px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

textarea {
  height: auto;
  min-height: 86px;
  padding: 10px 11px;
  resize: vertical;
}

.search {
  width: 260px;
}

input:focus,
select:focus,
textarea:focus,
.search:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.btn {
  height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
}

.btn:hover {
  border-color: #b9c6d8;
  box-shadow: 0 8px 18px rgba(15, 23, 42, .07);
}

.btn:disabled {
  cursor: wait;
  opacity: .68;
  box-shadow: none;
}

.btn.strong {
  color: white;
  background: var(--blue);
  border-color: var(--blue);
}

.btn.danger {
  color: white;
  background: var(--red);
  border-color: var(--red);
}

.btn.small {
  height: 30px;
  min-width: 52px;
  padding: 0 10px;
  font-size: 12px;
}

.btn.full {
  width: 100%;
}

.hidden {
  display: none !important;
}

.message {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  background: #eff6ff;
}

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

.login-panel {
  min-height: 60vh;
  display: grid;
  place-items: center;
}

.login-box {
  width: min(420px, 100%);
  padding: 26px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-box input {
  width: 100%;
  margin: 12px 0;
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.content {
  min-width: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.stat {
  min-height: 98px;
  padding: 14px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, .05);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin-top: 10px;
  font-size: 26px;
  line-height: 1;
}

.stat small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.dashboard-grid,
.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, .65fr);
  gap: 12px;
}

.panel {
  min-width: 0;
  padding: 14px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, .05);
}

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

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

.panel-head span {
  color: var(--muted);
  font-size: 12px;
}

.toolbar-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: -2px 0 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.toolbar-line label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.toolbar-line select {
  width: auto;
  min-width: 118px;
  height: 30px;
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 280px;
  border-radius: 8px;
  background: linear-gradient(180deg, #f8fafc, #eef4f8);
}

.warning-list {
  display: grid;
  gap: 8px;
}

.warning-list div {
  padding: 10px;
  border-left: 3px solid var(--amber);
  background: #fff8e6;
  border-radius: 6px;
}

.warning-list .ok {
  border-left-color: var(--green);
  background: #ecfdf3;
}

.table-wrap {
  overflow: auto;
  max-width: 100%;
}

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

.compact table {
  min-width: 560px;
}

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 700;
}

td {
  color: #243044;
}

.mono {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--surface-2);
  color: #334155;
}

.pill.ok {
  color: #166534;
  background: #dcfce7;
}

.pill.warn {
  color: #92400e;
  background: #fef3c7;
}

.pill.bad {
  color: #991b1b;
  background: #fee2e2;
}

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

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

.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
}

.full-row {
  grid-column: 1 / -1;
}

.mini-section {
  margin-top: 14px;
}

.feature-head {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.feature-checks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.check-row {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: flex-start;
  gap: 8px;
  min-height: 44px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text) !important;
}

.check-row input {
  width: auto;
  margin-top: 2px;
}

.check-row span {
  display: grid;
  gap: 2px;
}

.check-row small {
  color: var(--muted);
  font-size: 11px;
}

.health-card {
  display: grid;
  gap: 4px;
}

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

.summary-list {
  display: grid;
  gap: 8px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfd;
}

.summary-row strong {
  text-align: right;
}

.log-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.log-item strong,
.log-item span {
  display: block;
}

.log-item span {
  color: var(--muted);
  font-size: 12px;
}

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

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

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

  .sidebar {
    position: static;
    height: auto;
  }

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

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

  .search {
    width: 100%;
  }

  .stats-grid,
  .form-grid,
  .feature-checks {
    grid-template-columns: 1fr;
  }
}
