:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-soft: #f8faff;
  --text: #172033;
  --muted: #718096;
  --line: #e6eaf2;
  --brand: #4f46e5;
  --brand-dark: #3730a3;
  --brand-soft: #eef2ff;
  --danger: #dc2626;
  --warning: #d97706;
  --ok: #059669;
  --sidebar: #111827;
  --shadow-sm: 0 2px 10px rgba(15, 23, 42, .04);
  --shadow: 0 16px 45px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 85% 0, rgba(99, 102, 241, .07), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button {
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 650;
  line-height: 20px;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease, opacity .16s ease;
}
button:hover {
  background: var(--brand-dark);
  box-shadow: 0 8px 20px rgba(79, 70, 229, .18);
  transform: translateY(-1px);
}
button:active { transform: translateY(0); }
button:disabled {
  cursor: not-allowed;
  opacity: .48;
  box-shadow: none;
  transform: none;
}
button.secondary {
  border: 1px solid #dfe3fb;
  background: var(--brand-soft);
  color: var(--brand-dark);
}
button.secondary:hover {
  border-color: #c7d2fe;
  background: #e0e7ff;
}
button.ghost {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, .1);
  background: rgba(255, 255, 255, .06);
  color: #d1d5db;
}
button.ghost:hover {
  background: rgba(255, 255, 255, .11);
  color: #fff;
  box-shadow: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { min-height: 20px; color: var(--danger); }
.ok { min-height: 20px; color: var(--ok); }
code {
  border: 1px solid #e5e7eb;
  border-radius: 7px;
  background: #f8fafc;
  padding: 2px 7px;
  color: #475569;
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
}
pre {
  max-width: 440px;
  max-height: 200px;
  overflow: auto;
  margin: 0;
  border-radius: 10px;
  background: #111827;
  color: #e5e7eb;
  padding: 12px;
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.login {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 24px;
}
.login::before,
.login::after {
  position: absolute;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  content: "";
  filter: blur(1px);
  pointer-events: none;
}
.login::before {
  top: -190px;
  right: -100px;
  background: rgba(99, 102, 241, .1);
}
.login::after {
  bottom: -220px;
  left: -130px;
  background: rgba(14, 165, 233, .08);
}
.login-panel {
  position: relative;
  z-index: 1;
  width: min(430px, 100%);
  border: 1px solid rgba(226, 232, 240, .9);
  border-radius: 20px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 28px 80px rgba(51, 65, 85, .14);
  padding: 42px;
  backdrop-filter: blur(12px);
}
.login-logo {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 22px;
  border-radius: 15px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  box-shadow: 0 12px 28px rgba(79, 70, 229, .26);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
}
.login-panel h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -.02em;
}
.login-form {
  display: grid;
  gap: 16px;
  margin-top: 30px;
}
.login-form button { margin-top: 4px; padding-block: 12px; }

label {
  display: grid;
  gap: 8px;
  color: #475569;
  font-size: 13px;
  font-weight: 650;
}
input, select {
  width: 100%;
  border: 1px solid #dfe4ed;
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  line-height: 20px;
  transition: border .16s ease, box-shadow .16s ease, background .16s ease;
}
input:hover, select:hover { border-color: #cbd3df; }
input:focus, select:focus {
  border-color: #818cf8;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, .11);
}
input::placeholder { color: #a0aec0; }

.shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  overflow: hidden;
  background:
    radial-gradient(circle at 0 0, rgba(99, 102, 241, .22), transparent 34%),
    var(--sidebar);
  color: #fff;
  padding: 24px 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 7px;
}
.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(135deg, #818cf8, #4f46e5);
  box-shadow: 0 10px 24px rgba(79, 70, 229, .3);
  font-size: 18px;
  font-weight: 800;
}
.brand strong { font-size: 16px; letter-spacing: .02em; }
.brand small {
  display: block;
  margin-top: 3px;
  color: #8f9bad;
  font-size: 12px;
}
.nav {
  display: grid;
  align-content: start;
  gap: 6px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: #aeb7c6;
  padding: 10px 12px;
  text-align: left;
  font-weight: 550;
}
.nav-item:hover {
  border-color: rgba(255, 255, 255, .05);
  background: rgba(255, 255, 255, .07);
  color: #fff;
  box-shadow: none;
}
.nav-item.active {
  border-color: rgba(129, 140, 248, .15);
  background: linear-gradient(90deg, rgba(99, 102, 241, .24), rgba(99, 102, 241, .1));
  color: #fff;
  box-shadow: inset 3px 0 #818cf8;
}
.nav-symbol {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border-radius: 7px;
  background: rgba(255, 255, 255, .06);
  color: #98a5b8;
  font-size: 11px;
  font-weight: 700;
}
.nav-item.active .nav-symbol {
  background: rgba(129, 140, 248, .2);
  color: #c7d2fe;
}

.workspace {
  min-width: 0;
  padding: 28px 32px 44px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.topbar h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.3;
  letter-spacing: -.02em;
}
.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.refresh-btn span { font-size: 18px; line-height: 1; }
.view { display: grid; gap: 20px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 16px;
}
.stat, .panel, .table-panel, .list-toolbar {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}
.stat {
  position: relative;
  overflow: hidden;
  padding: 20px 22px;
}
.stat::before {
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  border-radius: 4px;
  background: var(--stat-color, var(--brand));
  content: "";
}
.stat span {
  position: relative;
  z-index: 1;
  color: #64748b;
  font-size: 13px;
  font-weight: 600;
}
.stat strong {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 8px;
  font-size: 27px;
  line-height: 1.2;
  letter-spacing: -.02em;
}
.stat small {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 7px;
  color: #94a3b8;
  font-size: 12px;
}
.stat-blue { --stat-color: #4f46e5; }
.stat-violet { --stat-color: #8b5cf6; }
.stat-orange { --stat-color: #f59e0b; }
.stat-red { --stat-color: #ef4444; }
.stat-cyan { --stat-color: #0891b2; }
.stat-green { --stat-color: #10b981; }

.panel { padding: 20px; }
.panel h3, .table-panel h3 {
  margin: 0;
  color: #273247;
  font-size: 16px;
}
.health { display: grid; }
.health-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 16px;
  align-items: start;
  border-left: 4px solid var(--ok);
}
.health-panel h3 { margin-bottom: 7px; }
.health-panel p { margin: 0; color: var(--muted); line-height: 1.6; }
.health-panel.ready { border-color: rgba(5, 150, 105, .5); }
.health-panel.warn { border-color: rgba(217, 119, 6, .5); }
.health-panel .missing { grid-column: 1 / -1; color: #b45309; }

.config-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(230px, 1fr));
  gap: 18px;
  align-items: start;
}
.config-grid .panel {
  display: grid;
  align-content: start;
  gap: 14px;
}
.config-grid .panel h3 {
  margin-bottom: 4px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}
.checkline {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 9px;
  background: var(--panel-soft);
  padding: 9px 11px;
}
.checkline input {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

.table-panel { overflow: hidden; }
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll::-webkit-scrollbar { height: 8px; }
.table-scroll::-webkit-scrollbar-track { background: #f8fafc; }
.table-scroll::-webkit-scrollbar-thumb { border-radius: 8px; background: #d8dee9; }
.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 13px;
}
table {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
}
th, td {
  border-top: 1px solid var(--line);
  padding: 13px 16px;
  text-align: left;
  font-size: 13px;
  line-height: 1.55;
  vertical-align: middle;
}
th {
  background: #f8f9fc;
  color: #667085;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #fafbff; }
td { color: #344054; }
td.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
td.actions button {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 18px;
}
td.actions button[data-status="matching"],
td.actions button[data-status="resolved"],
td.actions button[data-status="done"] {
  border-color: #bbf7d0;
  background: #ecfdf5;
  color: #047857;
}
td.actions button[data-status="reviewing"] {
  border-color: #fde68a;
  background: #fffbeb;
  color: #b45309;
}
td.actions button[data-status="closed"],
td.actions button[data-status="rejected"],
td.actions button[data-status="failed"] {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.pill i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.pill-success { background: #ecfdf5; color: #047857; }
.pill-warning { background: #fffbeb; color: #b45309; }
.pill-danger { background: #fef2f2; color: #b91c1c; }
.pill-info { background: #eff6ff; color: #1d4ed8; }
.empty {
  margin: 0;
  border-top: 1px solid var(--line);
  padding: 42px 20px;
  color: var(--muted);
  text-align: center;
}

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  padding: 14px;
}
.list-search {
  display: flex;
  gap: 8px;
  flex: 1 1 340px;
}
.list-search input { min-width: 180px; background: #fbfcfe; }
.list-filter {
  display: flex;
  align-items: center;
  gap: 8px;
}
.list-filter span { color: #64748b; white-space: nowrap; }
.list-filter select { min-width: 125px; background: #fbfcfe; }
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}
.pagination button { min-width: 82px; }

.toast-container {
  position: fixed;
  z-index: 1000;
  top: 22px;
  right: 22px;
  display: grid;
  gap: 10px;
  pointer-events: none;
}
.toast {
  min-width: 230px;
  max-width: 380px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 11px;
  background: #065f46;
  box-shadow: 0 16px 42px rgba(15, 23, 42, .22);
  color: #fff;
  padding: 13px 17px;
  animation: toast-in .22s ease-out;
}
.toast.error { min-height: 0; background: #b91c1c; color: #fff; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1180px) {
  .config-grid { grid-template-columns: 1fr 1fr; }
  .config-grid .panel:last-child { grid-column: 1 / -1; }
}

@media (max-width: 920px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    gap: 16px;
    padding: 16px;
  }
  .nav {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    padding-bottom: 3px;
  }
  .nav-item { flex: 0 0 auto; width: auto; }
  .nav-item.active { box-shadow: inset 0 -3px #818cf8; }
  button.ghost { width: auto; align-self: flex-start; }
  .workspace { padding: 24px; }
}

@media (max-width: 700px) {
  .workspace { padding: 20px 16px 34px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat { padding: 17px 18px; }
  .stat strong { font-size: 24px; }
  .config-grid { grid-template-columns: 1fr; }
  .config-grid .panel:last-child { grid-column: auto; }
  .topbar { margin-bottom: 18px; }
  .topbar h2 { font-size: 23px; }
  .list-toolbar { align-items: stretch; }
  .list-search { flex-basis: 100%; }
  .list-filter { flex: 1 1 150px; display: grid; }
  .pagination { justify-content: space-between; }
  .pagination span { text-align: center; }
  .toast-container { left: 16px; right: 16px; top: 16px; }
  .toast { min-width: 0; max-width: none; }
}

@media (max-width: 430px) {
  .login { padding: 16px; }
  .login-panel { padding: 30px 24px; border-radius: 16px; }
  .login-logo { width: 46px; height: 46px; margin-bottom: 18px; }
  .login-panel h1 { font-size: 26px; }
  .stats { grid-template-columns: 1fr; }
  .list-search { display: grid; grid-template-columns: 1fr auto; }
  .pagination { gap: 7px; }
  .pagination button { min-width: 72px; padding-inline: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
