:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e6e9ef;
  --text: #1f2733;
  --muted: #7c8698;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 6px 20px rgba(16,24,40,.06);
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", sans-serif;
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 18px 32px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { color: var(--accent); }
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px;
  border-radius: 999px; font-size: 12px; font-weight: 600;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.btn {
  border: 1px solid transparent; border-radius: 9px; padding: 9px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: .15s; font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: #f9fafb; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.container { max-width: 1320px; margin: 0 auto; padding: 28px 32px 60px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 30px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 30px; font-weight: 750; margin: 6px 0 2px; letter-spacing: -.5px; }
.stat-sub { font-size: 11px; color: var(--muted); }
.text-ok { color: var(--ok); }
.text-bad { color: var(--bad); }
.two-col { display: grid; grid-template-columns: 1.25fr 1fr; gap: 28px; align-items: start; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.muted { color: var(--muted); font-size: 12px; }
.empty, .empty-small {
  text-align: center; padding: 48px 20px; border: 1px dashed var(--border);
  border-radius: var(--radius); color: var(--muted); background: var(--surface);
}
.empty svg { color: #cbd5e1; margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; }
.empty p { margin: 0; font-size: 13px; }
.empty-small { padding: 30px 16px; font-size: 13px; }

.watch-list, .event-list { display: flex; flex-direction: column; gap: 10px; }
.watch-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow);
}
.watch-disabled { opacity: .55; }
.watch-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.stock-badge {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 700;
}
.stock-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-in { background: var(--ok-soft); color: var(--ok); }
.badge-out { background: var(--bad-soft); color: var(--bad); }
.badge-unknown { background: #f1f3f7; color: #64748b; }
.watch-title { min-width: 0; }
.watch-title h3 { margin: 0 0 3px; font-size: 13px; font-weight: 650; word-break: break-word; }
.watch-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.site-tag {
  font-size: 10px; font-weight: 700; color: var(--accent);
  background: #dbeafe; padding: 2px 7px; border-radius: 5px;
}
.watch-actions { display: flex; gap: 2px; flex: none; }
.icon-btn {
  width: 30px; height: 30px; display: inline-grid; place-items: center;
  border: none; background: transparent; color: var(--muted);
  border-radius: 7px; cursor: pointer; text-decoration: none; transition: .15s;
}
.icon-btn:hover { background: #f1f3f7; color: var(--text); }
.icon-btn.danger:hover { background: var(--bad-soft); color: var(--bad); }

.event-item {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--border); border-radius: 10px; padding: 12px 14px;
  box-shadow: var(--shadow);
}
.event-in { border-left-color: var(--ok); }
.event-out { border-left-color: var(--bad); }
.event-icon {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.event-in .event-icon { background: var(--ok-soft); color: var(--ok); }
.event-out .event-icon { background: var(--bad-soft); color: var(--bad); }
.event-body { min-width: 0; }
.event-text { font-size: 12.5px; font-weight: 600; word-break: break-word; }
.event-time { font-size: 11px; color: var(--muted); margin-top: 3px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 620px;
  max-height: 92vh; overflow-y: auto; box-shadow: 0 24px 60px rgba(0,0,0,.2);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.close-btn { border: none; background: transparent; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; }
.close-btn:hover { color: var(--text); }
.modal-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; font-weight: 650; }
.field input, .field select {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
  font-size: 13px; font-family: inherit; color: var(--text); background: #fff; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.search-row { display: flex; gap: 8px; }
.search-row select { width: 150px; }
.search-row input { flex: 1; }
.catalog-results {
  max-height: 260px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: 8px; background: #fbfcfe;
}
.catalog-hint { padding: 16px; font-size: 12px; color: var(--muted); text-align: center; }
.catalog-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; border-bottom: 1px solid #eef1f5;
}
.catalog-item:last-child { border-bottom: none; }
.catalog-name { font-size: 12.5px; word-break: break-word; }
.catalog-meta { font-size: 10px; color: var(--muted); margin-top: 2px; }
.catalog-add {
  flex: none; border: 1px solid var(--accent); color: var(--accent);
  background: transparent; border-radius: 7px; padding: 5px 11px;
  font-size: 12px; font-weight: 650; cursor: pointer;
}
.catalog-add:hover { background: var(--accent); color: #fff; }
.catalog-add.added { border-color: var(--ok); color: var(--ok); }
.divider {
  display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 22px; border-top: 1px solid var(--border);
}
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: #1f2937; color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 13px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: 0; transition: .2s; z-index: 200; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: #15803d; }
.toast.bad { background: #b91c1c; }

@keyframes flash-in { 0% { background: var(--ok-soft); } 100% { background: var(--surface); } }
.flash { animation: flash-in 1.5s ease; }

@media (max-width: 980px) {
  .two-col { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-direction: column; align-items: flex-start; padding: 16px 20px; }
  .container { padding: 20px 16px 40px; }
}
