:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #5e6c7b;
  --primary: #0a7f6f;
  --accent: #f4a261;
  --line: #dde4ec;
  --good: #227c4d;
  --hot: #e74c3c;
  --warm: #f39c12;
  --cool: #3498db;
  --cold: #95a5a6;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top right, #e3fff5, #f5f7fb 35%);
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px 32px; }
h1 { margin: 0 0 6px; font-size: 28px; }
.sub { color: var(--muted); margin-bottom: 18px; }
.grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 18px rgba(18, 38, 63, 0.06);
}
.panel h2 { margin: 0 0 10px; font-size: 18px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  margin-bottom: 10px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 60px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
button {
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 600;
}
.primary { background: var(--primary); color: #fff; }
.secondary { background: #edf2f7; color: var(--ink); }
.warn { background: var(--accent); color: #16232d; }
.danger { background: #e74c3c; color: #fff; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; }
th { color: var(--muted); font-size: 12px; }
.status { color: var(--good); font-weight: 600; }
.tag { font-size: 11px; background: #e8f1ff; padding: 2px 7px; border-radius: 999px; }
.full { margin-top: 16px; }
.msg { font-size: 13px; color: var(--muted); margin-top: 8px; min-height: 18px; }

/* Navigation */
nav.topnav {
  background: var(--panel);
  border-bottom: 2px solid var(--line);
  padding: 0;
  margin-bottom: 20px;
}
nav.topnav .nav-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 52px;
}
nav.topnav .brand {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
  margin-right: auto;
  letter-spacing: -0.3px;
}
nav.topnav a {
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  padding: 6px 14px;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
nav.topnav a:hover { background: #edf2f7; color: var(--ink); }
nav.topnav a.active {
  color: var(--primary);
  background: #e3fff5;
}

/* Detail page */
dl.detail-fields { margin: 0; }
dl.detail-fields dt {
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  margin-top: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
dl.detail-fields dd {
  margin: 2px 0 0 0;
  font-size: 15px;
}
dl.detail-fields dd a { color: var(--primary); }

/* Clickable table rows */
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f8fafc; }

/* Back link */
a.back-link {
  display: inline-block;
  margin-top: 16px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}
a.back-link:hover { text-decoration: underline; }

/* Need badges */
.need-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  margin: 3px 4px 3px 0;
}
.need-badge.high { background: #fce4e4; color: #c0392b; }
.need-badge.medium { background: #fef3cd; color: #856404; }
.need-badge.low { background: #e8f1ff; color: #2c5282; }

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(18,38,63,0.04);
}
.kpi-card .kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}
.kpi-card .kpi-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* Pipeline board */
.pipeline-board {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 10px;
}
.pipeline-column {
  min-width: 200px;
  flex: 1;
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px;
}
.pipeline-column h3 {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
  letter-spacing: 0.5px;
}
.pipeline-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.pipeline-card:hover { box-shadow: 0 4px 12px rgba(18,38,63,0.1); }
.pipeline-card .card-name { font-weight: 600; font-size: 14px; }
.pipeline-card .card-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Stage selector */
.stage-btns {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin: 8px 0;
}
.stage-btns button {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #edf2f7;
  color: var(--ink);
}
.stage-btns button.active-stage {
  background: var(--primary);
  color: #fff;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  z-index: 9999;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Custom multi-select dropdown */
.ms-wrap {
  position: relative;
  margin-bottom: 10px;
}
.ms-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  color: var(--ink);
  min-height: 38px;
  user-select: none;
}
.ms-trigger:hover { border-color: var(--primary); }
.ms-wrap.open .ms-trigger { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(10,127,111,0.15); }
.ms-trigger .ms-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ms-trigger .ms-arrow { font-size: 10px; color: var(--muted); margin-left: 8px; transition: transform 0.2s; }
.ms-wrap.open .ms-trigger .ms-arrow { transform: rotate(180deg); }
.ms-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 100;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(18, 38, 63, 0.12);
  max-height: 280px;
  overflow-y: auto;
  padding: 4px 0;
}
.ms-wrap.open .ms-dropdown { display: block; }
.ms-actions {
  display: flex;
  gap: 6px;
  padding: 6px 10px 8px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.ms-actions button {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 6px;
  background: #edf2f7;
  color: var(--ink);
}
.ms-group-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  padding: 8px 10px 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ms-option {
  display: flex !important;
  align-items: center;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  margin-bottom: 0 !important;
  transition: background 0.1s;
}
.ms-option:hover { background: #f0f7ff; }
.ms-option input[type="checkbox"] {
  width: auto;
  margin: 0 8px 0 0;
  padding: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Progress bar */
.progress-wrap {
  background: var(--line);
  border-radius: 8px;
  height: 6px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 8px;
  transition: width 0.3s;
}

@media (max-width: 920px) {
  .grid { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .pipeline-board { flex-direction: column; }
  .pipeline-column { min-width: unset; }
}
