:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #191b1f;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --ok: #047857;
  --bad: #b91c1c;
  --warn: #b45309;
  --shadow: 0 8px 22px rgba(15, 23, 42, .045);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

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

#app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 238px 1fr;
}

.sidebar {
  background: #fff;
  color: var(--text);
  padding: 18px 14px;
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 22px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #22c55e, #2563eb);
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

.nav {
  border: 0;
  color: #475569;
  background: transparent;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.nav:hover, .nav.active {
  background: #eff6ff;
  color: var(--accent);
  font-weight: 650;
}

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

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

.topbar h2 {
  margin: 0;
  font-size: 23px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 11px;
  background: #fff;
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.35;
}

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.btn.primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.btn.primary:hover {
  background: var(--accent-dark);
}

.btn.secondary:hover {
  background: #f3f4f6;
}

.grid {
  display: grid;
  gap: 12px;
}

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

.compact-stats {
  margin-top: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.card h3 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 15px;
}

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

.stat-value {
  font-size: 24px;
  font-weight: 750;
  margin-top: 6px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  background: #fff;
  cursor: pointer;
}

.tab.active {
  background: #111318;
  color: #fff;
  border-color: #111318;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 12.5px;
}

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

th {
  color: #4b5563;
  background: #f9fafb;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

th.thin,
td:has(.row-check),
td:has(.star-btn) {
  width: 36px;
  text-align: center;
}

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

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11.5px;
  background: #eef2ff;
}

.status.success {
  color: var(--ok);
  background: #ecfdf5;
}

.status.failed {
  color: var(--bad);
  background: #fef2f2;
}

.status.skipped {
  color: var(--warn);
  background: #fffbeb;
}

.status.warn {
  color: var(--warn);
  background: #fffbeb;
}

.status.error {
  color: var(--bad);
  background: #fef2f2;
}

.muted {
  color: var(--muted);
}

.linklike {
  border: 0;
  background: transparent;
  color: #2563eb;
  padding: 0;
  cursor: pointer;
}

.name-cell {
  min-width: 190px;
  max-width: 270px;
}

.name-wrap {
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

.title-two-line {
  display: -webkit-box;
  max-width: 230px;
  overflow: hidden;
  text-align: left;
  line-height: 1.45;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.trend-btn {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-top: -2px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: #64748b;
  background: transparent;
  cursor: pointer;
}

.trend-btn:hover,
.trend-btn.active {
  color: var(--accent);
  border-color: #bfdbfe;
  background: #eff6ff;
}

.trend-btn svg {
  width: 16px;
  height: 16px;
}

.table-open-btn {
  white-space: nowrap;
}

.trend-btn polyline,
.trend-btn circle {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trend-btn circle {
  fill: #fff;
}

.id-line {
  display: block;
  margin-top: 5px;
  font-size: 12px;
  word-break: break-all;
}

textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

input[type="time"] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

input, select {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 9px;
  background: #fff;
  font-size: 12.5px;
}

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

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

.hidden {
  display: none;
}

.detail-trend {
  padding: 6px 0 0;
}

.detail-trend-meta {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 10px;
  color: var(--muted);
}

.detail-trend-meta b {
  color: var(--text);
  font-size: 16px;
}

.detail-chart {
  width: 100%;
  height: 280px;
  margin-bottom: 10px;
  border-radius: 8px;
  background: linear-gradient(180deg, #f8fbff, #fff);
}

.detail-chart path {
  stroke: #e5e7eb;
  stroke-width: 1;
}

.detail-chart polyline {
  fill: none;
  stroke: #3763ff;
  stroke-width: 2.8;
  vector-effect: non-scaling-stroke;
}

.detail-chart circle {
  fill: #fff;
  stroke: #3763ff;
  stroke-width: 2.2;
  vector-effect: non-scaling-stroke;
}

.detail-chart text {
  fill: #64748b;
  font-size: 11px;
  text-anchor: middle;
}

.detail-chart .point-value {
  fill: #111827;
  font-size: 13px;
  font-weight: 700;
}

.detail-trend-foot {
  margin-top: 2px;
}

.detail-open-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.detail-header-actions {
  min-width: 0;
  justify-content: flex-end;
}

.small-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 168px;
}

.row-actions {
  min-width: 218px;
}

.note-cell {
  width: 96px;
}

.action-cell {
  width: 230px;
}

.shop-cell {
  min-width: 90px;
  max-width: 118px;
}

.target-table th,
.target-table td {
  padding-left: 9px;
  padding-right: 9px;
}

.bulkbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.search-box {
  position: relative;
  flex: 1 1 220px;
  max-width: 320px;
  margin-left: auto;
}

.search-box::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 50%;
  width: 12px;
  height: 12px;
  border: 1.8px solid #94a3b8;
  border-radius: 999px;
  transform: translateY(-58%);
  pointer-events: none;
}

.search-box::after {
  content: "";
  position: absolute;
  left: 21px;
  top: 50%;
  width: 6px;
  height: 1.8px;
  border-radius: 999px;
  background: #94a3b8;
  transform: translateY(3px) rotate(45deg);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding-left: 31px;
  border-radius: 999px;
  background: #f8fafc;
}

.search-input:focus {
  outline: 2px solid #bfdbfe;
  border-color: #93c5fd;
  background: #fff;
}

.category-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 12px;
}

.category-filter {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  padding: 7px 10px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(15, 23, 42, .04);
}

.category-filter.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.category-filter i {
  width: 9px;
  height: 9px;
  border-radius: 999px;
}

.category-filter span {
  color: inherit;
  opacity: .75;
}

.cat-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--cat);
  background: color-mix(in srgb, var(--cat) 12%, white);
  font-size: 11.5px;
  font-weight: 650;
  white-space: nowrap;
}

.cat-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--cat);
}

.category-select {
  max-width: 92px;
}

.form-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.form-row input[type="color"] {
  width: 44px;
  height: 38px;
  padding: 3px;
}

.form-row.compact input {
  width: 110px;
}

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

.settings-form label {
  color: var(--muted);
  line-height: 1.8;
}

.settings-form input:not([type="checkbox"]) {
  width: 100%;
}

.test-result {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
}

.test-result.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.test-result.error {
  border-color: #fecaca;
  background: #fef2f2;
}

.test-result p {
  margin: 6px 0 0;
}

.test-result pre {
  max-height: 180px;
  overflow: auto;
  margin: 10px 0 0;
  padding: 8px;
  border-radius: 7px;
  background: rgba(15, 23, 42, .06);
  white-space: pre-wrap;
  word-break: break-all;
}

.order-test-box {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.order-test-box h4 {
  margin: 0 0 6px;
  font-size: 15px;
}

.order-test-box .form-row {
  margin-top: 10px;
}

.order-test-box input {
  min-width: 320px;
}

.metric-badge,
.delta-hot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  padding: 3px 7px;
  border-radius: 7px;
  color: #475569;
  background: #eef2f7;
  font-weight: 750;
  white-space: nowrap;
}

.metric-badge.hot,
.delta-hot {
  color: #be123c;
  background: #ffe4e6;
}

.metric-pair {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-wrap: wrap;
}

.star-btn {
  border: 0;
  background: transparent;
  color: #9ca3af;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

.star-btn.on {
  color: #f59e0b;
}

.note-btn {
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 5px 7px;
  width: 84px;
  max-width: 84px;
  white-space: normal;
  text-align: left;
  cursor: pointer;
}

.task-panel {
  margin-bottom: 16px;
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #f3f4f6;
  margin-bottom: 12px;
}

.progress > div {
  height: 100%;
  background: var(--accent);
  transition: width .2s ease;
}

.log-box {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
  padding: 10px;
}

.log {
  color: #d1d5db;
  font-size: 13px;
  line-height: 1.7;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.log span {
  color: #94a3b8;
  display: inline-block;
  min-width: 150px;
  margin-right: 8px;
}

.log.success {
  color: #86efac;
}

.log.error {
  color: #fca5a5;
}

.log.warn {
  color: #fcd34d;
}

.log-table td:last-child {
  min-width: 320px;
  white-space: normal;
}

.sortable {
  cursor: pointer;
  user-select: none;
}

.sortable span {
  margin-left: 5px;
  color: #94a3b8;
  font-weight: 700;
}

.sortable.active {
  color: var(--accent);
}

.sortable.active span {
  color: var(--accent);
}

.trend-popover {
  position: fixed;
  z-index: 50;
  width: 440px;
  padding: 12px;
  border: 1px solid #dbe3ef;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 18px 45px rgba(15, 23, 42, .16);
}

.trend-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.trend-title {
  font-weight: 750;
  line-height: 1.45;
  margin-bottom: 8px;
}

.trend-close {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: #f8fafc;
  cursor: pointer;
}

.trend-close:hover {
  color: var(--text);
  background: #eef2f7;
}

.trend-meta {
  display: flex;
  gap: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.trend-meta b {
  color: var(--text);
}

.mini-chart {
  width: 100%;
  height: 190px;
  margin-bottom: 10px;
  border-radius: 8px;
  background: linear-gradient(180deg, #f8fbff, #fff);
}

.mini-chart path {
  stroke: #e5e7eb;
  stroke-width: 1;
}

.mini-chart polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  vector-effect: non-scaling-stroke;
}

.mini-chart circle {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.mini-chart text {
  fill: #64748b;
  font-size: 10px;
  text-anchor: middle;
}

.mini-chart .point-value {
  fill: #1f2937;
  font-weight: 700;
}

.trend-points {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  margin-bottom: 10px;
  padding: 8px;
  border-radius: 8px;
  background: #f8fafc;
}

.trend-points div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
}

.trend-points b {
  color: var(--text);
}

.mini-empty {
  display: grid;
  place-items: center;
  height: 92px;
  margin-bottom: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
}

@media (max-width: 900px) {
  #app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
  }
  .stats, .split {
    grid-template-columns: 1fr;
  }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .toolbar-actions,
  .search-box {
    width: 100%;
    max-width: none;
  }
  .detail-header,
  .detail-trend-meta,
  .detail-open-row {
    flex-direction: column;
    align-items: stretch;
  }
  .detail-chart {
    height: 220px;
  }
  .detail-chart .point-value {
    font-size: 12px;
  }
  .detail-header-actions,
  .detail-open-row .btn {
    width: 100%;
  }
  .detail-trend-meta {
    gap: 8px;
  }
  .stats .card {
    min-width: 0;
  }
  .detail-header .muted {
    word-break: break-all;
  }
  table {
    display: block;
    overflow-x: auto;
  }
}
