:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 8px 24px rgba(0, 0, 0, .05);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: linear-gradient(120deg, #1e3a8a, #2563eb 60%, #0ea5e9);
  color: #fff;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-emoji { font-size: 34px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: .3px; }
.brand p { margin: 0; font-size: 13px; opacity: .85; }

.topbar-actions { display: flex; align-items: center; gap: 16px; }
.progress { display: flex; align-items: center; gap: 10px; }
.progress-bar {
  width: 150px; height: 9px; border-radius: 99px;
  background: rgba(255, 255, 255, .25); overflow: hidden;
}
#progress-bar-fill {
  height: 100%; width: 0%; border-radius: 99px;
  background: #4ade80; transition: width .4s ease;
}
#progress-text { font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- Celebration banner ---------- */
.celebration {
  display: none;
  text-align: center;
  padding: 12px;
  background: var(--green-soft);
  color: var(--green);
  font-weight: 600;
  border-bottom: 1px solid #bbf7d0;
}
.celebration.show { display: block; animation: pop .5s ease; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  padding: 20px;
  align-items: start;
  max-width: 1400px;
  margin: 0 auto;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky; top: 20px;
  background: transparent;
}
.sidebar-title {
  font-size: 14px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); margin: 4px 4px 12px;
}
.sidebar-foot { font-size: 12px; color: var(--muted); margin: 14px 4px 0; }

.mission {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: border-color .2s;
}
.mission.active { border-color: var(--brand); }
.mission.done { border-color: #bbf7d0; }

.mission-head {
  width: 100%;
  display: flex; align-items: center; gap: 9px;
  padding: 13px 14px;
  background: none; border: none; cursor: pointer;
  text-align: left; font: inherit; color: var(--ink);
}
.mission-head:hover { background: #f8fafc; }
.mission-status {
  width: 22px; height: 22px; flex: 0 0 22px;
  display: grid; place-items: center;
  border-radius: 50%; font-size: 13px; font-weight: 700;
  background: #f1f5f9; color: var(--muted);
}
.mission.done .mission-status { background: var(--green); color: #fff; }
.mission-icon { font-size: 17px; }
.mission-title { flex: 1; font-size: 14px; font-weight: 600; }
.mission-chevron { color: var(--muted); font-size: 12px; }

.mission-body { padding: 0 14px 14px 14px; }
.mission-brief { font-size: 13.5px; color: #374151; margin: 4px 0 10px; }
.mission-hint summary {
  cursor: pointer; font-size: 13px; color: var(--brand); font-weight: 600;
  list-style: none;
}
.mission-hint summary::-webkit-details-marker { display: none; }
.mission-hint p {
  font-size: 13px; color: var(--muted);
  background: #f8fafc; border-radius: 8px; padding: 9px 11px; margin: 8px 0 0;
}

/* ---------- Cards / content ---------- */
.content { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.protocol h2 { margin: 0 0 4px; font-size: 18px; }
.study-code {
  background: var(--brand); color: #fff; font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: 6px; margin-right: 6px; vertical-align: middle;
}
.phase { margin: 0 0 14px; color: var(--muted); font-size: 13px; }

.criteria { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.criteria-col { border-radius: 10px; padding: 12px 14px; }
.criteria-col.inclusion { background: var(--green-soft); }
.criteria-col.exclusion { background: var(--red-soft); }
.criteria-col h3 { margin: 0 0 8px; font-size: 14px; }
.criteria-col.inclusion h3 { color: var(--green); }
.criteria-col.exclusion h3 { color: var(--red); }
.criteria-col ul { margin: 0; padding-left: 18px; font-size: 13px; }
.criteria-col li { margin: 3px 0; }

/* ---------- Toolbar ---------- */
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
#table-mission-label { font-size: 15px; }
.toolbar-btns { display: flex; gap: 8px; }

.btn-primary, .btn-ghost {
  font: inherit; font-size: 14px; font-weight: 600;
  border-radius: 9px; padding: 9px 16px; cursor: pointer;
  border: 1px solid transparent; transition: all .15s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { background: var(--green); cursor: default; opacity: .9; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: #f3f4f6; }
.topbar .btn-ghost { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.3); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.22); }

/* ---------- Feedback ---------- */
.feedback { font-size: 14px; border-radius: 10px; }
.feedback.ok, .feedback.err, .feedback.warn { padding: 11px 14px; margin-bottom: 12px; }
.feedback.ok { background: var(--green-soft); color: var(--green); }
.feedback.err { background: var(--red-soft); color: var(--red); }
.feedback.warn { background: var(--amber-soft); color: var(--amber); }

/* ---------- Table ---------- */
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.crd-table { width: 100%; border-collapse: collapse; font-size: 13.5px; white-space: nowrap; }
.crd-table th, .crd-table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.crd-table thead th {
  background: #f8fafc; color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: .4px; position: sticky; top: 0;
}
.crd-table tbody tr:hover { background: #f8fbff; }
.crd-table tbody tr.row-selected { background: #eff6ff; }
.crd-table td[data-col="id"] { font-weight: 700; color: var(--brand); }
.col-check { text-align: center; width: 56px; }
.col-check input { width: 17px; height: 17px; cursor: pointer; accent-color: var(--brand); }

.table-legend { font-size: 12px; color: var(--muted); margin: 10px 2px 0; }

/* ---------- Footer ---------- */
.footer { text-align: center; padding: 18px; color: var(--muted); font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .criteria { grid-template-columns: 1fr; }
}
