: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: 14px; flex-wrap: wrap; align-items: center; }
.filter-group { display: flex; gap: 4px; align-items: center; }
.group-label { color: rgba(255,255,255,0.55); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; margin-right: 4px; }
.filter-btn.active { background: rgba(255,255,255,0.22); border-color: rgba(255,255,255,0.4); }

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 { cursor: pointer; user-select: none; }
.property-head:hover { background: #eef0f5; }
.property-head h2 { margin: 0; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.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); }
.property-head .pcaret { color: var(--ink-mute); font-size: 11px; transition: transform 120ms ease; display: inline-block; width: 12px; }
.property.collapsed .property-head { border-bottom: none; }
.property.collapsed .row { display: none; }

.brand-actions { display: flex; gap: 6px; align-items: center; }
.brand-actions .btn-ghost { background: rgba(255,255,255,0.10); color: #fff; border-color: rgba(255,255,255,0.25); }
.brand-actions a.btn-ghost { text-decoration: none; display: inline-flex; align-items: center; }
.brand-actions .btn-ghost:hover { background: rgba(255,255,255,0.20); }
.brand-actions .btn-ghost:disabled { opacity: 0.55; cursor: progress; }

.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); }
.sev.SOFT { background: #fffaeb; color: #8a6500; }
.sev.ON_PACE { background: #f0f0f4; color: #6a6a7e; }
.sev.RELEASE { background: #e6f4ea; color: #1e6e3a; }
.release-info { padding: 12px 16px; background: #f4faf6; border-left: 3px solid #1e6e3a; border-radius: 4px; }
.release-info .release-line { font-size: 13px; color: #1e3a2a; }
.release-info .note { color: var(--ink-mute); font-size: 11px; margin-top: 4px; }

.history-panel { margin-top: 24px; padding: 12px 16px; background: #fafafc; border: 1px solid var(--border); border-radius: 6px; }
.history-panel summary { font-weight: 600; cursor: pointer; padding: 4px 0; color: var(--ink); font-size: 13px; }
.history-panel summary:hover { color: var(--primary); }
.history-row { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 12px; }
.history-row:last-child { border-bottom: none; }
.history-row .h-head { display: flex; gap: 12px; align-items: center; margin-bottom: 4px; }
.history-row .h-prop { font-weight: 600; }
.history-row .h-outcome { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.history-row .h-age { color: var(--ink-mute); margin-left: auto; font-size: 11px; }
.history-row .h-body { color: var(--ink-mute); font-variant-numeric: tabular-nums; }
.history-row .h-body .sep { color: var(--ink-faint); margin: 0 4px; }
.h-outcome.outcome-recovered { background: #e6f4ea; color: #1e6e3a; }
.h-outcome.outcome-improved { background: #e8f0ff; color: #2a4a8a; }
.h-outcome.outcome-flat { background: #f0f0f4; color: #6a6a7e; }
.h-outcome.outcome-worse { background: var(--critical-bg); color: var(--critical); }
.h-outcome.outcome-expired { background: #faf4e6; color: #8a6500; }
.h-outcome.outcome-unknown { background: #f0f0f4; color: #6a6a7e; }
.history-row.outcome-recovered { border-left: 3px solid #1e6e3a; padding-left: 9px; }
.history-row.outcome-improved { border-left: 3px solid #2a4a8a; padding-left: 9px; }
.history-row.outcome-worse { border-left: 3px solid var(--critical); padding-left: 9px; }

body.login-mode .topbar, body.login-mode #main, body.login-mode .bottombar { display: none; }
#loginOverlay { position: fixed; inset: 0; background: #f5f5f8; display: flex; align-items: center; justify-content: center; z-index: 9999; }
#loginForm { background: #fff; padding: 32px 36px; border-radius: 8px; box-shadow: 0 4px 24px rgba(0,0,0,0.08); width: 320px; display: flex; flex-direction: column; gap: 14px; }
#loginForm h2 { margin: 0 0 8px; font-size: 18px; color: var(--ink); }
#loginForm label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-mute); font-weight: 500; }
#loginForm input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px; }
#loginForm input:focus { outline: none; border-color: var(--primary); }
#loginForm button { background: var(--primary); color: #fff; border: 0; padding: 10px; border-radius: 4px; font-size: 14px; font-weight: 600; cursor: pointer; margin-top: 4px; }
#loginForm button:hover { filter: brightness(0.95); }
.login-error { color: var(--critical); font-size: 12px; }

.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; }
}
