:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --border: #e3e3e8;
  --ink: #1a1a2e;
  --ink-mute: #5a5a72;
  --ink-faint: #9494a6;
  --critical: #cc0000;
  --critical-bg: #fdecec;
  --behind: #f57c00;
  --behind-bg: #fff4e6;
  --ahead: #0a8a0a;
  --ahead-bg: #e8f5e9;
  --primary: #1a73e8;
  --primary-ink: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  padding-bottom: 90px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.topbar .meta { color: #aaa; font-size: 12px; margin-top: 2px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

.loader, .empty { padding: 40px; text-align: center; color: var(--ink-mute); }
.error {
  background: var(--critical-bg);
  color: var(--critical);
  border: 1px solid #f5c2c2;
  padding: 14px;
  border-radius: 6px;
  margin: 20px 0;
}

.property {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.property-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #f4f4f8;
  border-bottom: 1px solid var(--border);
}
.property-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.property-head .pcode { color: var(--ink-faint); font-weight: 500; margin-left: 6px; font-size: 12px; }
.property-head .pmeta { font-size: 12px; color: var(--ink-mute); }

.row {
  border-bottom: 1px solid var(--border);
  padding: 0;
}
.row:last-child { border-bottom: none; }
.row-head {
  display: grid;
  grid-template-columns: 24px 90px 1fr 100px 120px 110px 90px;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
}
.row-head:hover { background: #fafbff; }
.row.selected .row-head { background: #f0f6ff; }

.sev { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; }
.sev.CRITICAL { background: var(--critical-bg); color: var(--critical); }
.sev.BEHIND { background: var(--behind-bg); color: var(--behind); }
.sev.AHEAD { background: var(--ahead-bg); color: var(--ahead); }

.row .month { font-weight: 600; }
.row .label { color: var(--ink-mute); font-size: 13px; }
.row .stat { font-variant-numeric: tabular-nums; font-size: 13px; }
.row .stat .num { font-weight: 600; }
.row .stat .small { color: var(--ink-faint); font-size: 11px; display: block; }
.row .toggle { color: var(--primary); font-size: 12px; text-align: right; }

.row-body {
  padding: 14px 16px 18px 50px;
  background: #fbfbfd;
  border-top: 1px solid var(--border);
  display: none;
}
.row.expanded .row-body { display: block; }

.row-body .grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px 18px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-faint); }
.field input[type="number"] {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  width: 100%;
  background: #fff;
}
.field .note { font-size: 11px; color: var(--ink-mute); }

.context-table {
  margin-top: 14px;
  font-size: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
.context-table dt { color: var(--ink-faint); font-weight: 500; display: inline-block; min-width: 110px; }
.context-table dd { display: inline; margin: 0; }
.context-table .ctxrow { padding: 3px 0; }

.bottombar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
  z-index: 40;
}
.counts { display: flex; gap: 10px; align-items: center; color: var(--ink-mute); font-size: 13px; }
.counts .sep { color: var(--ink-faint); }
.dryrun { display: flex; gap: 6px; align-items: center; cursor: pointer; }

.btn-primary {
  font: inherit;
  font-weight: 600;
  background: var(--primary);
  color: var(--primary-ink);
  border: none;
  padding: 10px 24px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.btn-primary:disabled {
  background: #c5d2e8;
  color: #fff;
  cursor: not-allowed;
}
.btn-ghost {
  font: inherit;
  background: rgba(255,255,255,0.08);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.18);
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
}
.btn-ghost:hover { background: rgba(255,255,255,0.16); }
#closeModal {
  background: var(--ink);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 5px;
}

dialog#resultModal {
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 720px;
  width: 92%;
  padding: 0;
  box-shadow: 0 10px 40px rgba(0,0,0,0.18);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; }
#resultBody { padding: 16px 18px 22px; max-height: 70vh; overflow: auto; }
.result-item {
  padding: 8px 10px;
  margin-bottom: 6px;
  border-radius: 5px;
  font-size: 13px;
  border: 1px solid var(--border);
}
.result-item.ok { background: var(--ahead-bg); border-color: #b7e0b7; }
.result-item.fail { background: var(--critical-bg); border-color: #f0bcbc; }
.result-item.dry { background: #f1f3fb; border-color: #d6dceb; }
.result-item .id { font-weight: 600; }
.result-item .meta { color: var(--ink-mute); font-size: 12px; margin-top: 2px; }

@media (max-width: 720px) {
  .row-head { grid-template-columns: 24px 70px 1fr 80px; }
  .row-head .stat:not(.gap) { display: none; }
  .row-head .toggle { display: none; }
  .topbar { flex-direction: column; align-items: stretch; }
  .presets { justify-content: flex-start; }
}
