:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #d8dce3;
  --text: #1d2129;
  --muted: #667085;
  --accent: #2563eb;
  --danger: #dc2626;
  --ok: #0f9d70;
  --warn: #d97706;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}
button {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 12px; cursor: pointer; font-size: 13px;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger-btn { color: var(--danger); }
input, select, textarea {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 8px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 3px; }

#topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
#topbar h1 { font-size: 15px; font-weight: 600; white-space: nowrap; }
#topbar h1 .ver { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
#tabs { display: flex; gap: 4px; }
#tabs button { border: none; background: none; color: var(--muted); padding: 6px 14px; border-radius: 6px; position: relative; }
#tabs button.active { background: var(--surface-2); color: var(--text); }
#tabs .badge {
  background: var(--danger); color: #fff; border-radius: 9px;
  font-size: 11px; padding: 0 6px; margin-left: 4px;
}
#userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

.view { display: none; height: calc(100vh - 49px); overflow: auto; }
.view.active { display: block; }

/* ---------- calendar ---------- */
#view-calendar { display: none; flex-direction: column; overflow: hidden; }
#view-calendar.active { display: flex; }
#cal-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
#cal-toolbar .sep { width: 1px; height: 20px; background: var(--border); }
.chip {
  border: 1px solid var(--border); border-radius: 20px;
  padding: 2px 10px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none;
}
.chip.on { border-color: var(--accent); color: var(--accent); }
#cal-scroll { flex: 1; overflow: auto; position: relative; }
#cal-canvas { position: relative; }
#cal-months { position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--border); height: 74px; }
.month-cell {
  position: absolute; top: 20px; height: 18px; font-size: 12px; color: var(--muted);
  border-left: 1px solid var(--border); padding: 0 6px; white-space: nowrap; overflow: hidden;
}
.year-cell { position: absolute; top: 0; height: 20px; font-size: 12px; font-weight: 600; color: var(--text); padding: 1px 6px; border-left: 1px solid var(--border); }
.day-tick {
  position: absolute; top: 38px; height: 14px; font-size: 9px; line-height: 14px;
  color: var(--muted); border-left: 1px solid var(--border); padding-left: 2px;
  white-space: nowrap; overflow: visible;
}
.day-grid-line { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(0,0,0,0.04); z-index: 0; }
.anchor-band { position: absolute; top: 0; bottom: 0; background: rgba(226, 75, 74, 0.10); z-index: 1; }
.anchor-label {
  position: absolute; top: 54px; height: 18px; font-size: 10px; line-height: 18px;
  color: #b91c1c; background: rgba(226, 75, 74, 0.12); border-radius: 3px;
  padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; z-index: 2;
}
.today-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--warn); z-index: 20; }
.today-tag {
  position: sticky; font-size: 10px; color: #0b1420; background: var(--warn);
  border-radius: 3px; padding: 0 4px; z-index: 21;
}
.mkt-row { position: relative; }
.mkt-label { background: var(--surface); border-right: 1px solid var(--border); }
/* one gutter line per row, aligned with the first lane of cards (top 5px, height 26px) */
.mkt-label .lbl-line {
  position: absolute; top: 5px; height: 26px; left: 8px; right: 6px;
  display: flex; align-items: center; gap: 7px; white-space: nowrap; overflow: hidden;
}
.lbl-mkt {
  width: 22px; flex: none; font-size: 12px; font-weight: 700;
  color: var(--text); letter-spacing: 0.3px;
}
.lbl-act { font-size: 12px; font-weight: 600; }
.mkt-sub .lbl-act { color: var(--muted); font-weight: 500; }
.month-grid-line { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,0.04); z-index: 0; }
.ev-card {
  position: absolute; height: 26px; border-radius: 5px; z-index: 10;
  font-size: 11px; line-height: 24px; padding: 0 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: grab; border: 1px solid transparent; user-select: none;
  color: var(--text);
}
.rz {
  position: absolute; top: 0; bottom: 0; width: 7px; cursor: ew-resize; z-index: 11;
}
.rz-l { left: -2px; } .rz-r { right: -2px; }
.gap-line {
  position: absolute; height: 16px; z-index: 5; pointer-events: none;
  display: flex; align-items: center; gap: 3px; overflow: hidden;
}
.gap-line .gl { flex: 1; height: 1px; background: #b3bac4; min-width: 4px; }
.gap-line .gt { font-size: 10px; color: var(--muted); white-space: nowrap; }
.gap-line .ga { font-size: 7px; color: #b3bac4; line-height: 16px; }
#ctx-menu {
  position: fixed; z-index: 200; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12); display: none; min-width: 140px;
}
#ctx-menu .ctx-item {
  padding: 5px 12px; font-size: 13px; border-radius: 5px; cursor: pointer; white-space: nowrap;
}
#ctx-menu .ctx-item:hover { background: var(--surface-2); }
#ctx-menu .ctx-item.on::before { content: "✓ "; color: var(--accent); }
#ctx-menu .ctx-item:not(.on) { padding-left: 26px; }
#ctx-menu .ctx-sep { border-top: 1px solid var(--border); margin: 5px 0; }
#ctx-menu .ctx-head { font-size: 11px; color: var(--muted); padding: 3px 12px; }
/* a marketplace = one block: solid rule between blocks, dashed between its activities */
.mkt-row.mkt-first { border-top: 2px solid var(--border); }
.mkt-row.mkt-sub { border-top: 1px dashed var(--border); }
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 150;
  display: none; align-items: center; justify-content: center;
}
#modal-backdrop.open { display: flex; }
#modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 20px 24px; width: fit-content; min-width: 420px; max-width: 90vw;
  max-height: 80vh; overflow-y: auto;
}
#modal h2 { font-size: 15px; margin-bottom: 12px; }
#modal table { width: 100%; border-collapse: collapse; }
#modal td { padding: 4px 6px; font-size: 13px; }
.ev-card.status-planned { opacity: 0.92; border-style: dashed; }
.ev-card.status-ended, .ev-card.status-cancelled { opacity: 0.4; }
.ev-card.status-cancelled { text-decoration: line-through; }
.ev-card.has-error { border: 1.5px solid var(--danger) !important; border-style: solid; }
.st-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 5px; vertical-align: middle; flex: none;
  box-shadow: 0 0 0 1.5px rgba(255,255,255,0.7);
}
.ev-card:active { cursor: grabbing; }

/* ---------- drawer ---------- */
#backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 90; display: none;
}
#backdrop.open { display: block; }
#drawer {
  position: fixed; top: 0; right: -420px; width: 400px; height: 100vh; z-index: 100;
  background: var(--surface); border-left: 1px solid var(--border);
  transition: right 0.15s ease; padding: 20px; overflow-y: auto;
}
#drawer.open { right: 0; }
#drawer h2 { font-size: 15px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
#drawer-findings { margin: 14px 0; display: flex; flex-direction: column; gap: 6px; }
.finding { font-size: 12px; padding: 6px 10px; border-radius: 5px; }
.finding.error { background: rgba(255,107,107,0.12); color: var(--danger); }
.finding.check { background: var(--surface-2); color: var(--muted); }
.finding.check::before { content: "☐ "; }
#drawer-actions { display: flex; gap: 8px; margin-top: 16px; }
#drawer-actions .spacer { flex: 1; }

/* ---------- checklist ---------- */
#view-checklist, #view-recon, #view-rules { padding: 20px; }
.cl-group { margin-bottom: 24px; }
.cl-group h3 { font-size: 14px; margin-bottom: 10px; color: var(--accent); }
.cl-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 16px; margin-bottom: 10px; display: flex; gap: 16px; align-items: flex-start;
}
.cl-main { flex: 1; }
.cl-title { font-weight: 600; font-size: 14px; }
.cl-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.cl-checks { margin-top: 8px; font-size: 12px; color: var(--muted); }
.cl-checks div::before { content: "☐ "; }
.cl-checks div.err { color: var(--danger); }
.cl-checks div.err::before { content: "⚠ "; }
.overdue-badge { background: var(--danger); color: #fff; font-size: 11px; border-radius: 4px; padding: 1px 6px; margin-left: 8px; }
.submitby { font-size: 12px; color: var(--warn); white-space: nowrap; }

/* ---------- rules ---------- */
.rules-mkt { margin-bottom: 28px; }
.rules-mkt h3 { font-size: 14px; color: var(--accent); margin-bottom: 8px; }
table.rules { border-collapse: collapse; width: 100%; margin-bottom: 8px; }
table.rules th, table.rules td { border: 1px solid var(--border); padding: 6px 8px; font-size: 12px; text-align: left; vertical-align: top; }
table.rules th { color: var(--muted); font-weight: 500; background: var(--surface); }
table.rules input[type="number"] { width: 60px; }
table.rules textarea { width: 100%; min-height: 60px; resize: vertical; }
.strategy-note textarea { width: 100%; min-height: 70px; margin-top: 4px; }

/* ---------- login ---------- */
#login-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 200;
  display: none; align-items: center; justify-content: center;
}
#login-overlay.open { display: flex; }
#login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 32px; width: 320px; display: flex; flex-direction: column; gap: 12px;
}
#login-card h1 { font-size: 17px; }
#login-err { color: var(--danger); font-size: 12px; min-height: 16px; }

.empty-hint { color: var(--muted); padding: 30px; text-align: center; }
