:root {
  --ink: #14181f;
  --paper: #f7f6f3;
  --card: #ffffff;
  --line: #e2e0da;
  --navy: #1f3a5f;
  --navy-dim: #d9e1ec;
  --gold: #b98a2e;
  --gold-dim: #f3e6c8;
  --danger: #a8402f;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--navy);
  color: #fff;
  border-bottom: 3px solid var(--gold);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark {
  font-weight: 800;
  letter-spacing: 0.06em;
  background: var(--gold);
  color: var(--ink);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 13px;
}
.brand-name { font-weight: 600; font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.save-status { font-size: 12px; opacity: 0.8; min-width: 90px; text-align: right; }
.save-status.saving { color: var(--gold-dim); }
.save-status.error { color: #ffb4a8; }

.chart-root {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 80px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.loading { padding: 40px; text-align: center; color: #777; }

.team {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.team-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  cursor: pointer;
  background: var(--navy-dim);
}
.team-header h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--navy);
}
.team-header-right { display: flex; align-items: center; gap: 10px; }
.team-lead-chip {
  font-size: 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  padding: 3px 9px;
  border-radius: 999px;
}
.chevron { transition: transform 0.15s ease; font-size: 13px; color: var(--navy); }
.team.collapsed .chevron { transform: rotate(-90deg); }
.team-body { padding: 18px; display: flex; flex-direction: column; gap: 18px; }
.team.collapsed .team-body { display: none; }

.group { border-left: 3px solid var(--gold-dim); padding-left: 14px; }
.group-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
  margin-bottom: 8px;
}

.tree { display: flex; flex-direction: column; gap: 6px; }
.node {
  position: relative;
  margin-left: 0;
}
.node-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  width: fit-content;
  min-width: 200px;
}
.node-row.section-row {
  background: transparent;
  border: none;
  padding: 4px 0 2px;
  min-width: 0;
}
.section-label {
  font-size: 11px;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.node-info { display: flex; flex-direction: column; line-height: 1.25; }
.node-name { font-size: 13.5px; font-weight: 600; }
.node-role { font-size: 11.5px; color: #6b6b6b; }
.node-actions { display: flex; gap: 4px; margin-left: 4px; }
.icon-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: 12px; color: #999; padding: 2px 5px; border-radius: 5px;
}
.icon-btn:hover { background: var(--paper); color: var(--ink); }

.children {
  margin-left: 22px;
  padding-left: 14px;
  border-left: 2px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.add-child-btn {
  font-size: 11px;
  color: var(--navy);
  background: none;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  width: fit-content;
}
.add-child-btn:hover { border-color: var(--navy); }

.add-group-row, .add-people-row { margin-top: 4px; }

.btn {
  border: none;
  border-radius: 7px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--gold); color: #1a1a1a; }
.btn-ghost { background: rgba(255,255,255,0.12); color: #fff; }
.team-body .btn-ghost, .chart-root .btn-ghost.local { background: var(--paper); color: var(--navy); border: 1px solid var(--line); }
.btn-danger { background: var(--danger); color: #fff; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,24,31,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: #fff; border-radius: 12px; padding: 22px; width: 340px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.modal h2 { margin: 0; font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: #555; }
.field input {
  font-size: 14px; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--line);
}
.modal-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.modal-actions-right { display: flex; gap: 8px; }

@media (max-width: 640px) {
  .node-row { min-width: 0; }
  .children { margin-left: 12px; padding-left: 10px; }
}
